utils: Añadidas las funciones darkenColor y lightenColor

This commit is contained in:
2023-05-28 09:17:30 +02:00
parent 73849a2fef
commit 2b5a2cb588
3 changed files with 33 additions and 4 deletions

View File

@@ -61,7 +61,8 @@ void OnScreenKeyboard::fillTexture()
text->write(text->getCharacterSize(), text->getCharacterSize(), caption); text->write(text->getCharacterSize(), text->getCharacterSize(), caption);
// Dibuja el cuadro donde va el texto que se escribirá // 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 x_rect = (text->getCharacterSize() * 2) + text->lenght(caption);
const int y_rect = text->getCharacterSize(); const int y_rect = text->getCharacterSize();
const int w_rect = width - text->getCharacterSize() - x_rect; const int w_rect = width - text->getCharacterSize() - x_rect;

View File

@@ -1,6 +1,8 @@
#include "utils.h" #include "utils.h"
#include <math.h> #include <math.h>
using namespace std;
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2) double distanceSquared(int x1, int y1, int x2, int y2)
{ {
@@ -580,3 +582,23 @@ void initOptions(options_t *options)
options->notifications.sound = true; options->notifications.sound = true;
options->notifications.color = {48, 48, 48}; 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;
}

View File

@@ -201,4 +201,10 @@ bool colorAreEqual(color_t color1, color_t color2);
// Inicializa la estructura de opciones // Inicializa la estructura de opciones
void initOptions(options_t *options); 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 #endif