Ja torna a funcionar el borde

This commit is contained in:
2025-03-06 13:14:57 +01:00
parent 72efa0dc46
commit 12e27a1062
5 changed files with 38 additions and 63 deletions

View File

@@ -79,6 +79,7 @@ Director::Director(int argc, const char *argv[])
Screen::get()->setBorderColor(border_color); Screen::get()->setBorderColor(border_color);
Resource::init(); Resource::init();
Notifier::init("", "8bithud"); Notifier::init("", "8bithud");
Screen::get()->setNotificationsEnabled(true);
Input::init(Asset::get()->get("gamecontrollerdb.txt")); Input::init(Asset::get()->get("gamecontrollerdb.txt"));
initInput(); initInput();
Debug::init(); Debug::init();

View File

@@ -145,16 +145,17 @@ void LoadingScreen::renderLoad()
// Dibuja el efecto de carga en el borde // Dibuja el efecto de carga en el borde
void LoadingScreen::renderBorder() void LoadingScreen::renderBorder()
{ {
// Pinta el borde de colro azul // Obtiene la Surface del borde
Uint8 color = stringToColor("blue"); auto border = Screen::get()->getBorderSurface();
Screen::get()->clearSurface(color);
// Pinta el borde de color azul
border->clear(stringToColor("blue"));
// Añade lineas amarillas // 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 WIDTH = options.game.width + (options.video.border.width * 2);
const int HEIGHT = options.game.height + (options.video.border.height * 2); const int HEIGHT = options.game.height + (options.video.border.height * 2);
bool draw_enabled = rand() % 2 == 0 ? true : false; bool draw_enabled = rand() % 2 == 0 ? true : false;
auto surface = Screen::get()->getRendererSurface();
int row = 0; int row = 0;
while (row < HEIGHT) while (row < HEIGHT)
@@ -164,7 +165,7 @@ void LoadingScreen::renderBorder()
{ {
for (int i = row; i < row + ROW_HEIGHT; ++i) 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; row += ROW_HEIGHT;
@@ -192,9 +193,6 @@ void LoadingScreen::render()
{ {
if (options.video.border.enabled) 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 // Dibuja el efecto de carga en el borde
renderBorder(); renderBorder();
} }

View File

@@ -13,6 +13,7 @@
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "text.h" // for Text, loadTextFile #include "text.h" // for Text, loadTextFile
#include "utils.h" // for getFileName, printWithDots, Color #include "utils.h" // for getFileName, printWithDots, Color
#include "room.h"
struct JA_Music_t; // lines 12-12 struct JA_Music_t; // lines 12-12
struct JA_Sound_t; // lines 13-13 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}; SDL_Rect rect_full = {X_PADDING, bar_position, full_bar_width, X_PADDING};
surface->fillRect(&rect_full, stringToColor("white")); surface->fillRect(&rect_full, stringToColor("white"));
Screen::get()->renderWithoutNotifier(); Screen::get()->render();
} }
// Comprueba los eventos de la pantalla de carga // Comprueba los eventos de la pantalla de carga

View File

@@ -124,40 +124,22 @@ void Screen::start()
setRendererSurface(nullptr); setRendererSurface(nullptr);
} }
// Prepara para empezar a dibujar en la textura del borde
void Screen::startDrawOnBorder()
{
}
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
void Screen::render() void Screen::render()
{ {
// Renderiza sobre game_surface_ los overlays // Renderiza sobre game_surface_ los overlays
renderNotifications(); renderNotifications();
// Copia la surface a game_texture_
game_surface_->copyToTexture(renderer_, game_texture_);
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas // Si está el borde activo, vuelca gameCanvas sobre borderCanvas
if (options.video.border.enabled) 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_);
} }
else
// 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)
{ {
gameCanvasToBorderCanvas(); game_surface_->copyToTexture(renderer_, game_texture_);
} }
// Muestra el contenido por pantalla // Muestra el contenido por pantalla
@@ -232,11 +214,7 @@ bool Screen::incWindowZoom()
void Screen::setBorderColor(Uint8 color) void Screen::setBorderColor(Uint8 color)
{ {
border_color_ = color; border_color_ = color;
auto temp = SDL_GetRenderTarget(renderer_); border_surface_->clear(border_color_);
SDL_SetRenderTarget(renderer_, border_texture_);
SDL_SetRenderDrawColor(renderer_, color, color, color, 0xFF);
SDL_RenderClear(renderer_);
SDL_SetRenderTarget(renderer_, temp);
} }
// Cambia el tipo de mezcla // Cambia el tipo de mezcla
@@ -259,15 +237,12 @@ void Screen::toggleBorder()
} }
// Dibuja las notificaciones // Dibuja las notificaciones
void Screen::renderNotifications() { Notifier::get()->render(); } void Screen::renderNotifications()
// Copia el gameCanvas en el borderCanvas
void Screen::gameCanvasToBorderCanvas()
{ {
auto temp = SDL_GetRenderTarget(renderer_); if (notifications_enabled_)
SDL_SetRenderTarget(renderer_, border_texture_); {
SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_rect_); Notifier::get()->render();
SDL_SetRenderTarget(renderer_, temp); }
} }
// Muestra el contenido de Screen por pantalla // Muestra el contenido de Screen por pantalla

View File

@@ -26,28 +26,26 @@ private:
static Screen *screen_; static Screen *screen_;
// Objetos y punteros // Objetos y punteros
SDL_Window *window_; // Ventana de la aplicación SDL_Window *window_; // Ventana de la aplicación
SDL_Renderer *renderer_; // El renderizador de la ventana SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *game_texture_; // Textura donde se dibuja el juego SDL_Texture *game_texture_; // Textura donde se dibuja el juego
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
std::shared_ptr<Surface> game_surface_; // Surface principal para manejar game_surface_data_ std::shared_ptr<Surface> game_surface_; // Surface principal para manejar game_surface_data_
std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla
std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua
// Variables // Variables
int window_width_; // Ancho de la pantalla o ventana int window_width_; // Ancho de la pantalla o ventana
int window_height_; // Alto 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 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 Uint8 border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
std::vector<std::string> palettes_; // Listado de los ficheros de paletta disponibles std::vector<std::string> palettes_; // Listado de los ficheros de paletta disponibles
Uint8 current_palette_ = 0; // Indice para el vector de paletas Uint8 current_palette_ = 0; // Indice para el vector de paletas
bool notifications_enabled_ = false; // indica si se muestran las notificaciones
// Dibuja las notificaciones // Dibuja las notificaciones
void renderNotifications(); void renderNotifications();
// Copia el gameCanvas en el borderCanvas
void gameCanvasToBorderCanvas();
// Muestra el contenido de Screen por pantalla // Muestra el contenido de Screen por pantalla
void renderPresent(); void renderPresent();
@@ -88,11 +86,9 @@ public:
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
void start(); void start();
void startDrawOnBorder();
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
void render(); void render();
void renderWithoutNotifier();
// Actualiza la lógica de la clase // Actualiza la lógica de la clase
void update(); void update();
@@ -143,7 +139,11 @@ public:
// Getters // Getters
SDL_Renderer *getRenderer() { return renderer_; } SDL_Renderer *getRenderer() { return renderer_; }
std::shared_ptr<Surface> getRendererSurface() { return (*renderer_surface_); } std::shared_ptr<Surface> getRendererSurface() { return (*renderer_surface_); }
std::shared_ptr<Surface> getBorderSurface() { return border_surface_; }
// Cambia la paleta // Cambia la paleta
void nextPalette(); void nextPalette();
// Establece la visibilidad de las notificaciones
void setNotificationsEnabled(bool value) { notifications_enabled_ = value; }
}; };