Añadidos iconos a las notificaciones
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->renderer = renderer;
|
||||
@@ -13,8 +13,9 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
|
||||
waitTime = 300;
|
||||
|
||||
// Crea objetos
|
||||
texture = new Texture(renderer, bitmapFile);
|
||||
text = new Text(textFile, texture, renderer);
|
||||
iconTexture = new Texture(renderer, iconFile);
|
||||
textTexture = new Texture(renderer, bitmapFile);
|
||||
text = new Text(textFile, textTexture, renderer);
|
||||
sound = JA_LoadSound(soundFile.c_str());
|
||||
}
|
||||
|
||||
@@ -22,7 +23,8 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
|
||||
Notify::~Notify()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
delete texture;
|
||||
delete textTexture;
|
||||
delete iconTexture;
|
||||
delete text;
|
||||
JA_DeleteSound(sound);
|
||||
|
||||
@@ -128,7 +130,7 @@ void Notify::showText(std::string text1, std::string text2)
|
||||
{
|
||||
// Inicializa variables
|
||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||
const int width = text->lenght(txt) + text->getCharacterSize();
|
||||
const int width = text->lenght(txt) + text->getCharacterSize() + 16 + 4;
|
||||
const int height = text->getCharacterSize() * 3;
|
||||
const int padding = text->getCharacterSize() / 2;
|
||||
|
||||
@@ -189,23 +191,31 @@ void Notify::showText(std::string text1, std::string text2)
|
||||
n.rect = {despH, offset + travelDist, width, height};
|
||||
}
|
||||
|
||||
// Prepara el sprite con el icono
|
||||
Sprite *sp = new Sprite({0, 0, 16, 16}, iconTexture, renderer);
|
||||
sp->setPos({padding, padding, 16, 16});
|
||||
sp->setSpriteClip({16 * 2, 0, 16, 16});
|
||||
|
||||
// Crea la textura
|
||||
n.texture = new Texture(renderer);
|
||||
n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
sp->render();
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
color_t color = {255, 255, 255};
|
||||
if (text2 != "")
|
||||
{ // Dos lineas de texto
|
||||
text->writeDX(TXT_STROKE, padding, padding, text1, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
text->writeDX(TXT_STROKE, padding, padding + text->getCharacterSize() + 1, text2, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
text->writeColored(padding + 16 + 4, padding, text1, color);
|
||||
text->writeColored(padding + 16 + 4, padding + text->getCharacterSize(), text2, color);
|
||||
}
|
||||
else
|
||||
{ // Una linea de texto
|
||||
text->writeDX(TXT_STROKE, padding, (height / 2) - (text->getCharacterSize() / 2), text1, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
text->writeColored(padding + 16 + 4, (height / 2) - (text->getCharacterSize() / 2), text1, color);
|
||||
}
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
delete sp;
|
||||
|
||||
// Crea el sprite
|
||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
||||
|
||||
Reference in New Issue
Block a user