OpenTTD Source  12.0-beta2
osk_gui.cpp File Reference
#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 (NWidgetHorizontal *hor, int pad_y, int num_half, WidgetType widtype, int widnum, uint16 widdata, int *biggest_index)
 Add a key widget to a row of the keyboard. More...
 
static NWidgetBaseMakeTopKeys (int *biggest_index)
 Construct the top row keys (cancel, ok, backspace).
 
static NWidgetBaseMakeNumberKeys (int *biggest_index)
 Construct the row containing the digit keys.
 
static NWidgetBaseMakeQwertyKeys (int *biggest_index)
 Construct the qwerty row keys.
 
static NWidgetBaseMakeAsdfgKeys (int *biggest_index)
 Construct the asdfg row keys.
 
static NWidgetBaseMakeZxcvbKeys (int *biggest_index)
 Construct the zxcvb row keys.
 
static NWidgetBaseMakeSpacebarKeys (int *biggest_index)
 Construct the spacebar row keys.
 
void GetKeyboardLayout ()
 Retrieve keyboard layout from language string or (if set) config file. More...
 
void ShowOnScreenKeyboard (Window *parent, int button)
 Show the on-screen keyboard (osk) associated with a given textbox. More...
 
void UpdateOSKOriginalText (const Window *parent, int 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. More...
 
bool IsOSKOpenedFor (const Window *w, int button)
 Check whether the OSK is opened for a specific editbox. More...
 

Variables

std::string _keyboard_opt [2]
 The number of characters has to be OSK_KEYBOARD_ENTRIES. More...
 
static WChar _keyboard [2][OSK_KEYBOARD_ENTRIES]
 
static byte _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 const NWidgetPart _nested_osk_widgets []
 
static WindowDesc _osk_desc (WDP_CENTER, "query_osk", 0, 0, WC_OSK, WC_NONE, 0, _nested_osk_widgets, lengthof(_nested_osk_widgets))
 

Detailed Description

The On Screen Keyboard GUI

Definition in file osk_gui.cpp.

Function Documentation

◆ AddKey()

static void AddKey ( NWidgetHorizontal hor,
int  pad_y,
int  num_half,
WidgetType  widtype,
int  widnum,
uint16  widdata,
int *  biggest_index 
)
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.
biggest_indexCollected biggest widget index so far.
Note
Key width is measured in 1/2 keys to allow for 1/2 key shifting between rows.

Definition at line 229 of file osk_gui.cpp.

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 353 of file osk_gui.cpp.

References _keyboard_opt, and OSK_KEYBOARD_ENTRIES.

Referenced by ShowOnScreenKeyboard().

◆ IsOSKOpenedFor()

bool IsOSKOpenedFor ( const Window w,
int  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 440 of file osk_gui.cpp.

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

◆ ShowOnScreenKeyboard()

void ShowOnScreenKeyboard ( Window parent,
int  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 408 of file osk_gui.cpp.

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

◆ UpdateOSKOriginalText()

void UpdateOSKOriginalText ( const Window parent,
int  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 423 of file osk_gui.cpp.

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

Variable Documentation

◆ _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().

◆ _nested_osk_widgets

const NWidgetPart _nested_osk_widgets[]
static
Initial value:
= {
NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2),
NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(5, 2, 3),
}

Definition at line 327 of file osk_gui.cpp.

NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1239
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1139
MakeQwertyKeys
static NWidgetBase * MakeQwertyKeys(int *biggest_index)
Construct the qwerty row keys.
Definition: osk_gui.cpp:276
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
MakeSpacebarKeys
static NWidgetBase * MakeSpacebarKeys(int *biggest_index)
Construct the spacebar row keys.
Definition: osk_gui.cpp:314
WID_OSK_CAPTION
@ WID_OSK_CAPTION
Caption of window.
Definition: osk_widget.h:15
MakeZxcvbKeys
static NWidgetBase * MakeZxcvbKeys(int *biggest_index)
Construct the zxcvb row keys.
Definition: osk_gui.cpp:301
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
MakeNumberKeys
static NWidgetBase * MakeNumberKeys(int *biggest_index)
Construct the row containing the digit keys.
Definition: osk_gui.cpp:265
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
MakeTopKeys
static NWidgetBase * MakeTopKeys(int *biggest_index)
Construct the top row keys (cancel, ok, backspace).
Definition: osk_gui.cpp:254
MakeAsdfgKeys
static NWidgetBase * MakeAsdfgKeys(int *biggest_index)
Construct the asdfg row keys.
Definition: osk_gui.cpp:289
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_OSK_TEXT
@ WID_OSK_TEXT
Edit box.
Definition: osk_widget.h:16
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1169