|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
23 #include "table/strings.h"
35 static byte _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 if (!hor->IsEmpty()) key_width += INTER_KEY_SPACE;
231 auto spc = std::make_unique<NWidgetSpacer>(key_width, 0);
232 spc->SetMinimalTextLines(1, pad_y,
FS_NORMAL);
233 hor->Add(std::move(spc));
235 if (!hor->IsEmpty()) {
236 auto spc = std::make_unique<NWidgetSpacer>(INTER_KEY_SPACE, 0);
237 spc->SetMinimalTextLines(1, pad_y,
FS_NORMAL);
238 hor->Add(std::move(spc));
240 auto leaf = std::make_unique<NWidgetLeaf>(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
241 leaf->SetMinimalSize(key_width, 0);
242 leaf->SetMinimalTextLines(1, pad_y,
FS_NORMAL);
243 hor->Add(std::move(leaf));
250 auto hor = std::make_unique<NWidgetHorizontal>();
261 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
272 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
285 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
297 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
310 auto hor = std::make_unique<NWidgetHorizontal>();
321 static constexpr
NWidgetPart _nested_osk_widgets[] = {
336 static WindowDesc _osk_desc(__FILE__, __LINE__,
340 std::begin(_nested_osk_widgets), std::end(_nested_osk_widgets)
349 std::string keyboard[2];
350 std::string errormark[2];
351 bool has_error =
false;
356 for (uint j = 0; j < 2; j++) {
357 auto kbd = keyboard[j].begin();
360 _keyboard[j][i] = Utf8Consume(kbd);
363 if (_keyboard[j][i] ==
'\0' || ended) {
365 _keyboard[j][i] =
' ';
369 if (IsPrintable(_keyboard[j][i])) {
374 _keyboard[j][i] =
' ';
380 ShowInfo(
"The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
381 ShowInfo(
"Normal keyboard: {}", keyboard[0]);
382 ShowInfo(
" {}", errormark[0]);
383 ShowInfo(
"Caps Lock: {}", keyboard[1]);
384 ShowInfo(
" {}", errormark[1]);
398 new OskWindow(&_osk_desc, parent, button);
411 if (osk ==
nullptr || osk->
parent != parent || osk->
text_btn != button)
return;
427 return osk !=
nullptr && osk->
parent == w && osk->
text_btn == button;
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
bool InsertChar(char32_t key)
Insert a character to a textbuffer.
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
void Assign(StringID string)
Render a string into the textbuffer.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
std::string orig_str
Original string.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
@ WC_OSK
On Screen Keyboard; Window numbers:
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
bool MovePos(uint16_t keycode)
Handle text navigation with arrow keys left/right.
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.
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Data stored about a string that can be modified in the GUI.
virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget)
The text in an editbox has been edited.
char *const buf
buffer in which text is saved
High level window description.
@ 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 const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
Window * parent
Parent window.
Coordinates of a point in 2D.
CharSetFilter afilter
Allowed characters.
bool DeleteChar(uint16_t keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
StringID caption
the caption for this window.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
bool IsValidChar(char32_t key, CharSetFilter afilter)
Only allow certain keys.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
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.
WidgetID text_btn
widget number of parent's text field
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
void UpdateOskState()
Only show valid characters; do not show characters that would only insert a space when we have a spac...
void OnFocusLost(bool closing) override
The window has lost focus.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
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...
virtual void EditBoxLostFocus()
An edit box lost the input focus.
bool shift
Is the shift effectively pressed?
Data structure for an opened window.
Textbuf * text
pointer to parent's textbuffer (to update caret position)
Specification of a rectangle with absolute coordinates of all edges.
QueryString * qs
text-input
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.
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
@ WDP_CENTER
Center the window.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Helper/buffer for input fields.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.