Ya se puede dibujar en el borde. Útil para poner wallpapers o cualquier otro efectillo
This commit is contained in:
@@ -16,8 +16,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
borderWidth = options->borderWidth * 2;
|
||||
borderHeight = options->borderHeight * 2;
|
||||
notificationLogicalWidth = gameCanvasWidth;
|
||||
notificationLogicalHeight = gameCanvasHeight;
|
||||
|
||||
@@ -33,10 +31,21 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
std::cout << "gameCanvas could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
||||
borderCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth + options->borderWidth * 2, gameCanvasHeight + options->borderHeight * 2);
|
||||
if (borderCanvas == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "borderCanvas could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
setBorderColor(borderColor);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->videoMode);
|
||||
|
||||
@@ -49,6 +58,7 @@ Screen::~Screen()
|
||||
{
|
||||
delete notify;
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
SDL_DestroyTexture(borderCanvas);
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
@@ -64,6 +74,12 @@ void Screen::start()
|
||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura del borde
|
||||
void Screen::startDrawOnBorder()
|
||||
{
|
||||
SDL_SetRenderTarget(renderer, borderCanvas);
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void Screen::blit()
|
||||
{
|
||||
@@ -71,10 +87,16 @@ void Screen::blit()
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Borra el contenido previo
|
||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
// SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||
// SDL_RenderClear(renderer);
|
||||
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
// Copia la textura del borde en la ventana
|
||||
if (options->borderEnabled)
|
||||
{
|
||||
SDL_RenderCopy(renderer, borderCanvas, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Copia la textura de juego en la ventana en la posición adecuada
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||
|
||||
// Dibuja las notificaciones
|
||||
@@ -90,20 +112,21 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Aplica el modo de video
|
||||
SDL_SetWindowFullscreen(window, videoMode);
|
||||
|
||||
// Si está activo el modo ventana quita el borde
|
||||
// Modo ventana
|
||||
if (videoMode == 0)
|
||||
{
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
// Esconde la ventana
|
||||
//SDL_HideWindow(window);
|
||||
// SDL_HideWindow(window);
|
||||
|
||||
// Modifica el tamaño de la ventana en función del borde
|
||||
if (options->borderEnabled)
|
||||
{
|
||||
windowWidth = gameCanvasWidth + borderWidth;
|
||||
windowHeight = gameCanvasHeight + borderHeight;
|
||||
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
||||
windowWidth = gameCanvasWidth + options->borderWidth * 2;
|
||||
windowHeight = gameCanvasHeight + options->borderHeight * 2;
|
||||
dest = {options->borderWidth, options->borderHeight, gameCanvasWidth, gameCanvasHeight};
|
||||
}
|
||||
|
||||
else
|
||||
@@ -118,7 +141,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
// Muestra la ventana
|
||||
//SDL_ShowWindow(window);
|
||||
// SDL_ShowWindow(window);
|
||||
}
|
||||
|
||||
// Si está activo el modo de pantalla completa añade el borde
|
||||
@@ -217,6 +240,10 @@ void Screen::incWindowSize()
|
||||
void Screen::setBorderColor(color_t color)
|
||||
{
|
||||
borderColor = color;
|
||||
SDL_SetRenderTarget(renderer, borderCanvas);
|
||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Cambia el tipo de mezcla
|
||||
|
||||
@@ -20,7 +20,8 @@ private:
|
||||
SDL_Window *window; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con el listado de recursos
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
SDL_Texture *gameCanvas; // Textura donde se dibuja el juego
|
||||
SDL_Texture *borderCanvas; // Textura donde se dibuja el borde del juego
|
||||
options_t *options; // Variable con todas las opciones del programa
|
||||
Notify *notify; // Dibuja notificaciones por pantalla
|
||||
|
||||
@@ -29,8 +30,6 @@ private:
|
||||
int windowHeight; // Alto de la pantalla o ventana
|
||||
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||
int borderWidth; // Anchura del borde
|
||||
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 notifyActive; // Indica si hay notificaciones activas
|
||||
@@ -83,6 +82,9 @@ public:
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
void start();
|
||||
|
||||
// Prepara para empezar a dibujar en la textura del borde
|
||||
void startDrawOnBorder();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void blit();
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
|
||||
cheevosSprite->setSpriteClip(cheevosTextureView);
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor(options->palette, "bright_blue"));
|
||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
||||
Reference in New Issue
Block a user