comparison examples/example-debug/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-debug.c@133926e08d6e
children 76afe639fd72
comparison
equal deleted inserted replaced
208:c0e0d4accae8 209:23a844fdc911
1 /*
2 * example-debug.c -- example on how to use debug interface
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/window.h>
23 #include <core/painter.h>
24 #include <core/panic.h>
25 #include <core/state.h>
26 #include <core/util.h>
27
28 #include <ui/debug.h>
29 #include <ui/theme.h>
30 #include <ui/ui.h>
31
32 #define W 1280
33 #define H 720
34
35 static int mouse_x;
36 static int mouse_y;
37
38 static void
39 init(void)
40 {
41 if (!core_init() || !ui_init())
42 panic();
43 if (!window_open("Example - Debug", W, H))
44 panic();
45
46 debug_options.enable = true;
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_MOUSE:
56 mouse_x = ev->mouse.x;
57 mouse_y = ev->mouse.y;
58 break;
59 case EVENT_QUIT:
60 game_quit();
61 break;
62 default:
63 break;
64 }
65 }
66
67 static void
68 draw(struct state *st)
69 {
70 (void)st;
71
72 struct debug_report report = {0};
73
74 painter_set_color(0x4f8fbaff);
75 painter_clear();
76 debugf(&report, "Game running.");
77 debugf(&report, "mouse: %d, %d", mouse_x, mouse_y);
78 painter_present();
79 }
80
81 static void
82 run(void)
83 {
84 struct state state = {
85 .handle = handle,
86 .draw = draw
87 };
88
89 game_switch(&state, true);
90 game_loop();
91 }
92
93 static void
94 quit(void)
95 {
96 window_finish();
97 ui_finish();
98 core_finish();
99 }
100
101 int
102 main(int argc, char **argv)
103 {
104 (void)argc;
105 (void)argv;
106
107 init();
108 run();
109 quit();
110 }
111