utils: Añadidas las funciones darkenColor y lightenColor
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "utils.h"
|
||||
#include <math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
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.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;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user