comparison libui/ui/debug.h @ 148:c577c15df07f

misc: split libraries, closes #2496
author David Demelier <markand@malikania.fr>
date Thu, 15 Oct 2020 10:32:18 +0200
parents libcore/core/debug.h@b386d25832c8
children 2252f9efac9a
comparison
equal deleted inserted replaced
147:b386d25832c8 148:c577c15df07f
1 /*
2 * debug.h -- debugging interfaces
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 #ifndef MOLKO_DEBUG_H
20 #define MOLKO_DEBUG_H
21
22 /**
23 * \file debug.h
24 * \brief Debugging interfaces.
25 *
26 * This module provides functions to draw debugging information within the game
27 * window. It is mostly used for information only when state of the game is
28 * better inspected via direct window information rather than writing in the
29 * console.
30 *
31 * Predefined core states may print debugging information if
32 * debug_options.enabled variable is set to true. However, you need to specify
33 * the font to use in order to work.
34 *
35 * Each call to \ref debug_printf or \ref debug_vprintf automatically adjust
36 * next coordinate for rendering the text. As such, user may simply print
37 * several lines of text without having to deal with that manually.
38 *
39 * Example, activate global debugging.
40 *
41 * \code
42 * struct font *f = font_openf("foo.ttf", 10);
43 *
44 * if (!f)
45 * error_fatal();
46 *
47 * debug_options.default_font = f;
48 * debug_options.enabled = true;
49 * \endcode
50 *
51 * Example, print debugging information manually.
52 *
53 * \code
54 * struct debug_report report = {
55 * .color = 0x00ff00ff,
56 * .font = myfont // Optional if debug_options.default_font is set.
57 * };
58 *
59 * debug_printf("current position: %d, %d\n", x, y);
60 * \endcode
61 */
62
63 #include <stdbool.h>
64 #include <stdarg.h>
65
66 #include <core/font.h>
67
68 /**
69 * Maximum content length per report.
70 */
71 #define DEBUG_LINE_MAX 1024
72
73 struct theme;
74
75 /**
76 * \brief Debugging options.
77 *
78 * Fill this structure with appropriate values to change debugging behavior
79 * in core API.
80 */
81 struct debug_options {
82 bool enable; /*!< (+) Enable core API debugging. */
83 };
84
85 /**
86 * \brief Debug context.
87 *
88 * Use this structure each time you need to print one or more messages.
89 */
90 struct debug_report {
91 struct theme *theme; /*!< (+&?) Theme to use. */
92 unsigned long color; /*!< (+) Font foreground color to use. */
93 unsigned int count; /*!< (-) Number of messages already printed. */
94 };
95
96 /**
97 * Global debugging options.
98 */
99 extern struct debug_options debug_options;
100
101 /**
102 * Convenient macro to initialize \ref debug_report with default values.
103 */
104 #define DEBUG_INIT_DEFAULTS { \
105 .font = debug_options.default_font, \
106 .color = debug_options.default_color, \
107 .style = debug_options.default_style \
108 }
109
110 /**
111 * Print debugging information into the screen.
112 *
113 * \pre report != NULL
114 * \pre fmt != NULL
115 * \param report the reporting context
116 * \param fmt the printf(3) format string
117 * \note The message length must not exceed DEBUG_LINE_MAX, otherwise its
118 * result is truncated.
119 */
120 void
121 debug_printf(struct debug_report *report, const char *fmt, ...);
122
123 /**
124 * Similar to \ref debug_printf but with a va_list object.
125 *
126 * \see \ref debug_printf
127 */
128 void
129 debug_vprintf(struct debug_report *report, const char *fmt, va_list ap);
130
131 #endif /* !MOLKO_DEBUG_H */