From 30b962eb5184490c10cd9f44cd161e4b93403b37 Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Fri, 19 Oct 2012 20:48:59 -0400 Subject: Add keyboard key highlight --- gui/devices/1024x600/res/ui.xml | 1 + gui/devices/1024x768/res/ui.xml | 1 + gui/devices/1280x800/res/ui.xml | 1 + gui/devices/1920x1200/res/ui.xml | 1 + gui/devices/320x480/res/ui.xml | 1 + gui/devices/480x800/res/ui.xml | 1 + gui/devices/480x854/res/ui.xml | 1 + gui/devices/540x960/res/ui.xml | 1 + gui/devices/720x1280/res/ui.xml | 1 + gui/devices/800x1280/res/ui.xml | 1 + gui/devices/800x480/res/ui.xml | 1 + gui/keyboard.cpp | 90 ++++++++++++++++++++++++++++++++++++++-- gui/objects.hpp | 2 + gui/pages.cpp | 29 ++++++++----- 14 files changed, 117 insertions(+), 15 deletions(-) (limited to 'gui') diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml index 9873669ef..2542a1868 100755 --- a/gui/devices/1024x600/res/ui.xml +++ b/gui/devices/1024x600/res/ui.xml @@ -364,6 +364,7 @@ + diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml index ab269c1f4..af14bc219 100644 --- a/gui/devices/1024x768/res/ui.xml +++ b/gui/devices/1024x768/res/ui.xml @@ -364,6 +364,7 @@ + diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml index 8b9503def..14f2b77fc 100644 --- a/gui/devices/1280x800/res/ui.xml +++ b/gui/devices/1280x800/res/ui.xml @@ -364,6 +364,7 @@ + diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml index 3220dc045..62c07d626 100644 --- a/gui/devices/1920x1200/res/ui.xml +++ b/gui/devices/1920x1200/res/ui.xml @@ -364,6 +364,7 @@ + diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml index 3231f5f10..04807cdbb 100644 --- a/gui/devices/320x480/res/ui.xml +++ b/gui/devices/320x480/res/ui.xml @@ -321,6 +321,7 @@ + diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml index 3d6b8799e..5ac411310 100644 --- a/gui/devices/480x800/res/ui.xml +++ b/gui/devices/480x800/res/ui.xml @@ -320,6 +320,7 @@ + diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml index 1733b90b8..7593601d8 100644 --- a/gui/devices/480x854/res/ui.xml +++ b/gui/devices/480x854/res/ui.xml @@ -319,6 +319,7 @@ + diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml index 5a82579c0..587ccc72c 100644 --- a/gui/devices/540x960/res/ui.xml +++ b/gui/devices/540x960/res/ui.xml @@ -320,6 +320,7 @@ + diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml index 5490accc5..1c16783ac 100644 --- a/gui/devices/720x1280/res/ui.xml +++ b/gui/devices/720x1280/res/ui.xml @@ -325,6 +325,7 @@ + diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml index a86c7d6a3..0a9290e3c 100755 --- a/gui/devices/800x1280/res/ui.xml +++ b/gui/devices/800x1280/res/ui.xml @@ -321,6 +321,7 @@ + diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml index dc7324635..53530d58e 100755 --- a/gui/devices/800x480/res/ui.xml +++ b/gui/devices/800x480/res/ui.xml @@ -364,6 +364,7 @@ + diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp index 6595d8da2..f44e56357 100644 --- a/gui/keyboard.cpp +++ b/gui/keyboard.cpp @@ -1,4 +1,24 @@ -// keyboard.cpp - GUIKeyboard object +/* keyboard.cpp - GUIKeyboard object + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * The code was written from scratch by Dees_Troy dees_troy at + * yahoo + * + * Copyright (c) 2012 + */ #include #include @@ -30,6 +50,8 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node) : Conditional(node) { int layoutindex, rowindex, keyindex, Xindex, Yindex, keyHeight = 0, keyWidth = 0; + rowY = colX = -1; + highlightRenderCount = hasHighlight = 0; char resource[9], layout[7], row[4], key[5], longpress[6]; xml_attribute<>* attr; xml_node<>* child; @@ -53,6 +75,17 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node) mAction = new GUIAction(node); } + memset(&mHighlightColor, 0, sizeof(COLOR)); + child = node->first_node("highlight"); + if (child) { + attr = child->first_attribute("color"); + if (attr) { + hasHighlight = 1; + std::string color = attr->value(); + ConvertStrToColor(color, &mHighlightColor); + } + } + // Load the images for the different layouts child = node->first_node("layout"); if (child) @@ -294,7 +327,26 @@ int GUIKeyboard::Render(void) if (keyboardImg[currentLayout - 1] && keyboardImg[currentLayout - 1]->GetResource()) gr_blit(keyboardImg[currentLayout - 1]->GetResource(), 0, 0, KeyboardWidth, KeyboardHeight, mRenderX, mRenderY); - mRendered = true; + if (hasHighlight && highlightRenderCount != 0) { + int boxheight, boxwidth, x; + if (rowY == 0) + boxheight = row_heights[currentLayout - 1][rowY]; + else + boxheight = row_heights[currentLayout - 1][rowY] - row_heights[currentLayout - 1][rowY - 1]; + if (colX == 0) { + x = mRenderX; + boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x; + } else { + x = mRenderX + keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x; + boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x - keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x; + } + gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); + gr_fill(x, mRenderY + row_heights[currentLayout - 1][rowY - 1], boxwidth, boxheight); + if (highlightRenderCount > 0) + highlightRenderCount--; + } else + mRendered = true; + return ret; } @@ -323,7 +375,7 @@ int GUIKeyboard::SetRenderPos(int x, int y, int w, int h) int GUIKeyboard::GetSelection(int x, int y) { - if (x < mRenderX || x - mRenderX > KeyboardWidth || y < mRenderY || y - mRenderY > KeyboardHeight) return -1; + if (x < mRenderX || x - mRenderX > (int)KeyboardWidth || y < mRenderY || y - mRenderY > (int)KeyboardHeight) return -1; return 0; } @@ -349,6 +401,7 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) for (indexy=0; indexy rely) { rowIndex = indexy; + rowY = indexy; indexy = MAX_KEYBOARD_ROWS; } } @@ -358,10 +411,19 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) if (keyboard_keys[currentLayout - 1][rowIndex][indexx].end_x > relx) { // This is the key that was pressed! initial_key = keyboard_keys[currentLayout - 1][rowIndex][indexx].key; + colX = indexx; indexx = MAX_KEYBOARD_KEYS; } } + if (initial_key != 0) + highlightRenderCount = -1; + else + highlightRenderCount = 0; + mRendered = false; } else { + if (highlightRenderCount != 0) + mRendered = false; + highlightRenderCount = 0; startSelection = 0; } break; @@ -369,9 +431,17 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) break; case TOUCH_RELEASE: if (x < startX - (KeyboardWidth * 0.5)) { + if (highlightRenderCount != 0) { + highlightRenderCount = 0; + mRendered = false; + } PageManager::NotifyKeyboard(KEYBOARD_SWIPE_LEFT); return 0; } else if (x > startX + (KeyboardWidth * 0.5)) { + if (highlightRenderCount != 0) { + highlightRenderCount = 0; + mRendered = false; + } PageManager::NotifyKeyboard(KEYBOARD_SWIPE_RIGHT); return 0; } @@ -379,8 +449,19 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) case TOUCH_HOLD: case TOUCH_REPEAT: - if (startSelection == 0 || GetSelection(x, y) == -1) + if (startSelection == 0 || GetSelection(x, y) == -1) { + if (highlightRenderCount != 0) { + highlightRenderCount = 0; + mRendered = false; + } return 0; + } else if (highlightRenderCount != 0) { + if (state == TOUCH_RELEASE) + highlightRenderCount = 2; + else + highlightRenderCount = -1; + mRendered = false; + } // Find the correct row for (indexy=0; indexyNotifyTouch(state, x, y) : 1); diff --git a/gui/objects.hpp b/gui/objects.hpp index 8f7823663..c310b369a 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -675,7 +675,9 @@ protected: unsigned int currentLayout; unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS]; unsigned int KeyboardWidth, KeyboardHeight; + int rowY, colX, highlightRenderCount, hasHighlight; GUIAction* mAction; + COLOR mHighlightColor; }; // GUIInput - Used for keyboard input diff --git a/gui/pages.cpp b/gui/pages.cpp index 7e9274def..c4a65b43a 100644 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -54,17 +54,24 @@ int ConvertStrToColor(std::string str, COLOR* color) if (str[0] != '#') return -1; str.erase(0, 1); - int result = strtol(str.c_str(), NULL, 16); - if (str.size() > 6) - { - // We have alpha channel - color->alpha = result & 0x000000FF; - result = result >> 8; - } - color->red = (result >> 16) & 0x000000FF; - color->green = (result >> 8) & 0x000000FF; - color->blue = result & 0x000000FF; - return 0; + int result; + if (str.size() >= 8) { + // We have alpha channel + string alpha = str.substr(6, 2); + result = strtol(alpha.c_str(), NULL, 16); + color->alpha = result & 0x000000FF; + str.resize(6); + result = strtol(str.c_str(), NULL, 16); + color->red = (result >> 16) & 0x000000FF; + color->green = (result >> 8) & 0x000000FF; + color->blue = result & 0x000000FF; + } else { + result = strtol(str.c_str(), NULL, 16); + color->red = (result >> 16) & 0x000000FF; + color->green = (result >> 8) & 0x000000FF; + color->blue = result & 0x000000FF; + } + return 0; } // Helper APIs -- cgit v1.2.3