36 using tdme::gui::nodes::GUIInputInternalController_CursorMode;
54 constexpr int64_t GUIInputInternalController::CURSOR_MODE_DURATION;
55 constexpr int64_t GUIInputInternalController::DRAGGING_CALMDOWN;
57 GUIInputInternalController::GUIInputInternalController(
GUINode* node)
85 min = Float::parse(minAsString);
86 max = Float::parse(maxAsString);
87 step = Float::parse(stepAsString);
89 if (decimalsAsString.empty() ==
false)
90 decimals = Integer::parse(decimalsAsString);
92 haveMin = minAsString.empty() ==
false;
93 haveMax = maxAsString.empty() ==
false;
94 haveStep = stepAsString.empty() ==
false;
132 if (disabled ==
true) {
135 if (event->
getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
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) {
149 auto wordRightIdx = textLength;
150 for (
auto i =
index; i < textLength; i++) {
151 auto c = text.getUTF8CharAt(i);
152 if (Character::isAlphaNumeric(c) ==
false) {
157 if (wordLeftIdx != wordRightIdx) {
170 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
171 index = textInputNode->getFont()->getTextIndexByX(
172 textInputNode->getText(),
177 textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
178 textInputNode->border.left+ textInputNode->padding.left
182 event->setProcessed(
true);
185 selectionIndex = textInputNode->getText().length() == 0?-1:textInputNode->getText().length();
202 event->setProcessed(
true);
210 auto application = Application::getApplication();
221 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
228 auto value = Float::parse(textInputNode->getText().getString());
230 value+=
static_cast<float>(mouseDraggedX) *
step;
245 auto value = Integer::parse(textInputNode->getText().getString());
247 value+= mouseDraggedX *
static_cast<int>(
step);
255 textInputNode->getText().
set(
value);
260 auto application = Application::getApplication();
266 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
267 index = textInputNode->getFont()->getTextIndexByX(
268 textInputNode->getText(),
273 textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
274 textInputNode->border.left+ textInputNode->padding.left
278 event->setProcessed(
true);
280 if (
node == this->node &&
282 event->
getType() == GUIMouseEvent::MOUSEEVENT_PRESSED &&
295 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
296 index = textInputNode->getFont()->getTextIndexByX(
297 textInputNode->getText(),
302 textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
303 textInputNode->border.left+ textInputNode->padding.left
311 event->setProcessed(
true);
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;
335 if (disabled ==
true) {
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 &&
351 (
type ==
TYPE_FLOAT && ((keyChar >=
'0' && keyChar <=
'9') || (keyChar ==
'.') || keyChar ==
'-')) ||
352 (
type ==
TYPE_INT && ((keyChar >=
'0' && keyChar <=
'9') || keyChar ==
'-'))
354 event->setProcessed(
true);
360 if (textInputNode->getMaxLength() == 0 || textInputNode->getText().length() < textInputNode->getMaxLength()) {
361 if (
type ==
TYPE_FLOAT && keyChar ==
'.' && textInputNode->getText().getString().find(
'.') != string::npos) {
364 if (
type ==
TYPE_FLOAT && keyChar ==
'-' && (textInputNode->getText().getString().find(
'-') != string::npos ||
index != 0)) {
367 if (
type ==
TYPE_INT && keyChar ==
'-' && (textInputNode->getText().getString().find(
'-') != string::npos ||
index != 0)) {
370 textInputNode->getText().insert(
index, Character::toString(event->
getKeyChar()));
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;
385 if (Character::toLowerCase(event->
getKeyChar()) ==
'a' && keyControl ==
true) {
386 keyControlA = isKeyDown;
387 event->setProcessed(
true);
389 if (Character::toLowerCase(event->
getKeyChar()) ==
'x' && keyControl ==
true) {
390 keyControlX = isKeyDown;
391 event->setProcessed(
true);
393 if (Character::toLowerCase(event->
getKeyChar()) ==
'c' && keyControl ==
true) {
394 keyControlC = isKeyDown;
395 event->setProcessed(
true);
397 if (Character::toLowerCase(event->
getKeyChar()) ==
'v' && keyControl ==
true) {
398 keyControlV = isKeyDown;
399 event->setProcessed(
true);
402 if (keyControlA ==
true) {
406 if (keyControlX ==
true && disabled ==
false) {
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))));
416 if (keyControlC ==
true || keyControlX ==
true) {
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))));
422 if (keyControlV ==
true) {
423 if (disabled ==
false) {
424 auto clipboardContent = Application::getApplication()->getClipboardContent();
425 auto clipboardContentLength = StringTools::getUtf8Length(clipboardContent);
427 if (textInputNode->getMaxLength() == 0 || textInputNode->getText().length() - Math::abs(
index -
selectionIndex) + clipboardContentLength < textInputNode->getMaxLength()) {
433 if (textInputNode->getMaxLength() == 0 || textInputNode->getText().length() + clipboardContentLength < textInputNode->getMaxLength()) {
434 textInputNode->getText().insert(
index, clipboardContent);
435 index+= clipboardContentLength;
442 case GUIKeyboardEvent::KEYCODE_LEFT: {
443 event->setProcessed(
true);
444 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
445 auto wordLeftIdx = -1;
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) {
454 for (; i >= 0; i--) {
455 auto c = text.getUTF8CharAt(i);
456 if (Character::isAlphaNumeric(c) ==
true || delimiter.find(c) != string::npos)
break;
458 if (delimiter.find(text.getUTF8CharAt(i)) != string::npos) {
459 for (; i >= 0 && delimiter.find(text.getUTF8CharAt(i)) != string::npos; i--);
462 for (; i >= 0; i--) {
463 auto c = text.getUTF8CharAt(i);
464 if (Character::isAlphaNumeric(c) ==
false || delimiter.find(c) != string::npos) {
478 if (wordLeftIdx == -1) {
489 case GUIKeyboardEvent::KEYCODE_RIGHT: {
490 event->setProcessed(
true);
491 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
492 auto wordRightIdx = -1;
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;
501 for (; i < textLength; i++) {
502 auto c = text.getUTF8CharAt(i);
503 if (Character::isAlphaNumeric(c) ==
true || delimiter.find(c) != string::npos)
break;
505 if (delimiter.find(text.getUTF8CharAt(i)) != string::npos) {
506 for (; i < textLength && delimiter.find(text.getUTF8CharAt(i)) != string::npos; i++);
509 for (; i < textLength; i++) {
510 auto c = text.getUTF8CharAt(i);
511 if (Character::isAlphaNumeric(c) ==
false || delimiter.find(c) != string::npos) {
517 if (Character::isSpace(text.getUTF8CharAt(i)) ==
true) {
518 for (; i < textLength && Character::isSpace(text.getUTF8CharAt(i)) ==
true; i++);
528 if (index < textInputNode->getText().length()) {
529 if (wordRightIdx == -1) {
532 index = wordRightIdx;
540 case GUIKeyboardEvent::KEYCODE_BACKSPACE: {
541 if (disabled ==
false) {
542 event->setProcessed(
true);
543 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
552 textInputNode->getText().remove(
index - 1, 1);
563 case GUIKeyboardEvent::KEYCODE_DELETE: {
564 if (disabled ==
false) {
565 event->setProcessed(
true);
566 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
574 if (index < textInputNode->getText().length()) {
575 textInputNode->getText().remove(
index, 1);
584 case GUIKeyboardEvent::KEYCODE_RETURN: {
585 if (disabled ==
false) {
586 event->setProcessed(
true);
587 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
593 case GUIKeyboardEvent::KEYCODE_POS1: {
594 if (disabled ==
false) {
595 event->setProcessed(
true);
596 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
609 case GUIKeyboardEvent::KEYCODE_END: {
610 if (disabled ==
false) {
611 event->setProcessed(
true);
612 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
619 index = textInputNode->getText().length();
662 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
664 if (
index >= textInputNode->getText().length())
index = textInputNode->getText().length();
680 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
681 auto originalText = textInputNode->getText().getString();
687 auto stringValue = StringTools::trim(textInputNode->getText().getString());
688 auto value = stringValue ==
"-"?0.0f:Float::parse(stringValue);
695 if (
value == 0.0f && StringTools::startsWith(stringValue,
"-") ==
true && (
haveMin ==
false ||
min < 0.0f)) {
696 textInputNode->getText().set(
"-");
705 auto stringValue = StringTools::trim(textInputNode->getText().getString());
706 auto value = stringValue ==
"-"?0:Integer::parse(stringValue);
713 if (
value == 0 && StringTools::startsWith(stringValue,
"-") ==
true && (
haveMin ==
false ||
min < 0.0f)) {
714 textInputNode->getText().
set(
"-");
717 textInputNode->getText().
set(
value);
722 if (originalText != textInputNode->getText().getString()) {
#define MOUSE_CURSOR_NORMAL
#define MOUSE_CURSOR_DISABLED
Application base class, please make sure to allocate application on heap to have correct application ...
int32_t getKeyCode() const
bool isControlDown() const
int32_t getKeyChar() const
GUIKeyboardEventType getType() const
GUIMouseEventType getType() const
const string getOptionValue(const string &option)
GUI node controller base class.
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &nodeCoordinate)
Is event belonging to node.
GUINodeController * getController()
GUIParentNode * getParentControllerNode()
GUIScreenNode * getScreenNode()
GUI parent node base class thats supporting child nodes.
GUI screen node that represents a screen that can be rendered via GUI system.
void forwardChange(GUIElementNode *node)
Forward change event.
void forwardAction(GUIActionListenerType type, GUIElementNode *node)
Forward action event.
Mutable utf8 aware string class.
MutableString & append(char c)
Append character.
MutableString & set(char c)
Set character.
GUI node computed constraints.