changeset 461:d7874f11565f

core: color -> mlk_color
author David Demelier <markand@malikania.fr>
date Mon, 27 Feb 2023 09:46:20 +0100
parents 8fa69c770569
children 5729efd23286
files libmlk-core/mlk/core/color.h libmlk-core/mlk/core/font.c libmlk-core/mlk/core/painter.c libmlk-core/mlk/core/texture.c libmlk-rpg/mlk/rpg/battle-indicator.c tests/test-color.c
diffstat 6 files changed, 32 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libmlk-core/mlk/core/color.h	Mon Feb 27 09:14:27 2023 +0100
+++ b/libmlk-core/mlk/core/color.h	Mon Feb 27 09:46:20 2023 +0100
@@ -19,14 +19,15 @@
 #ifndef MLK_CORE_COLOR_H
 #define MLK_CORE_COLOR_H
 
-#define COLOR_R(c)              (c >> 24 & 0xff)
-#define COLOR_G(c)              (c >> 16 & 0xff)
-#define COLOR_B(c)              (c >> 8  & 0xff)
-#define COLOR_A(c)              (c       & 0xff)
-#define COLOR_HEX(r, g, b, a)   \
-        ((r << 24 & 0xff000000) | \
-         (g << 16 & 0x00ff0000) | \
-         (b << 8  & 0x0000ff00) | \
-         (a       & 0x000000ff))
+#define MLK_COLOR_R(c)                  ((c >> 24) & 0xff)
+#define MLK_COLOR_G(c)                  ((c >> 16) & 0xff)
+#define MLK_COLOR_B(c)                  ((c >> 8) & 0xff)
+#define MLK_COLOR_A(c)                  ((c) & 0xff)
+
+#define MLK_COLOR_HEX(r, g, b, a)       \
+        (((r << 24) & 0xff000000) |     \
+         ((g << 16) & 0x00ff0000) |     \
+         ((b << 8)  & 0x0000ff00) |     \
+         ((a)       & 0x000000ff))
 
 #endif /* !MLK_CORE_COLOR_H */
--- a/libmlk-core/mlk/core/font.c	Mon Feb 27 09:14:27 2023 +0100
+++ b/libmlk-core/mlk/core/font.c	Mon Feb 27 09:46:20 2023 +0100
@@ -68,10 +68,10 @@
 	assert(text);
 
 	SDL_Color fg = {
-		.r = COLOR_R(color),
-		.g = COLOR_G(color),
-		.b = COLOR_B(color),
-		.a = COLOR_A(color)
+		.r = MLK_COLOR_R(color),
+		.g = MLK_COLOR_G(color),
+		.b = MLK_COLOR_B(color),
+		.a = MLK_COLOR_A(color)
 	};
 	SDL_Surface *surface;
 	SDL_Surface *(*func)(TTF_Font *, const char *, SDL_Color);
--- a/libmlk-core/mlk/core/painter.c	Mon Feb 27 09:14:27 2023 +0100
+++ b/libmlk-core/mlk/core/painter.c	Mon Feb 27 09:46:20 2023 +0100
@@ -47,7 +47,7 @@
 
 	SDL_GetRenderDrawColor(RENDERER(), &r, &g, &b, &a);
 
-	return COLOR_HEX(r, g, b, a);
+	return MLK_COLOR_HEX(r, g, b, a);
 }
 
 void
@@ -55,10 +55,10 @@
 {
 	SDL_SetRenderDrawColor(
 		RENDERER(),
-		COLOR_R(color),
-		COLOR_G(color),
-		COLOR_B(color),
-		COLOR_A(color)
+		MLK_COLOR_R(color),
+		MLK_COLOR_G(color),
+		MLK_COLOR_B(color),
+		MLK_COLOR_A(color)
 	);
 }
 
--- a/libmlk-core/mlk/core/texture.c	Mon Feb 27 09:14:27 2023 +0100
+++ b/libmlk-core/mlk/core/texture.c	Mon Feb 27 09:46:20 2023 +0100
@@ -90,7 +90,7 @@
 {
 	assert(texture_ok(tex));
 
-	if (SDL_SetTextureColorMod(tex->handle, COLOR_R(color), COLOR_G(color), COLOR_B(color)) < 0)
+	if (SDL_SetTextureColorMod(tex->handle, MLK_COLOR_R(color), MLK_COLOR_G(color), MLK_COLOR_B(color)) < 0)
 		return errorf("%s", SDL_GetError());
 
 	return 0;
--- a/libmlk-rpg/mlk/rpg/battle-indicator.c	Mon Feb 27 09:14:27 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle-indicator.c	Mon Feb 27 09:46:20 2023 +0100
@@ -43,9 +43,9 @@
 colored(const struct battle_indicator *bti)
 {
 	/* Only check r, g, b and ignore alpha. */
-	return COLOR_R(bti->cur) == COLOR_R(bti->color) &&
-	       COLOR_G(bti->cur) == COLOR_G(bti->color) &&
-	       COLOR_B(bti->cur) == COLOR_B(bti->color);
+	return MLK_COLOR_R(bti->cur) == MLK_COLOR_R(bti->color) &&
+	       MLK_COLOR_G(bti->cur) == MLK_COLOR_G(bti->color) &&
+	       MLK_COLOR_B(bti->cur) == MLK_COLOR_B(bti->color);
 }
 
 void
@@ -93,10 +93,10 @@
 
 		if (!colored(bti)) {
 			/* Update colors first. */
-			bti->cur = COLOR_HEX(
-			    inc(COLOR_R(bti->cur), COLOR_R(bti->color)),
-			    inc(COLOR_G(bti->cur), COLOR_G(bti->color)),
-			    inc(COLOR_B(bti->cur), COLOR_B(bti->color)),
+			bti->cur = MLK_COLOR_HEX(
+			    inc(MLK_COLOR_R(bti->cur), MLK_COLOR_R(bti->color)),
+			    inc(MLK_COLOR_G(bti->cur), MLK_COLOR_G(bti->color)),
+			    inc(MLK_COLOR_B(bti->cur), MLK_COLOR_B(bti->color)),
 			    255
 			);
 
--- a/tests/test-color.c	Mon Feb 27 09:14:27 2023 +0100
+++ b/tests/test-color.c	Mon Feb 27 09:46:20 2023 +0100
@@ -23,31 +23,31 @@
 static void
 test_basics_red(void)
 {
-	DT_EQ_INT(COLOR_R(0xa3000000), 163);
+	DT_EQ_INT(MLK_COLOR_R(0xa3000000), 163);
 }
 
 static void
 test_basics_green(void)
 {
-	DT_EQ_INT(COLOR_G(0x00130000), 19);
+	DT_EQ_INT(MLK_COLOR_G(0x00130000), 19);
 }
 
 static void
 test_basics_blue(void)
 {
-	DT_EQ_INT(COLOR_B(0x0000ee00), 238);
+	DT_EQ_INT(MLK_COLOR_B(0x0000ee00), 238);
 }
 
 static void
 test_basics_alpha(void)
 {
-	DT_EQ_INT(COLOR_A(0x000000ff), 255);
+	DT_EQ_INT(MLK_COLOR_A(0x000000ff), 255);
 }
 
 static void
 test_basics_simple(void)
 {
-	DT_EQ_UINT(COLOR_HEX(170, 187, 204, 238), 0xaabbccee);
+	DT_EQ_UINT(MLK_COLOR_HEX(170, 187, 204, 238), 0xaabbccee);
 }
 
 int