Mercurial > molko
comparison examples/example-trace/main.c @ 209:23a844fdc911
examples: move all into subdirectories, closes #2513
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 11 Nov 2020 17:10:40 +0100 |
parents | examples/example-trace.c@133926e08d6e |
children | 76afe639fd72 |
comparison
equal
deleted
inserted
replaced
208:c0e0d4accae8 | 209:23a844fdc911 |
---|---|
1 /* | |
2 * example-trace.c -- example on how to use custom trace handlers | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <core/core.h> | |
20 #include <core/event.h> | |
21 #include <core/game.h> | |
22 #include <core/sys.h> | |
23 #include <core/window.h> | |
24 #include <core/painter.h> | |
25 #include <core/panic.h> | |
26 #include <core/state.h> | |
27 #include <core/trace.h> | |
28 #include <core/util.h> | |
29 | |
30 #include <ui/theme.h> | |
31 #include <ui/ui.h> | |
32 | |
33 #include <adventure/trace_hud.h> | |
34 | |
35 #define W 1280 | |
36 #define H 720 | |
37 | |
38 static void | |
39 init(void) | |
40 { | |
41 if (!core_init() || !ui_init()) | |
42 panic(); | |
43 if (!window_open("Example - Trace", W, H)) | |
44 panic(); | |
45 | |
46 trace_handler = trace_hud_handler; | |
47 } | |
48 | |
49 static void | |
50 handle(struct state *st, const union event *ev) | |
51 { | |
52 (void)st; | |
53 | |
54 switch (ev->type) { | |
55 case EVENT_KEYDOWN: | |
56 switch (ev->key.key) { | |
57 case KEY_ESCAPE: | |
58 trace_hud_clear(); | |
59 break; | |
60 default: | |
61 tracef("keydown pressed: %d", ev->key.key); | |
62 break; | |
63 } | |
64 break; | |
65 case EVENT_CLICKDOWN: | |
66 tracef("click at %d,%d", ev->click.x, ev->click.y); | |
67 break; | |
68 case EVENT_QUIT: | |
69 game_quit(); | |
70 break; | |
71 default: | |
72 break; | |
73 } | |
74 } | |
75 | |
76 static void | |
77 update(struct state *st, unsigned int ticks) | |
78 { | |
79 (void)st; | |
80 | |
81 trace_hud_update(ticks); | |
82 } | |
83 | |
84 static void | |
85 draw(struct state *st) | |
86 { | |
87 (void)st; | |
88 | |
89 painter_set_color(0x4f8fbaff); | |
90 painter_clear(); | |
91 trace_hud_draw(); | |
92 painter_present(); | |
93 } | |
94 | |
95 static void | |
96 run(void) | |
97 { | |
98 struct state state = { | |
99 .handle = handle, | |
100 .update = update, | |
101 .draw = draw | |
102 }; | |
103 | |
104 game_switch(&state, true); | |
105 game_loop(); | |
106 } | |
107 | |
108 static void | |
109 quit(void) | |
110 { | |
111 window_finish(); | |
112 ui_finish(); | |
113 core_finish(); | |
114 } | |
115 | |
116 int | |
117 main(int argc, char **argv) | |
118 { | |
119 (void)argc; | |
120 (void)argv; | |
121 | |
122 init(); | |
123 run(); | |
124 quit(); | |
125 } | |
126 |