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;
|
gameCanvasWidth = options->gameWidth;
|
||||||
gameCanvasHeight = options->gameHeight;
|
gameCanvasHeight = options->gameHeight;
|
||||||
borderWidth = options->borderWidth * 2;
|
|
||||||
borderHeight = options->borderHeight * 2;
|
|
||||||
notificationLogicalWidth = gameCanvasWidth;
|
notificationLogicalWidth = gameCanvasWidth;
|
||||||
notificationLogicalHeight = gameCanvasHeight;
|
notificationLogicalHeight = gameCanvasHeight;
|
||||||
|
|
||||||
@@ -33,10 +31,21 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
{
|
{
|
||||||
if (options->console)
|
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
|
// Establece el modo de video
|
||||||
setVideoMode(options->videoMode);
|
setVideoMode(options->videoMode);
|
||||||
|
|
||||||
@@ -49,6 +58,7 @@ Screen::~Screen()
|
|||||||
{
|
{
|
||||||
delete notify;
|
delete notify;
|
||||||
SDL_DestroyTexture(gameCanvas);
|
SDL_DestroyTexture(gameCanvas);
|
||||||
|
SDL_DestroyTexture(borderCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
@@ -64,6 +74,12 @@ void Screen::start()
|
|||||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
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
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::blit()
|
void Screen::blit()
|
||||||
{
|
{
|
||||||
@@ -71,10 +87,16 @@ void Screen::blit()
|
|||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Borra el contenido previo
|
// Borra el contenido previo
|
||||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
// SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
// 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);
|
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||||
|
|
||||||
// Dibuja las notificaciones
|
// Dibuja las notificaciones
|
||||||
@@ -90,20 +112,21 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
// Aplica el modo de video
|
// Aplica el modo de video
|
||||||
SDL_SetWindowFullscreen(window, videoMode);
|
SDL_SetWindowFullscreen(window, videoMode);
|
||||||
|
|
||||||
// Si está activo el modo ventana quita el borde
|
// Modo ventana
|
||||||
if (videoMode == 0)
|
if (videoMode == 0)
|
||||||
{
|
{
|
||||||
// Muestra el puntero
|
// Muestra el puntero
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
// Esconde la ventana
|
// Esconde la ventana
|
||||||
//SDL_HideWindow(window);
|
// SDL_HideWindow(window);
|
||||||
|
|
||||||
|
// Modifica el tamaño de la ventana en función del borde
|
||||||
if (options->borderEnabled)
|
if (options->borderEnabled)
|
||||||
{
|
{
|
||||||
windowWidth = gameCanvasWidth + borderWidth;
|
windowWidth = gameCanvasWidth + options->borderWidth * 2;
|
||||||
windowHeight = gameCanvasHeight + borderHeight;
|
windowHeight = gameCanvasHeight + options->borderHeight * 2;
|
||||||
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
dest = {options->borderWidth, options->borderHeight, gameCanvasWidth, gameCanvasHeight};
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -118,7 +141,7 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
|
|
||||||
// Muestra la ventana
|
// Muestra la ventana
|
||||||
//SDL_ShowWindow(window);
|
// SDL_ShowWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está activo el modo de pantalla completa añade el borde
|
// 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)
|
void Screen::setBorderColor(color_t color)
|
||||||
{
|
{
|
||||||
borderColor = 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
|
// Cambia el tipo de mezcla
|
||||||
|
|||||||
@@ -17,20 +17,19 @@ class Screen
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// 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
|
||||||
Asset *asset; // Objeto con el listado de recursos
|
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
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
SDL_Texture *borderCanvas; // Textura donde se dibuja el borde del juego
|
||||||
Notify *notify; // Dibuja notificaciones por pantalla
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
Notify *notify; // Dibuja notificaciones por pantalla
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int windowWidth; // Ancho de la pantalla o ventana
|
int windowWidth; // Ancho de la pantalla o ventana
|
||||||
int windowHeight; // Alto de la pantalla o ventana
|
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 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 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
|
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
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
bool notifyActive; // Indica si hay notificaciones activas
|
bool notifyActive; // Indica si hay notificaciones activas
|
||||||
@@ -83,6 +82,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();
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura del borde
|
||||||
|
void startDrawOnBorder();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void blit();
|
void blit();
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
|
|||||||
cheevosSprite->setSpriteClip(cheevosTextureView);
|
cheevosSprite->setSpriteClip(cheevosTextureView);
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, "bright_blue"));
|
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|||||||
Reference in New Issue
Block a user