@@ -86,6 +86,24 @@ constexpr int rowCharLengths[][5] = {
8686 {6 , 10 , 8 , 14 , 0 }, // symbols
8787};
8888
89+ //
90+ // KeypadImage
91+ //
92+ KeypadImage::KeypadImage () : ImageCodec() {
93+ }
94+
95+ void KeypadImage::draw (int x, int y, int w, int h) const {
96+ MAPoint2d dstPoint;
97+ MARect srcRect;
98+ dstPoint.x = x + (w - _width) / 2 ;
99+ dstPoint.y = y + (h - _height) / 2 ;
100+ srcRect.left = 0 ;
101+ srcRect.top = 0 ;
102+ srcRect.width = _width;
103+ srcRect.height = _height;
104+ maDrawRGB (&dstPoint, _pixels, &srcRect, 0 , _width);
105+ }
106+
89107//
90108// KeypadDrawContext
91109//
@@ -94,15 +112,30 @@ KeypadDrawContext::KeypadDrawContext(int charWidth, int charHeight) :
94112 _charHeight(charHeight),
95113 _shiftActive(false ),
96114 _capsLockActive(false ),
97- _cutImage(img_cut, img_cut_len),
98- _copyImage(img_copy, img_copy_len),
99- _pasteImage(img_clipboard_paste, img_clipboard_paste_len),
100- _saveImage(img_save, img_save_len),
101- _runImage(img_bug_play, img_bug_play_len),
102- _helpImage(img_book_info_2, img_book_info_2_len),
103- _backImage(img_backspace, img_backspace_len),
104- _enterImage(img_arrow_enter, img_arrow_enter_len),
105- _searchImage(img_search, img_search_len) {
115+ _cutImage(),
116+ _copyImage(),
117+ _pasteImage(),
118+ _saveImage(),
119+ _runImage(),
120+ _helpImage(),
121+ _backImage(),
122+ _enterImage(),
123+ _searchImage(),
124+ _shiftImage() {
125+
126+ if (!_cutImage.decode (img_cut, img_cut_len) ||
127+ !_copyImage.decode (img_copy, img_copy_len) ||
128+ !_pasteImage.decode (img_clipboard_paste, img_clipboard_paste_len) ||
129+ !_saveImage.decode (img_save, img_save_len) ||
130+ !_runImage.decode (img_bug_play, img_bug_play_len) ||
131+ !_helpImage.decode (img_book_info_2, img_book_info_2_len) ||
132+ !_backImage.decode (img_backspace, img_backspace_len) ||
133+ !_enterImage.decode (img_arrow_enter, img_arrow_enter_len) ||
134+ !_searchImage.decode (img_search, img_search_len) ||
135+ !_shiftImage.decode (img_keyboard_shift, img_keyboard_shift_len) ||
136+ !_toggleImage.decode (img_keyboard, img_keyboard_len)) {
137+ deviceLog (_cutImage.getLastError ());
138+ }
106139}
107140
108141void KeypadDrawContext::toggleShift () {
@@ -117,6 +150,25 @@ bool KeypadDrawContext::useShift(bool specialKey) {
117150 return useShift;
118151}
119152
153+ const KeypadImage *KeypadDrawContext::getImage (const KeyCode keycode) const {
154+ const KeypadImage *result;
155+ switch (keycode) {
156+ case K_CUT: result = &_cutImage; break ;
157+ case K_COPY: result = &_copyImage; break ;
158+ case K_PASTE: result = &_pasteImage; break ;
159+ case K_SAVE: result = &_saveImage; break ;
160+ case K_RUN: result = &_runImage; break ;
161+ case K_HELP: result = &_helpImage; break ;
162+ case K_BACKSPACE: result = &_backImage;break ;
163+ case K_ENTER: result = &_enterImage; break ;
164+ case K_SEARCH: result = &_searchImage; break ;
165+ case K_SHIFT: result = &_shiftImage; break ;
166+ case K_TOGGLE: result = &_toggleImage; break ;
167+ default : result = nullptr ; break ;
168+ }
169+ return result;
170+ }
171+
120172//
121173// Key
122174//
@@ -142,18 +194,6 @@ int Key::color(const KeypadTheme *theme, bool shiftActive) const {
142194 return result;
143195}
144196
145- void Key::drawImage (const ImageCodec *image) const {
146- MAPoint2d dstPoint;
147- MARect srcRect;
148- dstPoint.x = _x;
149- dstPoint.y = _y;
150- srcRect.left = 0 ;
151- srcRect.top = 0 ;
152- // srcRect.width = image->_width;
153- // srcRect.height = image->_height;
154- // maDrawRGB(&dstPoint, image->_pixels, &srcRect, 0, image->_width);
155- }
156-
157197void Key::draw (const KeypadTheme *theme, const KeypadDrawContext *context) const {
158198 int rc = 5 ;
159199 int pad = 2 ;
@@ -198,7 +238,10 @@ void Key::draw(const KeypadTheme *theme, const KeypadDrawContext *context) const
198238 maSetColor (color (theme, context->_shiftActive ));
199239 maDrawText (textX, textY, key, 1 );
200240 } else {
201- drawImage (&context->_enterImage );
241+ auto *image = context->getImage (_key);
242+ if (image) {
243+ image->draw (_x, _y, _w, _h);
244+ }
202245 }
203246}
204247
0 commit comments