summaryrefslogtreecommitdiffstats
path: root/src/help.c
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-19 11:32:43 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-19 11:32:43 (EDT)
commite4ee5e9bc0f441a646befa8196c52590473ce6c4 (patch)
treeff9b0ef311a457f794f9d016b7f1f5ca189ff47c /src/help.c
parent2b3d6f3c16342a25e852aa86c0f5ab3bc214a4ca (diff)
downloaddodge-balls-e4ee5e9bc0f441a646befa8196c52590473ce6c4.zip
dodge-balls-e4ee5e9bc0f441a646befa8196c52590473ce6c4.tar.gz
dodge-balls-e4ee5e9bc0f441a646befa8196c52590473ce6c4.tar.bz2
help: Handle mouse events
Diffstat (limited to 'src/help.c')
-rw-r--r--src/help.c78
1 files changed, 72 insertions, 6 deletions
diff --git a/src/help.c b/src/help.c
index 0399c36..eed28c6 100644
--- a/src/help.c
+++ b/src/help.c
@@ -20,6 +20,7 @@
#include <SDL.h>
#include <SDL_ttf.h>
#include <config.h>
+#include "collision.h"
#include "help.h"
#include "main.h"
#include "output.h"
@@ -96,6 +97,10 @@ db_help(void)
SDL_Texture *texture;
SDL_Rect text_src_rect;
SDL_Rect text_dst_rect;
+ SDL_Rect up_rect;
+ SDL_Rect dn_rect;
+ int up_over;
+ int dn_over;
SDL_Event event;
font_path = db_strcat(db_get_fonts_dir(), "/UbuntuTitling-Bold.ttf");
@@ -139,6 +144,18 @@ db_help(void)
text_dst_rect.w = 592;
text_dst_rect.h = 448;
+ up_rect.x = 608;
+ up_rect.y = 16;
+ up_rect.w = 16;
+ up_rect.h = 8;
+
+ dn_rect.x = 608;
+ dn_rect.y = 456;
+ dn_rect.w = 16;
+ dn_rect.h = 8;
+
+ up_over = 0;
+ dn_over = 0;
_db_help_quit = 0;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
@@ -180,6 +197,49 @@ db_help(void)
break;
}
break;
+ case SDL_MOUSEMOTION:
+ if (event.motion.state != 0) {
+ break;
+ }
+ if (db_pt_in_rect(event.motion.x,
+ event.motion.y,
+ &up_rect)) {
+ up_over = 1;
+ break;
+ } else {
+ up_over = 0;
+ }
+ if (db_pt_in_rect(event.motion.x,
+ event.motion.y,
+ &dn_rect)) {
+ dn_over = 1;
+ break;
+ } else {
+ dn_over = 0;
+ }
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ if (event.button.button != SDL_BUTTON_LEFT) {
+ break;
+ }
+ if (db_pt_in_rect(event.button.x,
+ event.button.y,
+ &up_rect)) {
+ text_src_rect.y -= 16;
+ if (text_src_rect.y < 0) {
+ text_src_rect.y = 0;
+ }
+ } else if (db_pt_in_rect(event.button.x,
+ event.button.y,
+ &dn_rect)) {
+ text_src_rect.y += 16;
+ if (text_src_rect.y > surface->h -
+ text_src_rect.h) {
+ text_src_rect.y = surface->h -
+ text_src_rect.h;
+ }
+ }
+ break;
default:
break;
}
@@ -190,19 +250,25 @@ db_help(void)
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture,
&text_src_rect, &text_dst_rect);
- if (text_src_rect.y > 0) {
+ if (text_src_rect.y <= 0) {
_db_help_triangle(renderer,
- 0x00, 0x00, 0xFF, 0xFF, 608, 16, -1);
+ 0x3F, 0x3F, 0x7F, 0xFF, 608, 16, -1);
+ } else if (up_over == 1) {
+ _db_help_triangle(renderer,
+ 0xFF, 0xFF, 0xFF, 0xFF, 608, 16, -1);
} else {
_db_help_triangle(renderer,
- 0x3F, 0x3F, 0x7F, 0xFF, 608, 16, -1);
+ 0x00, 0x00, 0xFF, 0xFF, 608, 16, -1);
}
- if (text_src_rect.y < surface->h - text_src_rect.h) {
+ if (text_src_rect.y >= surface->h - text_src_rect.h) {
_db_help_triangle(renderer,
- 0x00, 0x00, 0xFF, 0xFF, 608, 456, 1);
+ 0x3F, 0x3F, 0x7F, 0xFF, 608, 456, 1);
+ } else if (dn_over == 1) {
+ _db_help_triangle(renderer,
+ 0xFF, 0xFF, 0xFF, 0xFF, 608, 456, 1);
} else {
_db_help_triangle(renderer,
- 0x3F, 0x3F, 0x7F, 0xFF, 608, 456, 1);
+ 0x00, 0x00, 0xFF, 0xFF, 608, 456, 1);
}
SDL_RenderPresent(renderer);
}