14
14
#include " ui/keypad_icons.h"
15
15
#include " keypad.h"
16
16
17
- constexpr int ROW_LENGTHS[] = {7 , 10 , 9 , 9 , 8 };
17
+ constexpr int ROW_LENGTHS[] = {7 , 10 , 9 , 9 , 9 };
18
18
constexpr int MAX_ROWS = 5 ;
19
19
constexpr int MAX_COLS = 10 ;
20
20
constexpr int QWERTY_ROW = 1 ;
@@ -32,6 +32,12 @@ constexpr double MAX_HEIGHT_FACTOR = 0.48;
32
32
// image height based on available rectangle
33
33
constexpr double IMAGE_SIZE_FACTOR = 0.65 ;
34
34
35
+ // IMAGE_SIZE_FACTOR for the tag image
36
+ constexpr double TAG_IMAGE_SIZE_FACTOR = 0.42 ;
37
+
38
+ // IMAGE_SIZE_FACTOR for the page up/down images
39
+ constexpr double PAGE_IMAGE_SIZE_FACTOR = 0.52 ;
40
+
35
41
// https://materialui.co/colors
36
42
KeypadTheme MODERN_DARK_THEME = {
37
43
._bg = 0x121212 , // Material UI standard dark background
@@ -59,55 +65,55 @@ constexpr RawKey KEYS[MAX_ROWS][MAX_COLS] = {
59
65
},
60
66
// QWERTY
61
67
{
62
- {K_q, K_Q , K_1, K_EXCLAIM },
63
- {K_w, K_W , K_2, K_AT },
64
- {K_e, K_E , K_3, K_HASH },
65
- {K_r, K_R , K_4, K_DOLLAR },
66
- {K_t, K_T , K_5, K_PERCENT },
67
- {K_y, K_Y , K_6, K_CARET },
68
- {K_u, K_U , K_7, K_AMPERSAND },
69
- {K_i, K_I , K_8, K_ASTERISK },
70
- {K_o, K_O , K_9, K_LPAREN },
71
- {K_p, K_P , K_0, K_RPAREN }
68
+ {K_q, K_1 , K_1, K_Q },
69
+ {K_w, K_2 , K_2, K_W },
70
+ {K_e, K_3 , K_3, K_E },
71
+ {K_r, K_4 , K_4, K_R },
72
+ {K_t, K_5 , K_5, K_T },
73
+ {K_y, K_6 , K_6, K_Y },
74
+ {K_u, K_7 , K_7, K_U },
75
+ {K_i, K_8 , K_8, K_I },
76
+ {K_o, K_9 , K_9, K_O },
77
+ {K_p, K_0 , K_0, K_P }
72
78
},
73
79
// ASDF
74
80
{
75
- {K_a, K_A, K_BACKTICK, K_TILDE },
76
- {K_s, K_S, K_MINUS, K_UNDERSCORE },
77
- {K_d, K_D, K_EQUALS, K_PLUS },
78
- {K_f, K_F, K_LBRACKET, K_LBRACE },
79
- {K_g, K_G, K_RBRACKET, K_RBRACE },
80
- {K_h, K_H, K_BACKSLASH, K_PIPE },
81
- {K_j, K_J, K_SEMICOLON, K_COLON },
82
- {K_k, K_K, K_APOSTROPHE, K_QUOTE },
83
- {K_l, K_L, K_HASH, K_TAG },
81
+ {K_a, K_COMMA, K_SLASH, K_A },
82
+ {K_s, K_EQUALS, K_HASH, K_S },
83
+ {K_d, K_LPAREN, K_SEMICOLON, K_D },
84
+ {K_f, K_RPAREN, K_QUESTION, K_F },
85
+ {K_g, K_QUOTE, K_AMPERSAND, K_G },
86
+ {K_h, K_APOSTROPHE, K_DOLLAR, K_H },
87
+ {K_j, K_PERIOD, K_EXCLAIM, K_J },
88
+ {K_k, K_MINUS, K_AT, K_K },
89
+ {K_l, K_ASTERISK, K_BACKSLASH, K_L },
84
90
{K_NULL}
85
91
},
86
92
// ZXC
87
93
{
88
94
{K_TOGGLE, K_TOGGLE, K_TOGGLE, K_TOGGLE},
89
- {K_z, K_Z, K_LESS, K_COMMA },
90
- {K_x, K_X, K_GREATER, K_PERIOD },
91
- {K_c, K_C, K_QUESTION, K_SLASH },
92
- {K_v, K_V, K_PLUS, K_EXT2 },
93
- {K_b, K_B, K_ASTERISK, K_EXT3 },
94
- {K_n, K_N, K_LPAREN, K_EXT4 },
95
- {K_m, K_M, K_RPAREN, K_EXT5 },
95
+ {K_z, K_UNDERSCORE, K_CARET, K_Z },
96
+ {K_x, K_PLUS, K_LBRACE, K_X },
97
+ {K_c, K_COLON, K_RBRACE, K_C },
98
+ {K_v, K_LBRACKET, K_PIPE, K_V },
99
+ {K_b, K_RBRACKET, K_PERCENT, K_B },
100
+ {K_n, K_LESS, K_BACKTICK, K_N },
101
+ {K_m, K_GREATER, K_TILDE, K_M },
96
102
{K_BACKSPACE, K_BACKSPACE, K_BACKSPACE, K_BACKSPACE},
97
103
{K_NULL}
98
104
},
99
105
// FUNCs, SPACE
100
106
{
101
107
{K_LINE_UP, K_PAGE_UP, K_LINE_UP, K_PAGE_UP},
102
108
{K_LINE_DOWN, K_PAGE_DOWN, K_LINE_DOWN, K_PAGE_DOWN},
103
- {K_LPAREN, K_LBRACKET, K_LPAREN , K_LBRACKET},
109
+ {K_LPAREN, K_SLASH, K_COMMA , K_LBRACKET},
104
110
{K_SPACE, K_SPACE, K_SPACE, K_SPACE},
105
- {K_RPAREN, K_RBRACKET, K_RPAREN, K_RBRACKET},
111
+ {K_RPAREN, K_HASH, K_EQUALS, K_RBRACKET},
112
+ {K_TAG, K_TAG, K_TAG, K_TAG},
106
113
{K_ENTER, K_ENTER, K_ENTER, K_ENTER},
107
114
{K_NULL},
108
115
{K_NULL},
109
116
{K_NULL},
110
- {K_NULL}
111
117
}
112
118
};
113
119
@@ -144,6 +150,7 @@ KeypadDrawContext::KeypadDrawContext(int charWidth, int charHeight) :
144
150
_charWidth(charWidth),
145
151
_charHeight(charHeight),
146
152
_imageSize(IMAGE_SIZE),
153
+ _punctuation(false ),
147
154
_keySet(kLower ) {
148
155
if (!_cutImage.decode (img_cut, img_cut_len) ||
149
156
!_copyImage.decode (img_copy, img_copy_len) ||
@@ -200,8 +207,11 @@ KeyCode KeypadDrawContext::getKey(RawKey key) const {
200
207
}
201
208
202
209
void KeypadDrawContext::layoutHeight (int padding) {
203
- const int imageSize = static_cast <int >((padding * 2 + _charHeight) * IMAGE_SIZE_FACTOR);
210
+ const int baseSize = padding * 2 + _charHeight;
211
+ const int imageSize = static_cast <int >(baseSize * IMAGE_SIZE_FACTOR);
204
212
if (imageSize < _imageSize - 2 || imageSize > _imageSize + 2 ) {
213
+ const int tagImageSize = static_cast <int >(baseSize * TAG_IMAGE_SIZE_FACTOR);
214
+ const int pageImageSize = static_cast <int >(baseSize * PAGE_IMAGE_SIZE_FACTOR);
205
215
_cutImage.resize (imageSize, imageSize);
206
216
_copyImage.resize (imageSize, imageSize);
207
217
_pasteImage.resize (imageSize, imageSize);
@@ -211,26 +221,46 @@ void KeypadDrawContext::layoutHeight(int padding) {
211
221
_backImage.resize (imageSize, imageSize);
212
222
_enterImage.resize (imageSize, imageSize);
213
223
_searchImage.resize (imageSize, imageSize);
214
- _lineUpImage.resize (imageSize, imageSize);
215
- _pageUpImage.resize (imageSize, imageSize);
216
- _lineDownImage.resize (imageSize, imageSize);
217
- _pageDownImage.resize (imageSize, imageSize);
218
224
_toggleImage.resize (imageSize, imageSize);
219
- _tagImage.resize (imageSize, imageSize);
225
+ _lineUpImage.resize (pageImageSize, pageImageSize);
226
+ _lineDownImage.resize (pageImageSize, pageImageSize);
227
+ _pageDownImage.resize (pageImageSize, pageImageSize);
228
+ _pageUpImage.resize (pageImageSize, pageImageSize);
229
+ _tagImage.resize (tagImageSize, tagImageSize);
220
230
_imageSize = imageSize;
221
231
}
222
232
}
223
233
234
+ void KeypadDrawContext::onClick (RawKey key) {
235
+ switch (getKey (key)) {
236
+ case K_ENTER:
237
+ case K_RPAREN:
238
+ case K_RBRACKET:
239
+ case K_RBRACE:
240
+ _keySet = kLower ;
241
+ _punctuation = false ;
242
+ break ;
243
+ default :
244
+ _punctuation = (_keySet == kSymbol || _keySet == kNumber );
245
+ break ;
246
+ }
247
+ }
248
+
224
249
void KeypadDrawContext::toggle () {
225
- _keySet = static_cast <Keyset>((_keySet + 1 ) % kSize );
250
+ if (_punctuation) {
251
+ _keySet = kLower ;
252
+ _punctuation = false ;
253
+ } else {
254
+ _keySet = static_cast <Keyset>((_keySet + 1 ) % kSize );
255
+ }
226
256
}
227
257
228
258
//
229
259
// Key
230
260
//
231
261
Key::Key (const RawKey &k) :
232
262
_key(k) {
233
- _printable = isPrintable (k._lower ) || isExtended (k. _lower ) ;
263
+ _printable = isPrintable (k._lower );
234
264
}
235
265
236
266
int Key::color (const KeypadTheme *theme) const {
@@ -243,22 +273,6 @@ int Key::color(const KeypadTheme *theme) const {
243
273
return result;
244
274
}
245
275
246
- char Key::getKey (const KeypadDrawContext *context) const {
247
- char result;
248
- KeyCode keyCode = context->getKey (_key);
249
- switch (keyCode) {
250
- case K_EXT1: result = (char )164 ; break ;
251
- case K_EXT2: result = (char )172 ; break ;
252
- case K_EXT3: result = (char )182 ; break ;
253
- case K_EXT4: result = (char )222 ; break ;
254
- case K_EXT5: result = (char )223 ; break ;
255
- default :
256
- result = keyCode;
257
- break ;
258
- }
259
- return result;
260
- }
261
-
262
276
void Key::draw (const KeypadTheme *theme, const KeypadDrawContext *context, bool pressed) const {
263
277
int rc = 5 ;
264
278
int pad = 2 ;
@@ -273,7 +287,7 @@ void Key::draw(const KeypadTheme *theme, const KeypadDrawContext *context, bool
273
287
int ycT = _y + rc + pad; // y center for top arcs
274
288
int ycB = by - rc; // y center for bottom arcs
275
289
276
- char keyChar = getKey (context );
290
+ char keyChar = context-> getKey (_key );
277
291
bool printable = _printable && keyChar != K_TAG;
278
292
279
293
// Set background color
@@ -331,7 +345,7 @@ bool Key::inside(int x, int y) const {
331
345
y <= _yEnd);
332
346
}
333
347
334
- void Key::onClick (const KeypadDrawContext *context) const {
348
+ void Key::onClick (KeypadDrawContext *context) const {
335
349
auto *event = new MAEvent ();
336
350
event->type = EVENT_TYPE_KEY_PRESSED;
337
351
event->nativeKey = 0 ;
@@ -341,6 +355,7 @@ void Key::onClick(const KeypadDrawContext *context) const {
341
355
break ;
342
356
case K_ENTER:
343
357
event->key = SB_KEY_ENTER;
358
+ context->onClick (_key);
344
359
break ;
345
360
case K_SPACE:
346
361
event->key = SB_KEY_SPACE;
@@ -382,7 +397,8 @@ void Key::onClick(const KeypadDrawContext *context) const {
382
397
event->key = SB_KEY_CTRL (' t' );
383
398
break ;
384
399
default :
385
- event->key = (unsigned char )getKey (context);
400
+ event->key = (unsigned char )context->getKey (_key);
401
+ context->onClick (_key);
386
402
break ;
387
403
}
388
404
maPushEvent (event);
@@ -452,7 +468,7 @@ void Keypad::layout(int x, int y, int w, int h) {
452
468
keyWidth = _width / cols;
453
469
} else if (isArrow (key->_key ._lower )) {
454
470
keyWidth = static_cast <int >(keyWidth * 1.2 );
455
- } else if (!key->_printable ) {
471
+ } else if (!key->_printable && key-> _key . _lower != K_TAG ) {
456
472
const int numKeys = 2 ;
457
473
keyWidth = (_width - ((cols - numKeys) * keyW)) / numKeys;
458
474
} else if (key->_key ._lower == K_SPACE) {
0 commit comments