TDME2  1.9.200
GUIInputInternalController.cpp
Go to the documentation of this file.
2 
3 #include <tdme/tdme.h>
11 #include <tdme/gui/nodes/GUINode.h>
19 #include <tdme/gui/GUI.h>
20 #include <tdme/math/Math.h>
22 #include <tdme/utilities/Float.h>
23 #include <tdme/utilities/Integer.h>
26 #include <tdme/utilities/Time.h>
27 
29 
36 using tdme::gui::nodes::GUIInputInternalController_CursorMode;
46 using tdme::gui::GUI;
53 
54 constexpr int64_t GUIInputInternalController::CURSOR_MODE_DURATION;
55 constexpr int64_t GUIInputInternalController::DRAGGING_CALMDOWN;
56 
57 GUIInputInternalController::GUIInputInternalController(GUINode* node)
58  : GUINodeController(node)
59 {
60 }
61 
63 {
64  return false;
65 }
66 
68 {
69 }
70 
72 {
73  inputNode = required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode());
74 
75  auto typeAsString = StringTools::toLowerCase(inputNode->getOptionValue("type"));
76  if (typeAsString == "float") type = TYPE_FLOAT; else
77  if (typeAsString == "int") type = TYPE_INT; else
78  type = TYPE_STRING;
79 
80  auto minAsString = inputNode->getOptionValue("min");
81  auto maxAsString = inputNode->getOptionValue("max");
82  auto stepAsString = inputNode->getOptionValue("step");
83  auto decimalsAsString = inputNode->getOptionValue("decimals");
84 
85  min = Float::parse(minAsString);
86  max = Float::parse(maxAsString);
87  step = Float::parse(stepAsString);
88 
89  if (decimalsAsString.empty() == false)
90  decimals = Integer::parse(decimalsAsString);
91 
92  haveMin = minAsString.empty() == false;
93  haveMax = maxAsString.empty() == false;
94  haveStep = stepAsString.empty() == false;
95 
96  formatText();
97 }
98 
100 {
101 }
102 
104 {
105 }
106 
108 {
109  cursorModeStarted = Time::getCurrentMillis();
111 }
112 
114 {
115  if (cursorModeStarted == -1) {
116  resetCursorMode();
117  return cursorMode;
118  }
119  if (mouseDraggingSelectionActive == true) {
120  return CURSORMODE_SHOW;
121  }
122  if (Time::getCurrentMillis() - cursorModeStarted > CURSOR_MODE_DURATION) {
124  cursorModeStarted = Time::getCurrentMillis();
125  }
126  return cursorMode;
127 }
128 
130 {
131  auto disabled = required_dynamic_cast<GUIInputController*>(inputNode->getController())->isDisabled();
132  if (disabled == true) {
133  return;
134  }
135  if (event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
136  if (doubleClick == true) {
137  //
138  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
139  const auto& text = textInputNode->getText();
140  auto textLength = text.length();
141  if (textLength > 0) {
142  auto wordLeftIdx = 0;
143  for (auto i = 0; i < index && i < textLength; i++) {
144  auto c = text.getUTF8CharAt(i);
145  if (Character::isAlphaNumeric(c) == false) {
146  wordLeftIdx = i + 1;
147  }
148  }
149  auto wordRightIdx = textLength;
150  for (auto i = index; i < textLength; i++) {
151  auto c = text.getUTF8CharAt(i);
152  if (Character::isAlphaNumeric(c) == false) {
153  wordRightIdx = i;
154  break;
155  }
156  }
157  if (wordLeftIdx != wordRightIdx) {
158  index = wordLeftIdx;
159  selectionIndex = wordRightIdx;
160  }
161  //
162  resetCursorMode();
163  }
164  //
165  doubleClick = false;
166  } else
167  if (mouseDraggingSlideValueActive == false) {
168  if (node->isEventBelongingToNode(event) == true &&
169  event->getButton() == MOUSE_BUTTON_LEFT) {
170  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
171  index = textInputNode->getFont()->getTextIndexByX(
172  textInputNode->getText(),
173  offset,
174  0,
175  event->getX() -
176  (
177  textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
178  textInputNode->border.left+ textInputNode->padding.left
179  )
180  );
181  resetCursorMode();
182  event->setProcessed(true);
183  if (editMode == false) {
184  index = 0;
185  selectionIndex = textInputNode->getText().length() == 0?-1:textInputNode->getText().length();
186  }
187  editMode = true;
188  }
189  } else
190  if (mouseDraggingSlideValueActive == true) {
191  // Application::setMouseCursor(MOUSE_CURSOR_NORMAL);
192  Application::setMousePosition(mouseOriginalPosition[0], mouseOriginalPosition[1]);
193  }
194  Application::setMouseCursor(MOUSE_CURSOR_NORMAL); // TODO: fix me
195  mouseDraggingInit = false;
198  mouseDragPosition[0] = -1;
199  mouseDragPosition[1] = -1;
200  mouseOriginalPosition[0] = -1;
201  mouseOriginalPosition[1] = -1;
202  event->setProcessed(true);
203  } else
205  if (mouseDraggingInit == true &&
206  Math::abs(mouseDragPosition[0] - event->getXUnscaled()) >= 10) {
207  mouseDraggingInit = false;
208  if (editMode == false) {
210  auto application = Application::getApplication();
211  Application::setMouseCursor(MOUSE_CURSOR_DISABLED);
212  Application::setMousePosition(mouseOriginalPosition[0], mouseOriginalPosition[1]);
213  } else {
216  }
217  mouseDragPosition[0] = Application::getMousePositionX();
218  mouseDragPosition[1] = Application::getMousePositionY();
219  }
220  if (mouseDraggingSlideValueActive == true) {
221  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
222  switch (type) {
223  case TYPE_STRING:
224  break;
225  case TYPE_FLOAT:
226  {
227  auto mouseDraggedX = Application::getMousePositionX() - mouseDragPosition[0];
228  auto value = Float::parse(textInputNode->getText().getString());
229  if (haveStep == true) {
230  value+= static_cast<float>(mouseDraggedX) * step;
231  }
232  if (haveMin == true) {
233  if (value < min) value = min;
234  }
235  if (haveMax == true) {
236  if (value > max) value = max;
237  }
238  textInputNode->getText().set(value, decimals);
239  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
240  }
241  break;
242  case TYPE_INT:
243  {
244  auto mouseDraggedX = Application::getMousePositionX() - mouseDragPosition[0];
245  auto value = Integer::parse(textInputNode->getText().getString());
246  if (haveStep == true) {
247  value+= mouseDraggedX * static_cast<int>(step);
248  }
249  if (haveMin == true) {
250  if (value < static_cast<int>(min)) value = static_cast<int>(min);
251  }
252  if (haveMax == true) {
253  if (value > static_cast<int>(max)) value = static_cast<int>(max);
254  }
255  textInputNode->getText().set(value);
256  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
257  }
258  break;
259  }
260  auto application = Application::getApplication();
261  Application::setMousePosition(mouseOriginalPosition[0], mouseOriginalPosition[1]);
262  mouseDragPosition[0] = Application::getMousePositionX();
263  mouseDragPosition[1] = Application::getMousePositionY();
264  } else
265  if (mouseDraggingSelectionActive == true) {
266  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
267  index = textInputNode->getFont()->getTextIndexByX(
268  textInputNode->getText(),
269  offset,
270  0,
271  event->getX() -
272  (
273  textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
274  textInputNode->border.left+ textInputNode->padding.left
275  )
276  );
277  }
278  event->setProcessed(true);
279  } else
280  if (node == this->node &&
281  node->isEventBelongingToNode(event) == true &&
282  event->getType() == GUIMouseEvent::MOUSEEVENT_PRESSED &&
283  event->getButton() == MOUSE_BUTTON_LEFT) {
284  //
285  if (timeLastClick != -1LL &&
286  Time::getCurrentMillis() - timeLastClick < TIME_DOUBLECLICK) {
287  doubleClick = true;
288  timeLastClick = -1LL;
289  } else {
290  timeLastClick = Time::getCurrentMillis();
291  doubleClick = false;
292  }
293 
294  //
295  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
296  index = textInputNode->getFont()->getTextIndexByX(
297  textInputNode->getText(),
298  offset,
299  0,
300  event->getX() -
301  (
302  textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
303  textInputNode->border.left+ textInputNode->padding.left
304  )
305  );
306  resetCursorMode();
307  mouseDraggingInit = true;
308  mouseOriginalPosition[0] = Application::getMousePositionX();
309  mouseOriginalPosition[1] = Application::getMousePositionY();
310  selectionIndex = -1;
311  event->setProcessed(true);
312  }
313 }
314 
316 {
317  if (index < offset) {
318  offset = index;
319  return;
320  }
321  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
322  auto textInputNodeConstraints = textInputNode->computedConstraints;
323  auto textInputNodeBorder = textInputNode->border;
324  auto textInputNodePadding = textInputNode->padding;
325  auto textInputNodeWidth = textInputNodeConstraints.width - textInputNodeBorder.left - textInputNodeBorder.right - textInputNodePadding.left - textInputNodePadding.right;
326  auto charsMax = textInputNode->getFont()->getTextIndexByX(textInputNode->getText(), offset, 0, textInputNodeWidth) - offset;
327  if (index - offset >= charsMax) {
328  offset = index - charsMax;
329  }
330 }
331 
333 {
334  auto disabled = required_dynamic_cast<GUIInputController*>(inputNode->getController())->isDisabled();
335  if (disabled == true) {
336  return;
337  }
338 
339  //
340  editMode = true;
341 
342  //
343  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
344  auto keyControl = event->isControlDown();
345  auto keyChar = event->getKeyChar();
346  if (disabled == false &&
347  keyControl == false &&
348  event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_TYPED &&
349  (
350  (type == TYPE_STRING) ||
351  (type == TYPE_FLOAT && ((keyChar >= '0' && keyChar <= '9') || (keyChar == '.') || keyChar == '-')) ||
352  (type == TYPE_INT && ((keyChar >= '0' && keyChar <= '9') || keyChar == '-'))
353  )) {
354  event->setProcessed(true);
355  if (index != -1 && selectionIndex != -1 && index != selectionIndex) {
356  textInputNode->getText().remove(Math::min(index, selectionIndex), Math::abs(index - selectionIndex));
357  index = Math::min(index, selectionIndex);
358  selectionIndex = -1;
359  }
360  if (textInputNode->getMaxLength() == 0 || textInputNode->getText().length() < textInputNode->getMaxLength()) {
361  if (type == TYPE_FLOAT && keyChar == '.' && textInputNode->getText().getString().find('.') != string::npos) {
362  // no op
363  } else
364  if (type == TYPE_FLOAT && keyChar == '-' && (textInputNode->getText().getString().find('-') != string::npos || index != 0)) {
365  // no op
366  } else
367  if (type == TYPE_INT && keyChar == '-' && (textInputNode->getText().getString().find('-') != string::npos || index != 0)) {
368  // no op
369  } else {
370  textInputNode->getText().insert(index, Character::toString(event->getKeyChar()));
371  index++;
372  resetCursorMode();
373  checkOffset();
374  required_dynamic_cast<GUIInputController*>(inputNode->getController())->onChange();
375  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
376  }
377  }
378  } else {
379  auto keyControlA = false;
380  auto keyControlX = false;
381  auto keyControlC = false;
382  auto keyControlV = false;
383  auto isKeyDown = event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED;
384  // determine select all, copy, paste, cut
385  if (Character::toLowerCase(event->getKeyChar()) == 'a' && keyControl == true) {
386  keyControlA = isKeyDown;
387  event->setProcessed(true);
388  }
389  if (Character::toLowerCase(event->getKeyChar()) == 'x' && keyControl == true) {
390  keyControlX = isKeyDown;
391  event->setProcessed(true);
392  }
393  if (Character::toLowerCase(event->getKeyChar()) == 'c' && keyControl == true) {
394  keyControlC = isKeyDown;
395  event->setProcessed(true);
396  }
397  if (Character::toLowerCase(event->getKeyChar()) == 'v' && keyControl == true) {
398  keyControlV = isKeyDown;
399  event->setProcessed(true);
400  }
401  // handle them
402  if (keyControlA == true) {
403  index = 0;
404  selectionIndex = textInputNode->getText().length();
405  } else
406  if (keyControlX == true && disabled == false) {
407  if (index != -1 && selectionIndex != -1 && index != selectionIndex) {
408  const auto& text = textInputNode->getText();
409  Application::getApplication()->setClipboardContent(StringTools::substring(text.getString(), Math::min(text.getUtf8BinaryIndex(index), text.getUtf8BinaryIndex(selectionIndex)), Math::max(text.getUtf8BinaryIndex(index), text.getUtf8BinaryIndex(selectionIndex))));
410  textInputNode->getText().remove(Math::min(index, selectionIndex), Math::abs(index - selectionIndex));
411  index = Math::min(index, selectionIndex);
412  selectionIndex = -1;
413  checkOffset();
414  }
415  } else
416  if (keyControlC == true || keyControlX == true) {
417  if (index != -1 && selectionIndex != -1 && index != selectionIndex) {
418  const auto& text = textInputNode->getText();
419  Application::getApplication()->setClipboardContent(StringTools::substring(text.getString(), Math::min(text.getUtf8BinaryIndex(index), text.getUtf8BinaryIndex(selectionIndex)), Math::max(text.getUtf8BinaryIndex(index), text.getUtf8BinaryIndex(selectionIndex))));
420  }
421  } else
422  if (keyControlV == true) {
423  if (disabled == false) {
424  auto clipboardContent = Application::getApplication()->getClipboardContent();
425  auto clipboardContentLength = StringTools::getUtf8Length(clipboardContent);
426  if (index != -1 && selectionIndex != -1 && index != selectionIndex) {
427  if (textInputNode->getMaxLength() == 0 || textInputNode->getText().length() - Math::abs(index - selectionIndex) + clipboardContentLength < textInputNode->getMaxLength()) {
428  textInputNode->getText().remove(Math::min(index, selectionIndex), Math::abs(index - selectionIndex));
429  index = Math::min(index, selectionIndex);
430  selectionIndex = -1;
431  }
432  }
433  if (textInputNode->getMaxLength() == 0 || textInputNode->getText().length() + clipboardContentLength < textInputNode->getMaxLength()) {
434  textInputNode->getText().insert(index, clipboardContent);
435  index+= clipboardContentLength;
436  checkOffset();
437  }
438  }
439  } else {
440  // navigation, delete, return
441  switch (event->getKeyCode()) {
442  case GUIKeyboardEvent::KEYCODE_LEFT: {
443  event->setProcessed(true);
444  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
445  auto wordLeftIdx = -1;
446  if (event->isControlDown() == true) {
447  string delimiter = "^´!\"§$%&/()=?`+#<,.-*'>;:_";
448  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
449  const auto& text = textInputNode->getText();
450  auto textLength = text.length();
451  if (textLength > 0) {
452  wordLeftIdx = 0;
453  auto i = index - 1;
454  for (; i >= 0; i--) {
455  auto c = text.getUTF8CharAt(i);
456  if (Character::isAlphaNumeric(c) == true || delimiter.find(c) != string::npos) break;
457  }
458  if (delimiter.find(text.getUTF8CharAt(i)) != string::npos) {
459  for (; i >= 0 && delimiter.find(text.getUTF8CharAt(i)) != string::npos; i--);
460  wordLeftIdx = i + 1;
461  } else {
462  for (; i >= 0; i--) {
463  auto c = text.getUTF8CharAt(i);
464  if (Character::isAlphaNumeric(c) == false || delimiter.find(c) != string::npos) {
465  wordLeftIdx = i + 1;
466  break;
467  }
468  }
469  }
470  }
471  }
472  if (event->isShiftDown() == false) {
473  selectionIndex = -1;
474  } else {
475  if (selectionIndex == -1) selectionIndex = index;
476  }
477  if (index > 0) {
478  if (wordLeftIdx == -1) {
479  index--;
480  } else {
481  index = wordLeftIdx;
482  }
483  checkOffset();
484  resetCursorMode();
485  }
486  }
487  }
488  break;
489  case GUIKeyboardEvent::KEYCODE_RIGHT: {
490  event->setProcessed(true);
491  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
492  auto wordRightIdx = -1;
493  if (event->isControlDown() == true) {
494  string delimiter = "^´!\"§$%&/()=?`+#<,.-*'>;:_";
495  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
496  const auto& text = textInputNode->getText();
497  auto textLength = text.length();
498  if (textLength > 0) {
499  wordRightIdx = textLength;
500  auto i = index;
501  for (; i < textLength; i++) {
502  auto c = text.getUTF8CharAt(i);
503  if (Character::isAlphaNumeric(c) == true || delimiter.find(c) != string::npos) break;
504  }
505  if (delimiter.find(text.getUTF8CharAt(i)) != string::npos) {
506  for (; i < textLength && delimiter.find(text.getUTF8CharAt(i)) != string::npos; i++);
507  wordRightIdx = i;
508  } else {
509  for (; i < textLength; i++) {
510  auto c = text.getUTF8CharAt(i);
511  if (Character::isAlphaNumeric(c) == false || delimiter.find(c) != string::npos) {
512  wordRightIdx = i;
513  break;
514  }
515  }
516  }
517  if (Character::isSpace(text.getUTF8CharAt(i)) == true) {
518  for (; i < textLength && Character::isSpace(text.getUTF8CharAt(i)) == true; i++);
519  wordRightIdx = i;
520  }
521  }
522  }
523  if (event->isShiftDown() == false) {
524  selectionIndex = -1;
525  } else {
526  if (selectionIndex == -1) selectionIndex = index;
527  }
528  if (index < textInputNode->getText().length()) {
529  if (wordRightIdx == -1) {
530  index++;
531  } else {
532  index = wordRightIdx;
533  }
534  checkOffset();
535  resetCursorMode();
536  }
537  }
538  }
539  break;
540  case GUIKeyboardEvent::KEYCODE_BACKSPACE: {
541  if (disabled == false) {
542  event->setProcessed(true);
543  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
544  if (index != -1 && selectionIndex != -1 && index != selectionIndex) {
545  textInputNode->getText().remove(Math::min(index, selectionIndex), Math::abs(index - selectionIndex));
546  index = Math::min(index, selectionIndex);
547  selectionIndex = -1;
548  required_dynamic_cast<GUIInputController*>(inputNode->getController())->onChange();
549  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
550  } else
551  if (index > 0) {
552  textInputNode->getText().remove(index - 1, 1);
553  index--;
554  checkOffset();
555  resetCursorMode();
556  required_dynamic_cast<GUIInputController*>(inputNode->getController())->onChange();
557  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
558  }
559  }
560  }
561  }
562  break;
563  case GUIKeyboardEvent::KEYCODE_DELETE: {
564  if (disabled == false) {
565  event->setProcessed(true);
566  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
567  if (index != -1 && selectionIndex != -1 && index != selectionIndex) {
568  textInputNode->getText().remove(Math::min(index, selectionIndex), Math::abs(index - selectionIndex));
569  index = Math::min(index, selectionIndex);
570  selectionIndex = -1;
571  required_dynamic_cast<GUIInputController*>(inputNode->getController())->onChange();
572  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
573  } else
574  if (index < textInputNode->getText().length()) {
575  textInputNode->getText().remove(index, 1);
576  resetCursorMode();
577  required_dynamic_cast<GUIInputController*>(inputNode->getController())->onChange();
578  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
579  }
580  }
581  }
582  }
583  break;
584  case GUIKeyboardEvent::KEYCODE_RETURN: {
585  if (disabled == false) {
586  event->setProcessed(true);
587  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
588  node->getScreenNode()->forwardAction(GUIActionListenerType::PERFORMED, required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
589  }
590  }
591  }
592  break;
593  case GUIKeyboardEvent::KEYCODE_POS1: {
594  if (disabled == false) {
595  event->setProcessed(true);
596  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
597  resetCursorMode();
598  if (event->isShiftDown() == false) {
599  selectionIndex = -1;
600  } else {
601  if (selectionIndex == -1) selectionIndex = index;
602  }
603  index = 0;
604  checkOffset();
605  }
606  }
607  }
608  break;
609  case GUIKeyboardEvent::KEYCODE_END: {
610  if (disabled == false) {
611  event->setProcessed(true);
612  if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
613  resetCursorMode();
614  if (event->isShiftDown() == false) {
615  selectionIndex = -1;
616  } else {
617  if (selectionIndex == -1) selectionIndex = index;
618  }
619  index = textInputNode->getText().length();
620  checkOffset();
621  }
622  }
623  }
624  break;
625  }
626  }
627  }
628 }
629 
631 {
632 }
633 
635 {
636 }
637 
639 {
640  formatText();
641  editMode = false;
642  index = 0;
643  selectionIndex = -1;
644 }
645 
647 {
648  return false;
649 }
650 
652 {
653  return value;
654 }
655 
657 {
658 }
659 
661 {
662  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
663  if (index < 0) index = 0;
664  if (index >= textInputNode->getText().length()) index = textInputNode->getText().length();
665  if (selectionIndex != -1) {
666  if (selectionIndex < 0) selectionIndex = 0;
667  if (selectionIndex >= textInputNode->getText().length()) selectionIndex = textInputNode->getText().length();
668  }
669  checkOffset();
670  resetCursorMode();
671 }
672 
674 {
675  return editMode;
676 }
677 
679 {
680  auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(node);
681  auto originalText = textInputNode->getText().getString();
682  switch (type) {
683  case TYPE_STRING:
684  break;
685  case TYPE_FLOAT:
686  {
687  auto stringValue = StringTools::trim(textInputNode->getText().getString());
688  auto value = stringValue == "-"?0.0f:Float::parse(stringValue);
689  if (haveMin == true) {
690  if (value < min) value = min;
691  }
692  if (haveMax == true) {
693  if (value > max) value = max;
694  }
695  if (value == 0.0f && StringTools::startsWith(stringValue, "-") == true && (haveMin == false || min < 0.0f)) {
696  textInputNode->getText().set("-");
697  textInputNode->getText().append(value, decimals);
698  } else {
699  textInputNode->getText().set(value, decimals);
700  }
701  }
702  break;
703  case TYPE_INT:
704  {
705  auto stringValue = StringTools::trim(textInputNode->getText().getString());
706  auto value = stringValue == "-"?0:Integer::parse(stringValue);
707  if (haveMin == true) {
708  if (value < static_cast<int>(min)) value = static_cast<int>(min);
709  }
710  if (haveMax == true) {
711  if (value > static_cast<int>(max)) value = static_cast<int>(max);
712  }
713  if (value == 0 && StringTools::startsWith(stringValue, "-") == true && (haveMin == false || min < 0.0f)) {
714  textInputNode->getText().set("-");
715  textInputNode->getText().append(value);
716  } else {
717  textInputNode->getText().set(value);
718  }
719  }
720  break;
721  }
722  if (originalText != textInputNode->getText().getString()) {
723  node->getScreenNode()->forwardAction(GUIActionListenerType::PERFORMED, required_dynamic_cast<GUIElementNode*>(node->getParentControllerNode()));
724  }
725 }
726 
728 {
729 }
#define MOUSE_CURSOR_NORMAL
Definition: Application.h:13
#define MOUSE_CURSOR_DISABLED
Definition: Application.h:11
#define MOUSE_BUTTON_LEFT
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
GUI module class.
Definition: GUI.h:64
GUIKeyboardEventType getType() const
GUIMouseEventType getType() const
Definition: GUIMouseEvent.h:78
const string getOptionValue(const string &option)
void formatText()
Format text according to options.
void initialize() override
Initialize controller after element has been created.
void handleKeyboardEvent(GUIKeyboardEvent *event) override
Handle keyboard event.
void setValue(const MutableString &value) override
Set value.
void handleMouseEvent(GUINode *node, GUIMouseEvent *event) override
Handle mouse event.
void tick() override
Tick method will be executed once per frame.
void setDisabled(bool disabled) override
Set disabled.
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:64
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &nodeCoordinate)
Is event belonging to node.
Definition: GUINode.h:604
GUINodeController * getController()
Definition: GUINode.h:661
GUIParentNode * getParentControllerNode()
Definition: GUINode.cpp:1011
GUIScreenNode * getScreenNode()
Definition: GUINode.h:325
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void forwardChange(GUIElementNode *node)
Forward change event.
void forwardAction(GUIActionListenerType type, GUIElementNode *node)
Forward action event.
GUI font class.
Definition: GUIFont.h:41
Character class.
Definition: Character.h:17
Float class.
Definition: Float.h:27
Integer class.
Definition: Integer.h:25
Mutable utf8 aware string class.
Definition: MutableString.h:23
MutableString & append(char c)
Append character.
MutableString & set(char c)
Set character.
String tools class.
Definition: StringTools.h:22
Time utility class.
Definition: Time.h:20
GUI node border entity.
GUI node padding entity.