notificacions: paleta semàntica pastel centralitzada amb outline derivat

This commit is contained in:
2026-05-18 17:03:50 +02:00
parent a8c0386355
commit 3ac495f444
4 changed files with 109 additions and 33 deletions
+54
View File
@@ -0,0 +1,54 @@
#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
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include <SDL3/SDL.h>
#include <cstdint>
#include <string>
// Notificacions overlay centralitzades. Cada call site tria una entrada de
// la `Palette` semàntica i una durada; el color base (pastel) i el seu
// outline (versió fosca derivada) viuen en un sol lloc — `notifications.cpp`.
//
// Per a tunejar l'estètica només cal editar les constants del .cpp.
namespace Notifications {
enum class Palette : std::uint8_t {
INFO, // pastel groc — zoom, finestra/fullscreen
TOGGLE, // pastel cian — activacions on/off (shader)
CHOICE, // pastel magenta — selecció entre opcions (tipus shader)
SUCCESS, // pastel verd — acceptat / connectat (preset, mando added)
DANGER, // pastel roig — confirmacions perilloses / desconnexions
};
constexpr Uint32 STANDARD_MS = 1500; // Hotkeys "normals"
constexpr Uint32 CONFIRM_MS = 2000; // Doble pulsació d'ESC
constexpr Uint32 LONG_MS = 2500; // Esdeveniments rellevants (mando)
// Mostra una notificació. L'outline es deriva automàticament del color
// base com a versió fosca (~25% de lluminositat).
void show(const std::string &text, Palette palette, Uint32 duration_ms);
} // namespace Notifications