diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index d5399647..46d64ef7 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -3465,7 +3465,10 @@ FONT_HUD = 2 FONT_TINY = 3 --- @type DjuiFontType -FONT_COUNT = 4 +FONT_ALIASED = 4 + +--- @type DjuiFontType +FONT_COUNT = 5 --- @class HudUtilsFilter diff --git a/bin/custom_font.c b/bin/custom_font.c index 120af938..f4e2afce 100644 --- a/bin/custom_font.c +++ b/bin/custom_font.c @@ -49,3 +49,26 @@ const f32 font_title_widths[] = { }; ////////////////////////////////////////////////////////// + +ALIGNED8 const u8 texture_font_aliased[] = { +#include "textures/custom_font/custom_font_aliased.rgba32.inc.c" +}; + +const f32 font_aliased_widths[] = { +/* ! " # $ % & ' ( ) * + , - . / */ + 7, 12, 14, 12, 14, 16, 8, 10, 10, 12, 14, 8, 12, 8, 10, +/* 0 1 2 3 4 5 6 7 8 9 */ + 14, 12, 13, 14, 14, 14, 14, 13, 14, 14, +/* : ; < = > ? @ */ + 6, 8, 10, 12, 10, 11, 18, +/* A B C D E F G H I J K L M N O P Q R S T U V W X Y Z */ + 12, 12, 12, 12, 11, 10, 12, 12, 9, 12, 12, 10, 16, 16, 12, 11, 12, 12, 12, 10, 12, 10, 16, 14, 12, 12, +/* [ \ ] ^ _ ` */ + 10, 10, 10, 12, 12, 8, +/* a b c d e f g h i j k l m n o p q r s t u v w x y z */ + 10, 10, 10, 10, 9, 8, 12, 10, 7, 9, 10, 4, 13, 10, 9, 9, 10, 9, 10, 9, 10, 9, 14, 12, 10, 10, +/* { | } ~ DEL */ + 10, 8, 10, 16, 10, +}; + +////////////////////////////////////////////////////////// diff --git a/docs/lua/constants.md b/docs/lua/constants.md index e5406a27..09b377ff 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -1170,7 +1170,8 @@ | FONT_MENU | 1 | | FONT_HUD | 2 | | FONT_TINY | 3 | -| FONT_COUNT | 4 | +| FONT_ALIASED | 4 | +| FONT_COUNT | 5 | ### [enum HudUtilsFilter](#HudUtilsFilter) | Identifier | Value | diff --git a/src/pc/djui/djui_font.c b/src/pc/djui/djui_font.c index 6b75896c..18000524 100644 --- a/src/pc/djui/djui_font.c +++ b/src/pc/djui/djui_font.c @@ -147,6 +147,38 @@ static const struct DjuiFont sDjuiFontTiny = { .char_width = djui_font_normal_char_width, }; + //////////////////////////////// + // font 5 (DJ's aliased font) // +//////////////////////////////// + +static void djui_font_aliased_render_char(char* c) { + // replace undisplayable characters + if (*c == ' ') { return; } + + u32 index = djui_unicode_get_sprite_index(c); + u32 tx = index % 32; + u32 ty = index / 32; + + extern ALIGNED8 const u8 texture_font_aliased[]; + djui_gfx_render_texture_tile(texture_font_aliased, 512, 256, 32, tx * 16, ty * 32, 16, 32, false); +} + +static f32 djui_font_aliased_char_width(char* c) { + if (*c == ' ') { return 6 / 32.0f; } + extern const f32 font_aliased_widths[]; + return djui_unicode_get_sprite_width(c, font_aliased_widths) / 32.0f; +} + +static const struct DjuiFont sDjuiFontAliased = { + .charWidth = 0.5f, + .charHeight = 1.0f, + .lineHeight = 0.8125f, + .defaultFontScale = 32.0f, + .textBeginDisplayList = NULL, + .render_char = djui_font_aliased_render_char, + .char_width = djui_font_aliased_char_width, +}; + /////////////// // font list // /////////////// @@ -156,4 +188,5 @@ const struct DjuiFont* gDjuiFonts[] = { &sDjuiFontTitle, &sDjuiFontHud, &sDjuiFontTiny, + &sDjuiFontAliased }; \ No newline at end of file diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h index e81ddce4..60403e00 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -18,6 +18,7 @@ enum DjuiFontType { FONT_MENU, FONT_HUD, FONT_TINY, + FONT_ALIASED, FONT_COUNT, }; diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 1e29b1c4..902e3d83 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1372,7 +1372,8 @@ char gSmluaConstants[] = "" "FONT_MENU = 1\n" "FONT_HUD = 2\n" "FONT_TINY = 3\n" -"FONT_COUNT = 4\n" +"FONT_ALIASED = 4\n" +"FONT_COUNT = 5\n" "ENVFX_MODE_NONE = 0\n" "ENVFX_SNOW_NORMAL = 1\n" "ENVFX_SNOW_WATER = 2\n" diff --git a/textures/custom_font/custom_font_aliased.rgba32.png b/textures/custom_font/custom_font_aliased.rgba32.png new file mode 100644 index 00000000..fa02a747 Binary files /dev/null and b/textures/custom_font/custom_font_aliased.rgba32.png differ