summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-19 10:14:30 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-19 10:21:02 (EDT)
commit990f7710c892b2fe8690d5a28ccb35137e58934e (patch)
treeb56d455b4bc6807cf6d393641fabc34123818c9b
parentcbd4831540e8cf26b63ae13fa06aac7b68ac0b0e (diff)
downloaddodge-balls-990f7710c892b2fe8690d5a28ccb35137e58934e.zip
dodge-balls-990f7710c892b2fe8690d5a28ccb35137e58934e.tar.gz
dodge-balls-990f7710c892b2fe8690d5a28ccb35137e58934e.tar.bz2
help: Draw scrollbar triangles
-rw-r--r--src/help.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/help.c b/src/help.c
index dc5c071..60bcdb7 100644
--- a/src/help.c
+++ b/src/help.c
@@ -56,6 +56,31 @@ const char *_db_help_text =
"they bounce off walls in the opposite direction. To stop, move "
"against a wall.";
+static void
+_db_help_triangle(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
+ int x_min, int y_min, int dir)
+{
+ int i;
+ int y;
+ int x;
+ SDL_Point points[(16 * (16 + 2)) / 4];
+
+ i = 0;
+ for (y = 0; y < (16 / 2); ++y) {
+ for (x = y; x < (16 - y); ++x) {
+ points[i].x = x_min + x;
+ if (dir > 0) {
+ points[i].y = y_min + y;
+ } else {
+ points[i].y = y_min + (16 / 2) - 1 - y;
+ }
+ ++i;
+ }
+ }
+ SDL_SetRenderDrawColor(renderer, r, g, b, a);
+ SDL_RenderDrawPoints(renderer, points, i);
+}
+
void
db_help(void)
{
@@ -65,7 +90,8 @@ db_help(void)
SDL_Color color;
SDL_Surface *surface;
SDL_Texture *texture;
- SDL_Rect dest_rect;
+ SDL_Rect text_src_rect;
+ SDL_Rect text_dst_rect;
font_path = db_strcat(db_get_fonts_dir(), "/UbuntuTitling-Bold.ttf");
@@ -84,7 +110,7 @@ db_help(void)
color.a = 0xFF;
surface = TTF_RenderText_Blended_Wrapped(font, _db_help_text, color,
- 608);
+ 592);
if (surface == NULL) {
db_err("Failed to create surface (%s)", TTF_GetError());
return;
@@ -96,13 +122,20 @@ db_help(void)
return;
}
- dest_rect.x = 16;
- dest_rect.y = 16;
- dest_rect.w = surface->w;
- dest_rect.h = surface->h;
+ text_src_rect.x = 0;
+ text_src_rect.y = 0;
+ text_src_rect.w = 592;
+ text_src_rect.h = 448;
+
+ text_dst_rect.x = 16;
+ text_dst_rect.y = 16;
+ text_dst_rect.w = 592;
+ text_dst_rect.h = 448;
SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, texture, NULL, &dest_rect);
+ SDL_RenderCopy(renderer, texture, &text_src_rect, &text_dst_rect);
+ _db_help_triangle(renderer, 0x3F, 0x3F, 0x7F, 0xFF, 608, 16, -1);
+ _db_help_triangle(renderer, 0x00, 0x00, 0xFF, 0xFF, 608, 456, 1);
SDL_RenderPresent(renderer);
SDL_Delay(1000);
}