-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicator.c
52 lines (43 loc) · 1.31 KB
/
indicator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "indicator.h"
#include "debug.h"
#include <stdio.h>
void cse(int ret_val) {
if (ret_val < 0) {
term_indicator(0);
exit(1);
}
}
void *csp(void *possibly_null) {
if (possibly_null == NULL) {
term_indicator(0);
exit(1);
}
return possibly_null;
}
void term_indicator(int silent) {
if (!silent) {
fprintf(stderr, "SDL Error: %s\n", SDL_GetError());
}
SDL_Quit();
}
void draw_indicator(indicator_t *i, int progress) {
// Background
SDL_SetRenderDrawColor(i->renderer, BACKGROUND_COLOR, 255);
SDL_RenderClear(i->renderer);
// Bar
SDL_SetRenderDrawColor(i->renderer, BAR_COLOR, 255);
SDL_Rect bar = {.x = BORDER_SIZE,
.y = BORDER_SIZE,
.w = (IND_W - 2 * BORDER_SIZE) * (progress / 100.0f),
.h = IND_H - 2 * BORDER_SIZE};
SDL_RenderFillRect(i->renderer, &bar);
}
void init_indicator(indicator_t *i, int w, int h) {
cse(SDL_Init(SDL_INIT_VIDEO));
i->window = csp(SDL_CreateWindow(
"volind", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h,
SDL_WINDOW_BORDERLESS | SDL_WINDOW_TOOLTIP));
i->renderer = csp(SDL_CreateRenderer(i->window, -1, 0));
cse(SDL_SetRenderDrawBlendMode(i->renderer, SDL_BLENDMODE_BLEND));
i->progress = -1.0f;
}