diff --git a/main.cpp b/main.cpp index 8a934e3..7ecffdb 100644 --- a/main.cpp +++ b/main.cpp @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) switch (event->key.keysym.scancode) { case SDL_SCANCODE_N: - screen->showNotification("Ejemplo de", "notificacion", 1); + screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0); break; default: @@ -135,6 +135,9 @@ int main(int argc, char *argv[]) // Incrementa el contador counter++; + // Actualiza el objeto screen + screen->update(); + // Actualiza el sprite if (sprite->getPosX() + sprite->getWidth() > options->gameWidth or sprite->getPosX() < 0) { diff --git a/units/screen.cpp b/units/screen.cpp index 3bae021..0cbfa8d 100644 --- a/units/screen.cpp +++ b/units/screen.cpp @@ -14,8 +14,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) gameCanvasHeight = options->gameHeight; borderWidth = options->borderWidth * 2; borderHeight = options->borderHeight * 2; - notificationLogicalWidth = gameCanvasWidth; - notificationLogicalHeight = gameCanvasHeight; iniFade(); iniSpectrumFade(); @@ -35,10 +33,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) // Establece el modo de video setVideoMode(options->videoMode); - - // Inicializa variables - notifyAdded = false; - notifyActive = false; } // Destructor @@ -96,9 +90,6 @@ void Screen::setVideoMode(int videoMode) // Muestra el puntero SDL_ShowCursor(SDL_ENABLE); - // Esconde la ventana - // SDL_HideWindow(window); - if (options->borderEnabled) { windowWidth = gameCanvasWidth + borderWidth; @@ -116,9 +107,6 @@ void Screen::setVideoMode(int videoMode) // Modifica el tamaño de la ventana SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); - - // Muestra la ventana - // SDL_ShowWindow(window); } // Si está activo el modo de pantalla completa añade el borde @@ -178,9 +166,6 @@ void Screen::setVideoMode(int videoMode) options->videoMode = videoMode; options->screen.windowWidth = windowWidth; options->screen.windowHeight = windowHeight; - - // Establece el tamaño de las notificaciones - setNotificationSize(); } // Camibia entre pantalla completa y ventana @@ -389,64 +374,34 @@ void Screen::renderFX() void Screen::addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile) { notify = new Notify(renderer, iconsFile, bitmapFontFile, offsetFontFile, soundFile, options); - notifyAdded = true; } // Actualiza el notificador void Screen::updateNotifier() { - if (notifyAdded) - { - notify->update(); - notifyActive = notify->active(); - } + notify->update(); } // Muestra una notificación de texto por pantalla; void Screen::showNotification(std::string text1, std::string text2, int icon) { - if (notifyAdded) - { - notify->showText(text1, text2, icon); - } + notify->showText(text1, text2, icon); } // Dibuja las notificaciones void Screen::renderNotifications() { - //if (notifyAdded) + if (!notify->active()) { - if (!notifyActive) - { - return; - } - - //SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight); - notify->render(); - //SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); + return; } + + notify->render(); } -// Establece el tamaño de las notificaciones -void Screen::setNotificationSize() +// Actualiza la lógica del objeto +void Screen::update() { - if (options->videoMode == 0) - { - if (options->windowSize == 3) - { - notificationLogicalWidth = (windowWidth * 3) / 2; - notificationLogicalHeight = (windowHeight * 3) / 2; - } - else - { - notificationLogicalWidth = windowWidth * 2; - notificationLogicalHeight = windowHeight * 2; - } - } - - if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP) - { - notificationLogicalWidth = windowWidth / 3; - notificationLogicalHeight = windowHeight / 3; - } + updateNotifier(); + updateFX(); } \ No newline at end of file diff --git a/units/screen.h b/units/screen.h index f55d70a..bcc32ef 100644 --- a/units/screen.h +++ b/units/screen.h @@ -30,10 +30,6 @@ private: int borderHeight; // Anltura del borde SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla - bool notifyAdded; // Indica si se ha añadido un notificador - bool notifyActive; // Indica si hay notificaciones activas - int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla - int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla // Variables - Efectos bool fade; // Indica si esta activo el efecto de fade @@ -65,9 +61,6 @@ private: // Dibuja las notificaciones void renderNotifications(); - // Establece el tamaño de las notificaciones - void setNotificationSize(); - public: // Constructor Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options); @@ -141,6 +134,9 @@ public: // Muestra una notificación de texto por pantalla; void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1); + + // Actualiza la lógica del objeto + void update(); }; #endif