Skip to content

Commit

Permalink
Adding clipboard select/cut/copy/paste support.
Browse files Browse the repository at this point in the history
  • Loading branch information
nevumx committed Jul 4, 2024
1 parent ab681aa commit d6fe058
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 41 deletions.
12 changes: 6 additions & 6 deletions arm9/source/common/swkbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static char KeyboardWait(TouchBox* swkbd, bool uppercase, const bool multi_line)
else if (pressed & BUTTON_B) return KEY_ESCAPE;
else if (pressed & BUTTON_A) return KEY_ENTER;
else if (pressed & BUTTON_X) return KEY_BKSPC;
else if (pressed & BUTTON_Y) return multi_line ? KEY_CAPS : KEY_INSERT;
else if (pressed & BUTTON_Y) return multi_line ? KEY_CLIP : KEY_INSERT;
else if (!multi_line && pressed & BUTTON_R1) return KEY_CAPS;
else if (pressed & BUTTON_RIGHT) return KEY_RIGHT;
else if (pressed & BUTTON_LEFT) return KEY_LEFT;
Expand Down Expand Up @@ -392,14 +392,14 @@ bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
return ret;
}

char ShowMultiLineKeyboard(TouchBox* swkbd_alphabet, TouchBox* swkbd_special, TouchBox* swkbd_numpad, TouchBox** swkbd, TouchBox** swkbd_prev, u32* uppercase) {
if (!*swkbd) {
u32 str_width = GetDrawStringWidth(STR_TEXTEDITOR_CONTROLS_KEYBOARD);
char ShowMultiLineKeyboard(const char* instructions, TouchBox* swkbd_alphabet, TouchBox* swkbd_special, TouchBox* swkbd_numpad, TouchBox** swkbd, TouchBox** swkbd_prev, u32* uppercase) {
if (instructions) {
u32 str_width = GetDrawStringWidth(instructions);
if (str_width < (24 * FONT_WIDTH_EXT)) str_width = 24 * FONT_WIDTH_EXT;
u32 str_x = (str_width >= SCREEN_WIDTH_BOT) ? 0 : (SCREEN_WIDTH_BOT - str_width) / 2;
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
DrawStringF(BOT_SCREEN, str_x, 20, COLOR_STD_FONT, COLOR_STD_BG, "%s", STR_TEXTEDITOR_CONTROLS_KEYBOARD);
*swkbd = swkbd_alphabet;
DrawStringF(BOT_SCREEN, str_x, 20, COLOR_STD_FONT, COLOR_STD_BG, "%s", instructions);
*swkbd_prev = NULL; // Force keyboard redraw
}

// handle keyboard
Expand Down
3 changes: 2 additions & 1 deletion arm9/source/common/swkbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum {
KEY_UNICODE = 0x8C,
KEY_UP = 0x8D,
KEY_DOWN = 0x8E,
KEY_CLIP = 0x8F,
KEY_TXTBOX = 0xFF
};

Expand Down Expand Up @@ -108,4 +109,4 @@ enum {
#define ShowKeyboardOrPrompt (TouchIsCalibrated() ? ShowKeyboard : ShowStringPrompt)
bool PRINTF_ARGS(3) ShowKeyboard(char* inputstr, u32 max_size, const char *format, ...);
bool BuildKeyboard(TouchBox* swkbd, const char* keys, const u8* layout, bool multi_line);
char ShowMultiLineKeyboard(TouchBox* swkbd_alphabet, TouchBox* swkbd_special, TouchBox* swkbd_numpad, TouchBox** swkbd, TouchBox** swkbd_prev, u32* uppercase);
char ShowMultiLineKeyboard(const char* instructions, TouchBox* swkbd_alphabet, TouchBox* swkbd_special, TouchBox* swkbd_numpad, TouchBox** swkbd, TouchBox** swkbd_prev, u32* uppercase);
3 changes: 2 additions & 1 deletion arm9/source/language.inl
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ STRING(ERROR_INVALID_TEXT_DATA, "Error: Invalid text data")
STRING(ERROR_TEXT_FILE_TOO_BIG, "Error: Text file is too large.\nText file size is %u bytes.\nMax file size is %i bytes.")
STRING(TEXTVIEWER_CONTROLS_DETAILS, "Textviewer Controls:\n \n↑↓→←(+R) - Scroll\nR+Y - Toggle wordwrap\nR+X - Goto line #\nB - Exit\n")
STRING(TEXTEDITOR_CONTROLS_DETAILS, "Text Editor Controls:\n \n↑↓→←(+R) - Scroll\nR+Y - Toggle wordwrap\nR+X - Goto line #\nA - Enter edit mode\nB - Exit\n")
STRING(TEXTEDITOR_CONTROLS_KEYBOARD, "Text Editor Controls:\n \n↑↓→←(+R) - Move cursor\nY - Caps / Capslock\nX - Delete char\nA - Insert newline\nB - Enter view mode\n")
STRING(TEXTEDITOR_CONTROLS_KEYBOARD, "Text Editor Controls:\n \n↑↓→←(+R) - Move cursor\nX - Delete char\nA - Insert newline\nL+↑↓→← - Select text\nY - COPY / [+R] CUT\nB - Enter view mode\n")
STRING(TEXTEDITOR_CONTROLS_CLIPBOARD, "Text Editor Controls:\n \n↑↓→←(+R) - Move cursor\nX - Delete char\nA - Insert newline\nL+↑↓→← - Select text\nY - PASTE / [+R] CLEAR\nB - Enter view mode\n")
STRING(TEXT_EDITS_SAVE_CHANGES, "You made text edits.\nWrite changes to file?")
STRING(CURRENT_LINE_N_ENTER_NEW_LINE_BELOW, "Current line: %i\nEnter new line below.")
STRING(PREVIEW_DISABLED, "(preview disabled)")
Expand Down
Loading

0 comments on commit d6fe058

Please sign in to comment.