From c3120d41b8accb828d5a4f9ddb297d4588ae33f5 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Mon, 17 Feb 2014 07:55:00 -0600 Subject: Add capslock support to keyboard Change-Id: I4be3849ff0485536575395d798aa5edbe12651a7 --- gui/devices/1024x600/res/ui.xml | 4 ++- gui/devices/1024x768/res/ui.xml | 4 ++- gui/devices/1080x1920/res/ui.xml | 4 ++- gui/devices/1200x1920/res/ui.xml | 4 ++- gui/devices/1280x800/res/ui.xml | 4 ++- gui/devices/1920x1200/res/ui.xml | 4 ++- gui/devices/2560x1600/res/ui.xml | 4 ++- gui/devices/320x480/res/ui.xml | 4 ++- gui/devices/480x800/res/ui.xml | 4 ++- gui/devices/480x854/res/ui.xml | 4 ++- gui/devices/540x960/res/ui.xml | 4 ++- gui/devices/720x1280/res/ui.xml | 4 ++- gui/devices/800x1280/res/ui.xml | 4 ++- gui/devices/800x480/res/ui.xml | 4 ++- gui/keyboard.cpp | 63 ++++++++++++++++++++++++++++++++++++++-- gui/objects.hpp | 10 ++++++- 16 files changed, 112 insertions(+), 17 deletions(-) (limited to 'gui') diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml index 4597fb3a3..190e6f5d1 100755 --- a/gui/devices/1024x600/res/ui.xml +++ b/gui/devices/1024x600/res/ui.xml @@ -102,6 +102,7 @@ + @@ -382,6 +383,7 @@ + @@ -390,7 +392,7 @@ - + diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml index 84f470298..434fe36d5 100644 --- a/gui/devices/1024x768/res/ui.xml +++ b/gui/devices/1024x768/res/ui.xml @@ -102,6 +102,7 @@ + @@ -382,6 +383,7 @@ + @@ -390,7 +392,7 @@ - + diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml index 3ab69a6ed..c336dbade 100644 --- a/gui/devices/1080x1920/res/ui.xml +++ b/gui/devices/1080x1920/res/ui.xml @@ -101,6 +101,7 @@ + @@ -368,6 +369,7 @@ + @@ -376,7 +378,7 @@ - + diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml index 5aedca8b1..175121632 100644 --- a/gui/devices/1200x1920/res/ui.xml +++ b/gui/devices/1200x1920/res/ui.xml @@ -104,6 +104,7 @@ + @@ -371,6 +372,7 @@ + @@ -379,7 +381,7 @@ - + diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml index c7d914893..447f760fa 100644 --- a/gui/devices/1280x800/res/ui.xml +++ b/gui/devices/1280x800/res/ui.xml @@ -102,6 +102,7 @@ + @@ -382,6 +383,7 @@ + @@ -390,7 +392,7 @@ - + diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml index dbd6a0b2d..251c5fb6c 100644 --- a/gui/devices/1920x1200/res/ui.xml +++ b/gui/devices/1920x1200/res/ui.xml @@ -102,6 +102,7 @@ + @@ -382,6 +383,7 @@ + @@ -390,7 +392,7 @@ - + diff --git a/gui/devices/2560x1600/res/ui.xml b/gui/devices/2560x1600/res/ui.xml index 0a501afc0..5344de200 100644 --- a/gui/devices/2560x1600/res/ui.xml +++ b/gui/devices/2560x1600/res/ui.xml @@ -102,6 +102,7 @@ + @@ -382,6 +383,7 @@ + @@ -390,7 +392,7 @@ - + diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml index 3c3b73d26..5b6fa02bb 100644 --- a/gui/devices/320x480/res/ui.xml +++ b/gui/devices/320x480/res/ui.xml @@ -97,6 +97,7 @@ + @@ -355,6 +356,7 @@ + @@ -363,7 +365,7 @@ - + diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml index 32c90d936..be2db8f9b 100644 --- a/gui/devices/480x800/res/ui.xml +++ b/gui/devices/480x800/res/ui.xml @@ -97,6 +97,7 @@ + @@ -355,6 +356,7 @@ + @@ -363,7 +365,7 @@ - + diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml index a8357703c..42e6749ed 100644 --- a/gui/devices/480x854/res/ui.xml +++ b/gui/devices/480x854/res/ui.xml @@ -96,6 +96,7 @@ + @@ -354,6 +355,7 @@ + @@ -362,7 +364,7 @@ - + diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml index 0a43bebc2..a60fb3db0 100644 --- a/gui/devices/540x960/res/ui.xml +++ b/gui/devices/540x960/res/ui.xml @@ -97,6 +97,7 @@ + @@ -355,6 +356,7 @@ + @@ -363,7 +365,7 @@ - + diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml index 37003da45..2cdd966c7 100644 --- a/gui/devices/720x1280/res/ui.xml +++ b/gui/devices/720x1280/res/ui.xml @@ -101,6 +101,7 @@ + @@ -368,6 +369,7 @@ + @@ -376,7 +378,7 @@ - + diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml index 31006e6fa..fffe31cd8 100755 --- a/gui/devices/800x1280/res/ui.xml +++ b/gui/devices/800x1280/res/ui.xml @@ -97,6 +97,7 @@ + @@ -356,6 +357,7 @@ + @@ -364,7 +366,7 @@ - + diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml index 8f881d779..35ca6e275 100755 --- a/gui/devices/800x480/res/ui.xml +++ b/gui/devices/800x480/res/ui.xml @@ -102,6 +102,7 @@ + @@ -390,6 +391,7 @@ + @@ -398,7 +400,7 @@ - + diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp index 78e27a164..bb52d55f9 100644 --- a/gui/keyboard.cpp +++ b/gui/keyboard.cpp @@ -47,7 +47,7 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node) { int layoutindex, rowindex, keyindex, Xindex, Yindex, keyHeight = 0, keyWidth = 0; rowY = colX = -1; - highlightRenderCount = hasHighlight = 0; + highlightRenderCount = hasHighlight = hasCapsHighlight = 0; char resource[10], layout[8], row[5], key[6], longpress[7]; xml_attribute<>* attr; xml_node<>* child; @@ -82,6 +82,17 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node) } } + memset(&mCapsHighlightColor, 0, sizeof(COLOR)); + child = node->first_node("capshighlight"); + if (child) { + attr = child->first_attribute("color"); + if (attr) { + hasCapsHighlight = 1; + std::string color = attr->value(); + ConvertStrToColor(color, &mCapsHighlightColor); + } + } + // Load the images for the different layouts child = node->first_node("layout"); if (child) @@ -128,6 +139,16 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node) keyWidth = atoi(attr->value()); else keyWidth = 0; + attr = child->first_attribute("capslock"); + if (attr) + caps_tracking[layoutindex - 1].capslock = atoi(attr->value()); + else + caps_tracking[layoutindex - 1].capslock = 1; + attr = child->first_attribute("revert_layout"); + if (attr) + caps_tracking[layoutindex - 1].revert_layout = atoi(attr->value()); + else + caps_tracking[layoutindex - 1].revert_layout = -1; } rowindex = 1; @@ -320,6 +341,30 @@ int GUIKeyboard::Render(void) if (keyboardImg[currentLayout - 1] && keyboardImg[currentLayout - 1]->GetResource()) gr_blit(keyboardImg[currentLayout - 1]->GetResource(), 0, 0, KeyboardWidth, KeyboardHeight, mRenderX, mRenderY); + // Draw highlight for capslock + if (hasCapsHighlight && caps_tracking[currentLayout - 1].capslock == 0 && caps_tracking[currentLayout - 1].set_capslock) { + int boxheight, boxwidth, x; + gr_color(mCapsHighlightColor.red, mCapsHighlightColor.green, mCapsHighlightColor.blue, mCapsHighlightColor.alpha); + for (int indexy=0; indexy 0) { // Regular key PageManager::NotifyKeyboard(keyboard_keys[currentLayout - 1][rowIndex][indexx].key); + if (caps_tracking[currentLayout - 1].capslock == 0 && !caps_tracking[currentLayout - 1].set_capslock) { + // caps lock was not set, change layouts + currentLayout = caps_tracking[currentLayout - 1].revert_layout; + mRendered = false; + } } else if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key == KEYBOARD_LAYOUT) { // Switch layouts - currentLayout = keyboard_keys[currentLayout - 1][rowIndex][indexx].layout; + if (caps_tracking[currentLayout - 1].capslock == 0 && keyboard_keys[currentLayout - 1][rowIndex][indexx].layout == caps_tracking[currentLayout - 1].revert_layout) { + if (!caps_tracking[currentLayout - 1].set_capslock) { + caps_tracking[currentLayout - 1].set_capslock = 1; // Set the caps lock + } else { + caps_tracking[currentLayout - 1].set_capslock = 0; // Unset the caps lock and change layouts + currentLayout = keyboard_keys[currentLayout - 1][rowIndex][indexx].layout; + } + } else { + currentLayout = keyboard_keys[currentLayout - 1][rowIndex][indexx].layout; + } mRendered = false; } else if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key == KEYBOARD_ACTION) { // Action diff --git a/gui/objects.hpp b/gui/objects.hpp index 472d23b42..f8a4e8ca8 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -828,18 +828,26 @@ protected: unsigned int end_x; unsigned int layout; }; + struct capslock_tracking_struct + { + int capslock; + int set_capslock; + int revert_layout; + }; Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS]; struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS]; + struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS]; bool mRendered; std::string mVariable; unsigned int cursorLocation; unsigned int currentLayout; unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS]; unsigned int KeyboardWidth, KeyboardHeight; - int rowY, colX, highlightRenderCount, hasHighlight; + int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight; GUIAction* mAction; COLOR mHighlightColor; + COLOR mCapsHighlightColor; }; // GUIInput - Used for keyboard input -- cgit v1.2.3