24#include "table/strings.h"
56 assert(par_wid !=
nullptr);
60 this->caption = (par_wid->
GetString() != STR_NULL) ? par_wid->
GetString() : this->qs->caption;
61 this->text_btn = button;
62 this->text = &this->qs->text;
66 this->orig_str = this->qs->text.
GetText();
88 !
IsValidChar(_keyboard[this->shift][i], this->qs->text.
afilter) || _keyboard[this->shift][i] ==
' ');
167 if (!this->qs->orig.has_value() || this->qs->text.GetText() != this->qs->orig) {
184 qs->text.Assign(this->orig_str);
185 qs->text.MovePos(WKC_END);
202 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
204 if (!gui_scope)
return;
212 if (!closing) this->
Close();
237 auto spc = std::make_unique<NWidgetSpacer>(key_width, 0);
239 hor->Add(std::move(spc));
241 auto leaf = std::make_unique<NWidgetLeaf>(widtype,
Colours::Grey, widnum, widdata, STR_NULL);
242 leaf->SetMinimalSize(key_width, 0);
244 hor->Add(std::move(leaf));
251 auto hor = std::make_unique<NWidgetHorizontal>();
263 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
275 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
289 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
302 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
316 auto hor = std::make_unique<NWidgetHorizontal>();
328static constexpr std::initializer_list<NWidgetPart> _nested_osk_widgets = {
348 WindowClass::OnScreenKeyboard, WindowClass::None,
359 std::string keyboard[2];
360 std::string errormark[2];
361 bool has_error =
false;
366 for (uint j = 0; j < 2; j++) {
372 if (IsPrintable(_keyboard[j][i])) {
377 _keyboard[j][i] =
' ';
383 ShowInfo(
"The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
384 ShowInfo(
"Normal keyboard: {}", keyboard[0]);
385 ShowInfo(
" {}", errormark[0]);
386 ShowInfo(
"Caps Lock: {}", keyboard[1]);
387 ShowInfo(
" {}", errormark[1]);
414 if (osk ==
nullptr || osk->
parent != parent || osk->
text_btn != button)
return;
430 return osk !=
nullptr && osk->
parent == w && osk->
text_btn == button;
Parse data from a string / buffer.
char32_t ReadUtf8(char32_t def='?')
Read UTF-8 character, and advance reader.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
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.
@ Normal
Index of the normal font in the font tables.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
#define Point
Macro that prevents name conflicts between included headers.
static void AddKey(std::unique_ptr< NWidgetHorizontal > &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
Add a key widget to a row of the keyboard.
static const int TOP_KEY_PADDING
Vertical padding for the top row of keys.
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
static const int INTER_KEY_SPACE
Number of pixels between two keys.
static const int HALF_KEY_WIDTH
Width of 1/2 key in pixels.
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.
KeyState
Keys that modify the behaviour/visuals of the keyboard.
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
EnumBitSet< KeyState, uint8_t > KeyStates
Bitset of KeyState elements.
static const int KEY_PADDING
Vertical padding for remaining key rows.
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
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...
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
static WindowDesc _osk_desc(WindowPosition::Center, {}, 0, 0, WindowClass::OnScreenKeyboard, WindowClass::None, {}, _nested_osk_widgets)
Window definition for the on screen keyboard window.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
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?
static KeyStates keystate
States of the keys of the on screen window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnEditboxChanged(WidgetID widget) override
The text in an editbox has been edited.
void OnFocusLost(bool closing) override
The window has lost focus.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
QueryString * qs
text-input
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string orig_str
Original string.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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...
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...
std::string_view GetText() const
Get the current text.
CharSetFilter afilter
Allowed characters.
bool InsertChar(char32_t key)
Insert a character to a textbuffer.
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.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
virtual void OnClick(Point pt, WidgetID widget, int click_count)
A click with the left mouse button has been made on the window.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
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.
@ Center
Center the window.
Functions related to zooming.