Index: src/settings.cpp =================================================================== --- src/settings.cpp (revision 12357) +++ src/settings.cpp (working copy) @@ -49,6 +49,7 @@ #endif #include "spritecache.h" #include "transparency.h" +#include "textbuf_gui.h" #include "string_func.h" #include "gui.h" #include "town.h" @@ -1281,9 +1282,11 @@ SDTG_BOOL("large_aa", S, 0, _freetype.large_aa, false, STR_NULL, NULL), #endif SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size, 4, 1, 64, 0, STR_NULL, NULL), - SDTG_VAR("player_face", SLE_UINT32, S, 0, _player_face, 0,0,0xFFFFFFFF,0, STR_NULL, NULL), + SDTG_VAR("player_face", SLE_UINT32, S, 0, _player_face, 0,0,0xFFFFFFFF,0, STR_NULL, NULL), SDTG_VAR("transparency_options", SLE_UINT, S, 0, _transparency_opt, 0,0,0x1FF,0, STR_NULL, NULL), SDTG_VAR("transparency_locks", SLE_UINT, S, 0, _transparency_lock, 0,0,0x1FF,0, STR_NULL, NULL), + SDTG_STR("keyboard", SLE_STRB, S, 0, _keyboard_opt[0],NULL, STR_NULL, NULL), + SDTG_STR("keyboard_caps", SLE_STRB, S, 0, _keyboard_opt[1],NULL, STR_NULL, NULL), SDTG_END() }; Index: src/gfx_func.h =================================================================== --- src/gfx_func.h (revision 12357) +++ src/gfx_func.h (working copy) @@ -99,6 +99,8 @@ void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw); void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color); +void DrawCharCentered(uint32 c, int x, int y, uint16 color); + void GfxFillRect(int left, int top, int right, int bottom, int color); void GfxDrawLine(int left, int top, int right, int bottom, int color); void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); Index: src/lang/german.txt =================================================================== --- src/lang/german.txt (revision 12357) +++ src/lang/german.txt (working copy) @@ -3468,3 +3468,8 @@ STR_DRAG_SIGNALS_DENSITY_DECREASE_TIP :{BLACK}Signalabstand verringern STR_DRAG_SIGNALS_DENSITY_INCREASE_TIP :{BLACK}Signalabstand erhöhen ######## + +############ on screen keyboard +STR_OSK_KEYBOARD_LAYOUT :^1234567890ß' qwertzuiopü+asdfghjklöä#YXCVBNM;:_ . +######## Index: src/lang/english.txt =================================================================== --- src/lang/english.txt (revision 12357) +++ src/lang/english.txt (working copy) @@ -3484,3 +3484,8 @@ STR_DRAG_SIGNALS_DENSITY_DECREASE_TIP :{BLACK}Decrease dragging signal density STR_DRAG_SIGNALS_DENSITY_INCREASE_TIP :{BLACK}Increase dragging signal density ######## + +############ on screen keyboard +STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . +STR_OSK_KEYBOARD_LAYOUT_CAPS :~!@#$%^&*()_+|QWERTYUIOP ASDFGHJKL:" ZXCVBNM<>? . +######## Index: src/genworld_gui.cpp =================================================================== --- src/genworld_gui.cpp (revision 12357) +++ src/genworld_gui.cpp (working copy) @@ -127,7 +127,7 @@ { WWT_DROPDOWN, RESIZE_NONE, 12, 114, 175, 130, 141, 0x0, STR_NULL}, // Number of industries { WWT_TEXT, RESIZE_NONE, 0, 12, 110, 153, 163, STR_RANDOM_SEED, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, 15, 114, 207, 152, 163, 0x0, STR_RANDOM_SEED_HELP}, // Edit box for seed +{ WWT_EDITBOX, RESIZE_NONE, 15, 114, 207, 152, 163, 0x0, STR_RANDOM_SEED_HELP}, // Edit box for seed { WWT_TEXTBTN, RESIZE_NONE, 12, 216, 326, 152, 163, STR_RANDOM, STR_RANDOM_HELP}, { WWT_TEXTBTN, RESIZE_NONE, 6, 243, 326, 228, 257, STR_GENERATE, STR_NULL}, // Generate button @@ -181,7 +181,7 @@ { WWT_DROPDOWN, RESIZE_NONE, 12, 114, 175, 152, 163, 0x0, STR_NULL}, // Number of industries { WWT_TEXT, RESIZE_NONE, 0, 12, 110, 175, 185, STR_RANDOM_SEED, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, 15, 114, 207, 174, 185, 0x0, STR_RANDOM_SEED_HELP}, // Edit box for seed +{ WWT_EDITBOX, RESIZE_NONE, 15, 114, 207, 174, 185, 0x0, STR_RANDOM_SEED_HELP}, // Edit box for seed { WWT_TEXTBTN, RESIZE_NONE, 12, 216, 326, 174, 185, STR_RANDOM, STR_RANDOM_HELP}, { WWT_TEXTBTN, RESIZE_NONE, 6, 243, 326, 196, 225, STR_GENERATE, STR_NULL}, // Generate button @@ -373,7 +373,9 @@ UpdateTextBufferSize(&_genseed_query.text); SetWindowDirty(w); break; - + case GLAND_RANDOM_EDITBOX: // edit box for random seed + ShowOnScreenKeyboard(w, & _genseed_query, GLAND_RANDOM_EDITBOX, 0, 0); + break; case GLAND_GENERATE_BUTTON: // Generate UpdatePatches(); Index: src/textbuf_gui.h =================================================================== --- src/textbuf_gui.h (revision 12357) +++ src/textbuf_gui.h (working copy) @@ -43,4 +43,7 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter); void ShowQuery(StringID caption, StringID message, Window *w, void (*callback)(Window*, bool)); +extern char _keyboard_opt[2][100]; +void ShowOnScreenKeyboard(Window *parent, querystr_d *q, int button, int cancel, int ok); + #endif /* TEXTBUF_GUI_H */ Index: src/misc_gui.cpp =================================================================== --- src/misc_gui.cpp (revision 12357) +++ src/misc_gui.cpp (working copy) @@ -60,6 +60,16 @@ static char _landinfo_data[LAND_INFO_LINES][LAND_INFO_LINE_BUFF_SIZE]; +struct osk_d { + querystr_d *qs; // text-input + int text_btn; // widget number of parent's text field + int ok_btn; // widget number of parent's ok button (=0 when ok shouldn't be passed on) + int cancel_btn; // widget number of parent's cancel button (=0 when cancel shouldn't be passed on; text will be reverted to original) + Textbuf *text; // pointer to parent's textbuffer (to update caret position) + char *orig; // the original text, in case we cancel +}; +assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(osk_d)); + static void LandInfoWndProc(Window *w, WindowEvent *e) { if (e->event == WE_PAINT) { @@ -939,6 +949,7 @@ return false; } + /** * Handle text navigation with arrow keys left/right. * This defines where the caret will blink and the next characer interaction will occur @@ -1084,6 +1095,8 @@ const Widget *wi = &w->widget[wid]; const Textbuf *tb = &string->text; + assert((wi->type & WWT_MASK) == WWT_EDITBOX); + GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215); /* Limit the drawing of the string inside the widget boundaries */ @@ -1135,6 +1148,9 @@ case WE_CLICK: switch (e->we.click.widget) { + case QUERY_STR_WIDGET_TEXT: + ShowOnScreenKeyboard(w, &WP(w, querystr_d), QUERY_STR_WIDGET_TEXT, QUERY_STR_WIDGET_CANCEL, QUERY_STR_WIDGET_OK); + break; case QUERY_STR_WIDGET_OK: press_ok:; if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) { @@ -1188,7 +1204,7 @@ { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CAPTION, RESIZE_NONE, 14, 11, 259, 0, 13, STR_012D, STR_NULL}, { WWT_PANEL, RESIZE_NONE, 14, 0, 259, 14, 29, 0x0, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, 14, 2, 257, 16, 27, 0x0, STR_NULL}, +{ WWT_EDITBOX, RESIZE_NONE, 14, 2, 257, 16, 27, 0x0, STR_NULL}, { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 129, 30, 41, STR_012E_CANCEL, STR_NULL}, { WWT_TEXTBTN, RESIZE_NONE, 14, 130, 259, 30, 41, STR_012F_OK, STR_NULL}, { WIDGETS_END}, @@ -1203,6 +1219,7 @@ }; static char _edit_str_buf[64]; +static char orig_str_buf[lengthof(_edit_str_buf)]; /** Show a query popup window with a textbox in it. * @param str StringID for the text shown in the textbox @@ -1215,7 +1232,6 @@ * @param afilter filters out unwanted character input */ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter) { - static char orig_str_buf[lengthof(_edit_str_buf)]; Window *w; uint realmaxlen = maxlen & ~0x1000; @@ -1243,7 +1259,307 @@ InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, realmaxlen, maxwidth); } +enum OskWidgets { + OSK_WIDGET_TEXT = 3, + OSK_WIDGET_CANCEL = 5, + OSK_WIDGET_OK, + OSK_WIDGET_BACKSPACE, + OSK_WIDGET_SPECIAL, + OSK_WIDGET_CAPS, + OSK_WIDGET_SHIFT, + OSK_WIDGET_SPACE, + OSK_WIDGET_LEFT, + OSK_WIDGET_RIGHT, + OSK_WIDGET_LETTERS +}; +char _keyboard_opt[2][100]; +WChar _keyboard[2][50]; + +#define KEYS_NONE 0x0 +#define KEYS_SHIFT 1 +#define KEYS_CAPS 2 +byte _keystate = KEYS_NONE; + +/* on screen keyboard */ +static void OskWndProc(Window *w, WindowEvent *e) +{ + querystr_d *qs = WP(w,osk_d).qs; + + switch (e->event) { + case WE_CREATE: + SetBit(_no_scroll, SCROLL_EDIT); + break; + + case WE_PAINT: { + bool shift = HasBit(_keystate, KEYS_CAPS) || HasBit(_keystate, KEYS_SHIFT); + + w->LowerWidget(OSK_WIDGET_TEXT); + w->SetWidgetLoweredState(OSK_WIDGET_SHIFT, HasBit(_keystate, KEYS_SHIFT)); + w->SetWidgetLoweredState(OSK_WIDGET_CAPS, HasBit(_keystate, KEYS_CAPS)); + + SetDParam(0, qs->caption); + DrawWindowWidgets(w); + + for(int i=0; i<50; i++) { + DrawCharCentered(_keyboard[shift][i], + w->widget[OSK_WIDGET_LETTERS + i].left + 8, + w->widget[OSK_WIDGET_LETTERS + i].top + 3, + TC_BLACK); + } + + DrawEditBox(w, qs, OSK_WIDGET_TEXT); + break; + } + + case WE_CLICK: + /* clicked a letter */ + if (e->we.click.widget >= OSK_WIDGET_LETTERS) { + bool shift = HasBit(_keystate, KEYS_CAPS) || HasBit(_keystate, KEYS_SHIFT); + + WChar c = _keyboard[shift][ e->we.click.widget - OSK_WIDGET_LETTERS ]; + if(!IsValidChar(c, qs->afilter)) + break; + + if (InsertTextBufferChar(&qs->text, c)) + w->InvalidateWidget(OSK_WIDGET_TEXT); + + if(HasBit(_keystate, KEYS_SHIFT)) { + ToggleBit(_keystate, KEYS_SHIFT); + w->widget[OSK_WIDGET_SHIFT].color = HasBit(_keystate, KEYS_SHIFT)?15:14; + SetWindowDirty(w); + } + break; + } + + switch (e->we.click.widget) { + case OSK_WIDGET_BACKSPACE: + if (DeleteTextBufferChar(&qs->text, WKC_BACKSPACE)) + w->InvalidateWidget(OSK_WIDGET_TEXT); + break; + case OSK_WIDGET_SPECIAL: + /* anything device specific can go here. for the NDS i plan to insert the username, which can be read from the firmware */ + break; + case OSK_WIDGET_CAPS: + ToggleBit(_keystate, KEYS_CAPS); + SetWindowDirty(w); + break; + case OSK_WIDGET_SHIFT: + ToggleBit(_keystate, KEYS_SHIFT); + SetWindowDirty(w); + break; + case OSK_WIDGET_SPACE: + if (InsertTextBufferChar(&qs->text, ' ')) + w->InvalidateWidget(OSK_WIDGET_TEXT); + break; + case OSK_WIDGET_LEFT: + if (MoveTextBufferPos(&qs->text, WKC_LEFT)) + w->InvalidateWidget(OSK_WIDGET_TEXT); + break; + case OSK_WIDGET_RIGHT: + if (MoveTextBufferPos(&qs->text, WKC_RIGHT)) + w->InvalidateWidget(OSK_WIDGET_TEXT); + break; + case OSK_WIDGET_OK: + if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) { + /* pass information by simulating a button press on parent window */ + if(WP(w,osk_d).ok_btn != 0) { + Window *parent = w->parent; + WindowEvent e; + e.event = WE_CLICK; + e.we.click.widget = WP(w,osk_d).ok_btn; + parent->wndproc(parent, &e); + } + } + DeleteWindow(w); + break; + case OSK_WIDGET_CANCEL: + if(WP(w,osk_d).cancel_btn != 0) { // pass a cancel event to the parent window + Window *parent = w->parent; + WindowEvent e; + e.event = WE_CLICK; + e.we.click.widget = WP(w,osk_d).cancel_btn; + parent->wndproc(parent, &e); + } else { // or reset to original string + strcpy(qs->text.buf, WP(w,osk_d).orig); + UpdateTextBufferSize(&qs->text); + MoveTextBufferPos(&qs->text, WKC_END); + } + DeleteWindow(w); + break; + } + // make sure that the parent window's textbox also gets updated + if(w->parent != NULL) + w->parent->InvalidateWidget(WP(w,osk_d).text_btn); + break; + + case WE_MOUSELOOP: + HandleEditBox(w, qs, OSK_WIDGET_TEXT); + // make the caret of the parent window also blink + w->parent->InvalidateWidget(WP(w,osk_d).text_btn); + break; + + case WE_DESTROY: + break; + + } + +} + +static const Widget _osk_widgets[] = { +{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, +{ WWT_CAPTION, RESIZE_NONE, 14, 0, 255, 0, 13, STR_012D, STR_NULL}, +{ WWT_PANEL, RESIZE_NONE, 14, 0, 255, 14, 29, 0x0, STR_NULL}, +{ WWT_EDITBOX, RESIZE_NONE, 14, 2, 253, 16, 27, 0x0, STR_NULL}, + +{ WWT_PANEL, RESIZE_NONE, 14, 0, 255, 30, 139, 0x0, STR_NULL}, + +{ WWT_TEXTBTN, RESIZE_NONE, 14, 3, 108, 35, 46, STR_012E_CANCEL, STR_NULL}, +{ WWT_TEXTBTN, RESIZE_NONE, 14, 111, 216, 35, 46, STR_012F_OK, STR_NULL}, +{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 219, 252, 35, 46, SPR_OSK_BACKSPACE,STR_NULL}, + +{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 3, 27, 67, 82, SPR_OSK_SPECIAL, STR_NULL}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 3, 36, 85, 100, SPR_OSK_CAPS, STR_NULL}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 3, 27, 103, 118, SPR_OSK_SHIFT, STR_NULL}, + +{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 75, 189, 121, 136, STR_EMPTY, STR_NULL}, + +{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 219, 234, 121, 136, SPR_OSK_LEFT, STR_NULL}, +{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 237, 252, 121, 136, SPR_OSK_RIGHT, STR_NULL}, + +{ WWT_PUSHBTN, RESIZE_NONE, 14, 3, 18, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 21, 36, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 39, 54, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 57, 72, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 75, 90, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 93, 108, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 111, 126, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 129, 144, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 147, 162, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 165, 180, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 183, 198, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 201, 216, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 219, 234, 49, 64, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 237, 252, 49, 64, 0x0, STR_NULL}, + +{ WWT_PUSHBTN, RESIZE_NONE, 14, 30, 45, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 48, 63, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 66, 81, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 84, 99, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 102, 117, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 120, 135, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 138, 153, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 156, 171, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 174, 189, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 192, 207, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 210, 225, 67, 82, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 228, 243, 67, 82, 0x0, STR_NULL}, + +{ WWT_PUSHBTN, RESIZE_NONE, 14, 39, 54, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 57, 72, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 75, 90, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 93, 108, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 111, 126, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 129, 144, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 147, 162, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 165, 180, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 183, 198, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 201, 216, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 219, 234, 85, 100, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 237, 252, 85, 100, 0x0, STR_NULL}, + +{ WWT_PUSHBTN, RESIZE_NONE, 14, 30, 45, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 48, 63, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 66, 81, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 84, 99, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 102, 117, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 120, 135, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 138, 153, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 156, 171, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 174, 189, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 192, 207, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 210, 225, 103, 118, 0x0, STR_NULL}, +{ WWT_PUSHBTN, RESIZE_NONE, 14, 228, 243, 103, 118, 0x0, STR_NULL}, + +{ WIDGETS_END}, +}; + +WindowDesc _osk_desc = { + WDP_CENTER, WDP_CENTER, 256, 140, 256, 140, + WC_OSK, WC_NONE, + WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, + _osk_widgets, + OskWndProc +}; + +/* Retrieve keyboard layout from language string or (if set) config file. + * Also check for invalid characters. */ +void GetKeyboardLayout() +{ + char keyboard[2][100]; + + if(_keyboard_opt[0][0] == '\0') + GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT, lastof(keyboard[0])); + else + strncpy (keyboard[0], _keyboard_opt[0], 100); + + if(_keyboard_opt[1][0] == '\0') + GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS, lastof(keyboard[1])); + else + strncpy (keyboard[1], _keyboard_opt[1], 100); + + const char *kbd[2] = { keyboard[0], keyboard[1] }; + + DEBUG(misc, 1, "Keyboard: >>>%s<<<", keyboard[0]); + DEBUG(misc, 1, " Caps: >>>%s<<<", keyboard[1]); + + for(int j=0; j<2; j++) + for(int i=0; i<50; i++) { + _keyboard[j][i] = Utf8Consume(&kbd[j]); + + if(!IsPrintable(_keyboard[j][i])) { + ShowInfoF("The keyboard layout you selected contains an invalid char at position %i in %s layout! (Between %c and %c)", i, j?"caps lock":"normal", _keyboard[j][i-1], _keyboard[j][i+1]); + _keyboard[j][i] = ' '; + } + } +} + +/** Show the osk associated with a given textbox + * @param parent pointer to the Window where this keyboard originated from + * @param q querystr_d pointer to the query string of the parent, which is + * shared for both windows + * @param int button widget number of parent's textbox + * @param int cancel widget number of parent's cancel button (0 if cancel events + * should not be passed) + * @param int ok widget number of parent's ok button (0 if ok events should not + * be passed) */ +void ShowOnScreenKeyboard(Window *parent, querystr_d *q, int button, int cancel, int ok) +{ + Window *w; + + DeleteWindowById(WC_OSK, 0); + + w = AllocateWindowDesc(&_osk_desc); + + w->parent = parent; + assert(parent != NULL); + + if(parent->widget[button].data != 0) + q->caption = parent->widget[button].data; + + WP(w, osk_d).qs = q; + WP(w, osk_d).text_btn = button; + WP(w, osk_d).cancel_btn = cancel; + WP(w, osk_d).ok_btn = ok; + WP(w, osk_d).text = &q->text; + + GetKeyboardLayout(); + + // make a copy in case we need to reset later + strcpy(orig_str_buf, WP(w, osk_d).qs->text.buf); + WP(w, osk_d).orig = orig_str_buf; +} + enum QueryWidgets { QUERY_WIDGET_CAPTION = 1, QUERY_WIDGET_NO = 3, @@ -1379,7 +1695,7 @@ { WWT_INSET, RESIZE_RB, 14, 2, 243, 50, 150, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, { WWT_SCROLLBAR, RESIZE_LRB, 14, 245, 256, 60, 151, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { WWT_PANEL, RESIZE_RTB, 14, 0, 256, 152, 167, 0x0, STR_NULL}, -{ WWT_PANEL, RESIZE_RTB, 14, 2, 254, 154, 165, 0x0, STR_400B_CURRENTLY_SELECTED_NAME}, +{ WWT_EDITBOX, RESIZE_RTB, 14, 2, 254, 154, 165, 0x0, STR_400B_CURRENTLY_SELECTED_NAME}, { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 127, 168, 179, STR_4003_DELETE, STR_400C_DELETE_THE_CURRENTLY_SELECTED}, { WWT_PUSHTXTBTN, RESIZE_TB, 14, 128, 244, 168, 179, STR_4002_SAVE, STR_400D_SAVE_THE_CURRENT_GAME_USING}, { WWT_RESIZEBOX, RESIZE_LRTB, 14, 245, 256, 168, 179, 0x0, STR_RESIZE_BUTTON}, @@ -1586,7 +1902,10 @@ } break; } - + case 10: // edit box + ShowOnScreenKeyboard(w, &WP(w, querystr_d), e->we.click.widget, 0, 0); + break; + case 11: case 12: // Delete, Save game break; } Index: src/table/sprites.h =================================================================== --- src/table/sprites.h (revision 12357) +++ src/table/sprites.h (working copy) @@ -49,7 +49,7 @@ /* Extra graphic spritenumbers */ SPR_OPENTTD_BASE = 4896, - OPENTTD_SPRITE_COUNT = 138, + OPENTTD_SPRITE_COUNT = 144, /* Halftile-selection sprites */ SPR_HALFTILE_SELECTION_FLAT = SPR_OPENTTD_BASE, @@ -73,6 +73,14 @@ SPR_PIN_UP = SPR_OPENTTD_BASE + 51, // pin icon SPR_PIN_DOWN = SPR_OPENTTD_BASE + 52, + /* on screen keyboard icons */ + SPR_OSK_LEFT = SPR_OPENTTD_BASE + 138, + SPR_OSK_RIGHT = SPR_OPENTTD_BASE + 139, + SPR_OSK_CAPS = SPR_OPENTTD_BASE + 140, + SPR_OSK_SHIFT = SPR_OPENTTD_BASE + 141, + SPR_OSK_BACKSPACE = SPR_OPENTTD_BASE + 142, + SPR_OSK_SPECIAL = SPR_OPENTTD_BASE + 143, + /* Clone vehicles stuff */ SPR_CLONE_TRAIN = SPR_OPENTTD_BASE + 106, SPR_CLONE_ROADVEH = SPR_OPENTTD_BASE + 107, Index: src/window_type.h =================================================================== --- src/window_type.h (revision 12357) +++ src/window_type.h (working copy) @@ -90,6 +90,7 @@ WC_VEHICLE_TIMETABLE, WC_BUILD_SIGNAL, WC_COMPANY_PASSWORD_WINDOW, + WC_OSK, }; struct Window; Index: src/window_gui.h =================================================================== --- src/window_gui.h (revision 12357) +++ src/window_gui.h (working copy) @@ -499,6 +499,7 @@ WWT_CLOSEBOX, WWT_DROPDOWN, ///< Raised drop down list (regular) WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only) + WWT_EDITBOX, ///< a textbox for typing (don't forget to call ShowOnScreenKeyboard() when clicked) WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!! WWT_MASK = 0x1F, Index: src/widget.cpp =================================================================== --- src/widget.cpp (revision 12357) +++ src/widget.cpp (working copy) @@ -222,6 +222,11 @@ break; } + case WWT_EDITBOX: { + DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); + break; + } + case WWT_TEXTBTN: case WWT_TEXTBTN_2: { DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); Index: src/window.cpp =================================================================== --- src/window.cpp (revision 12357) +++ src/window.cpp (working copy) @@ -1674,6 +1674,8 @@ */ if (e.we.keypress.key == 0 && e.we.keypress.keycode == 0) return; +// reminder to add a query string flag to window descriptions + /* check if we have a query string window open before allowing hotkeys */ if (FindWindowById(WC_QUERY_STRING, 0) != NULL || FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL || @@ -1683,7 +1685,6 @@ FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) { query_open = true; } - /* Call the event, start with the uppermost window. */ for (wz = _last_z_window; wz != _z_windows;) { Window *w = *--wz; Index: src/network/network_gui.cpp =================================================================== --- src/network/network_gui.cpp (revision 12357) +++ src/network/network_gui.cpp (working copy) @@ -425,6 +425,10 @@ case WE_CLICK: nd->field = e->we.click.widget; switch (e->we.click.widget) { + + case NGWW_PLAYER: + ShowOnScreenKeyboard(w, &WP(w, network_ql_d).q, NGWW_PLAYER, 0, 0); + break; case NGWW_CANCEL: // Cancel button DeleteWindowById(WC_NETWORK_WINDOW, 0); break; @@ -573,7 +577,7 @@ { WWT_TEXT, RESIZE_NONE, BGC, 9, 85, 23, 35, STR_NETWORK_CONNECTION, STR_NULL}, { WWT_DROPDOWNIN, RESIZE_NONE, BGC, 90, 181, 22, 33, STR_NETWORK_LAN_INTERNET_COMBO, STR_NETWORK_CONNECTION_TIP}, // NGWW_CONN_BTN -{ WWT_PANEL, RESIZE_LR, BGC, 290, 440, 22, 33, 0x0, STR_NETWORK_ENTER_NAME_TIP}, // NGWW_PLAYER +{ WWT_EDITBOX, RESIZE_LR, BGC, 290, 440, 22, 33, STR_NETWORK_PLAYER_NAME, STR_NETWORK_ENTER_NAME_TIP}, // NGWW_PLAYER /* LEFT SIDE */ { WWT_PUSHTXTBTN, RESIZE_RIGHT, BTC, 10, 70, 42, 53, STR_NETWORK_GAME_NAME, STR_NETWORK_GAME_NAME_TIP}, // NGWW_NAME @@ -734,7 +738,9 @@ case NSSW_CANCEL: // Cancel button ShowNetworkGameWindow(); break; - + case NSSW_GAMENAME: + ShowOnScreenKeyboard(w, &WP(w, network_ql_d).q, NSSW_GAMENAME, 0, 0); + break; case NSSW_SETPWD: // Set password button nd->widget_id = NSSW_SETPWD; ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, w, CS_ALPHANUMERAL); @@ -885,7 +891,7 @@ /* Set game name and password widgets */ { WWT_TEXT, RESIZE_NONE, BGC, 10, 90, 22, 34, STR_NETWORK_NEW_GAME_NAME, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, BGC, 100, 272, 22, 33, 0x0, STR_NETWORK_NEW_GAME_NAME_TIP}, // NSSW_GAMENAME +{ WWT_EDITBOX, RESIZE_NONE, BGC, 100, 272, 22, 33, 0x0, STR_NETWORK_NEW_GAME_NAME_TIP}, // NSSW_GAMENAME { WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 285, 405, 22, 33, STR_NETWORK_SET_PASSWORD, STR_NETWORK_PASSWORD_TIP}, // NSSW_SETPWD /* List of playable scenarios */ @@ -1818,6 +1824,10 @@ case WE_CLICK: switch (e->we.click.widget) { + case 2: + ShowOnScreenKeyboard(w, &WP(w, chatquerystr_d), 2, 0, 3); + break; + case 3: { /* Send */ DestType type = (DestType)WP(w, chatquerystr_d).caption; int dest = WP(w, chatquerystr_d).dest; @@ -1857,7 +1867,7 @@ static const Widget _chat_window_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_PANEL, RESIZE_RIGHT, 14, 11, 319, 0, 13, 0x0, STR_NULL}, // background -{ WWT_PANEL, RESIZE_RIGHT, 14, 75, 257, 1, 12, 0x0, STR_NULL}, // text box +{ WWT_EDITBOX, RESIZE_RIGHT, 14, 75, 257, 1, 12, 0x0, STR_NULL}, // text box { WWT_PUSHTXTBTN, RESIZE_LR, 14, 258, 319, 1, 12, STR_NETWORK_SEND, STR_NULL}, // send button { WIDGETS_END}, }; @@ -1944,10 +1954,12 @@ e->we.click.widget = NCPWW_OK; NetworkCompanyPasswordWindowWndProc(w, e); break; - case 2: // Escape DeleteWindow(w); break; + case 4: + ShowOnScreenKeyboard(w, &WP(w, chatquerystr_d), 4, 2, 1); + break; } break; } @@ -1958,7 +1970,7 @@ { WWT_CAPTION, RESIZE_NONE, 14, 11, 299, 0, 13, STR_COMPANY_PASSWORD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, { WWT_PANEL, RESIZE_NONE, 14, 0, 299, 14, 50, 0x0, STR_NULL}, { WWT_TEXT, RESIZE_NONE, 14, 5, 100, 19, 30, STR_COMPANY_PASSWORD, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, 14, 101, 294, 19, 30, 0x0, STR_NULL}, +{ WWT_EDITBOX, RESIZE_NONE, 14, 101, 294, 19, 30, 0x0, STR_NULL}, { WWT_TEXTBTN, RESIZE_NONE, 14, 101, 294, 35, 46, STR_MAKE_DEFAULT_COMPANY_PASSWORD, STR_MAKE_DEFAULT_COMPANY_PASSWORD_TIP}, { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 149, 51, 62, STR_012E_CANCEL, STR_COMPANY_PASSWORD_CANCEL}, { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 150, 299, 51, 62, STR_012F_OK, STR_COMPANY_PASSWORD_OK}, Index: src/signs_gui.cpp =================================================================== --- src/signs_gui.cpp (revision 12357) +++ src/signs_gui.cpp (working copy) @@ -249,6 +249,10 @@ UpdateSignEditWindow(w, si); break; + case QUERY_EDIT_SIGN_WIDGET_TEXT: + ShowOnScreenKeyboard(w, qs, e->we.click.widget, QUERY_EDIT_SIGN_WIDGET_CANCEL, QUERY_EDIT_SIGN_WIDGET_OK); + break; + case QUERY_EDIT_SIGN_WIDGET_DELETE: /* Only need to set the buffer to null, the rest is handled as the OK button */ DeleteTextBufferAll(&qs->text); @@ -290,7 +294,7 @@ { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CAPTION, RESIZE_NONE, 14, 11, 259, 0, 13, STR_012D, STR_NULL }, { WWT_PANEL, RESIZE_NONE, 14, 0, 259, 14, 29, STR_NULL, STR_NULL }, -{ WWT_PANEL, RESIZE_NONE, 14, 2, 257, 16, 27, STR_NULL, STR_NULL }, // Text field +{ WWT_EDITBOX, RESIZE_NONE, 14, 2, 257, 16, 27, STR_NULL, STR_NULL }, // Text field { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 60, 30, 41, STR_012F_OK, STR_NULL }, { WWT_TEXTBTN, RESIZE_NONE, 14, 61, 120, 30, 41, STR_012E_CANCEL, STR_NULL }, { WWT_TEXTBTN, RESIZE_NONE, 14, 121, 180, 30, 41, STR_0290_DELETE, STR_NULL }, Index: src/gfx.cpp =================================================================== --- src/gfx.cpp (revision 12357) +++ src/gfx.cpp (working copy) @@ -561,6 +561,20 @@ return br; } +void DrawCharCentered(WChar c, int x, int y, uint16 real_color) +{ + FontSize size = FS_NORMAL; + byte color = real_color & 0xFF; + uint palette = _use_dos_palette ? 1 : 0; + int w = GetCharacterWidth(size, c); + + _string_colorremap[1] = _string_colormap[palette][color].text; + _string_colorremap[2] = _string_colormap[palette][color].shadow; + _color_remap_ptr = _string_colorremap; + + GfxMainBlitter(GetGlyph(size, c), x - w/2, y, BM_COLOUR_REMAP); +} + /** Draw a string at the given coordinates with the given colour * @param string the string to draw * @param x offset from left side of the screen, if negative offset from the right side Index: bin/data/openttdw.grf =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream