Debian Codegraph @

prboom2/src/dsda/hud_components/local_time.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 Local Time HUD Component
16 //
17
18 #include <time.h>
19
20 #include "base.h"
21
22 #include "local_time.h"
23
24 typedef struct {
25 dsda_text_t component;
26 } local_component_t;
27
28 static local_component_t* local;
29
30 static void dsda_UpdateComponentText(char* str, size_t max_size) {
31 size_t length;
32 time_t now;
33 struct tm* local_tm;
34
35 length = snprintf(str, max_size, "%s", dsda_TextColor(dsda_tc_exhud_local_time));
36
37 now = time(NULL);
38 local_tm = localtime(&now);
39
40 strftime(str + length, max_size - length, "%H:%M:%S", local_tm);
41 }
42
43 void dsda_InitLocalTimeHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
44 *data = Z_Calloc(1, sizeof(local_component_t));
45 local = *data;
46
47 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
48 }
49
50 void dsda_UpdateLocalTimeHC(void* data) {
51 local = data;
52
53 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
54 dsda_RefreshHudText(&local->component);
55 }
56
57 void dsda_DrawLocalTimeHC(void* data) {
58 local = data;
59
60 dsda_DrawBasicText(&local->component);
61 }