From 990f7710c892b2fe8690d5a28ccb35137e58934e Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 19 Mar 2021 10:14:30 -0400 Subject: help: Draw scrollbar triangles --- (limited to 'src/help.c') 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); } -- cgit v0.9.1