|
|
@@ -6,7 +6,7 @@
|
|
|
#include "BsSpriteTexture.h"
|
|
|
#include "BsTextSprite.h"
|
|
|
#include "BsGUILayoutOptions.h"
|
|
|
-#include "BsGUIButtonEvent.h"
|
|
|
+#include "BsGUITextInputEvent.h"
|
|
|
#include "BsGUIMouseEvent.h"
|
|
|
#include "BsGUICommandEvent.h"
|
|
|
#include "CmFont.h"
|
|
|
@@ -470,247 +470,252 @@ namespace BansheeEngine
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- bool GUIInputBox::keyEvent(const GUIKeyEvent& ev)
|
|
|
+ bool GUIInputBox::textInputEvent(const GUITextInputEvent& ev)
|
|
|
{
|
|
|
- if(ev.getType() == GUIKeyEventType::KeyDown)
|
|
|
- {
|
|
|
- if(ev.getKey() == BC_BACK)
|
|
|
- {
|
|
|
- if(mText.size() > 0)
|
|
|
- {
|
|
|
- if(mSelectionShown)
|
|
|
- {
|
|
|
- deleteSelectedText();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos() - 1;
|
|
|
-
|
|
|
- if(charIdx < (UINT32)mText.size())
|
|
|
- {
|
|
|
- eraseChar(charIdx);
|
|
|
+ if(mSelectionShown)
|
|
|
+ deleteSelectedText();
|
|
|
|
|
|
- if(charIdx > 0)
|
|
|
- charIdx--;
|
|
|
+ UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
|
|
|
+ insertChar(charIdx, ev.getInputChar());
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
- }
|
|
|
- }
|
|
|
+ scrollTextToCaret();
|
|
|
|
|
|
- markContentAsDirty();
|
|
|
- }
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
+ bool GUIInputBox::commandEvent(const GUICommandEvent& ev)
|
|
|
+ {
|
|
|
+ if(ev.getType() == GUICommandEventType::Redraw)
|
|
|
+ {
|
|
|
+ markMeshAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- if(ev.getKey() == BC_DELETE)
|
|
|
+ if(ev.getType() == GUICommandEventType::Backspace)
|
|
|
+ {
|
|
|
+ if(mText.size() > 0)
|
|
|
{
|
|
|
- if(mText.size() > 0)
|
|
|
+ if(mSelectionShown)
|
|
|
{
|
|
|
- if(mSelectionShown)
|
|
|
- {
|
|
|
- deleteSelectedText();
|
|
|
- }
|
|
|
- else
|
|
|
+ deleteSelectedText();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos() - 1;
|
|
|
+
|
|
|
+ if(charIdx < (UINT32)mText.size())
|
|
|
{
|
|
|
- UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
|
|
|
- if(charIdx < (UINT32)mText.size())
|
|
|
- {
|
|
|
- eraseChar(charIdx);
|
|
|
+ eraseChar(charIdx);
|
|
|
|
|
|
- if(charIdx > 0)
|
|
|
- charIdx--;
|
|
|
+ if(charIdx > 0)
|
|
|
+ charIdx--;
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
- }
|
|
|
+ scrollTextToCaret();
|
|
|
}
|
|
|
-
|
|
|
- markContentAsDirty();
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ markContentAsDirty();
|
|
|
}
|
|
|
-
|
|
|
- if(ev.getKey() == BC_LEFT)
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ev.getType() == GUICommandEventType::Delete)
|
|
|
+ {
|
|
|
+ if(mText.size() > 0)
|
|
|
{
|
|
|
- if(ev.isShiftDown())
|
|
|
+ if(mSelectionShown)
|
|
|
{
|
|
|
- if(!mSelectionShown)
|
|
|
- showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
-
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretLeft();
|
|
|
- gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
+ deleteSelectedText();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(mSelectionShown)
|
|
|
+ UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
|
|
|
+ if(charIdx < (UINT32)mText.size())
|
|
|
{
|
|
|
- UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
|
|
|
- clearSelection();
|
|
|
+ eraseChar(charIdx);
|
|
|
+
|
|
|
+ if(charIdx > 0)
|
|
|
+ charIdx--;
|
|
|
+
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
|
|
|
|
|
|
- if(selStart > 0)
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(selStart - 1, CARET_AFTER);
|
|
|
- else
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
|
|
|
+ scrollTextToCaret();
|
|
|
}
|
|
|
- else
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretLeft();
|
|
|
}
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
markContentAsDirty();
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
- if(ev.getKey() == BC_RIGHT)
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ev.getType() == GUICommandEventType::CursorMoveLeft)
|
|
|
+ {
|
|
|
+ if(mSelectionShown)
|
|
|
{
|
|
|
- if(ev.isShiftDown())
|
|
|
- {
|
|
|
- if(!mSelectionShown)
|
|
|
- showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
+ UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
|
|
|
+ clearSelection();
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretRight();
|
|
|
- gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
- }
|
|
|
+ if(selStart > 0)
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(selStart - 1, CARET_AFTER);
|
|
|
else
|
|
|
- {
|
|
|
- if(mSelectionShown)
|
|
|
- {
|
|
|
- UINT32 selEnd = gGUIManager().getInputSelectionTool()->getSelectionEnd();
|
|
|
- clearSelection();
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretLeft();
|
|
|
|
|
|
- if(selEnd > 0)
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(selEnd - 1, CARET_AFTER);
|
|
|
- else
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
|
|
|
- }
|
|
|
- else
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretRight();
|
|
|
- }
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
- markContentAsDirty();
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if(ev.getType() == GUICommandEventType::SelectLeft)
|
|
|
+ {
|
|
|
+ if(!mSelectionShown)
|
|
|
+ showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
+
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretLeft();
|
|
|
+ gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
|
|
|
- if(ev.getKey() == BC_UP)
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ev.getType() == GUICommandEventType::CursorMoveRight)
|
|
|
+ {
|
|
|
+ if(mSelectionShown)
|
|
|
{
|
|
|
- if(ev.isShiftDown())
|
|
|
- {
|
|
|
- if(!mSelectionShown)
|
|
|
- showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
- }
|
|
|
+ UINT32 selEnd = gGUIManager().getInputSelectionTool()->getSelectionEnd();
|
|
|
+ clearSelection();
|
|
|
+
|
|
|
+ if(selEnd > 0)
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(selEnd - 1, CARET_AFTER);
|
|
|
else
|
|
|
- clearSelection();
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretRight();
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretUp();
|
|
|
-
|
|
|
- if(ev.isShiftDown())
|
|
|
- gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
- markContentAsDirty();
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if(ev.getType() == GUICommandEventType::SelectRight)
|
|
|
+ {
|
|
|
+ if(!mSelectionShown)
|
|
|
+ showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
|
|
|
- if(ev.getKey() == BC_DOWN)
|
|
|
- {
|
|
|
- if(ev.isShiftDown())
|
|
|
- {
|
|
|
- if(!mSelectionShown)
|
|
|
- showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
- }
|
|
|
- else
|
|
|
- clearSelection();
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretRight();
|
|
|
+ gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretDown();
|
|
|
-
|
|
|
- if(ev.isShiftDown())
|
|
|
- gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
- markContentAsDirty();
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if(ev.getType() == GUICommandEventType::CursorMoveUp)
|
|
|
+ {
|
|
|
+ clearSelection();
|
|
|
|
|
|
- if(ev.getKey() == BC_RETURN)
|
|
|
- {
|
|
|
- if(mIsMultiline)
|
|
|
- {
|
|
|
- if(mSelectionShown)
|
|
|
- deleteSelectedText();
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretUp();
|
|
|
|
|
|
- insertChar(gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos(), '\n');
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretRight();
|
|
|
- scrollTextToCaret();
|
|
|
+ if(ev.getType() == GUICommandEventType::SelectUp)
|
|
|
+ {
|
|
|
+ if(!mSelectionShown)
|
|
|
+ showSelection(gGUIManager().getInputCaretTool()->getCaretPos());;
|
|
|
|
|
|
- markContentAsDirty();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretUp();
|
|
|
+ gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
|
|
|
- if(ev.getKey() == BC_A && ev.isCtrlDown())
|
|
|
- {
|
|
|
- showSelection(0);
|
|
|
- gGUIManager().getInputSelectionTool()->selectAll();
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- markContentAsDirty();
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if(ev.getType() == GUICommandEventType::CursorMoveDown)
|
|
|
+ {
|
|
|
+ clearSelection();
|
|
|
|
|
|
- if(ev.getKey() == BC_X && ev.isCtrlDown())
|
|
|
- {
|
|
|
- cutText();
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretDown();
|
|
|
|
|
|
- markContentAsDirty();
|
|
|
- return true;
|
|
|
- }
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- if(ev.getKey() == BC_C && ev.isCtrlDown())
|
|
|
- {
|
|
|
- copyText();
|
|
|
+ if(ev.getType() == GUICommandEventType::SelectDown)
|
|
|
+ {
|
|
|
+ if(!mSelectionShown)
|
|
|
+ showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretDown();
|
|
|
+ gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
|
|
|
+
|
|
|
+ scrollTextToCaret();
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- if(ev.getKey() == BC_V && ev.isCtrlDown())
|
|
|
+ if(ev.getType() == GUICommandEventType::Return)
|
|
|
+ {
|
|
|
+ if(mIsMultiline)
|
|
|
{
|
|
|
- pasteText();
|
|
|
+ if(mSelectionShown)
|
|
|
+ deleteSelectedText();
|
|
|
+
|
|
|
+ insertChar(gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos(), '\n');
|
|
|
+
|
|
|
+ gGUIManager().getInputCaretTool()->moveCaretRight();
|
|
|
+ scrollTextToCaret();
|
|
|
|
|
|
markContentAsDirty();
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
- else if(ev.getType() == GUIKeyEventType::TextInput)
|
|
|
- {
|
|
|
- if(mSelectionShown)
|
|
|
- deleteSelectedText();
|
|
|
|
|
|
- UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
|
|
|
- insertChar(charIdx, ev.getInputChar());
|
|
|
+ if(ev.getType() == GUICommandEventType::SelectAll)
|
|
|
+ {
|
|
|
+ showSelection(0);
|
|
|
+ gGUIManager().getInputSelectionTool()->selectAll();
|
|
|
|
|
|
- gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
|
|
|
+ markContentAsDirty();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- scrollTextToCaret();
|
|
|
+ if(ev.getType() == GUICommandEventType::Cut)
|
|
|
+ {
|
|
|
+ cutText();
|
|
|
|
|
|
markContentAsDirty();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if(ev.getType() == GUICommandEventType::Copy)
|
|
|
+ {
|
|
|
+ copyText();
|
|
|
|
|
|
- bool GUIInputBox::commandEvent(const GUICommandEvent& ev)
|
|
|
- {
|
|
|
- if(ev.getType() == GUICommandEventType::Redraw)
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ev.getType() == GUICommandEventType::Paste)
|
|
|
{
|
|
|
- markMeshAsDirty();
|
|
|
+ pasteText();
|
|
|
+
|
|
|
+ markContentAsDirty();
|
|
|
return true;
|
|
|
}
|
|
|
|