diff --git a/src/guiengine/screen_keyboard.cpp b/src/guiengine/screen_keyboard.cpp index 641ec3c3d..8781f855e 100644 --- a/src/guiengine/screen_keyboard.cpp +++ b/src/guiengine/screen_keyboard.cpp @@ -36,29 +36,38 @@ using namespace GUIEngine; -#define KEYBOARD_COLS_NUM 11 -#define KEYBOARD_ROWS_NUM 3 -typedef std::string KeyboardLayout[KEYBOARD_ROWS_NUM][KEYBOARD_COLS_NUM]; - +typedef std::vector > KeyboardLayout; +typedef std::vector > KeyboardLayoutProportions; + KeyboardLayout layout_lower = - {{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "123" }, - {"a", "s", "d", "f", "g", "h", "j", "k", "l", "Shift", "Back" }, - {"z", "x", "c", "v", "b", "n", "m", ",", ".", "Space", "Enter"}}; - -KeyboardLayout layout_upper = - {{"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "123" }, - {"A", "S", "D", "F", "G", "H", "J", "K", "L", "Shift", "Back" }, - {"Z", "X", "C", "V", "B", "N", "M", ",", ".", "Space", "Enter"}}; + {{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"}, + {"Separator", "a", "s", "d", "f", "g", "h", "j", "k", "l", "Separator"}, + {"Shift", "z", "x", "c", "v", "b", "n", "m", "?", "Back"}, + {"123", ".", "Space", ",", "Enter"}}; +KeyboardLayout layout_upper = + {{"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"}, + {"Separator", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Separator"}, + {"Shift", "Z", "X", "C", "V", "B", "N", "M", "!", "Back"}, + {"123", ".", "Space", ",", "Enter"}}; + KeyboardLayout layout_digits = - {{"1", "2", "3", "!", "@", "#", "$", "%", "^", "&", "Text" }, - {"4", "5", "6", "*", "(", ")", "-", "+", "?", "Shift", "Back" }, - {"7", "8", "9", "0", "\"", ";", ":", ",", ".", "Space", "Enter"}}; - + {{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}, + {"Separator", "@", "#", "$", "%", "^", "&", "*", "(", ")", "Separator"}, + {"Shift", "-", "+", ":", ";", "\"", "\'", "/", "?", "Back"}, + {"Text", ".", "Space", ",", "Enter"}}; + KeyboardLayout layout_digits2 = - {{"1", "2", "3", "[", "]", "{", "}", "~", "`", "\\", "Text" }, - {"4", "5", "6", "|", "<", ">", "_", "=", "/", "Shift", "Back" }, - {"7", "8", "9", "0", "\'", ";", ":", ",", ".", "Space", "Enter"}}; + {{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}, + {"Separator", "@", "[", "]", "{", "}", "~", "`", "\\", "|", "Separator"}, + {"Shift", "_", "=", ":", ";", "<", ">", "/", "!", "Back"}, + {"Text", ".", "Space", ",", "Enter"}}; + +KeyboardLayoutProportions layout_proportions = + {{2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, + {1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1}, + {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, + {3, 2, 10, 2, 3}}; ScreenKeyboard* ScreenKeyboard::m_screen_keyboard = NULL; @@ -155,26 +164,41 @@ void ScreenKeyboard::init() */ void ScreenKeyboard::createButtons() { - int pos_x = 1; - int pos_y = 10; - int width = (m_area.getWidth() - 2 * pos_x) / KEYBOARD_COLS_NUM; - int height = (m_area.getHeight() - 2 * pos_y) / KEYBOARD_ROWS_NUM; + int rows_num = layout_proportions.size(); + int pos_y = 3; - char width_str[100]; - sprintf(width_str, "%i", width); + int height = (m_area.getHeight() - 2 * pos_y) / rows_num; char height_str[100]; sprintf(height_str, "%i", height); - - for (int i = 0; i < KEYBOARD_ROWS_NUM; i++) + + for (int i = 0; i < rows_num; i++) { + float pos_x = 3; + int total_width = m_area.getWidth() - 2 * (int)pos_x; + char tmp[100]; sprintf(tmp, "%i", pos_y + height * i); std::string pos_y_str = tmp; - for (int j = 0; j < KEYBOARD_COLS_NUM; j++) + int total_proportions = 0; + + for (int value : layout_proportions[i]) { + total_proportions += value; + } + + int cols_num = layout_proportions[i].size(); + + for (int j = 0; j < cols_num; j++) + { + float width = (float)total_width * layout_proportions[i][j] + / total_proportions; + + char width_str[100]; + sprintf(width_str, "%i", (int)roundf(width)); + char tmp[100]; - sprintf(tmp, "%i", pos_x + width * j); + sprintf(tmp, "%i", (int)roundf(pos_x)); std::string pos_x_str = tmp; ButtonWidget* button = new ButtonWidget(); @@ -185,6 +209,8 @@ void ScreenKeyboard::createButtons() button->m_properties[PROP_Y] = pos_y_str; m_widgets.push_back(button); m_buttons.push_back(button); + + pos_x += width; } } @@ -232,6 +258,8 @@ std::wstring ScreenKeyboard::getKeyName(std::string key_id) */ void ScreenKeyboard::assignButtons(ButtonsType buttons_type) { + int rows_num = layout_proportions.size(); + m_buttons_type = buttons_type; KeyboardLayout* keys = NULL; @@ -255,17 +283,32 @@ void ScreenKeyboard::assignButtons(ButtonsType buttons_type) break; }; - for (int i = 0; i < KEYBOARD_ROWS_NUM; i++) + unsigned int current_button_id = 0; + + for (int i = 0; i < rows_num; i++) { - for (int j = 0; j < KEYBOARD_COLS_NUM; j++) + int cols_num = layout_proportions[i].size(); + + for (int j = 0; j < cols_num; j++) { std::string key = keys != NULL ? (*keys)[i][j] : "?"; std::wstring key_name = getKeyName(key); - ButtonWidget* button = m_buttons[i * KEYBOARD_COLS_NUM + j]; + assert(current_button_id < m_buttons.size()); + ButtonWidget* button = m_buttons[current_button_id]; - button->setText(key_name.c_str()); - button->m_properties[PROP_ID] = key; + if (key == "Separator") + { + button->setVisible(false); + } + else + { + button->setVisible(true); + button->setText(key_name.c_str()); + button->m_properties[PROP_ID] = key; + } + + current_button_id++; } } } // assignButtons diff --git a/src/guiengine/widgets/CGUIEditBox.cpp b/src/guiengine/widgets/CGUIEditBox.cpp index 4e63213a1..21fdb30db 100644 --- a/src/guiengine/widgets/CGUIEditBox.cpp +++ b/src/guiengine/widgets/CGUIEditBox.cpp @@ -1786,6 +1786,6 @@ void CGUIEditBox::openScreenKeyboard() setTextMarkers(CursorPos, CursorPos); calculateScrollPos(); - new GUIEngine::ScreenKeyboard(0.98f, 0.30f, this); + new GUIEngine::ScreenKeyboard(0.98f, 0.40f, this); }