OpenTTD Source 20241224-master-gee860a5c8e
osk_gui.cpp File Reference

The On Screen Keyboard GUI. More...

#include "stdafx.h"
#include "string_func.h"
#include "strings_func.h"
#include "debug.h"
#include "window_func.h"
#include "gfx_func.h"
#include "querystring_gui.h"
#include "video/video_driver.hpp"
#include "zoom_func.h"
#include "widgets/osk_widget.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  OskWindow
 

Enumerations

enum  KeyStateBits { KEYS_NONE , KEYS_SHIFT , KEYS_CAPS }
 

Functions

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< NWidgetBaseMakeTopKeys ()
 Construct the top row keys (cancel, ok, backspace).
 
static std::unique_ptr< NWidgetBaseMakeNumberKeys ()
 Construct the row containing the digit keys.
 
static std::unique_ptr< NWidgetBaseMakeQwertyKeys ()
 Construct the qwerty row keys.
 
static std::unique_ptr< NWidgetBaseMakeAsdfgKeys ()
 Construct the asdfg row keys.
 
static std::unique_ptr< NWidgetBaseMakeZxcvbKeys ()
 Construct the zxcvb row keys.
 
static std::unique_ptr< NWidgetBaseMakeSpacebarKeys ()
 Construct the spacebar row keys.
 
void GetKeyboardLayout ()
 Retrieve keyboard layout from language string or (if set) config file.
 
void ShowOnScreenKeyboard (Window *parent, WidgetID button)
 Show the on-screen keyboard (osk) associated with a given textbox.
 
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 cancel you won't get the 'old' original text but the updated one.
 
bool IsOSKOpenedFor (const Window *w, WidgetID button)
 Check whether the OSK is opened for a specific editbox.
 

Variables

std::string _keyboard_opt [2]
 The number of characters has to be OSK_KEYBOARD_ENTRIES.
 
static char32_t _keyboard [2][OSK_KEYBOARD_ENTRIES]
 
static uint8_t _keystate = KEYS_NONE
 
static const int HALF_KEY_WIDTH = 7
 
static const int INTER_KEY_SPACE = 2
 
static const int TOP_KEY_PADDING = 2
 
static const int KEY_PADDING = 6
 
static constexpr NWidgetPart _nested_osk_widgets []
 
static WindowDesc _osk_desc (WDP_CENTER, nullptr, 0, 0, WC_OSK, WC_NONE, 0, _nested_osk_widgets)
 

Detailed Description

The On Screen Keyboard GUI.

Definition in file osk_gui.cpp.

Enumeration Type Documentation

◆ KeyStateBits

enum KeyStateBits

Definition at line 30 of file osk_gui.cpp.

Function Documentation

◆ AddKey()

static void AddKey ( std::unique_ptr< NWidgetHorizontal > &  hor,
int  pad_y,
int  num_half,
WidgetType  widtype,
WidgetID  widnum,
uint16_t  widdata 
)
static

Add a key widget to a row of the keyboard.

Parameters
horRow container to add key widget to.
pad_yVertical padding of the key (all keys in a row should have equal padding).
num_halfNumber of 1/2 key widths that this key has.
widtypeWidget type of the key. Must be either NWID_SPACER for an invisible key, or a WWT_* widget.
widnumWidget number of the key.
widdataData value of the key widget.
Note
Key width is measured in 1/2 keys to allow for 1/2 key shifting between rows.

Definition at line 225 of file osk_gui.cpp.

References FS_NORMAL, and NWID_SPACER.

Referenced by MakeAsdfgKeys(), MakeNumberKeys(), MakeQwertyKeys(), MakeSpacebarKeys(), MakeTopKeys(), and MakeZxcvbKeys().

◆ GetKeyboardLayout()

void GetKeyboardLayout ( )

Retrieve keyboard layout from language string or (if set) config file.

Also check for invalid characters.

Definition at line 349 of file osk_gui.cpp.

References _keyboard_opt, GetString(), and OSK_KEYBOARD_ENTRIES.

Referenced by ShowOnScreenKeyboard().

◆ IsOSKOpenedFor()

bool IsOSKOpenedFor ( const Window w,
WidgetID  button 
)

Check whether the OSK is opened for a specific editbox.

Parameters
wWindow to check for
buttonEditbox of w to check for
Returns
true if the OSK is opened for button.

Definition at line 426 of file osk_gui.cpp.

References FindWindowById(), Window::parent, OskWindow::text_btn, and WC_OSK.

◆ MakeAsdfgKeys()

static std::unique_ptr< NWidgetBase > MakeAsdfgKeys ( )
static

Construct the asdfg row keys.

Definition at line 280 of file osk_gui.cpp.

References AddKey(), WID_OSK_ASDFG_FIRST, WID_OSK_ASDFG_LAST, WID_OSK_CAPS, WWT_IMGBTN, and WWT_PUSHBTN.

◆ MakeNumberKeys()

static std::unique_ptr< NWidgetBase > MakeNumberKeys ( )
static

Construct the row containing the digit keys.

Definition at line 254 of file osk_gui.cpp.

References AddKey(), WID_OSK_NUMBERS_FIRST, WID_OSK_NUMBERS_LAST, and WWT_PUSHBTN.

◆ MakeQwertyKeys()

static std::unique_ptr< NWidgetBase > MakeQwertyKeys ( )
static

Construct the qwerty row keys.

Definition at line 266 of file osk_gui.cpp.

References AddKey(), NWID_SPACER, WID_OSK_QWERTY_FIRST, WID_OSK_QWERTY_LAST, WID_OSK_SPECIAL, WWT_PUSHBTN, and WWT_PUSHIMGBTN.

◆ MakeSpacebarKeys()

static std::unique_ptr< NWidgetBase > MakeSpacebarKeys ( )
static

Construct the spacebar row keys.

Definition at line 307 of file osk_gui.cpp.

References AddKey(), NWID_SPACER, WID_OSK_LEFT, WID_OSK_RIGHT, WID_OSK_SPACE, WWT_PUSHIMGBTN, and WWT_PUSHTXTBTN.

◆ MakeTopKeys()

static std::unique_ptr< NWidgetBase > MakeTopKeys ( )
static

Construct the top row keys (cancel, ok, backspace).

Definition at line 242 of file osk_gui.cpp.

References AddKey(), WID_OSK_BACKSPACE, WID_OSK_CANCEL, WID_OSK_OK, WWT_PUSHIMGBTN, and WWT_TEXTBTN.

◆ MakeZxcvbKeys()

static std::unique_ptr< NWidgetBase > MakeZxcvbKeys ( )
static

Construct the zxcvb row keys.

Definition at line 293 of file osk_gui.cpp.

References AddKey(), NWID_SPACER, WID_OSK_SHIFT, WID_OSK_ZXCVB_FIRST, WID_OSK_ZXCVB_LAST, WWT_IMGBTN, and WWT_PUSHBTN.

◆ ShowOnScreenKeyboard()

void ShowOnScreenKeyboard ( Window parent,
WidgetID  button 
)

Show the on-screen keyboard (osk) associated with a given textbox.

Parameters
parentpointer to the Window where this keyboard originated from
buttonwidget number of parent's textbox

Definition at line 395 of file osk_gui.cpp.

References CloseWindowById(), GetKeyboardLayout(), and WC_OSK.

◆ UpdateOSKOriginalText()

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 cancel you won't get the 'old' original text but the updated one.

Parameters
parentwindow that just updated its original text
buttonwidget number of parent's textbox to update

Definition at line 410 of file osk_gui.cpp.

References Textbuf::buf, FindWindowById(), OskWindow::orig_str, Window::parent, OskWindow::qs, Window::SetDirty(), OskWindow::text_btn, and WC_OSK.

Variable Documentation

◆ _keyboard

char32_t _keyboard[2][OSK_KEYBOARD_ENTRIES]
static

Definition at line 28 of file osk_gui.cpp.

◆ _keyboard_opt

std::string _keyboard_opt[2]

The number of characters has to be OSK_KEYBOARD_ENTRIES.

However, these have to be UTF-8 encoded, which means up to 4 bytes per character.

Definition at line 27 of file osk_gui.cpp.

Referenced by GetKeyboardLayout().

◆ _keystate

uint8_t _keystate = KEYS_NONE
static

Definition at line 35 of file osk_gui.cpp.

◆ _nested_osk_widgets

constexpr NWidgetPart _nested_osk_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetDataTip(STR_JUST_STRING, STR_NULL), SetTextStyle(TC_WHITE),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 0), SetPadding(2, 2, 2, 2),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_VERTICAL), SetPadding(3), SetPIP(0, INTER_KEY_SPACE, 0),
}
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
Definition osk_gui.cpp:293
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
Definition osk_gui.cpp:254
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
Definition osk_gui.cpp:280
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
Definition osk_gui.cpp:242
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
Definition osk_gui.cpp:307
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
Definition osk_gui.cpp:266
@ WID_OSK_CAPTION
Caption of window.
Definition osk_widget.h:15
@ WID_OSK_TEXT
Edit box.
Definition osk_widget.h:16
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:71
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77

Definition at line 321 of file osk_gui.cpp.

◆ HALF_KEY_WIDTH

const int HALF_KEY_WIDTH = 7
static

Definition at line 209 of file osk_gui.cpp.

◆ INTER_KEY_SPACE

const int INTER_KEY_SPACE = 2
static

Definition at line 210 of file osk_gui.cpp.

◆ KEY_PADDING

const int KEY_PADDING = 6
static

Definition at line 213 of file osk_gui.cpp.

◆ TOP_KEY_PADDING

const int TOP_KEY_PADDING = 2
static

Definition at line 212 of file osk_gui.cpp.