Skip to content

Commit

Permalink
Proper handling of UTF-8
Browse files Browse the repository at this point in the history
Note: This commit may be slightly broken, I'm just splitting up it and the next one at the end.
  • Loading branch information
Epicpkmn11 authored and d0k3 committed Nov 14, 2021
1 parent 55385a5 commit 13eb4f8
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 82 deletions.
4 changes: 2 additions & 2 deletions arm9/source/common/swkbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void DrawKey(const TouchBox* key, const bool pressed, const u32 uppercase
const u32 f_offs_y = (key->h - FONT_HEIGHT_EXT) / 2;

DrawRectangle(BOT_SCREEN, key->x, key->y, key->w, key->h, color);
DrawString(BOT_SCREEN, keystr, key->x + f_offs_x, key->y + f_offs_y, COLOR_SWKBD_CHARS, color, false);
DrawString(BOT_SCREEN, keystr, key->x + f_offs_x, key->y + f_offs_y, COLOR_SWKBD_CHARS, color);
}

static void DrawKeyBoardBox(TouchBox* swkbd, u32 color) {
Expand Down Expand Up @@ -227,7 +227,7 @@ bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
TouchBox* textbox = swkbd_alphabet; // always use this textbox

static bool show_instr = true;
static const char* instr = "Keyboard Controls:\n \n\x1B/\x1A - Move cursor\nR - Caps / Capslock\nX - Delete char\nY - Insert char\nA - Submit\nB - Cancel\n \nSELECT switches to\nclassic prompt";
static const char* instr = "Keyboard Controls:\n \n←/→ - Move cursor\nR - Caps / Capslock\nX - Delete char\nY - Insert char\nA - Submit\nB - Cancel\n \nSELECT switches to\nclassic prompt";
if (show_instr) {
ShowPrompt(false, instr);
show_instr = false;
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/common/swkbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum {
};

// special key strings
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "\x1b", "\x1a", "ESC", "SWITCH"
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "", "", "ESC", "SWITCH"

#define COLOR_SWKBD_NORMAL COLOR_GREY
#define COLOR_SWKBD_PRESSED COLOR_LIGHTGREY
Expand Down
8 changes: 4 additions & 4 deletions arm9/source/common/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void DrawRectangle(u16 *screen, int x, int y, u32 width, u32 height, u32 color);
void DrawBitmap(u16 *screen, int x, int y, u32 w, u32 h, const u16* bitmap);
void DrawQrCode(u16 *screen, const u8* qrcode);

void DrawCharacter(u16 *screen, int character, int x, int y, u32 color, u32 bgcolor);
void DrawString(u16 *screen, const char *str, int x, int y, u32 color, u32 bgcolor, bool fix_utf8);
void DrawCharacter(u16 *screen, u32 character, int x, int y, u32 color, u32 bgcolor);
void DrawString(u16 *screen, const char *str, int x, int y, u32 color, u32 bgcolor);
void DrawStringF(u16 *screen, int x, int y, u32 color, u32 bgcolor, const char *format, ...);
void DrawStringCenter(u16 *screen, u32 color, u32 bgcolor, const char *format, ...);

Expand All @@ -69,8 +69,8 @@ u32 GetFontHeight(void);

void MultiLineString(char* dest, const char* orig, int llen, int maxl);
void WordWrapString(char* str, int llen);
void ResizeString(char* dest, const char* orig, int nsize, int tpos, bool align_right);
void TruncateString(char* dest, const char* orig, int nsize, int tpos);
void ResizeString(char* dest, const char* orig, int nlength, int tpos, bool align_right);
void TruncateString(char* dest, const char* orig, int nlength, int tpos);
void FormatNumber(char* str, u64 number);
void FormatBytes(char* str, u64 bytes);

Expand Down
2 changes: 1 addition & 1 deletion arm9/source/filesys/fsgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool GoodRenamer(DirEntry* entry, bool ask) {
return false;

if (ask) { // ask for confirmatiom
char oldname_tr[32+1];
char oldname_tr[32 * 4 + 1];
char newname_ww[256];
TruncateString(oldname_tr, entry->name, 32, 8);
strncpy(newname_ww, goodname, 256);
Expand Down
14 changes: 7 additions & 7 deletions arm9/source/filesys/fsutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool FileUnlock(const char* path) {

if (!(DriveType(path) & DRV_FAT)) return true; // can't really check this
if ((res = fx_open(&file, path, FA_READ | FA_OPEN_EXISTING)) != FR_OK) {
char pathstr[32 + 1];
char pathstr[32 * 4 + 1];
TruncateString(pathstr, path, 32, 8);
if (GetMountState() && (res == FR_LOCKED) &&
(ShowPrompt(true, "%s\nFile is currently mounted.\nUnmount to unlock?", pathstr))) {
Expand Down Expand Up @@ -461,7 +461,7 @@ bool PathMoveCopyRec(char* dest, char* orig, u32* flags, bool move, u8* buffer,
if (move && (to_virtual || fno.fattrib & AM_VRT)) return false; // trying to move a virtual file

// path string (for output)
char deststr[36 + 1];
char deststr[36 * 4 + 1];
TruncateString(deststr, dest, 36, 8);

// the copy process takes place here
Expand Down Expand Up @@ -609,7 +609,7 @@ bool PathMoveCopy(const char* dest, const char* orig, u32* flags, bool move) {
char lorig[256];
strncpy(ldest, dest, 256);
strncpy(lorig, orig, 256);
char deststr[36 + 1];
char deststr[36 * 4 + 1];
TruncateString(deststr, ldest, 36, 8);

// moving only for regular FAT drives (= not alias drives)
Expand Down Expand Up @@ -749,8 +749,8 @@ bool PathCopy(const char* destdir, const char* orig, u32* flags) {
return false;
snprintf(dest, 255, "%s/%s", destdir, dvfile.name);
} else if (osize < dvfile.size) { // if origin is smaller than destination...
char deststr[36 + 1];
char origstr[36 + 1];
char deststr[36 * 4 + 1];
char origstr[36 * 4 + 1];
char osizestr[32];
char dsizestr[32];
TruncateString(deststr, dest, 36, 8);
Expand Down Expand Up @@ -822,7 +822,7 @@ bool FileSelectorWorker(char* result, const char* text, const char* path, const
GetDirContents(contents, path_local);

while (pos < contents->n_entries) {
char opt_names[_MAX_FS_OPT+1][32+1];
char opt_names[_MAX_FS_OPT+1][32 * 4 + 1];
DirEntry* res_entry[MAX_DIR_ENTRIES+1] = { NULL };
u32 n_opt = 0;
for (; pos < contents->n_entries; pos++) {
Expand Down Expand Up @@ -872,7 +872,7 @@ bool FileSelectorWorker(char* result, const char* text, const char* path, const
}
}
if (!n_found) { // not a single matching entry found
char pathstr[32+1];
char pathstr[32 * 4 + 1];
TruncateString(pathstr, path_local, 32, 8);
ShowPrompt(false, "%s\nNo usable entries found.", pathstr);
return false;
Expand Down
Loading

0 comments on commit 13eb4f8

Please sign in to comment.