36using tdme::gui::nodes::GUIInputInternalController_CursorMode;
54constexpr int64_t GUIInputInternalController::CURSOR_MODE_DURATION;
55constexpr int64_t GUIInputInternalController::DRAGGING_CALMDOWN;
57GUIInputInternalController::GUIInputInternalController(
GUINode* node)
93 min = Float::parse(minAsString);
94 max = Float::parse(maxAsString);
95 step = Float::parse(stepAsString);
97 if (decimalsAsString.empty() ==
false)
98 decimals = Integer::parse(decimalsAsString);
100 haveMin = minAsString.empty() ==
false;
101 haveMax = maxAsString.empty() ==
false;
102 haveStep = stepAsString.empty() ==
false;
140 if (disabled ==
true) {
143 if (
node == this->node &&
144 event->
getType() == GUIMouseEvent::MOUSEEVENT_RELEASED ==
true) {
148 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
149 index = textInputNode->getFont()->getTextIndexByX(
150 textInputNode->getText(),
155 textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
156 textInputNode->border.left+ textInputNode->padding.left
160 event->setProcessed(
true);
180 event->setProcessed(
true);
188 auto application = Application::getApplication();
190 Application::setMousePosition(
191 application->getWindowXPosition() + application->getWindowWidth() / 2,
192 application->getWindowYPosition() + application->getWindowHeight() / 2
202 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
209 auto value = Float::parse(textInputNode->getText().getString());
211 value+=
static_cast<float>(mouseDraggedX) *
step;
226 auto value = Integer::parse(textInputNode->getText().getString());
228 value+= mouseDraggedX *
static_cast<int>(
step);
236 textInputNode->getText().
set(
value);
241 auto application = Application::getApplication();
242 Application::setMousePosition(
243 application->getWindowXPosition() + application->getWindowWidth() / 2,
244 application->getWindowYPosition() + application->getWindowHeight() / 2
250 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
251 index = textInputNode->getFont()->getTextIndexByX(
252 textInputNode->getText(),
257 textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
258 textInputNode->border.left+ textInputNode->padding.left
262 event->setProcessed(
true);
265 event->
getType() == GUIMouseEvent::MOUSEEVENT_PRESSED ==
true &&
267 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
268 index = textInputNode->getFont()->getTextIndexByX(
269 textInputNode->getText(),
274 textInputNode->computedConstraints.left + textInputNode->computedConstraints.alignmentLeft +
275 textInputNode->border.left+ textInputNode->padding.left
279 event->setProcessed(
true);
293 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
294 auto textInputNodeConstraints = textInputNode->computedConstraints;
295 auto textInputNodeBorder = textInputNode->border;
296 auto textInputNodePadding = textInputNode->padding;
297 auto textInputNodeWidth = textInputNodeConstraints.width - textInputNodeBorder.left - textInputNodeBorder.right - textInputNodePadding.left - textInputNodePadding.right;
298 auto charsMax = textInputNode->getFont()->getTextIndexByX(textInputNode->getText(),
offset, 0, textInputNodeWidth) -
offset;
307 if (disabled ==
true) {
315 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
316 auto keyControl =
event->isControlDown();
317 auto keyChar =
event->getKeyChar();
318 if (disabled ==
false &&
319 keyControl ==
false &&
322 (
type ==
TYPE_FLOAT && ((keyChar >=
'0' && keyChar <
'9') || (keyChar ==
'.') || keyChar ==
'-')) ||
323 (
type ==
TYPE_INT && ((keyChar >=
'0' && keyChar <
'9') || keyChar ==
'-'))
325 event->setProcessed(
true);
326 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_TYPED) {
332 if (textInputNode->getMaxLength() == 0 || textInputNode->getText().size() < textInputNode->getMaxLength()) {
333 if (
type ==
TYPE_FLOAT && keyChar ==
'.' && textInputNode->getText().getString().find(
'.') != string::npos) {
336 if (
type ==
TYPE_FLOAT && keyChar ==
'-' && (textInputNode->getText().getString().find(
'-') != string::npos ||
index != 0)) {
339 if (
type ==
TYPE_INT && keyChar ==
'-' && (textInputNode->getText().getString().find(
'-') != string::npos ||
index != 0)) {
352 auto keyControlX =
false;
353 auto keyControlC =
false;
354 auto keyControlV =
false;
355 auto isKeyDown =
event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED;
359 keyControlX = isKeyDown;
360 event->setProcessed(
true);
363 keyControlC = isKeyDown;
364 event->setProcessed(
true);
367 keyControlV = isKeyDown;
368 event->setProcessed(
true);
370 if (Character::toLowerCase(event->
getKeyChar()) ==
'x' && keyControl ==
true) {
371 keyControlX = isKeyDown;
372 event->setProcessed(
true);
374 if (Character::toLowerCase(event->
getKeyChar()) ==
'c' && keyControl ==
true) {
375 keyControlC = isKeyDown;
376 event->setProcessed(
true);
378 if (Character::toLowerCase(event->
getKeyChar()) ==
'v' && keyControl ==
true) {
379 keyControlV = isKeyDown;
380 event->setProcessed(
true);
383 if (keyControlX ==
true) {
392 if (keyControlC ==
true) {
397 if (keyControlV ==
true) {
398 auto clipboardContent = Application::getApplication()->getClipboardContent();
400 if (textInputNode->getMaxLength() == 0 || textInputNode->getText().size() - Math::abs(
index -
selectionIndex) + clipboardContent.size() < textInputNode->getMaxLength()) {
406 if (textInputNode->getMaxLength() == 0 || textInputNode->getText().size() + clipboardContent.size() < textInputNode->getMaxLength()) {
407 textInputNode->getText().insert(
index, clipboardContent);
408 index+= clipboardContent.size();
414 case GUIKeyboardEvent::KEYCODE_LEFT: {
415 event->setProcessed(
true);
416 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
430 case GUIKeyboardEvent::KEYCODE_RIGHT: {
431 event->setProcessed(
true);
432 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
438 if (index < textInputNode->getText().size()) {
446 case GUIKeyboardEvent::KEYCODE_BACKSPACE: {
447 if (disabled ==
false) {
448 event->setProcessed(
true);
449 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
456 textInputNode->getText().remove(
index - 1, 1);
467 case GUIKeyboardEvent::KEYCODE_DELETE: {
468 if (disabled ==
false) {
469 event->setProcessed(
true);
470 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
476 if (index < textInputNode->getText().size()) {
477 textInputNode->getText().remove(
index, 1);
486 case GUIKeyboardEvent::KEYCODE_RETURN: {
487 if (disabled ==
false) {
488 event->setProcessed(
true);
489 if (event->
getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
495 case GUIKeyboardEvent::KEYCODE_POS1: {
496 if (disabled ==
false) {
497 event->setProcessed(
true);
509 case GUIKeyboardEvent::KEYCODE_END: {
510 if (disabled ==
false) {
517 index = textInputNode->getText().size();
559 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
561 if (
index >= textInputNode->getText().size())
index = textInputNode->getText().size();
577 auto textInputNode = required_dynamic_cast<GUIInputInternalNode*>(
node);
578 auto originalText = textInputNode->getText().getString();
584 auto stringValue = StringTools::trim(textInputNode->getText().getString());
585 auto value = stringValue ==
"-"?0.0f:Float::parse(stringValue);
592 if (
value == 0.0f && StringTools::startsWith(stringValue,
"-") ==
true && (
haveMin ==
false ||
min < 0.0f)) {
593 textInputNode->getText().set(
"-");
602 auto stringValue = StringTools::trim(textInputNode->getText().getString());
603 auto value = stringValue ==
"-"?0:Integer::parse(stringValue);
610 if (
value == 0 && StringTools::startsWith(stringValue,
"-") ==
true && (
haveMin ==
false ||
min < 0.0f)) {
611 textInputNode->getText().
set(
"-");
614 textInputNode->getText().
set(
value);
619 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 ...
GUIKeyboardEventType getType()
GUIMouseEventType getType()
const string getOptionValue(const string &option)
GUI node controller base class.
GUIParentNode * getParentControllerNode()
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &position)
Is event belonging to node.
GUIScreenNode * getScreenNode()
GUINodeController * getController()
GUI parent node base class thats supporting child nodes.
GUI screen node that represents a screen that can be rendered via GUI system.
void delegateValueChanged(GUIElementNode *node)
Delegate value changed.
void delegateActionPerformed(GUIActionListenerType type, GUIElementNode *node)
Delegate action performed.
GUI Font A font implementation that will parse the output of the AngelCode font tool available at:
MutableString & append(char c)
Append character.
MutableString & set(char c)
Set character.
GUI node computed constraints.