migrant a SDL3
This commit is contained in:
@@ -181,60 +181,60 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
constexpr int icon_size = 16;
|
||||
constexpr int padding_out = 1;
|
||||
const auto padding_in_h = text_->getCharacterSize();
|
||||
const auto padding_in_v = text_->getCharacterSize() / 2;
|
||||
const int icon_space = icon >= 0 ? icon_size + padding_in_h : 0;
|
||||
const int width = text_->lenght(longest) + (padding_in_h * 2) + icon_space;
|
||||
const int height = (text_->getCharacterSize() * texts.size()) + (padding_in_v * 2);
|
||||
const auto shape = NotificationShape::SQUARED;
|
||||
constexpr int ICON_SIZE = 16;
|
||||
constexpr int PADDING_OUT = 1;
|
||||
const float PADDING_IN_H = text_->getCharacterSize();
|
||||
const float PADDING_IN_V = text_->getCharacterSize() / 2;
|
||||
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
|
||||
const float WIDTH = text_->lenght(longest) + (PADDING_IN_H * 2) + ICON_SPACE;
|
||||
const float HEIGHT = (text_->getCharacterSize() * texts.size()) + (PADDING_IN_V * 2);
|
||||
const auto SHAPE = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
auto desp_h = 0;
|
||||
if (param.notification.pos_h == NotifyPosition::LEFT)
|
||||
float desp_h = 0;
|
||||
switch (param.notification.pos_h)
|
||||
{
|
||||
desp_h = padding_out;
|
||||
}
|
||||
else if (param.notification.pos_h == NotifyPosition::MIDDLE)
|
||||
{
|
||||
desp_h = ((param.game.width / 2) - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
desp_h = param.game.width - width - padding_out;
|
||||
case NotifyPosition::LEFT:
|
||||
desp_h = PADDING_OUT;
|
||||
break;
|
||||
|
||||
case NotifyPosition::MIDDLE:
|
||||
desp_h = ((param.game.width / 2) - (WIDTH / 2));
|
||||
break;
|
||||
|
||||
case NotifyPosition::RIGHT:
|
||||
desp_h = param.game.width - WIDTH - PADDING_OUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
desp_h = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
const int desp_v = (param.notification.pos_v == NotifyPosition::TOP) ? padding_out : (param.game.height - height - padding_out);
|
||||
const int DESP_V = (param.notification.pos_v == NotifyPosition::TOP) ? PADDING_OUT : (param.game.height - HEIGHT - PADDING_OUT);
|
||||
|
||||
// Offset
|
||||
const auto travel_dist = height + padding_out;
|
||||
auto offset = 0;
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
offset = !notifications_.empty() ? notifications_.back().y + travel_dist : desp_v;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = !notifications_.empty() ? notifications_.back().y - travel_dist : desp_v;
|
||||
}
|
||||
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT;
|
||||
auto OFFSET = notifications_.empty()
|
||||
? DESP_V
|
||||
: notifications_.back().y + (param.notification.pos_v == NotifyPosition::TOP ? TRAVEL_DIST : -TRAVEL_DIST);
|
||||
|
||||
// Crea la notificacion
|
||||
Notification n;
|
||||
|
||||
// Inicializa variables
|
||||
n.code = code;
|
||||
n.y = offset;
|
||||
n.travel_dist = travel_dist;
|
||||
n.y = OFFSET;
|
||||
n.travel_dist = TRAVEL_DIST;
|
||||
n.texts = texts;
|
||||
n.shape = shape;
|
||||
auto y_pos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travel_dist : travel_dist);
|
||||
n.rect = {desp_h, y_pos, width, height};
|
||||
n.shape = SHAPE;
|
||||
const float POS_Y = OFFSET + (param.notification.pos_v == NotifyPosition::TOP ? -TRAVEL_DIST : TRAVEL_DIST);
|
||||
n.rect = {desp_h, POS_Y, WIDTH, HEIGHT};
|
||||
|
||||
// Crea la textura
|
||||
n.texture = std::make_shared<Texture>(renderer_);
|
||||
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->createBlank(WIDTH, HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Prepara para dibujar en la textura
|
||||
@@ -243,22 +243,22 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(renderer_, bg_color_.r, bg_color_.g, bg_color_.b, 255);
|
||||
SDL_FRect rect;
|
||||
if (shape == NotificationShape::ROUNDED)
|
||||
if (SHAPE == NotificationShape::ROUNDED)
|
||||
{
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
rect = {4, 0, WIDTH - (4 * 2), HEIGHT};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
rect = {4 / 2, 1, width - 4, height - 2};
|
||||
rect = {4 / 2, 1, WIDTH - 4, HEIGHT - 2};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
rect = {1, 4 / 2, width - 2, height - 4};
|
||||
rect = {1, 4 / 2, WIDTH - 2, HEIGHT - 4};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
rect = {0, 4, WIDTH, HEIGHT - (4 * 2)};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
}
|
||||
|
||||
else if (shape == NotificationShape::SQUARED)
|
||||
else if (SHAPE == NotificationShape::SQUARED)
|
||||
{
|
||||
SDL_RenderClear(renderer_);
|
||||
}
|
||||
@@ -266,9 +266,13 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
||||
// Dibuja el icono de la notificación
|
||||
if (has_icons_ && icon >= 0 && texts.size() >= 2)
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_FRect){0, 0, icon_size, icon_size});
|
||||
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
|
||||
sp->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
|
||||
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_FRect){0, 0, ICON_SIZE, ICON_SIZE});
|
||||
sp->setPosition({PADDING_IN_H, PADDING_IN_V, ICON_SIZE, ICON_SIZE});
|
||||
sp->setSpriteClip(SDL_FRect{
|
||||
static_cast<float>(ICON_SIZE * (icon % 10)),
|
||||
static_cast<float>(ICON_SIZE * (icon / 10)),
|
||||
ICON_SIZE,
|
||||
ICON_SIZE});
|
||||
sp->render();
|
||||
}
|
||||
|
||||
@@ -277,7 +281,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
||||
int iterator = 0;
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v + iterator * (text_->getCharacterSize() + 1), text, color);
|
||||
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + iterator * (text_->getCharacterSize() + 1), text, color);
|
||||
++iterator;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user