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.

This commit is contained in:
2021-12-16 19:42:53 +00:00
parent 968458cf1c
commit 9728abd294
+24 -2
View File
@@ -1,6 +1,7 @@
#include "../include/cpu_display.h"
#include <SDL2/SDL_render.h>
#include <stdio.h>
#include <string.h>
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;
}