23 #include "table/strings.h"
35 static uint8_t _keystate = KEYS_NONE;
51 assert(par_wid !=
nullptr);
56 this->text_btn = button;
57 this->text = &this->qs->text;
61 this->orig_str = this->qs->text.buf;
79 this->shift =
HasBit(_keystate, KEYS_CAPS) ^
HasBit(_keystate, KEYS_SHIFT);
83 !
IsValidChar(_keyboard[this->shift][i], this->qs->text.
afilter) || _keyboard[this->shift][i] ==
' ');
91 void SetStringParameters(
WidgetID widget)
const override
96 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
104 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
114 if (
HasBit(_keystate, KEYS_SHIFT)) {
160 if (!this->qs->orig.has_value() || this->qs->text.buf != this->qs->orig) {
186 void OnEditboxChanged(
WidgetID widget)
override
195 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
197 if (!gui_scope)
return;
205 if (!closing) this->
Close();
209 static const int HALF_KEY_WIDTH = 7;
210 static const int INTER_KEY_SPACE = 2;
212 static const int TOP_KEY_PADDING = 2;
213 static const int KEY_PADDING = 6;
225 static void AddKey(std::unique_ptr<NWidgetHorizontal> &hor,
int pad_y,
int num_half,
WidgetType widtype,
WidgetID widnum, uint16_t widdata)
227 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
230 auto spc = std::make_unique<NWidgetSpacer>(key_width, 0);
231 spc->SetMinimalTextLines(1, pad_y,
FS_NORMAL);
232 hor->Add(std::move(spc));
234 auto leaf = std::make_unique<NWidgetLeaf>(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
235 leaf->SetMinimalSize(key_width, 0);
236 leaf->SetMinimalTextLines(1, pad_y,
FS_NORMAL);
237 hor->Add(std::move(leaf));
244 auto hor = std::make_unique<NWidgetHorizontal>();
245 hor->SetPIP(0, INTER_KEY_SPACE, 0);
256 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
257 hor->SetPIP(0, INTER_KEY_SPACE, 0);
268 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
269 hor->SetPIP(0, INTER_KEY_SPACE, 0);
282 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
283 hor->SetPIP(0, INTER_KEY_SPACE, 0);
295 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
296 hor->SetPIP(0, INTER_KEY_SPACE, 0);
309 auto hor = std::make_unique<NWidgetHorizontal>();
310 hor->SetPIP(0, INTER_KEY_SPACE, 0);
321 static constexpr
NWidgetPart _nested_osk_widgets[] = {
351 std::string keyboard[2];
352 std::string errormark[2];
353 bool has_error =
false;
358 for (uint j = 0; j < 2; j++) {
359 auto kbd = keyboard[j].begin();
362 _keyboard[j][i] = Utf8Consume(kbd);
365 if (_keyboard[j][i] ==
'\0' || ended) {
367 _keyboard[j][i] =
' ';
371 if (IsPrintable(_keyboard[j][i])) {
376 _keyboard[j][i] =
' ';
382 ShowInfo(
"The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
383 ShowInfo(
"Normal keyboard: {}", keyboard[0]);
384 ShowInfo(
" {}", errormark[0]);
385 ShowInfo(
"Caps Lock: {}", keyboard[1]);
386 ShowInfo(
" {}", errormark[1]);
400 new OskWindow(_osk_desc, parent, button);
413 if (osk ==
nullptr || osk->
parent != parent || osk->
text_btn != button)
return;
429 return osk !=
nullptr && osk->
parent == w && osk->
text_btn == button;
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
virtual void EditBoxLostFocus()
An edit box lost the input focus.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Functions related to debugging.
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
Functions related to the gfx engine.
@ FS_NORMAL
Index of the normal font in the font tables.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
static void AddKey(std::unique_ptr< NWidgetHorizontal > &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, uint16_t widdata)
Add a key widget to a row of the keyboard.
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
void UpdateOSKOriginalText(const Window *parent, WidgetID button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
bool IsValidChar(char32_t key, CharSetFilter afilter)
Only allow certain keys.
Functions related to low-level strings.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
StringID caption
the caption for this window.
WidgetID text_btn
widget number of parent's text field
bool shift
Is the shift effectively pressed?
void OnFocusLost(bool closing) override
The window has lost focus.
QueryString * qs
text-input
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
std::string orig_str
Original string.
Textbuf * text
pointer to parent's textbuffer (to update caret position)
void UpdateOskState()
Only show valid characters; do not show characters that would only insert a space when we have a spac...
Coordinates of a point in 2D.
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Specification of a rectangle with absolute coordinates of all edges.
Helper/buffer for input fields.
bool MovePos(uint16_t keycode)
Handle text navigation with arrow keys left/right.
bool DeleteChar(uint16_t keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
void Assign(StringID string)
Render a string into the textbuffer.
CharSetFilter afilter
Allowed characters.
bool InsertChar(char32_t key)
Insert a character to a textbuffer.
char *const buf
buffer in which text is saved
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Window * parent
Parent window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
virtual void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] int click_count)
A click with the left mouse button has been made on the window.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget)
The text in an editbox has been edited.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
Base of all video drivers.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window functions not directly related to making/drawing windows.
@ WDP_CENTER
Center the window.
@ WC_OSK
On Screen Keyboard; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Functions related to zooming.