diff --git a/source/director.cpp b/source/director.cpp index 67fa2c8..00dd599 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -79,6 +79,7 @@ Director::Director(int argc, const char *argv[]) Screen::get()->setBorderColor(border_color); Resource::init(); Notifier::init("", "8bithud"); + Screen::get()->setNotificationsEnabled(true); Input::init(Asset::get()->get("gamecontrollerdb.txt")); initInput(); Debug::init(); diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 5195335..714e9ba 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -145,16 +145,17 @@ void LoadingScreen::renderLoad() // Dibuja el efecto de carga en el borde void LoadingScreen::renderBorder() { - // Pinta el borde de colro azul - Uint8 color = stringToColor("blue"); - Screen::get()->clearSurface(color); + // Obtiene la Surface del borde + auto border = Screen::get()->getBorderSurface(); + + // Pinta el borde de color azul + border->clear(stringToColor("blue")); // Añade lineas amarillas - color = stringToColor("yellow"); + const Uint8 COLOR = stringToColor("yellow"); const int WIDTH = options.game.width + (options.video.border.width * 2); const int HEIGHT = options.game.height + (options.video.border.height * 2); bool draw_enabled = rand() % 2 == 0 ? true : false; - auto surface = Screen::get()->getRendererSurface(); int row = 0; while (row < HEIGHT) @@ -164,7 +165,7 @@ void LoadingScreen::renderBorder() { for (int i = row; i < row + ROW_HEIGHT; ++i) { - surface->drawLine(0, i, WIDTH, i, color); + border->drawLine(0, i, WIDTH, i, COLOR); } } row += ROW_HEIGHT; @@ -192,9 +193,6 @@ void LoadingScreen::render() { if (options.video.border.enabled) { - // Prepara para empezar a dibujar en la textura del borde - Screen::get()->startDrawOnBorder(); - // Dibuja el efecto de carga en el borde renderBorder(); } diff --git a/source/resource.cpp b/source/resource.cpp index 628e263..7d192aa 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -13,6 +13,7 @@ #include "screen.h" // for Screen #include "text.h" // for Text, loadTextFile #include "utils.h" // for getFileName, printWithDots, Color +#include "room.h" struct JA_Music_t; // lines 12-12 struct JA_Sound_t; // lines 13-13 @@ -436,7 +437,7 @@ void Resource::renderProgress() SDL_Rect rect_full = {X_PADDING, bar_position, full_bar_width, X_PADDING}; surface->fillRect(&rect_full, stringToColor("white")); - Screen::get()->renderWithoutNotifier(); + Screen::get()->render(); } // Comprueba los eventos de la pantalla de carga diff --git a/source/screen.cpp b/source/screen.cpp index c06981a..723d8f9 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -124,40 +124,22 @@ void Screen::start() setRendererSurface(nullptr); } -// Prepara para empezar a dibujar en la textura del borde -void Screen::startDrawOnBorder() -{ -} - // Vuelca el contenido del renderizador en pantalla void Screen::render() { // Renderiza sobre game_surface_ los overlays renderNotifications(); - // Copia la surface a game_texture_ - game_surface_->copyToTexture(renderer_, game_texture_); - // Si está el borde activo, vuelca gameCanvas sobre borderCanvas if (options.video.border.enabled) { - gameCanvasToBorderCanvas(); + setRendererSurface(border_surface_); + game_surface_->render(options.video.border.width, options.video.border.height); + border_surface_->copyToTexture(renderer_, border_texture_); } - - // Muestra el contenido por pantalla - renderPresent(); -} - -// Vuelca el contenido del renderizador en pantalla -void Screen::renderWithoutNotifier() -{ - // Copia la surface a game_texture_ - game_surface_->copyToTexture(renderer_, game_texture_); - - // Si está el borde activo, vuelca gameCanvas sobre borderCanvas - if (options.video.border.enabled) + else { - gameCanvasToBorderCanvas(); + game_surface_->copyToTexture(renderer_, game_texture_); } // Muestra el contenido por pantalla @@ -232,11 +214,7 @@ bool Screen::incWindowZoom() void Screen::setBorderColor(Uint8 color) { border_color_ = color; - auto temp = SDL_GetRenderTarget(renderer_); - SDL_SetRenderTarget(renderer_, border_texture_); - SDL_SetRenderDrawColor(renderer_, color, color, color, 0xFF); - SDL_RenderClear(renderer_); - SDL_SetRenderTarget(renderer_, temp); + border_surface_->clear(border_color_); } // Cambia el tipo de mezcla @@ -259,15 +237,12 @@ void Screen::toggleBorder() } // Dibuja las notificaciones -void Screen::renderNotifications() { Notifier::get()->render(); } - -// Copia el gameCanvas en el borderCanvas -void Screen::gameCanvasToBorderCanvas() +void Screen::renderNotifications() { - auto temp = SDL_GetRenderTarget(renderer_); - SDL_SetRenderTarget(renderer_, border_texture_); - SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_rect_); - SDL_SetRenderTarget(renderer_, temp); + if (notifications_enabled_) + { + Notifier::get()->render(); + } } // Muestra el contenido de Screen por pantalla diff --git a/source/screen.h b/source/screen.h index 6362b51..7ff0427 100644 --- a/source/screen.h +++ b/source/screen.h @@ -26,28 +26,26 @@ private: static Screen *screen_; // Objetos y punteros - SDL_Window *window_; // Ventana de la aplicación - SDL_Renderer *renderer_; // El renderizador de la ventana - SDL_Texture *game_texture_; // Textura donde se dibuja el juego - SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego - std::shared_ptr game_surface_; // Surface principal para manejar game_surface_data_ - std::shared_ptr border_surface_; // Surface para pintar el el borde de la pantalla + SDL_Window *window_; // Ventana de la aplicación + SDL_Renderer *renderer_; // El renderizador de la ventana + SDL_Texture *game_texture_; // Textura donde se dibuja el juego + SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego + std::shared_ptr game_surface_; // Surface principal para manejar game_surface_data_ + std::shared_ptr border_surface_; // Surface para pintar el el borde de la pantalla std::shared_ptr> renderer_surface_; // Puntero a la Surface que actua // Variables - int window_width_; // Ancho de la pantalla o ventana - int window_height_; // Alto de la pantalla o ventana - SDL_Rect game_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana - Uint8 border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla - std::vector palettes_; // Listado de los ficheros de paletta disponibles - Uint8 current_palette_ = 0; // Indice para el vector de paletas + int window_width_; // Ancho de la pantalla o ventana + int window_height_; // Alto de la pantalla o ventana + SDL_Rect game_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana + Uint8 border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla + std::vector palettes_; // Listado de los ficheros de paletta disponibles + Uint8 current_palette_ = 0; // Indice para el vector de paletas + bool notifications_enabled_ = false; // indica si se muestran las notificaciones // Dibuja las notificaciones void renderNotifications(); - // Copia el gameCanvas en el borderCanvas - void gameCanvasToBorderCanvas(); - // Muestra el contenido de Screen por pantalla void renderPresent(); @@ -88,11 +86,9 @@ public: // Prepara para empezar a dibujar en la textura de juego void start(); - void startDrawOnBorder(); // Vuelca el contenido del renderizador en pantalla void render(); - void renderWithoutNotifier(); // Actualiza la lógica de la clase void update(); @@ -143,7 +139,11 @@ public: // Getters SDL_Renderer *getRenderer() { return renderer_; } std::shared_ptr getRendererSurface() { return (*renderer_surface_); } + std::shared_ptr getBorderSurface() { return border_surface_; } // Cambia la paleta void nextPalette(); + + // Establece la visibilidad de las notificaciones + void setNotificationsEnabled(bool value) { notifications_enabled_ = value; } }; \ No newline at end of file