From edc45b6cecfad4a39f2905ed4591fd3dc65636fa Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 29 Sep 2024 19:35:33 +0200 Subject: [PATCH] Afegides funcions per oscurir o aclarir colors --- source/utils.cpp | 20 ++++++++++++++++++++ source/utils.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/source/utils.cpp b/source/utils.cpp index 56fbeeb..9039ebf 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -268,4 +268,24 @@ void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_ error += (tx - diameter); } } +} + +// Aclara el color +color_t lightenColor(color_t color, int amount) +{ + color_t newColor; + newColor.r = std::min(255, (int)color.r + amount); + newColor.g = std::min(255, (int)color.g + amount); + newColor.b = std::min(255, (int)color.b + amount); + return newColor; +} + +// Oscurece el color +color_t DarkenColor(color_t color, int amount) +{ + color_t newColor; + newColor.r = std::max(0, (int)color.r - amount); + newColor.g = std::max(0, (int)color.g - amount); + newColor.b = std::max(0, (int)color.b - amount); + return newColor; } \ No newline at end of file diff --git a/source/utils.h b/source/utils.h index 788c01d..9bf412b 100644 --- a/source/utils.h +++ b/source/utils.h @@ -296,6 +296,12 @@ hiScoreEntry_t sortHiScoreTable(hiScoreEntry_t entry1, hiScoreEntry_t entry2); // Dibuja un circulo void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius); +// Aclara el color +color_t lightenColor(color_t color, int amount); + +// Oscurece el color +color_t DarkenColor(color_t color, int amount); + // Colores extern const color_t bgColor; extern const color_t noColor;