changeset 528:95792046d3d2

core: doxygenize maths
author David Demelier <markand@malikania.fr>
date Sat, 04 Mar 2023 20:16:03 +0100
parents 3d004b068744
children 7e835d43ef74
files examples/example-action/chest.c examples/example-audio/example-audio.c examples/example-ui/example-ui.c libmlk-core/mlk/core/event.c libmlk-core/mlk/core/maths.c libmlk-core/mlk/core/maths.h libmlk-ui/mlk/ui/button.c libmlk-ui/mlk/ui/checkbox.c libmlk-ui/mlk/ui/gridmenu.c
diffstat 9 files changed, 45 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-action/chest.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/examples/example-action/chest.c	Sat Mar 04 20:16:03 2023 +0100
@@ -49,7 +49,7 @@
 	cw = mlk_registry_sprites[MLK_REGISTRY_TEXTURE_CHEST].cellw;
 	ch = mlk_registry_sprites[MLK_REGISTRY_TEXTURE_CHEST].cellh;
 
-	if (!mlk_maths_is_boxed(chest->x, chest->y, cw, ch, ev->click.x, ev->click.y))
+	if (!mlk_maths_is_boxed(ev->click.x, ev->click.y, chest->x, chest->y, cw, ch))
 		return;
 
 	mlk_sound_play(&mlk_registry_sounds[MLK_REGISTRY_SOUND_OPEN_CHEST]);
--- a/examples/example-audio/example-audio.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/examples/example-audio/example-audio.c	Sat Mar 04 20:16:03 2023 +0100
@@ -81,16 +81,16 @@
 		break;
 	case MLK_EVENT_KEYDOWN:
 		switch (ev->key.key) {
-		case MLK_KEY_p:
+		case MLK_KEY_P:
 			mlk_music_pause(music);
 			break;
-		case MLK_KEY_r:
+		case MLK_KEY_R:
 			mlk_music_resume(music);
 			break;
-		case MLK_KEY_q:
+		case MLK_KEY_Q:
 			mlk_music_stop(music);
 			break;
-		case MLK_KEY_l:
+		case MLK_KEY_L:
 			mlk_music_play(music, MLK_MUSIC_LOOP);
 			break;
 		case MLK_KEY_SPACE:
--- a/examples/example-ui/example-ui.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/examples/example-ui/example-ui.c	Sat Mar 04 20:16:03 2023 +0100
@@ -229,12 +229,12 @@
 headerclick(int x, int y)
 {
 	return mlk_maths_is_boxed(
+	    x,
+	    y,
 	    ui.panel.frame.x,
 	    ui.panel.frame.y,
 	    ui.panel.frame.w,
-	    HEADER_HEIGHT,
-	    x,
-	    y
+	    HEADER_HEIGHT
 	);
 }
 
--- a/libmlk-core/mlk/core/event.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/libmlk-core/mlk/core/event.c	Sat Mar 04 20:16:03 2023 +0100
@@ -37,8 +37,8 @@
 	{ SDLK_DOLLAR,          MLK_KEY_DOLLAR                  },
 	{ SDLK_AMPERSAND,       MLK_KEY_AMPERSAND               },
 	{ SDLK_QUOTE,           MLK_KEY_QUOTE                   },
-	{ SDLK_LEFTPAREN,       MLK_KEY_LEFT_PAREN              },
-	{ SDLK_RIGHTPAREN,      MLK_KEY_RIGHT_PAREN             },
+	{ SDLK_LEFTPAREN,       MLK_KEY_LPAREN                  },
+	{ SDLK_RIGHTPAREN,      MLK_KEY_RPAREN                  },
 	{ SDLK_ASTERISK,        MLK_KEY_ASTERISK                },
 	{ SDLK_PLUS,            MLK_KEY_PLUS                    },
 	{ SDLK_COMMA,           MLK_KEY_COMMA                   },
@@ -62,9 +62,9 @@
 	{ SDLK_GREATER,         MLK_KEY_GREATER                 },
 	{ SDLK_QUESTION,        MLK_KEY_QUESTION                },
 	{ SDLK_AT,              MLK_KEY_AT                      },
-	{ SDLK_LEFTBRACKET,     MLK_KEY_LEFT_BRACKET            },
+	{ SDLK_LEFTBRACKET,     MLK_KEY_LBRACKET                },
 	{ SDLK_BACKSLASH,       MLK_KEY_BACKSLASH               },
-	{ SDLK_RIGHTBRACKET,    MLK_KEY_RIGHT_BRACKET           },
+	{ SDLK_RIGHTBRACKET,    MLK_KEY_RBRACKET                },
 	{ SDLK_CARET,           MLK_KEY_CARET                   },
 	{ SDLK_UNDERSCORE,      MLK_KEY_UNDERSCORE              },
 	{ SDLK_BACKQUOTE,       MLK_KEY_BACKQUOTE               },
--- a/libmlk-core/mlk/core/maths.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/libmlk-core/mlk/core/maths.c	Sat Mar 04 20:16:03 2023 +0100
@@ -19,12 +19,9 @@
 #include "maths.h"
 
 int
-mlk_maths_is_boxed(int x, int y, unsigned int w, unsigned int h, int px, int py)
+mlk_maths_is_boxed(int x, int y, int px, int py, unsigned int pw, unsigned int ph)
 {
-	return px > x &&
-	       py > y &&
-	       px < x + (int)w &&
-	       py < y + (int)h;
+	return x >= px && x <= (int)(px + pw) && y >= py && y <= (int)(py + ph);
 }
 
 float
--- a/libmlk-core/mlk/core/maths.h	Sat Mar 04 20:03:08 2023 +0100
+++ b/libmlk-core/mlk/core/maths.h	Sat Mar 04 20:16:03 2023 +0100
@@ -19,17 +19,41 @@
 #ifndef MLK_CORE_MATHS_H
 #define MLK_CORE_MATHS_H
 
-#include "core.h"
+/**
+ * \file maths.h
+ * \brief Basic maths
+ */
 
 #if defined(__cplusplus)
 extern "C" {
 #endif
 
+/**
+ * Returns non-zero if the coordinates x, y inside the bounding rectangle.
+ *
+ * \param x the x coordinate
+ * \param y the y coordinate
+ * \param px rectangle x coordinate
+ * \param py rectangle y coordinate
+ * \param pw rectangle width
+ * \param ph rectangle height
+ * \return non-zero if x, y is within pw, ph, px, py
+ */
 int
-mlk_maths_is_boxed(int, int, unsigned int, unsigned int, int, int);
+mlk_maths_is_boxed(int x, int y, int px, int py, unsigned int pw, unsigned int ph);
 
+/**
+ * Scale a value within two ranges.
+ *
+ * \param in the value to scale
+ * \param old_min old minimum
+ * \param old_max old maximum
+ * \param new_min new minimum
+ * \param new_max new maximum
+ * \return scaled value
+ */
 float
-mlk_maths_scale(float, float, float, float, float);
+mlk_maths_scale(float in, float old_min, float old_max, float new_min, float new_max);
 
 #if defined(__cplusplus)
 }
--- a/libmlk-ui/mlk/ui/button.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/libmlk-ui/mlk/ui/button.c	Sat Mar 04 20:16:03 2023 +0100
@@ -36,8 +36,8 @@
 	assert(click);
 	assert(click->type == MLK_EVENT_CLICKDOWN || click->type == MLK_EVENT_CLICKUP);
 
-	return mlk_maths_is_boxed(button->x, button->y, button->w, button->h,
-	    click->x, click->y);
+	return mlk_maths_is_boxed(click->x, click->y,
+	    button->x, button->y, button->w, button->h);
 }
 
 static inline struct mlk_font *
--- a/libmlk-ui/mlk/ui/checkbox.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/libmlk-ui/mlk/ui/checkbox.c	Sat Mar 04 20:16:03 2023 +0100
@@ -33,7 +33,7 @@
 	assert(cb);
 	assert(click && click->type == MLK_EVENT_CLICKDOWN);
 
-	return mlk_maths_is_boxed(cb->x, cb->y, cb->w, cb->h, click->x, click->y);
+	return mlk_maths_is_boxed(click->x, click->y, cb->x, cb->y, cb->w, cb->h);
 }
 
 static void
--- a/libmlk-ui/mlk/ui/gridmenu.c	Sat Mar 04 20:03:08 2023 +0100
+++ b/libmlk-ui/mlk/ui/gridmenu.c	Sat Mar 04 20:16:03 2023 +0100
@@ -156,7 +156,7 @@
 		x = (int)(menu->x + style->padding + (c * menu->eltw) + (c * menu->spacew));
 		y = (int)(menu->y + style->padding + (r * menu->elth) + (r * menu->spaceh));
 
-		if (mlk_maths_is_boxed(x, y, menu->eltw, menu->elth, click->x, click->y)) {
+		if (mlk_maths_is_boxed(click->x, click->y, x, y, menu->eltw, menu->elth)) {
 			selected  = c + r * menu->ncols;
 			selected += pagesz * pagenr;