Files
coffee-crisis/source/core/rendering/notifications.cpp
T

56 lines
2.1 KiB
C++

#include "core/rendering/notifications.hpp"
#include "core/rendering/screen.h"
#include "utils/utils.h"
namespace Notifications {
namespace {
// Paleta semi-saturada: a mig cami entre pastel i color "pur". Manté
// contrast del outline (foscor) sense diluir el matís.
// (Color no és literal type ⇒ const, no constexpr.)
const Color INFO_COLOR{0xF0, 0xD0, 0x40}; // groc
const Color TOGGLE_COLOR{0x60, 0xC0, 0xF0}; // cian
const Color CHOICE_COLOR{0xD0, 0x60, 0xD0}; // magenta
const Color SUCCESS_COLOR{0x70, 0xD0, 0x70}; // verd
const Color DANGER_COLOR{0xF0, 0x60, 0x60}; // vermell
// 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