BsGUIInputBox.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElement.h"
  4. #include "BsImageSprite.h"
  5. #include "BsTextSprite.h"
  6. #include "BsVirtualInput.h"
  7. namespace BansheeEngine
  8. {
  9. class BS_EXPORT GUIInputBox : public GUIElement
  10. {
  11. enum class State
  12. {
  13. Normal,
  14. Hover,
  15. Focused
  16. };
  17. public:
  18. static const CM::String& getGUITypeName();
  19. static GUIInputBox* create(bool multiline = false, const CM::String& styleName = CM::StringUtil::BLANK);
  20. static GUIInputBox* create(bool multiline, const GUIOptions& layoutOptions, const CM::String& styleName = CM::StringUtil::BLANK);
  21. static GUIInputBox* create(const GUIOptions& layoutOptions, const CM::String& styleName = CM::StringUtil::BLANK);
  22. const CM::WString& getText() const { return mText; }
  23. void setText(const CM::WString& text);
  24. void setFilter(std::function<bool(const CM::WString&)> filter) { mFilter = filter; }
  25. virtual ElementType getElementType() const { return ElementType::InputBox; }
  26. virtual CM::Vector2I _getOptimalSize() const;
  27. protected:
  28. GUIInputBox(const CM::String& styleName, const GUILayoutOptions& layoutOptions, bool multiline);
  29. virtual ~GUIInputBox();
  30. /**
  31. * @copydoc GUIElement::getNumRenderElements()
  32. */
  33. virtual CM::UINT32 getNumRenderElements() const;
  34. /**
  35. * @copydoc GUIElement::getMaterial()
  36. */
  37. virtual const GUIMaterialInfo& getMaterial(CM::UINT32 renderElementIdx) const;
  38. /**
  39. * @copydoc GUIElement::getNumQuads()
  40. */
  41. virtual CM::UINT32 getNumQuads(CM::UINT32 renderElementIdx) const;
  42. /**
  43. * @copydoc GUIElement::fillBuffer()
  44. */
  45. virtual void fillBuffer(CM::UINT8* vertices, CM::UINT8* uv, CM::UINT32* indices, CM::UINT32 startingQuad,
  46. CM::UINT32 maxNumQuads, CM::UINT32 vertexStride, CM::UINT32 indexStride, CM::UINT32 renderElementIdx) const;
  47. /**
  48. * @copydoc GUIElement::updateRenderElementsInternal()
  49. */
  50. virtual void updateRenderElementsInternal();
  51. /**
  52. * @copydoc GUIElement::updateBounds()
  53. */
  54. virtual void updateClippedBounds();
  55. virtual bool mouseEvent(const GUIMouseEvent& ev);
  56. virtual bool textInputEvent(const GUITextInputEvent& ev);
  57. virtual bool commandEvent(const GUICommandEvent& ev);
  58. virtual bool virtualButtonEvent(const GUIVirtualButtonEvent& ev);
  59. virtual CM::Vector2I _getTextInputOffset() const;
  60. virtual CM::RectI _getTextInputRect() const;
  61. virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
  62. virtual bool _hasCustomCursor(const CM::Vector2I position, CursorType& type) const;
  63. virtual GUIContextMenu* getContextMenu() const;
  64. private:
  65. static VirtualButton mCopyVB;
  66. static VirtualButton mPasteVB;
  67. static VirtualButton mCutVB;
  68. static VirtualButton mSelectAllVB;
  69. // Sprites
  70. ImageSprite* mImageSprite;
  71. TextSprite* mTextSprite;
  72. bool mIsMultiline;
  73. CM::Vector2I mTextOffset;
  74. bool mHasFocus;
  75. bool mIsMouseOver;
  76. State mState;
  77. IMAGE_SPRITE_DESC mImageDesc;
  78. CM::WString mText;
  79. std::function<bool(const CM::WString&)> mFilter;
  80. bool mCaretShown;
  81. bool mSelectionShown;
  82. bool mDragInProgress;
  83. Sprite* renderElemToSprite(CM::UINT32 renderElemIdx, CM::UINT32& localRenderElemIdx) const;
  84. CM::Vector2I renderElemToOffset(CM::UINT32 renderElemIdx) const;
  85. CM::RectI renderElemToClipRect(CM::UINT32 renderElemIdx) const;
  86. void insertString(CM::UINT32 charIdx, const CM::WString& string);
  87. void insertChar(CM::UINT32 charIdx, CM::UINT32 charCode);
  88. void eraseChar(CM::UINT32 charIdx);
  89. void deleteSelectedText();
  90. CM::WString getSelectedText();
  91. void showCaret();
  92. void hideCaret();
  93. void showSelection(CM::UINT32 anchorCaretPos);
  94. void clearSelection();
  95. void moveSelectionLeft(bool skipNewline);
  96. void moveSelectionRight(bool skipNewline);
  97. void scrollTextToCaret();
  98. void clampScrollToBounds(CM::RectI unclippedTextBounds);
  99. CM::Vector2I getTextOffset() const;
  100. CM::RectI getTextClipRect() const;
  101. TEXT_SPRITE_DESC getTextDesc() const;
  102. const HSpriteTexture& getActiveTexture() const;
  103. void cutText();
  104. void copyText();
  105. void pasteText();
  106. };
  107. }