55 lines
2.0 KiB
C++
55 lines
2.0 KiB
C++
#include "core/rendering/notifications.hpp"
|
|
|
|
#include "core/rendering/screen.h"
|
|
#include "utils/utils.h"
|
|
|
|
namespace Notifications {
|
|
|
|
namespace {
|
|
// Paleta pastel. Per a tunejar l'aparença només cal tocar aquí.
|
|
// (Color no és literal type ⇒ const, no constexpr.)
|
|
const Color INFO_COLOR{0xF0, 0xE0, 0x90}; // groc trigo
|
|
const Color TOGGLE_COLOR{0xA0, 0xE0, 0xF0}; // cian gel
|
|
const Color CHOICE_COLOR{0xE0, 0xA0, 0xE0}; // rosa orquídia
|
|
const Color SUCCESS_COLOR{0xB0, 0xE6, 0xB0}; // verd menta
|
|
const Color DANGER_COLOR{0xF0, 0xA0, 0xA0}; // rosa salmó
|
|
|
|
// Factor de foscor per a l'outline (~40% de la lluminositat del
|
|
// color base): manté el matís i queda prou fosc per a contrastar
|
|
// amb el text pastel sobre el fons del joc.
|
|
constexpr float OUTLINE_FACTOR = 0.40F;
|
|
|
|
auto baseColor(Palette p) -> Color {
|
|
switch (p) {
|
|
case Palette::INFO:
|
|
return INFO_COLOR;
|
|
case Palette::TOGGLE:
|
|
return TOGGLE_COLOR;
|
|
case Palette::CHOICE:
|
|
return CHOICE_COLOR;
|
|
case Palette::SUCCESS:
|
|
return SUCCESS_COLOR;
|
|
case Palette::DANGER:
|
|
return DANGER_COLOR;
|
|
}
|
|
return INFO_COLOR;
|
|
}
|
|
|
|
auto darken(Color c, float factor) -> Color {
|
|
return Color{
|
|
static_cast<Uint8>(static_cast<float>(c.r) * factor),
|
|
static_cast<Uint8>(static_cast<float>(c.g) * factor),
|
|
static_cast<Uint8>(static_cast<float>(c.b) * factor),
|
|
};
|
|
}
|
|
} // namespace
|
|
|
|
void show(const std::string &text, Palette palette, Uint32 duration_ms) {
|
|
if (Screen::get() == nullptr) { return; }
|
|
const Color BASE = baseColor(palette);
|
|
const Color OUTLINE = darken(BASE, OUTLINE_FACTOR);
|
|
Screen::get()->notify(text, BASE, OUTLINE, duration_ms);
|
|
}
|
|
|
|
} // namespace Notifications
|