Debian Codegraph @

prboom2/src/dsda/hud_components/speed_text.c

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Speed Text HUD Component
16 //
17
18 #include "base.h"
19
20 #include "speed_text.h"
21
22 typedef struct {
23 dsda_text_t component;
24 char label[9];
25 } local_component_t;
26
27 static local_component_t* local;
28
29 static void dsda_UpdateComponentText(char* str, size_t max_size) {
30 int speed;
31
32 speed = dsda_GameSpeed();
33
34 snprintf(
35 str,
36 max_size,
37 "%s%s%d%%",
38 local->label,
39 speed < 100 ? dsda_TextColor(dsda_tc_exhud_speed_slow)
40 : speed == 100 ? dsda_TextColor(dsda_tc_exhud_speed_normal)
41 : dsda_TextColor(dsda_tc_exhud_speed_fast),
42 speed
43 );
44 }
45
46 void dsda_InitSpeedTextHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
47 *data = Z_Calloc(1, sizeof(local_component_t));
48 local = *data;
49
50 if (arg_count < 1 || args[0])
51 snprintf(local->label, sizeof(local->label), "%sSPEED ", dsda_TextColor(dsda_tc_exhud_speed_label));
52 else
53 local->label[0] = '\0';
54
55 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
56 }
57
58 void dsda_UpdateSpeedTextHC(void* data) {
59 local = data;
60
61 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
62 dsda_RefreshHudText(&local->component);
63 }
64
65 void dsda_DrawSpeedTextHC(void* data) {
66 local = data;
67
68 dsda_DrawBasicText(&local->component);
69 }