summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-04-26 16:51:50 +0000
committeralberth <alberth@openttd.org>2009-04-26 16:51:50 +0000
commit5b5cee940516636f50f4ddbd2cf4de7e7ee1d97c (patch)
tree642b8cbf377f42670588dbc2b457f1ea12b700e4 /src
parent78a4a68926e5bd06929b51506008c1530f8b5964 (diff)
downloadopenttd-5b5cee940516636f50f4ddbd2cf4de7e7ee1d97c.tar.xz
(svn r16170) -Codechange: Added nested widgets to OSK.
Diffstat (limited to 'src')
-rw-r--r--src/osk_gui.cpp129
1 files changed, 128 insertions, 1 deletions
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index d4a865406..d22a14ea4 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -323,11 +323,138 @@ static const Widget _osk_widgets[] = {
{ WIDGETS_END},
};
+static const int HALF_KEY_WIDTH = 7; // Width of 1/2 key in pixels.
+static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys.
+
+/**
+ * Add a key widget to a row of the keyboard.
+ * @param hor Row container to add key widget to.
+ * @param height Height of the key (all keys in a row should have equal height).
+ * @param numhalf Number of 1/2 key widths that this key has.
+ * @param widtype Widget type of the key. Must be either \c NWID_SPACER for an invisible key, or a \c WWT_* widget.
+ * @param widnum Widget number of the key.
+ * @param widdata Data value of the key widget.
+ * @note Key width is measured in 1/2 keys to allow for 1/2 key shifting between rows.
+ */
+static void AddKey(NWidgetHorizontal *hor, int height, int num_half, WidgetType widtype, int widnum, uint16 widdata)
+{
+ int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
+
+ if (widtype == NWID_SPACER) {
+ if (!hor->IsEmpty()) key_width += INTER_KEY_SPACE;
+ NWidgetSpacer *spc = new NWidgetSpacer(key_width, height);
+ hor->Add(spc);
+ } else {
+ if (!hor->IsEmpty()) {
+ NWidgetSpacer *spc = new NWidgetSpacer(INTER_KEY_SPACE, height);
+ hor->Add(spc);
+ }
+ NWidgetLeaf *leaf = new NWidgetLeaf(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
+ leaf->SetMinimalSize(key_width, height);
+ hor->Add(leaf);
+ }
+}
+
+/** Construct the top row keys (cancel, ok, backspace). */
+static NWidgetBase *MakeTopKeys()
+{
+ NWidgetHorizontal *hor = new NWidgetHorizontal;
+ int key_height = 12;
+
+ AddKey(hor, key_height, 6 * 2, WWT_TEXTBTN, OSK_WIDGET_CANCEL, STR_QUERY_CANCEL);
+ AddKey(hor, key_height, 6 * 2, WWT_TEXTBTN, OSK_WIDGET_OK, STR_QUERY_OK);
+ AddKey(hor, key_height, 2 * 2, WWT_PUSHIMGBTN, OSK_WIDGET_BACKSPACE, SPR_OSK_BACKSPACE);
+ return hor;
+}
+
+/** Construct the row containing the digit keys. */
+static NWidgetBase *MakeNumberKeys()
+{
+ NWidgetHorizontal *hor = new NWidgetHorizontal;
+ int key_height = 16;
+
+ for (int widnum = OSK_WIDGET_NUMBERS_FIRST; widnum <= OSK_WIDGET_NUMBERS_LAST; widnum++) {
+ AddKey(hor, key_height, 2, WWT_PUSHBTN, widnum, 0x0);
+ }
+ return hor;
+}
+
+/** Construct the qwerty row keys. */
+static NWidgetBase *MakeQwertyKeys()
+{
+ NWidgetHorizontal *hor = new NWidgetHorizontal;
+ int key_height = 16;
+
+ AddKey(hor, key_height, 3, WWT_PUSHIMGBTN, OSK_WIDGET_SPECIAL, SPR_OSK_SPECIAL);
+ for (int widnum = OSK_WIDGET_QWERTY_FIRST; widnum <= OSK_WIDGET_QWERTY_LAST; widnum++) {
+ AddKey(hor, key_height, 2, WWT_PUSHBTN, widnum, 0x0);
+ }
+ AddKey(hor, key_height, 1, NWID_SPACER, 0, 0);
+ return hor;
+}
+
+/** Construct the asdfg row keys. */
+static NWidgetBase *MakeAsdfgKeys()
+{
+ NWidgetHorizontal *hor = new NWidgetHorizontal;
+ int key_height = 16;
+
+ AddKey(hor, key_height, 4, WWT_IMGBTN, OSK_WIDGET_CAPS, SPR_OSK_CAPS);
+ for (int widnum = OSK_WIDGET_ASDFG_FIRST; widnum <= OSK_WIDGET_ASDFG_LAST; widnum++) {
+ AddKey(hor, key_height, 2, WWT_PUSHBTN, widnum, 0x0);
+ }
+ return hor;
+}
+
+/** Construct the zxcvb row keys. */
+static NWidgetBase *MakeZxcvbKeys()
+{
+ NWidgetHorizontal *hor = new NWidgetHorizontal;
+ int key_height = 16;
+
+ AddKey(hor, key_height, 3, WWT_IMGBTN, OSK_WIDGET_SHIFT, SPR_OSK_SHIFT);
+ for (int widnum = OSK_WIDGET_ZXCVB_FIRST; widnum <= OSK_WIDGET_ZXCVB_LAST; widnum++) {
+ AddKey(hor, key_height, 2, WWT_PUSHBTN, widnum, 0x0);
+ }
+ AddKey(hor, key_height, 1, NWID_SPACER, 0, 0);
+ return hor;
+}
+
+/** Construct the spacebar row keys. */
+static NWidgetBase *MakeSpacebarKeys()
+{
+ NWidgetHorizontal *hor = new NWidgetHorizontal;
+ int key_height = 16;
+
+ AddKey(hor, key_height, 8, NWID_SPACER, 0, 0);
+ AddKey(hor, key_height, 13, WWT_PUSHTXTBTN, OSK_WIDGET_SPACE, STR_EMPTY);
+ AddKey(hor, key_height, 3, NWID_SPACER, 0, 0);
+ AddKey(hor, key_height, 2, WWT_PUSHIMGBTN, OSK_WIDGET_LEFT, SPR_OSK_LEFT);
+ AddKey(hor, key_height, 2, WWT_PUSHIMGBTN, OSK_WIDGET_RIGHT, SPR_OSK_RIGHT);
+ return hor;
+}
+
+
+static const NWidgetPart _nested_osk_widgets[] = {
+ NWidget(WWT_CAPTION, COLOUR_GREY, OSK_WIDGET_CAPTION), SetDataTip(STR_QUERY_CAPTION, STR_NULL),
+ NWidget(WWT_PANEL, COLOUR_GREY, OSK_WIDGET_TEXT_BACKGROUND),
+ NWidget(WWT_EDITBOX, COLOUR_GREY, OSK_WIDGET_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2),
+ EndContainer(),
+ NWidget(WWT_PANEL, COLOUR_GREY, OSK_WIDGET_KEYS_BACKGROUND), SetPIP(5, 2, 3),
+ NWidgetFunction(MakeTopKeys), SetPadding(0, 3, 0, 3),
+ NWidgetFunction(MakeNumberKeys), SetPadding(0, 3, 0, 3),
+ NWidgetFunction(MakeQwertyKeys), SetPadding(0, 3, 0, 3),
+ NWidgetFunction(MakeAsdfgKeys), SetPadding(0, 3, 0, 3),
+ NWidgetFunction(MakeZxcvbKeys), SetPadding(0, 3, 0, 3),
+ NWidgetFunction(MakeSpacebarKeys), SetPadding(0, 3, 0, 3),
+ EndContainer(),
+};
+
static const WindowDesc _osk_desc(
WDP_CENTER, WDP_CENTER, 256, 140, 256, 140,
WC_OSK, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _osk_widgets
+ _osk_widgets, _nested_osk_widgets, lengthof(_nested_osk_widgets)
);
/**