Debian Codegraph @

prboom2/src/dsda/hud_components/map_coordinates.c

raw
1 //
2 // Copyright(C) 2023 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 Map Coordinates HUD Component
16 //
17
18 #include "base.h"
19
20 #include "map_coordinates.h"
21
22 typedef struct {
23 dsda_text_t component;
24 } local_component_t;
25
26 static local_component_t* local;
27
28 static void dsda_UpdateComponentText(char* str, size_t max_size) {
29 snprintf(
30 str,
31 max_size,
32 "%sX: %-5d\n"
33 "Y: %-5d\n"
34 "Z: %-5d",
35 dsda_TextColor(dsda_tc_map_coords),
36 (players[displayplayer].mo->x >> FRACBITS),
37 (players[displayplayer].mo->y >> FRACBITS),
38 (players[displayplayer].mo->z >> FRACBITS)
39 );
40 }
41
42 void dsda_InitMapCoordinatesHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
43 *data = Z_Calloc(1, sizeof(local_component_t));
44 local = *data;
45
46 dsda_InitBlockyHC(&local->component, x_offset, y_offset, vpt);
47 }
48
49 void dsda_UpdateMapCoordinatesHC(void* data) {
50 local = data;
51
52 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
53 dsda_RefreshHudText(&local->component);
54 }
55
56 void dsda_DrawMapCoordinatesHC(void* data) {
57 local = data;
58
59 dsda_DrawBasicText(&local->component);
60 }