Transició a surface acabada. Ja compila
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
#include "options.h" // for Options, options, OptionsNotification
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "s_sprite.h" // for Sprite
|
||||
#include "s_sprite.h" // for SSprite
|
||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
||||
#include "surface.h" // for Texture
|
||||
#include "surface.h" // for Surface
|
||||
|
||||
// [SINGLETON]
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
@@ -234,47 +234,45 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
n.rect = {desp_h, y_pos, width, height};
|
||||
|
||||
// Crea la textura
|
||||
n.surface = std::make_shared<Texture>(Screen::get()->getRenderer());
|
||||
n.surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
n.surface->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
n.surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), width, height);
|
||||
|
||||
// Prepara para dibujar en la textura
|
||||
n.surface->setAsRenderTarget(Screen::get()->getRenderer());
|
||||
Screen::get()->setRenderSurfaceData(n.surface);
|
||||
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, 255);
|
||||
SDL_Rect rect;
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
if (shape == NotificationShape::ROUNDED)
|
||||
{
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
|
||||
rect = {4 / 2, 1, width - 4, height - 2};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
|
||||
rect = {1, 4 / 2, width - 2, height - 4};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
}
|
||||
|
||||
else if (shape == NotificationShape::SQUARED)
|
||||
{
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->clear(bg_color_);
|
||||
}
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (has_icons_ && icon >= 0 && texts.size() >= 2)
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(icon_surface_, (SDL_Rect){0, 0, ICON_SIZE_, ICON_SIZE_});
|
||||
auto sp = std::make_unique<SSprite>(icon_surface_, (SDL_Rect){0, 0, ICON_SIZE_, ICON_SIZE_});
|
||||
sp->setPosition({padding_in_h, padding_in_v, ICON_SIZE_, ICON_SIZE_});
|
||||
sp->setClip({ICON_SIZE_ * (icon % 10), ICON_SIZE_ * (icon / 10), ICON_SIZE_, ICON_SIZE_});
|
||||
sp->render();
|
||||
}
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
const Color color{255, 255, 255};
|
||||
const Uint8 color = stringToColor("white");
|
||||
int iterator = 0;
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
@@ -290,13 +288,13 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
|
||||
// Crea el sprite de la notificación
|
||||
n.sprite = std::make_shared<Sprite>(n.surface, n.rect);
|
||||
n.sprite = std::make_shared<SSprite>(n.surface, n.rect);
|
||||
|
||||
// Deja la notificación invisible
|
||||
n.surface->setAlpha(0);
|
||||
//n.surface->setAlpha(0);
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications_.emplace_back(n);
|
||||
|
||||
Reference in New Issue
Block a user