From 2b5a2cb588700783261af4b78058f949404c5cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 28 May 2023 09:17:30 +0200 Subject: [PATCH] =?UTF-8?q?utils:=20A=C3=B1adidas=20las=20funciones=20dark?= =?UTF-8?q?enColor=20y=20lightenColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- units/on_screen_keyboard.cpp | 3 ++- units/utils.cpp | 28 +++++++++++++++++++++++++--- units/utils.h | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/units/on_screen_keyboard.cpp b/units/on_screen_keyboard.cpp index a668afc..1bd55b7 100644 --- a/units/on_screen_keyboard.cpp +++ b/units/on_screen_keyboard.cpp @@ -61,7 +61,8 @@ void OnScreenKeyboard::fillTexture() text->write(text->getCharacterSize(), text->getCharacterSize(), caption); // Dibuja el cuadro donde va el texto que se escribirá - SDL_SetRenderDrawColor(renderer, bgColor.r - 10, bgColor.g - 10, bgColor.b - 10, 255); + const color_t darkColor = darkenColor(bgColor, 10); + SDL_SetRenderDrawColor(renderer, darkColor.r, darkColor.g, darkColor.b, 255); const int x_rect = (text->getCharacterSize() * 2) + text->lenght(caption); const int y_rect = text->getCharacterSize(); const int w_rect = width - text->getCharacterSize() - x_rect; diff --git a/units/utils.cpp b/units/utils.cpp index 0ec44e6..0650d7d 100644 --- a/units/utils.cpp +++ b/units/utils.cpp @@ -1,6 +1,8 @@ #include "utils.h" #include +using namespace std; + // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) { @@ -576,7 +578,27 @@ void initOptions(options_t *options) options->screen.borderHeight = 0; options->notifications.posV = pos_top; - options->notifications.posH = pos_left; - options->notifications.sound = true; - options->notifications.color = {48, 48, 48}; + options->notifications.posH = pos_left; + options->notifications.sound = true; + options->notifications.color = {48, 48, 48}; +} + +// Oscurece un color +color_t darkenColor(color_t color, int amount) +{ + color_t newColor; + newColor.r = max(0, color.r - amount); + newColor.g = max(0, color.g - amount); + newColor.b = max(0, color.b - amount); + return newColor; +} + +// Aclara un color +color_t lightenColor(color_t color, int amount) +{ + color_t newColor; + newColor.r = min(255, color.r + amount); + newColor.g = min(255, color.g + amount); + newColor.b = min(255, color.b + amount); + return newColor; } \ No newline at end of file diff --git a/units/utils.h b/units/utils.h index 3e80288..b776c86 100644 --- a/units/utils.h +++ b/units/utils.h @@ -201,4 +201,10 @@ bool colorAreEqual(color_t color1, color_t color2); // Inicializa la estructura de opciones void initOptions(options_t *options); +// Oscurece un color +color_t darkenColor(color_t color, int amount); + +// Aclara un color +color_t lightenColor(color_t color, int amount); + #endif \ No newline at end of file