colorins en la consola

This commit is contained in:
2026-04-10 20:56:12 +02:00
parent a40967e23a
commit 342b46ca32
7 changed files with 124 additions and 7 deletions

View File

@@ -133,14 +133,23 @@ void Console::redrawText() {
const float WIDTH = Options::game.width;
constexpr int PADDING_IN_H = TEXT_SIZE;
constexpr int PADDING_IN_V = TEXT_SIZE / 2;
constexpr Uint8 TRANSPARENT_SENTINEL = 255; // Coincide con Surface::transparent_color_ por defecto
auto previous_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(surface_);
// Colores leídos de Options (modificables en caliente con el comando CONSOLE)
const Uint8 BG_COLOR = Options::console.transparent
? TRANSPARENT_SENTINEL
: static_cast<Uint8>(Options::console.bg_color);
const auto MSG_COLOR = static_cast<Uint8>(Options::console.msg_color);
const auto PROMPT_COLOR = static_cast<Uint8>(Options::console.prompt_color);
const auto COMMAND_COLOR = static_cast<Uint8>(Options::console.command_color);
// Fondo y borde
surface_->clear(BG_COLOR);
SDL_FRect rect = {.x = 0, .y = 0, .w = WIDTH, .h = height_};
surface_->drawRectBorder(&rect, BORDER_COLOR);
surface_->drawRectBorder(&rect, PROMPT_COLOR);
// La surface de la fuente tiene transparent_color_=255 por defecto,
// pero sus píxeles de fondo son color 0. Cambiarlo temporalmente a 0
@@ -160,10 +169,12 @@ void Console::redrawText() {
y_pos += TEXT_SIZE;
}
// Línea de input (siempre la última)
// Línea de input (siempre la última): prompt en PROMPT_COLOR, comando + cursor en COMMAND_COLOR
const bool SHOW_CURSOR = cursor_visible_ && (static_cast<int>(input_line_.size()) < MAX_LINE_CHARS);
const std::string INPUT_STR = prompt_ + input_line_ + (SHOW_CURSOR ? "_" : "");
text_->writeColored(PADDING_IN_H, y_pos, INPUT_STR, BORDER_COLOR);
text_->writeColored(PADDING_IN_H, y_pos, prompt_, PROMPT_COLOR);
const int PROMPT_PX = text_->length(prompt_);
const std::string CMD_STR = input_line_ + (SHOW_CURSOR ? "_" : "");
text_->writeColored(PADDING_IN_H + PROMPT_PX, y_pos, CMD_STR, COMMAND_COLOR);
// Restaurar transparent_color_ original de la fuente
font_surface->setTransparentColor(PREV_TRANSPARENT);