Improve screen keyboard layout
This commit is contained in:
parent
9078438b23
commit
2d219f29cc
@ -36,29 +36,38 @@
|
|||||||
|
|
||||||
using namespace GUIEngine;
|
using namespace GUIEngine;
|
||||||
|
|
||||||
#define KEYBOARD_COLS_NUM 11
|
typedef std::vector<std::vector<std::string> > KeyboardLayout;
|
||||||
#define KEYBOARD_ROWS_NUM 3
|
typedef std::vector<std::vector<int> > KeyboardLayoutProportions;
|
||||||
typedef std::string KeyboardLayout[KEYBOARD_ROWS_NUM][KEYBOARD_COLS_NUM];
|
|
||||||
|
|
||||||
KeyboardLayout layout_lower =
|
KeyboardLayout layout_lower =
|
||||||
{{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "123" },
|
{{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"},
|
||||||
{"a", "s", "d", "f", "g", "h", "j", "k", "l", "Shift", "Back" },
|
{"Separator", "a", "s", "d", "f", "g", "h", "j", "k", "l", "Separator"},
|
||||||
{"z", "x", "c", "v", "b", "n", "m", ",", ".", "Space", "Enter"}};
|
{"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", "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"},
|
||||||
|
{"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 =
|
KeyboardLayout layout_digits =
|
||||||
{{"1", "2", "3", "!", "@", "#", "$", "%", "^", "&", "Text" },
|
{{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"},
|
||||||
{"4", "5", "6", "*", "(", ")", "-", "+", "?", "Shift", "Back" },
|
{"Separator", "@", "#", "$", "%", "^", "&", "*", "(", ")", "Separator"},
|
||||||
{"7", "8", "9", "0", "\"", ";", ":", ",", ".", "Space", "Enter"}};
|
{"Shift", "-", "+", ":", ";", "\"", "\'", "/", "?", "Back"},
|
||||||
|
{"Text", ".", "Space", ",", "Enter"}};
|
||||||
|
|
||||||
KeyboardLayout layout_digits2 =
|
KeyboardLayout layout_digits2 =
|
||||||
{{"1", "2", "3", "[", "]", "{", "}", "~", "`", "\\", "Text" },
|
{{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"},
|
||||||
{"4", "5", "6", "|", "<", ">", "_", "=", "/", "Shift", "Back" },
|
{"Separator", "@", "[", "]", "{", "}", "~", "`", "\\", "|", "Separator"},
|
||||||
{"7", "8", "9", "0", "\'", ";", ":", ",", ".", "Space", "Enter"}};
|
{"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;
|
ScreenKeyboard* ScreenKeyboard::m_screen_keyboard = NULL;
|
||||||
|
|
||||||
@ -155,26 +164,41 @@ void ScreenKeyboard::init()
|
|||||||
*/
|
*/
|
||||||
void ScreenKeyboard::createButtons()
|
void ScreenKeyboard::createButtons()
|
||||||
{
|
{
|
||||||
int pos_x = 1;
|
int rows_num = layout_proportions.size();
|
||||||
int pos_y = 10;
|
int pos_y = 3;
|
||||||
int width = (m_area.getWidth() - 2 * pos_x) / KEYBOARD_COLS_NUM;
|
|
||||||
int height = (m_area.getHeight() - 2 * pos_y) / KEYBOARD_ROWS_NUM;
|
|
||||||
|
|
||||||
char width_str[100];
|
int height = (m_area.getHeight() - 2 * pos_y) / rows_num;
|
||||||
sprintf(width_str, "%i", width);
|
|
||||||
char height_str[100];
|
char height_str[100];
|
||||||
sprintf(height_str, "%i", height);
|
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];
|
char tmp[100];
|
||||||
sprintf(tmp, "%i", pos_y + height * i);
|
sprintf(tmp, "%i", pos_y + height * i);
|
||||||
std::string pos_y_str = tmp;
|
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];
|
char tmp[100];
|
||||||
sprintf(tmp, "%i", pos_x + width * j);
|
sprintf(tmp, "%i", (int)roundf(pos_x));
|
||||||
std::string pos_x_str = tmp;
|
std::string pos_x_str = tmp;
|
||||||
|
|
||||||
ButtonWidget* button = new ButtonWidget();
|
ButtonWidget* button = new ButtonWidget();
|
||||||
@ -185,6 +209,8 @@ void ScreenKeyboard::createButtons()
|
|||||||
button->m_properties[PROP_Y] = pos_y_str;
|
button->m_properties[PROP_Y] = pos_y_str;
|
||||||
m_widgets.push_back(button);
|
m_widgets.push_back(button);
|
||||||
m_buttons.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)
|
void ScreenKeyboard::assignButtons(ButtonsType buttons_type)
|
||||||
{
|
{
|
||||||
|
int rows_num = layout_proportions.size();
|
||||||
|
|
||||||
m_buttons_type = buttons_type;
|
m_buttons_type = buttons_type;
|
||||||
|
|
||||||
KeyboardLayout* keys = NULL;
|
KeyboardLayout* keys = NULL;
|
||||||
@ -255,17 +283,32 @@ void ScreenKeyboard::assignButtons(ButtonsType buttons_type)
|
|||||||
break;
|
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::string key = keys != NULL ? (*keys)[i][j] : "?";
|
||||||
std::wstring key_name = getKeyName(key);
|
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());
|
if (key == "Separator")
|
||||||
button->m_properties[PROP_ID] = key;
|
{
|
||||||
|
button->setVisible(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
button->setVisible(true);
|
||||||
|
button->setText(key_name.c_str());
|
||||||
|
button->m_properties[PROP_ID] = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_button_id++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // assignButtons
|
} // assignButtons
|
||||||
|
@ -1786,6 +1786,6 @@ void CGUIEditBox::openScreenKeyboard()
|
|||||||
setTextMarkers(CursorPos, CursorPos);
|
setTextMarkers(CursorPos, CursorPos);
|
||||||
calculateScrollPos();
|
calculateScrollPos();
|
||||||
|
|
||||||
new GUIEngine::ScreenKeyboard(0.98f, 0.30f, this);
|
new GUIEngine::ScreenKeyboard(0.98f, 0.40f, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user