From ecceb4f7eebc8204836e164c4ff655e9abbc2636 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 19 Mar 2021 14:29:17 -0400 Subject: src/defs.h: New macro definitions file --- (limited to 'src/help.c') diff --git a/src/help.c b/src/help.c index 5cdd40f..3e3d365 100644 --- a/src/help.c +++ b/src/help.c @@ -21,6 +21,7 @@ #include #include #include "collision.h" +#include "defs.h" #include "help.h" #include "main.h" #include "output.h" @@ -68,16 +69,16 @@ _db_help_triangle(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int i; int y; int x; - SDL_Point points[(16 * (16 + 2)) / 4]; + SDL_Point points[(DB_SCROLL_W * (DB_SCROLL_W + 2)) / 4]; i = 0; - for (y = 0; y < (16 / 2); ++y) { - for (x = y; x < (16 - y); ++x) { + for (y = 0; y < DB_SCROLL_H; ++y) { + for (x = y; x < (DB_SCROLL_W - 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; + points[i].y = y_min + DB_SCROLL_H - 1 - y; } ++i; } @@ -107,20 +108,20 @@ db_help(void) renderer = db_get_renderer(); - font = TTF_OpenFont(font_path, 16); + font = TTF_OpenFont(font_path, DB_FONT_TEXT_SIZE); if (font == NULL) { db_err("Failed to open font (%s)", TTF_GetError()); free(font_path); return -1; } - color.r = 0x00; - color.g = 0x00; - color.b = 0xFF; - color.a = 0xFF; + color.r = DB_COLOR_FORE_R; + color.g = DB_COLOR_FORE_G; + color.b = DB_COLOR_FORE_B; + color.a = DB_COLOR_FORE_A; surface = TTF_RenderText_Blended_Wrapped(font, _db_help_text, color, - 592); + DB_WINDOW_W - DB_WINDOW_P * 2 - DB_SCROLL_W); if (surface == NULL) { db_err("Failed to create surface (%s)", TTF_GetError()); return -1; @@ -136,23 +137,23 @@ db_help(void) text_src_rect.x = 0; text_src_rect.y = 0; - text_src_rect.w = 592; - text_src_rect.h = 448; + text_src_rect.w = DB_WINDOW_W - DB_WINDOW_P * 2 - DB_SCROLL_W; + text_src_rect.h = DB_WINDOW_H - DB_WINDOW_P * 2; - text_dst_rect.x = 16; - text_dst_rect.y = 16; - text_dst_rect.w = 592; - text_dst_rect.h = 448; + text_dst_rect.x = DB_WINDOW_P; + text_dst_rect.y = DB_WINDOW_P; + text_dst_rect.w = DB_WINDOW_W - DB_WINDOW_P * 2 - DB_SCROLL_W; + text_dst_rect.h = DB_WINDOW_H - DB_WINDOW_P * 2; - up_rect.x = 608; - up_rect.y = 16; - up_rect.w = 16; - up_rect.h = 8; + up_rect.x = DB_WINDOW_W - DB_WINDOW_P - DB_SCROLL_W; + up_rect.y = DB_WINDOW_P; + up_rect.w = DB_SCROLL_W; + up_rect.h = DB_SCROLL_H; - dn_rect.x = 608; - dn_rect.y = 456; - dn_rect.w = 16; - dn_rect.h = 8; + dn_rect.x = DB_WINDOW_W - DB_WINDOW_P - DB_SCROLL_W; + dn_rect.y = DB_WINDOW_H - DB_WINDOW_P - DB_SCROLL_H; + dn_rect.w = DB_SCROLL_W; + dn_rect.h = DB_SCROLL_H; up_over = 0; dn_over = 0; @@ -165,13 +166,13 @@ db_help(void) case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_UP: - text_src_rect.y -= 16; + text_src_rect.y -= DB_SCROLL_S; if (text_src_rect.y < 0) { text_src_rect.y = 0; } break; case SDLK_DOWN: - text_src_rect.y += 16; + text_src_rect.y += DB_SCROLL_S; if (text_src_rect.y > surface->h - text_src_rect.h) @@ -225,14 +226,14 @@ db_help(void) if (db_pt_in_rect(event.button.x, event.button.y, &up_rect)) { - text_src_rect.y -= 16; + text_src_rect.y -= DB_SCROLL_S; 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; + text_src_rect.y += DB_SCROLL_S; if (text_src_rect.y > surface->h - text_src_rect.h) { text_src_rect.y = surface->h - @@ -246,29 +247,55 @@ db_help(void) if (_db_help_quit > 0) { break; } - SDL_SetRenderDrawColor(renderer, 0x7F, 0x7F, 0x7F, 0xFF); + SDL_SetRenderDrawColor(renderer, + DB_COLOR_BACK_R, DB_COLOR_BACK_G, + DB_COLOR_BACK_B, DB_COLOR_BACK_A); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, &text_src_rect, &text_dst_rect); if (text_src_rect.y <= 0) { _db_help_triangle(renderer, - 0x3F, 0x3F, 0x7F, 0xFF, 608, 16, -1); + DB_COLOR_DISA_R, DB_COLOR_DISA_G, + DB_COLOR_DISA_B, DB_COLOR_DISA_A, + DB_WINDOW_W - DB_WINDOW_P * 2, + DB_WINDOW_P, + -1); } else if (up_over == 1) { _db_help_triangle(renderer, - 0xFF, 0xFF, 0xFF, 0xFF, 608, 16, -1); + DB_COLOR_ACTV_R, DB_COLOR_ACTV_G, + DB_COLOR_ACTV_B, DB_COLOR_ACTV_A, + DB_WINDOW_W - DB_WINDOW_P * 2, + DB_WINDOW_P, + -1); } else { _db_help_triangle(renderer, - 0x00, 0x00, 0xFF, 0xFF, 608, 16, -1); + DB_COLOR_FORE_R, DB_COLOR_FORE_G, + DB_COLOR_FORE_B, DB_COLOR_FORE_A, + DB_WINDOW_W - DB_WINDOW_P * 2, + DB_WINDOW_P, + -1); } if (text_src_rect.y >= surface->h - text_src_rect.h) { _db_help_triangle(renderer, - 0x3F, 0x3F, 0x7F, 0xFF, 608, 456, 1); + DB_COLOR_DISA_R, DB_COLOR_DISA_G, + DB_COLOR_DISA_B, DB_COLOR_DISA_A, + DB_WINDOW_W - DB_WINDOW_P * 2, + DB_WINDOW_H - DB_WINDOW_P - DB_SCROLL_H, + 1); } else if (dn_over == 1) { _db_help_triangle(renderer, - 0xFF, 0xFF, 0xFF, 0xFF, 608, 456, 1); + DB_COLOR_ACTV_R, DB_COLOR_ACTV_G, + DB_COLOR_ACTV_B, DB_COLOR_ACTV_A, + DB_WINDOW_W - DB_WINDOW_P * 2, + DB_WINDOW_H - DB_WINDOW_P - DB_SCROLL_H, + 1); } else { _db_help_triangle(renderer, - 0x00, 0x00, 0xFF, 0xFF, 608, 456, 1); + DB_COLOR_FORE_R, DB_COLOR_FORE_G, + DB_COLOR_FORE_B, DB_COLOR_FORE_A, + DB_WINDOW_W - DB_WINDOW_P * 2, + DB_WINDOW_H - DB_WINDOW_P - DB_SCROLL_H, + 1); } SDL_RenderPresent(renderer); } -- cgit v0.9.1