comparison libmlk-ui/ui/debug.c @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents libui/ui/debug.c@6992085d47fd
children 196264679079
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * debug.c -- 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 #include <assert.h>
20 #include <stdio.h>
21
22 #include <core/texture.h>
23
24 #include "debug.h"
25 #include "theme.h"
26
27 struct debug_options debug_options = {
28 #if !defined(NDEBUG)
29 .enable = true
30 #endif
31 };
32
33 void
34 debugf(struct debug_report *report, const char *fmt, ...)
35 {
36 assert(report);
37 assert(fmt);
38
39 if (!debug_options.enable)
40 return;
41
42 va_list ap;
43
44 va_start(ap, fmt);
45 vdebugf(report, fmt, ap);
46 va_end(ap);
47 }
48
49 void
50 vdebugf(struct debug_report *report, const char *fmt, va_list ap)
51 {
52 assert(report);
53 assert(fmt);
54
55 if (!debug_options.enable)
56 return;
57
58 char line[DEBUG_LINE_MAX];
59 const struct theme *theme;
60 struct font *font;
61 struct texture tex;
62 int x, y;
63
64 vsnprintf(line, sizeof (line), fmt, ap);
65
66 theme = report->theme ? report->theme : theme_default();
67 font = theme->fonts[THEME_FONT_DEBUG];
68
69 if (!font_render(font, &tex, line, theme->colors[THEME_COLOR_DEBUG]))
70 return;
71
72 x = theme->padding;
73 y = (theme->padding * (report->count + 1)) + (tex.h * (report->count));
74 report->count++;
75
76 texture_draw(&tex, x, y);
77 texture_finish(&tex);
78 }