From 9728abd294edbff6590d38f0c408ecbd7637e0d5 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Thu, 16 Dec 2021 19:42:53 +0000 Subject: [PATCH] Got a 'GroupBox' type of display going on for the CPU Stats display. Seems to be a bug with the text having a lot of whitespace, but good enough for this test. --- src/cpu_display.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/cpu_display.c b/src/cpu_display.c index 92b0926..3354fdd 100644 --- a/src/cpu_display.c +++ b/src/cpu_display.c @@ -1,6 +1,7 @@ #include "../include/cpu_display.h" #include #include +#include void renderStatsBox(SDL_Renderer* renderer, TTF_Font* font, char* msg) { SDL_Rect dest, text_rect; @@ -30,19 +31,40 @@ void renderStatsBox(SDL_Renderer* renderer, TTF_Font* font, char* msg) { void renderBorderAndHeader(SDL_Renderer* renderer, TTF_Font* font) { SDL_Rect viewPort; + SDL_Color fg = {.r = 255, .g = 255, .b = 255, .a = 255}; SDL_RenderGetViewport(renderer, &viewPort); SDL_Rect cell = {.x = 0, .y = 0}; + SDL_Rect headerTextRect = {.x = 0, .y = 0}; cell.w = viewPort.w / CPU_STATS_DISPLAY_COLUMN_COUNT; cell.h = viewPort.h / CPU_STATS_DISPLAY_ROW_COUNT; + int maxWidth, maxHeight; + maxWidth = cell.w * (CPU_STATS_DISPLAY_COLUMN_COUNT - 1) + cell.w / 2; + maxHeight = cell.h * (CPU_STATS_DISPLAY_ROW_COUNT - 1) + cell.h / 2; unsigned int bg = 0x00000000; //Set line color SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); - SDL_RenderDrawLine(renderer, cell.w / 2, cell.h / 2, cell.w / 2, cell.h * (CPU_STATS_DISPLAY_ROW_COUNT - 1) + cell.h / 2); + SDL_RenderDrawLine(renderer, cell.w / 2, cell.h / 2, cell.w, cell.h / 2); + + SDL_Surface* text = TTF_RenderText_Solid(font, cpu_display_header_text, fg); + TTF_SizeText(font, cpu_display_header_text, &headerTextRect.w, &headerTextRect.h); + SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, text); + + headerTextRect.x = cell.w; + headerTextRect.w = cell.w * strlen(cpu_display_header_text); + SDL_RenderCopy(renderer, tex, NULL, &headerTextRect); + + SDL_DestroyTexture(tex); + SDL_FreeSurface(text); + + SDL_RenderDrawLine(renderer, maxWidth - headerTextRect.w, cell.h / 2, maxWidth, cell.h / 2); + SDL_RenderDrawLine(renderer, maxWidth, cell.h / 2, maxWidth, maxHeight); + SDL_RenderDrawLine(renderer, cell.w / 2, maxHeight, maxWidth, maxHeight); + SDL_RenderDrawLine(renderer, cell.w / 2, cell.h / 2, cell.w / 2, maxHeight); for (int i = 1; i < CPU_STATS_DISPLAY_ROW_COUNT - 1; i++) { for(int j = 1; j < CPU_STATS_DISPLAY_COLUMN_COUNT - 1; j++) { @@ -60,7 +82,7 @@ void renderBorderAndHeader(SDL_Renderer* renderer, TTF_Font* font) { SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); - SDL_RenderDrawLine(renderer, cell.x, cell.y + cell.h / 2, cell.x + cell.w, cell.y + cell.h / 2); + //SDL_RenderDrawLine(renderer, cell.x, cell.y + cell.h / 2, cell.x + cell.w, cell.y + cell.h / 2); bg ^= 0xFFFFFFFF; }