Demo: añadidas notificaciones
This commit is contained in:
5
main.cpp
5
main.cpp
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
|
|||||||
switch (event->key.keysym.scancode)
|
switch (event->key.keysym.scancode)
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_N:
|
case SDL_SCANCODE_N:
|
||||||
screen->showNotification("Ejemplo de", "notificacion", 1);
|
screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -135,6 +135,9 @@ int main(int argc, char *argv[])
|
|||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Actualiza el sprite
|
// Actualiza el sprite
|
||||||
if (sprite->getPosX() + sprite->getWidth() > options->gameWidth or sprite->getPosX() < 0)
|
if (sprite->getPosX() + sprite->getWidth() > options->gameWidth or sprite->getPosX() < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
|||||||
gameCanvasHeight = options->gameHeight;
|
gameCanvasHeight = options->gameHeight;
|
||||||
borderWidth = options->borderWidth * 2;
|
borderWidth = options->borderWidth * 2;
|
||||||
borderHeight = options->borderHeight * 2;
|
borderHeight = options->borderHeight * 2;
|
||||||
notificationLogicalWidth = gameCanvasWidth;
|
|
||||||
notificationLogicalHeight = gameCanvasHeight;
|
|
||||||
|
|
||||||
iniFade();
|
iniFade();
|
||||||
iniSpectrumFade();
|
iniSpectrumFade();
|
||||||
@@ -35,10 +33,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
|||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options->videoMode);
|
setVideoMode(options->videoMode);
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
notifyAdded = false;
|
|
||||||
notifyActive = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -96,9 +90,6 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
// Muestra el puntero
|
// Muestra el puntero
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
// Esconde la ventana
|
|
||||||
// SDL_HideWindow(window);
|
|
||||||
|
|
||||||
if (options->borderEnabled)
|
if (options->borderEnabled)
|
||||||
{
|
{
|
||||||
windowWidth = gameCanvasWidth + borderWidth;
|
windowWidth = gameCanvasWidth + borderWidth;
|
||||||
@@ -116,9 +107,6 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
// Modifica el tamaño de la ventana
|
// Modifica el tamaño de la ventana
|
||||||
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
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
|
// 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->videoMode = videoMode;
|
||||||
options->screen.windowWidth = windowWidth;
|
options->screen.windowWidth = windowWidth;
|
||||||
options->screen.windowHeight = windowHeight;
|
options->screen.windowHeight = windowHeight;
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
|
||||||
setNotificationSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
@@ -389,64 +374,34 @@ void Screen::renderFX()
|
|||||||
void Screen::addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile)
|
void Screen::addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile)
|
||||||
{
|
{
|
||||||
notify = new Notify(renderer, iconsFile, bitmapFontFile, offsetFontFile, soundFile, options);
|
notify = new Notify(renderer, iconsFile, bitmapFontFile, offsetFontFile, soundFile, options);
|
||||||
notifyAdded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el notificador
|
// Actualiza el notificador
|
||||||
void Screen::updateNotifier()
|
void Screen::updateNotifier()
|
||||||
{
|
|
||||||
if (notifyAdded)
|
|
||||||
{
|
{
|
||||||
notify->update();
|
notify->update();
|
||||||
notifyActive = notify->active();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
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
|
// Dibuja las notificaciones
|
||||||
void Screen::renderNotifications()
|
void Screen::renderNotifications()
|
||||||
{
|
{
|
||||||
//if (notifyAdded)
|
if (!notify->active())
|
||||||
{
|
|
||||||
if (!notifyActive)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
|
||||||
notify->render();
|
notify->render();
|
||||||
//SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
// Actualiza la lógica del objeto
|
||||||
void Screen::setNotificationSize()
|
void Screen::update()
|
||||||
{
|
{
|
||||||
if (options->videoMode == 0)
|
updateNotifier();
|
||||||
{
|
updateFX();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -30,10 +30,6 @@ private:
|
|||||||
int borderHeight; // Anltura 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 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
|
// Variables - Efectos
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
bool fade; // Indica si esta activo el efecto de fade
|
||||||
@@ -65,9 +61,6 @@ private:
|
|||||||
// Dibuja las notificaciones
|
// Dibuja las notificaciones
|
||||||
void renderNotifications();
|
void renderNotifications();
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
|
||||||
void setNotificationSize();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
|
||||||
@@ -141,6 +134,9 @@ public:
|
|||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||||
|
|
||||||
|
// Actualiza la lógica del objeto
|
||||||
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user