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/keyboard.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'gui/keyboard.cpp') 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 -- cgit v1.2.3