diff --git a/bin/segment2.c b/bin/segment2.c index 7592a7a5..de8ae9fd 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -3591,14 +3591,73 @@ ALIGNED8 static const u8 texture_font_normal_char_93[] = { #include "textures/segment2/custom_font_normal_char_93.ia4.inc.c" }; +// spanish + +ALIGNED8 static const u8 texture_font_normal_char_sa[] = { +#include "textures/segment2/custom_font_normal_char_sa.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_se[] = { +#include "textures/segment2/custom_font_normal_char_se.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_si[] = { +#include "textures/segment2/custom_font_normal_char_si.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_so[] = { +#include "textures/segment2/custom_font_normal_char_so.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_su[] = { +#include "textures/segment2/custom_font_normal_char_su.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_su2[] = { +#include "textures/segment2/custom_font_normal_char_su2.ia4.inc.c" +}; + ALIGNED8 static const u8 texture_font_normal_char_sn[] = { #include "textures/segment2/custom_font_normal_char_sn.ia4.inc.c" }; +ALIGNED8 static const u8 texture_font_normal_char_sca[] = { +#include "textures/segment2/custom_font_normal_char_sca.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_sce[] = { +#include "textures/segment2/custom_font_normal_char_sce.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_sci[] = { +#include "textures/segment2/custom_font_normal_char_sci.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_sco[] = { +#include "textures/segment2/custom_font_normal_char_sco.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_scu[] = { +#include "textures/segment2/custom_font_normal_char_scu.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_scu2[] = { +#include "textures/segment2/custom_font_normal_char_scu2.ia4.inc.c" +}; + ALIGNED8 static const u8 texture_font_normal_char_scn[] = { #include "textures/segment2/custom_font_normal_char_scn.ia4.inc.c" }; +ALIGNED8 static const u8 texture_font_normal_char_sex[] = { +#include "textures/segment2/custom_font_normal_char_sex.ia4.inc.c" +}; + +ALIGNED8 static const u8 texture_font_normal_char_squ[] = { +#include "textures/segment2/custom_font_normal_char_squ.ia4.inc.c" +}; + + const u8* const font_normal_chars[] = { texture_font_char_us_exclamation, // ! texture_font_char_us_double_quote_open, // " @@ -3695,8 +3754,24 @@ const u8* const font_normal_chars[] = { texture_font_normal_char_93, // } texture_font_char_us_tilde, // ~ texture_font_char_us_star_filled, // DEL + + texture_font_normal_char_sa, // á + texture_font_normal_char_se, // é + texture_font_normal_char_si, // í + texture_font_normal_char_so, // ó + texture_font_normal_char_su, // ú + texture_font_normal_char_su2, // ü texture_font_normal_char_sn, // ñ + texture_font_normal_char_sca, // Á + texture_font_normal_char_sce, // É + texture_font_normal_char_sci, // Í + texture_font_normal_char_sco, // Ó + texture_font_normal_char_scu, // Ú + texture_font_normal_char_scu2, // Ü texture_font_normal_char_scn, // Ñ + texture_font_normal_char_sex, // ¡ + texture_font_normal_char_squ, // ¿ + }; const f32 font_normal_widths[] = { @@ -3714,8 +3789,13 @@ const f32 font_normal_widths[] = { 0.3750f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.2500f, 0.3125f, 0.3125f, 0.1875f, 0.4375f, 0.3125f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, 0.4375f, 0.4375f, 0.3125f, 0.3125f, /* { | } ~ DEL */ 0.3125f, 0.2500f, 0.3125f, 0.5000f, 0.5000f, -/* ñ Ñ */ - 0.3125f, 0.5000f, + +/* á é í ó ú ü ñ */ + 0.3750f, 0.3125f, 0.2500f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, +/* Á É Í Ó Ú Ü Ñ */ + 0.3750f, 0.3750f, 0.3125f, 0.3750f, 0.3750f, 0.3750f, 0.5000f, +/* ¡ ¿ */ + 0.3125f, 0.4375f, }; diff --git a/src/pc/djui/djui_font.c b/src/pc/djui/djui_font.c index a11d6d30..68353e88 100644 --- a/src/pc/djui/djui_font.c +++ b/src/pc/djui/djui_font.c @@ -1,6 +1,66 @@ #include "djui.h" #include "game/segment2.h" +struct SmCodeGlyph { + s8 unicode1; + s8 unicode2; + u8 smcode; +}; + +struct SmCodeGlyph sSmCodeGlyphs[] = { + { -61, -95, 128 }, // á + { -61, -87, 129 }, // é + { -61, -83, 130 }, // í + { -61, -77, 131 }, // ó + { -61, -70, 132 }, // ú + { -61, -68, 133 }, // ü + { -61, -79, 134 }, // ñ + { -61, -127, 135 }, // Á + { -61, -119, 136 }, // É + { -61, -115, 137 }, // Í + { -61, -109, 138 }, // Ó + { -61, -102, 139 }, // Ú + { -61, -100, 140 }, // Ü + { -61, -111, 141 }, // Ñ + { -62, -95, 142 }, // ¡ + { -62, -65, 143 }, // ¿ +}; + +void djui_font_convert_to_smcode(char* text) { + size_t glyphCount = sizeof(sSmCodeGlyphs) / sizeof(sSmCodeGlyphs[0]); + + char* t = text; + while (*t != '\0') { + for (size_t i = 0; i < glyphCount; i++) { + struct SmCodeGlyph* glyph = &sSmCodeGlyphs[i]; + if (t[0] == glyph->unicode1 && t[1] == glyph->unicode2) { + // consume down to one character + char* t2 = t; + while (*t2 != '\0') { t2[0] = t2[1]; t2++; } + // replace + t[0] = (s8)glyph->smcode; + } + } + t++; + } +} + +bool djui_font_valid_smcode(char c) { + if (c >= '!' && c <= '~') { + return true; + } else if (c == ' ') { + return true; + } + + size_t glyphCount = sizeof(sSmCodeGlyphs) / sizeof(sSmCodeGlyphs[0]); + for (size_t i = 0; i < glyphCount; i++) { + struct SmCodeGlyph* glyph = &sSmCodeGlyphs[i]; + if ((u8)c == glyph->smcode) { return true; } + } + + return false; +} + /////////////////////////////////// // font 0 (built-in normal font) // /////////////////////////////////// @@ -35,7 +95,8 @@ const Gfx dl_font_normal_display_list[] = { static void djui_font_normal_render_char(char c) { extern const u8* const font_normal_chars[]; // replace undisplayable characters - if ((u8)c < ' ' || (u8)c > ('~' + 3)) { c = '?'; } + //if ((u8)c < ' ' || (u8)c > ('~' + 3)) { c = '?'; } + if (!djui_font_valid_smcode(c)) { c = '?'; } if (c == ' ') { return; } void* fontChar = (void*)font_normal_chars[(u8)c - '!']; if (fontChar == NULL) { fontChar = (void*)font_normal_chars[94]; } diff --git a/src/pc/djui/djui_font.h b/src/pc/djui/djui_font.h index 685a6729..2531789d 100644 --- a/src/pc/djui/djui_font.h +++ b/src/pc/djui/djui_font.h @@ -1,12 +1,6 @@ #pragma once #include "djui.h" -#define SPANISH_UNICODE_START -61 -#define SPANISH_UNICODE_LOWER_N -79 // ñ -#define SPANISH_UNICODE_UPPER_N -111 // Ñ -#define SPANISH_SMCODE_LOWER_N ((s8)('~' + 2)) -#define SPANISH_SMCODE_UPPER_N ((s8)('~' + 3)) - struct DjuiFont { f32 charWidth; f32 charHeight; @@ -19,4 +13,7 @@ struct DjuiFont { f32 (*char_width)(char); }; -extern const struct DjuiFont* gDjuiFonts[]; \ No newline at end of file +extern const struct DjuiFont* gDjuiFonts[]; + +void djui_font_convert_to_smcode(char* text); +bool djui_font_valid_smcode(char c); diff --git a/src/pc/djui/djui_inputbox.c b/src/pc/djui/djui_inputbox.c index 3f960769..c2cbd8b7 100644 --- a/src/pc/djui/djui_inputbox.c +++ b/src/pc/djui/djui_inputbox.c @@ -291,55 +291,19 @@ static void djui_inputbox_on_focus_end(UNUSED struct DjuiBase* base) { wm_api->stop_text_input(); } -#define SPANISH_UNICODE_START -61 -#define SPANISH_UNICODE_LOWER_N -79 // ñ -#define SPANISH_UNICODE_UPPER_N -111 // Ñ -#define SPANISH_SMCODE_LOWER_N ((s8)('~' + 2)) -#define SPANISH_SMCODE_UPPER_N ((s8)('~' + 3)) - static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) { struct DjuiInputbox *inputbox = (struct DjuiInputbox *) base; char* msg = inputbox->buffer; int msgLen = strlen(msg); int textLen = strlen(text); - // special case ñ and Ñ - char* tinput = text; - while (*tinput != '\0') { - if (tinput[0] == SPANISH_UNICODE_START) { - if ((tinput[1] == SPANISH_UNICODE_LOWER_N || tinput[1] == SPANISH_UNICODE_UPPER_N)) { - // consume SPANISH_UNICODE_START - char* t2 = tinput; - while (*t2 != '\0') { - t2[0] = t2[1]; - t2++; - } - - // translate - if (tinput[0] == SPANISH_UNICODE_LOWER_N) { - tinput[0] = SPANISH_SMCODE_LOWER_N; - } else if (tinput[0] == SPANISH_UNICODE_UPPER_N) { - tinput[0] = SPANISH_SMCODE_UPPER_N; - } - } - } - tinput++; - } + djui_font_convert_to_smcode(text); // make sure we're not just printing garbage characters bool containsValidAscii = false; - tinput = text; + char* tinput = text; while (*tinput != '\0') { - if (*tinput >= '!' && *tinput <= '~') { - containsValidAscii = true; - break; - } else if (*tinput == ' ') { - containsValidAscii = true; - break; - } else if (*tinput == SPANISH_SMCODE_LOWER_N) { - containsValidAscii = true; - break; - } else if (*tinput == SPANISH_SMCODE_UPPER_N) { + if (djui_font_valid_smcode(*tinput)) { containsValidAscii = true; break; } @@ -367,9 +331,7 @@ static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) { while (*t != '\0') { if (*t == '\n') { *t = ' '; } else if (*t == '\r') { *t = ' '; } - else if (*t == ' ') { ; } - else if (*t == SPANISH_SMCODE_LOWER_N) { ; } - else if (*t == SPANISH_SMCODE_UPPER_N) { ; } + else if (djui_font_valid_smcode(*t)) { ; } else if (*t < '!' || *t > '~') { *t = '?'; } t++; } diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 42eaa64a..a75b9b18 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -100,6 +100,7 @@ static void gfx_sdl_reset_dimension_and_pos(void) { static void gfx_sdl_init(const char *window_title) { SDL_Init(SDL_INIT_VIDEO); + SDL_StartTextInput(); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); @@ -163,7 +164,6 @@ static void gfx_sdl_onkeyup(int scancode) { } static void gfx_sdl_handle_events(void) { - SDL_StartTextInput(); SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { diff --git a/textures/segment2/custom_font_normal_char_sa.ia4.png b/textures/segment2/custom_font_normal_char_sa.ia4.png new file mode 100644 index 00000000..075c747f Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sa.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_sca.ia4.png b/textures/segment2/custom_font_normal_char_sca.ia4.png new file mode 100644 index 00000000..fc72fb92 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sca.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_sce.ia4.png b/textures/segment2/custom_font_normal_char_sce.ia4.png new file mode 100644 index 00000000..7bf393ef Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sce.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_sci.ia4.png b/textures/segment2/custom_font_normal_char_sci.ia4.png new file mode 100644 index 00000000..fba95b28 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sci.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_sco.ia4.png b/textures/segment2/custom_font_normal_char_sco.ia4.png new file mode 100644 index 00000000..70eb755d Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sco.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_scu.ia4.png b/textures/segment2/custom_font_normal_char_scu.ia4.png new file mode 100644 index 00000000..3a0f6b6e Binary files /dev/null and b/textures/segment2/custom_font_normal_char_scu.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_scu2.ia4.png b/textures/segment2/custom_font_normal_char_scu2.ia4.png new file mode 100644 index 00000000..d2cf65f7 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_scu2.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_se.ia4.png b/textures/segment2/custom_font_normal_char_se.ia4.png new file mode 100644 index 00000000..91628110 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_se.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_sex.ia4.png b/textures/segment2/custom_font_normal_char_sex.ia4.png new file mode 100644 index 00000000..b8d7af11 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sex.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_sex.ia4.png~ b/textures/segment2/custom_font_normal_char_sex.ia4.png~ new file mode 100644 index 00000000..0df0de62 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_sex.ia4.png~ differ diff --git a/textures/segment2/custom_font_normal_char_si.ia4.png b/textures/segment2/custom_font_normal_char_si.ia4.png new file mode 100644 index 00000000..dc9a5448 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_si.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_so.ia4.png b/textures/segment2/custom_font_normal_char_so.ia4.png new file mode 100644 index 00000000..68e0e525 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_so.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_squ.ia4.png b/textures/segment2/custom_font_normal_char_squ.ia4.png new file mode 100644 index 00000000..028c6113 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_squ.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_squ.ia4.png~ b/textures/segment2/custom_font_normal_char_squ.ia4.png~ new file mode 100644 index 00000000..183ba19f Binary files /dev/null and b/textures/segment2/custom_font_normal_char_squ.ia4.png~ differ diff --git a/textures/segment2/custom_font_normal_char_su.ia4.png b/textures/segment2/custom_font_normal_char_su.ia4.png new file mode 100644 index 00000000..96db79a6 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_su.ia4.png differ diff --git a/textures/segment2/custom_font_normal_char_su2.ia4.png b/textures/segment2/custom_font_normal_char_su2.ia4.png new file mode 100644 index 00000000..f86c6427 Binary files /dev/null and b/textures/segment2/custom_font_normal_char_su2.ia4.png differ