diff options
Diffstat (limited to '')
-rw-r--r-- | gui/keyboard.cpp | 63 |
1 files changed, 61 insertions, 2 deletions
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<MAX_KEYBOARD_ROWS; indexy++) { + for (int indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) { + if ((int)keyboard_keys[currentLayout - 1][indexy][indexx].key == KEYBOARD_LAYOUT && (int)keyboard_keys[currentLayout - 1][indexy][indexx].layout == caps_tracking[currentLayout - 1].revert_layout) { + if (indexy == 0) + boxheight = row_heights[currentLayout - 1][indexy]; + else + boxheight = row_heights[currentLayout - 1][indexy] - row_heights[currentLayout - 1][indexy - 1]; + if (indexx == 0) { + x = mRenderX; + boxwidth = keyboard_keys[currentLayout - 1][indexy][indexx].end_x; + } else { + x = mRenderX + keyboard_keys[currentLayout - 1][indexy][indexx - 1].end_x; + boxwidth = keyboard_keys[currentLayout - 1][indexy][indexx].end_x - keyboard_keys[currentLayout - 1][indexy][indexx - 1].end_x; + } + gr_fill(x, mRenderY + row_heights[currentLayout - 1][indexy - 1], boxwidth, boxheight); + } + } + } + } + if (hasHighlight && highlightRenderCount != 0) { int boxheight, boxwidth, x; if (rowY == 0) @@ -477,9 +522,23 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key < KEYBOARD_SPECIAL_KEYS && (int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key > 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 |