Mercurial > molko
changeset 133:c46f80820b42
core: revamp debug using theme
While here remove unneeded assets and move there where they belong.
line wrap: on
line diff
--- a/libadventure/CMakeLists.txt Sun Oct 11 14:23:10 2020 +0200 +++ b/libadventure/CMakeLists.txt Sun Oct 11 14:41:31 2020 +0200 @@ -30,6 +30,9 @@ set( ASSETS + ${libadventure_SOURCE_DIR}/adventure/assets/fonts/lato.ttf + ${libadventure_SOURCE_DIR}/adventure/assets/fonts/teutonic.ttf + ${libadventure_SOURCE_DIR}/adventure/assets/fonts/pirata-one.ttf ${libadventure_SOURCE_DIR}/adventure/assets/maps/overworld.map ${libadventure_SOURCE_DIR}/adventure/assets/tilesets/world.png )
--- a/libadventure/adventure/mainmenu_state.c Sun Oct 11 14:23:10 2020 +0200 +++ b/libadventure/adventure/mainmenu_state.c Sun Oct 11 14:41:31 2020 +0200 @@ -32,9 +32,9 @@ #include <core/texture.h> #include <core/window.h> -#include <core/assets/fonts/pirata-one.h> #include <core/assets/sprites/test-walk.h> +#include <adventure/assets/fonts/pirata-one.h> #include <adventure/assets/maps/overworld.h> #include <adventure/assets/tilesets/world.h>
--- a/libadventure/adventure/panic_state.c Sun Oct 11 14:23:10 2020 +0200 +++ b/libadventure/adventure/panic_state.c Sun Oct 11 14:41:31 2020 +0200 @@ -31,7 +31,7 @@ #include <core/window.h> #include <core/map_state.h> -#include <core/assets/fonts/Lato-Regular.h> +#include <adventure/assets/fonts/lato.h> #include "panic_state.h" @@ -222,6 +222,6 @@ * useful information to the screen so as last resort print them * on the console. */ - if (!(font_openmem(&data.font, Lato_Regular, sizeof (Lato_Regular), SIZE))) + if (!(font_openmem(&data.font, lato, sizeof (lato), SIZE))) die("%s", error()); }
--- a/libadventure/adventure/splashscreen_state.c Sun Oct 11 14:23:10 2020 +0200 +++ b/libadventure/adventure/splashscreen_state.c Sun Oct 11 14:41:31 2020 +0200 @@ -28,7 +28,7 @@ #include <core/texture.h> #include <core/window.h> -#include <core/assets/fonts/teutonic1.h> +#include <adventure/assets/fonts/teutonic.h> #include "splashscreen_state.h" #include "mainmenu_state.h" @@ -44,7 +44,7 @@ .color = 0x000000ff }; - if (!(font_openmem(&font, teutonic1, sizeof (teutonic1), 130))) + if (!(font_openmem(&font, teutonic, sizeof (teutonic), 130))) panic(); if (!(font_render(&font, &splashscreen_state_data.text, "Molko's Adventure"))) panic();
--- a/libcore/CMakeLists.txt Sun Oct 11 14:23:10 2020 +0200 +++ b/libcore/CMakeLists.txt Sun Oct 11 14:41:31 2020 +0200 @@ -20,15 +20,10 @@ set( ASSETS + ${libcore_SOURCE_DIR}/core/assets/fonts/comic-neue.ttf + ${libcore_SOURCE_DIR}/core/assets/fonts/f25-bank-printer.ttf ${libcore_SOURCE_DIR}/core/assets/images/message.png ${libcore_SOURCE_DIR}/core/assets/sprites/test-walk.png - ${libcore_SOURCE_DIR}/core/assets/fonts/DejaVuSansCondensed.ttf - ${libcore_SOURCE_DIR}/core/assets/fonts/DejaVuSans.ttf - ${libcore_SOURCE_DIR}/core/assets/fonts/Lato-Regular.ttf - ${libcore_SOURCE_DIR}/core/assets/fonts/ComicNeue-Regular.ttf - ${libcore_SOURCE_DIR}/core/assets/fonts/pirata-one.ttf - ${libcore_SOURCE_DIR}/core/assets/fonts/teutonic1.ttf - ${libcore_SOURCE_DIR}/core/assets/fonts/knights-quest.ttf ) set(
--- a/libcore/core/debug.c Sun Oct 11 14:23:10 2020 +0200 +++ b/libcore/core/debug.c Sun Oct 11 14:41:31 2020 +0200 @@ -28,8 +28,9 @@ #define PADDING_Y 5 struct debug_options debug_options = { - .default_color = 0x0000ffff, - .default_style = FONT_STYLE_ANTIALIASED +#if !defined(NDEBUG) + .enable = true +#endif }; void @@ -38,6 +39,9 @@ assert(report); assert(fmt); + if (!debug_options.enable) + return; + va_list ap; va_start(ap, fmt); @@ -51,16 +55,20 @@ assert(report); assert(fmt); + if (!debug_options.enable) + return; + char line[DEBUG_LINE_MAX]; + struct theme *theme; + struct font *font; struct texture tex; - struct font *font; unsigned int gapy; vsnprintf(line, sizeof (line), fmt, ap); - font = report->font ? report->font : theme_default()->fonts[THEME_FONT_INTERFACE]; + theme = report->theme ? report->theme : theme_default(); + font = theme->fonts[THEME_FONT_DEBUG]; font->color = report->color; - font->style = report->style; if (!font_render(font, &tex, line)) return;
--- a/libcore/core/debug.h Sun Oct 11 14:23:10 2020 +0200 +++ b/libcore/core/debug.h Sun Oct 11 14:41:31 2020 +0200 @@ -70,6 +70,8 @@ */ #define DEBUG_LINE_MAX 1024 +struct theme; + /** * \brief Debugging options. * @@ -77,9 +79,6 @@ * in core API. */ struct debug_options { - struct font *default_font; /*!< (RW) Default font for reports. */ - enum font_style default_style; /*!< (RW) Default font style. */ - unsigned long default_color; /*!< (RW) Default font color. */ bool enable; /*!< (RW) Enable core API debugging. */ }; @@ -89,8 +88,7 @@ * Use this structure each time you need to print one or more messages. */ struct debug_report { - struct font *font; /*!< (RW) Font to use. */ - enum font_style style; /*!< (RW) Font style to use. */ + struct theme *theme; /*!< (RW, ref, optional) Theme to use. */ unsigned long color; /*!< (RW) Font foreground color to use. */ unsigned int count; /*!< (PV) Number of messages already printed. */ };
--- a/libcore/core/map_state.c Sun Oct 11 14:23:10 2020 +0200 +++ b/libcore/core/map_state.c Sun Oct 11 14:41:31 2020 +0200 @@ -324,7 +324,7 @@ static void draw(void) { - struct debug_report report = DEBUG_INIT_DEFAULTS; + struct debug_report report = {0}; map_draw(&map_state_data.map.map, VIEW()->x, VIEW()->y); walksprite_draw(
--- a/libcore/core/theme.c Sun Oct 11 14:23:10 2020 +0200 +++ b/libcore/core/theme.c Sun Oct 11 14:41:31 2020 +0200 @@ -31,7 +31,8 @@ #include "theme.h" #include "util.h" -#include "core/assets/fonts/ComicNeue-Regular.h" +#include <core/assets/fonts/f25-bank-printer.h> +#include <core/assets/fonts/comic-neue.h> #define THEME(t) (t ? t : &default_theme) @@ -39,8 +40,6 @@ #define CHECKBOX_H 16 #define CHECKBOX_RAD 6 -static struct font default_font; - static void box(int x, int y, unsigned int w, unsigned int h) { @@ -175,7 +174,8 @@ struct font **dest; struct font font; } default_fonts[] = { - FONT(ComicNeue_Regular, 20, THEME_FONT_INTERFACE) + FONT(f25_bank_printer, 10, THEME_FONT_DEBUG), + FONT(comic_neue, 20, THEME_FONT_INTERFACE) }; bool
--- a/libcore/core/theme.h Sun Oct 11 14:23:10 2020 +0200 +++ b/libcore/core/theme.h Sun Oct 11 14:41:31 2020 +0200 @@ -36,6 +36,7 @@ * \brief Font component. */ enum theme_font { + THEME_FONT_DEBUG, /*!< Font for debug messages. */ THEME_FONT_INTERFACE, /*!< Font for interface elements. */ THEME_FONT_LAST /*!< Unused. */ }; @@ -44,6 +45,7 @@ * \brief Theme colors. */ enum theme_color { + THEME_COLOR_DEBUG, /*!< Debug color font. */ THEME_COLOR_NORMAL, /*!< Normal font color. */ THEME_COLOR_SELECTED, /*!< Font color for selected elements. */ THEME_COLOR_SHADOW, /*!< Shadow color. */