Some more progress

This commit is contained in:
2025-05-30 22:31:59 +02:00
parent d01bdbe819
commit 0c9698879b
13 changed files with 290 additions and 72 deletions

View File

@@ -3,7 +3,7 @@
//
#include "util.h"
#include "../tiles/tile.h"
//#include "font.h"
//The window we'll be rendering to
SDL_Window *window = NULL;
@@ -72,3 +72,45 @@ void DrawThickRect(SDL_Renderer* renderer, SDL_Rect rect, int thickness) {
SDL_RenderDrawRect(renderer, &r);
}
}
void renderBar(SDL_Renderer *renderer,
int x, int y, int width, int height,
int maxValue, int currentValue,
SDL_Color barColor, int margin)
{
if (maxValue <= 0) return; // Avoid division by zero
// Clamp value
if (currentValue < 0) currentValue = 0;
if (currentValue == 0) {
return;
}
if (currentValue > maxValue) currentValue = maxValue;
// Calculate filled width based on currentValue
int filledWidth = (width * currentValue) / maxValue;
// Bar rectangle
SDL_Rect barRect = { x, y, filledWidth, height };
// Background rectangle with margin
SDL_Rect bgRect = {
x - margin,
y - margin,
width + margin * 2,
height + margin * 2
};
// Draw background (black)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderFillRect(renderer, &bgRect);
// Draw bar with provided color
SDL_SetRenderDrawColor(renderer, barColor.r, barColor.g, barColor.b, barColor.a);
SDL_RenderFillRect(renderer, &barRect);
char barString[20];
sprintf(barString, "%d/%d", currentValue, maxValue);
//renderText(renderer, fonts[3], barString, width / 2, margin);
}