@@ -52,17 +52,76 @@ void TouchKeyboardLayout::calculateKeyHeight(DeviceDrawableHelper& helper) {
5252 if (actualRows && eachKeyHeight > size.y / actualRows) eachKeyHeight = size.y / actualRows;
5353}
5454
55+ SingleValuePerFieldTouchEditor* SingleValuePerFieldTouchEditor::initSingle (MenuItem* item) {
56+ initFor (item);
57+ if (item->getMenuType () == MENUTYPE_LARGENUM_VALUE ) {
58+ if (auto numItem = reinterpret_cast <EditableLargeNumberMenuItem*>(item); numItem->isNegativeAllowed ()) {
59+ numItem->nextPart ();
60+ }
61+ }
62+
63+ return this ;
64+ }
65+
5566void SingleValuePerFieldTouchEditor::keypress (TcTouchKeyboardController* controller, char ch) {
67+ bool moreToGo = true ;
5668 if (menuItem->getMenuType () == MENUTYPE_TEXT_VALUE ) {
57- const auto txtItem = reinterpret_cast <TextMenuItem*>(menuItem);
58- txtItem->valueChangedFromKeyboard (ch);
59- } else {
60- menuItem->valueChanged (ch);
69+ if (ch == 0xFE ) {
70+ capsLock = true ;
71+ } else {
72+ const auto txtItem = reinterpret_cast <TextMenuItem*>(menuItem);
73+ if (capsLock) {
74+ ch = toupper (ch);
75+ }
76+ txtItem->valueChangedFromKeyboard (ch);
77+ moreToGo = menuItem->nextPart () != 0 ;
78+ }
79+ } else if (menuItem->getMenuType () == MENUTYPE_LARGENUM_VALUE ) {
80+ const auto lgeItem = reinterpret_cast <EditableLargeNumberMenuItem*>(menuItem);
81+ if (ch == ' +' && lgeItem->isNegativeAllowed ()) {
82+ const auto neg = lgeItem->getLargeNumber ()->isNegative () ? 0 : 1 ;
83+ lgeItem->setNegativeFlagValue (neg);
84+ } else if (ch == ' >' ) {
85+ moreToGo = menuItem->nextPart () != 0 ;
86+ } else if (ch >= ' 0' && ch <= ' 9' ) {
87+ menuItem->valueChanged (ch);
88+ moreToGo = menuItem->nextPart () != 0 ;
89+ }
6190 }
62- bool moreToGo = menuItem->nextPart () != 0 ;
6391 controller->needsRedraw (moreToGo);
6492}
6593
94+ SummingValueKeyboardTouchEditor* SummingValueKeyboardTouchEditor::initSumming (MenuItem* item) {
95+ initFor (item);
96+ currentValueBeingEdited = 0 ;
97+ return this ;
98+ }
99+
100+ void SummingValueKeyboardTouchEditor::keypress (TcTouchKeyboardController* controller, char ch) {
101+ const auto range = menuItem->getCurrentRange ();
102+ if (ch == ' <' ) {
103+ currentValueBeingEdited = 0 ;
104+ menuItem->valueChanged (0 );
105+ controller->needsRedraw (true );
106+ return ;
107+ } else if (ch == ' >' || ch == ' .' ) {
108+ currentValueBeingEdited = 0 ;
109+ const bool moreToGo = menuItem->nextPart () != 0 ;
110+ controller->needsRedraw (moreToGo);
111+ return ;
112+ } else if (ch < ' 0' || ch > ' 9' ) return ;
113+
114+ const auto num = ch - ' 0' ;
115+ currentValueBeingEdited = currentValueBeingEdited * 10 + num;
116+ if (range < currentValueBeingEdited) {
117+ currentValueBeingEdited = 0 ;
118+ controller->needsRedraw (true );
119+ } else {
120+ menuItem->valueChanged (currentValueBeingEdited);
121+ controller->needsRedraw (true );
122+ }
123+ }
124+
66125void TouchKeyboardRow::drawRow (GraphicsDeviceRenderer& renderer, ItemDisplayProperties& properties, int yLocationStart, int height) {
67126 auto * drawable = renderer.getDeviceDrawable ();
68127 DeviceDrawableHelper helper (drawable);
@@ -82,9 +141,9 @@ void TouchKeyboardRow::drawRow(GraphicsDeviceRenderer& renderer, ItemDisplayProp
82141}
83142
84143
85- TcTouchKeyboardController::TcTouchKeyboardController (TouchKeyboardLayout* defKeyboard, GraphicsDeviceRenderer& renderer, ItemDisplayProperties& properties ) :
144+ TcTouchKeyboardController::TcTouchKeyboardController (TouchKeyboardLayout* numKeyboard, TouchKeyboardLayout* txtKeyboard, GraphicsDeviceRenderer& renderer ) :
86145 upButton(&drawUpArrowLgeBitmap), downButton(&drawDownArrowLgeBitmap), keyboardLayout(nullptr ),
87- touchRenderer(renderer), properties(properties ), defKeyboard(defKeyboard ) {
146+ touchRenderer(renderer), defNumKeyboard(numKeyboard ), defTxtKeyboard(txtKeyboard ) {
88147}
89148
90149void TcTouchKeyboardController::started (BaseMenuRenderer* currentRenderer) {
@@ -100,6 +159,7 @@ void TcTouchKeyboardController::started(BaseMenuRenderer* currentRenderer) {
100159}
101160
102161void TcTouchKeyboardController::reset () {
162+ stopEditing ();
103163}
104164
105165void TcTouchKeyboardController::renderLoop (unsigned int currentValue, RenderPressMode userClick) {
@@ -113,16 +173,14 @@ void TcTouchKeyboardController::renderLoop(unsigned int currentValue, RenderPres
113173 }
114174}
115175
116- void TcTouchKeyboardController::startEditing (MenuItem* menuItem, KeyboardTouchEditor* actEditor ) {
176+ void TcTouchKeyboardController::startEditing (MenuItem* menuItem) {
117177 if (menuItem == nullptr ) {
118178 serlogF (SER_WARNING , " TchEd-null" );
119179 return ;
120- } else if (actEditor) {
121- itemEditor = actEditor;
122180 } else if (menuItem->getMenuType () == MENUTYPE_TEXT_VALUE || menuItem->getMenuType () == MENUTYPE_LARGENUM_VALUE ) {
123- itemEditor = perCharEditor.initFor (menuItem);
181+ itemEditor = perCharEditor.initSingle (menuItem);
124182 } else if (menuItem->getMenuType () == MENUTYPE_DATE || menuItem->getMenuType () == MENUTYPE_IPADDRESS || menuItem->getMenuType () == MENUTYPE_COLOR_VALUE || menuItem->getMenuType () == MENUTYPE_TIME ) {
125- itemEditor = summingEditor.initFor (menuItem);
183+ itemEditor = summingEditor.initSumming (menuItem);
126184 } else {
127185 // it has been called with an unsupported menu type, only runtime editable items can use this path
128186 return ;
@@ -133,7 +191,7 @@ void TcTouchKeyboardController::startEditing(MenuItem* menuItem, KeyboardTouchEd
133191 menuMgr.setEditorHintsLocked (false );
134192 menuMgr.setCurrentEditor (menuItem);
135193 itemBeingEdited = multi;
136- keyboardLayout = defKeyboard ;
194+ keyboardLayout = (menuItem-> getMenuType () == MENUTYPE_TEXT_VALUE ) ? defTxtKeyboard : defNumKeyboard ;
137195
138196 // here we take over the display to render a keyboard
139197 touchRenderer.setCustomDrawingHandler (this );
@@ -149,6 +207,9 @@ void TcTouchKeyboardController::renderItem() {
149207 DeviceDrawableHelper helper (touchRenderer.getDeviceDrawable ());
150208 char buffer[64 ] = " Edit " ;
151209 itemBeingEdited->copyNameToBuffer (buffer, 5 , sizeof buffer);
210+ if (itemEditor->isCapsDown ()) {
211+ appendChar (buffer, ' ^' , sizeof buffer);
212+ }
152213 helper.setFontFromParameters (titleProps->getFont (), titleProps->getFontMagnification ());
153214 int baseline;
154215 int titleHeight = helper.textExtents (buffer, &baseline).y ;
@@ -161,8 +222,8 @@ void TcTouchKeyboardController::renderItem() {
161222 auto & hints = menuMgr.getEditorHints ();
162223 if (hints.getEditorRenderingType () == CurrentEditorRenderingHints::EDITOR_RUNTIME_TEXT ) {
163224 auto length = strlen (buffer);
164- const int start = internal_min (length, internal_max (0 , hints.getStartIndex ()));
165- const int end = internal_min (length, internal_max (start, hints.getEndIndex ()));
225+ const int start = internal_min (( int ) length, internal_max (0 , hints.getStartIndex ()));
226+ const int end = internal_min (( int ) length, internal_max (start, hints.getEndIndex ()));
166227 char saved = buffer[start];
167228 buffer[start] = 0 ;
168229 int startX = helper.textExtents (buffer, &baseline).x ;
@@ -200,24 +261,31 @@ void TcTouchKeyboardController::needsRedraw(bool moreToGo) {
200261 }
201262}
202263
203- void TcTouchKeyboardController::renderKeyboard () {
204- auto * layout = keyboardLayout ? keyboardLayout : defKeyboard ;
264+ void TcTouchKeyboardController::renderKeyboard () const {
265+ auto * layout = keyboardLayout ? keyboardLayout : defNumKeyboard ;
205266 if (layout && touchRenderer.getDeviceDrawable ()) {
267+ auto & factory = touchRenderer.getGraphicsPropertiesFactory ();
268+ const auto location = keyboardLayout->getKeysPerRow () > 5 ? ItemDisplayProperties::COMPTYPE_ITEM : ItemDisplayProperties::COMPTYPE_TITLE ;
269+ auto * properties = factory.configFor (itemBeingEdited, location);
270+
206271 DeviceDrawableHelper helper (touchRenderer.getDeviceDrawable ());
207- helper.setFontFromParameters (properties. getFont (), properties. getFontMagnification ());
272+ helper.setFontFromParameters (properties-> getFont (), properties-> getFontMagnification ());
208273 layout->calculateKeyHeight (helper);
209- layout->drawRows (touchRenderer, properties, touchRenderer.getHeight () - layout->getRequiredHeight ());
274+ layout->drawRows (touchRenderer, * properties, touchRenderer.getHeight () - layout->getRequiredHeight ());
210275 }
211276}
212277
213278void TcTouchKeyboardController::drawScrollbar (DeviceDrawable* drawable, const Coord& displayDims, int titleHeight) {
279+ auto & factory = touchRenderer.getGraphicsPropertiesFactory ();
280+ auto * properties = factory.configFor (nullptr , ItemDisplayProperties::COMPTYPE_TITLE );
281+
214282 const auto yHei = displayDims.y - titleHeight;
215283 const auto xLoc = displayDims.x - TC_KEYBOARD_BUTTON_SIZE ;
216284 upButton.setPositionAndSize (Coord (xLoc, titleHeight), Coord (TC_KEYBOARD_BUTTON_SIZE , yHei / 2 ));
217- upButton.setColors (properties. getColor (ItemDisplayProperties::TEXT ), properties. getColor (ItemDisplayProperties::BACKGROUND ), properties. getColor (ItemDisplayProperties::HIGHLIGHT1 ));
285+ upButton.setColors (properties-> getColor (ItemDisplayProperties::TEXT ), properties-> getColor (ItemDisplayProperties::BACKGROUND ), properties-> getColor (ItemDisplayProperties::HIGHLIGHT1 ));
218286 upButton.paintButton (drawable);
219287 downButton.setPositionAndSize (Coord (xLoc, titleHeight + yHei / 2 ), Coord (TC_KEYBOARD_BUTTON_SIZE , yHei / 2 ));
220- downButton.setColors (properties. getColor (ItemDisplayProperties::TEXT ), properties. getColor (ItemDisplayProperties::BACKGROUND ), properties. getColor (ItemDisplayProperties::HIGHLIGHT1 ));
288+ downButton.setColors (properties-> getColor (ItemDisplayProperties::TEXT ), properties-> getColor (ItemDisplayProperties::BACKGROUND ), properties-> getColor (ItemDisplayProperties::HIGHLIGHT1 ));
221289 downButton.paintButton (drawable);
222290}
223291
@@ -241,9 +309,19 @@ void TcTouchKeyboardController::stopEditing() {
241309 itemBeingEdited = nullptr ;
242310}
243311
244- TcTouchKeyboardController* tcgfx::defaultTouchKeyboardController (const Coord& size, GraphicsDeviceRenderer& renderer, ItemDisplayProperties& properties ) {
312+ TcTouchKeyboardController* tcgfx::defaultTouchKeyboardController (const Coord& size, GraphicsDeviceRenderer& renderer) {
245313 auto * layout = new TouchKeyboardLayout (size);
246- layout->withRow (" 789>" , 4 )->withRow (" 456<" , 4 )->withRow (" 123X" , 4 )->withRow (" .0+" , 3 );
247- auto * touchKeyboard = new TcTouchKeyboardController (layout, renderer, properties);
314+ auto * layoutText = new TouchKeyboardLayout (size);
315+ layout->withRow (" 789>" , 4 )
316+ ->withRow (" 456<" , 4 )
317+ ->withRow (" 123X" , 4 )
318+ ->withRow (" .0+" , 3 );
319+ layoutText->withRow (" 1234567890" , 10 )
320+ ->withRow (" qwertyuiop" , 10 )
321+ ->withRow (" asdfghjkl!" , 10 )
322+ ->withRow (" zxcvbnm,.?" , 10 )
323+ ->withRow (" *#@$\0 xFE" , 6 );
324+
325+ auto * touchKeyboard = new TcTouchKeyboardController (layout, layoutText, renderer);
248326 return touchKeyboard;
249327}
0 commit comments