BsGUIInputBox.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElement.h"
  4. #include "BsImageSprite.h"
  5. #include "BsTextSprite.h"
  6. namespace BansheeEngine
  7. {
  8. class BS_EXPORT GUIInputBox : public GUIElement
  9. {
  10. public:
  11. static const CM::String& getGUITypeName();
  12. static GUIInputBox* create(GUIWidget& parent, bool multiline = false, const GUIElementStyle* style = nullptr);
  13. static GUIInputBox* create(GUIWidget& parent, bool multiline, const GUIOptions& layoutOptions, const GUIElementStyle* style = nullptr);
  14. static GUIInputBox* create(GUIWidget& parent, const GUIOptions& layoutOptions, const GUIElementStyle* style = nullptr);
  15. const CM::WString& getText() const { return mText; }
  16. void setText(const CM::WString& text);
  17. virtual CM::Vector2I _getOptimalSize() const;
  18. protected:
  19. ~GUIInputBox();
  20. /**
  21. * @copydoc GUIElement::getNumRenderElements()
  22. */
  23. virtual CM::UINT32 getNumRenderElements() const;
  24. /**
  25. * @copydoc GUIElement::getMaterial()
  26. */
  27. virtual const GUIMaterialInfo& getMaterial(CM::UINT32 renderElementIdx) const;
  28. /**
  29. * @copydoc GUIElement::getNumQuads()
  30. */
  31. virtual CM::UINT32 getNumQuads(CM::UINT32 renderElementIdx) const;
  32. /**
  33. * @copydoc GUIElement::fillBuffer()
  34. */
  35. virtual void fillBuffer(CM::UINT8* vertices, CM::UINT8* uv, CM::UINT32* indices, CM::UINT32 startingQuad,
  36. CM::UINT32 maxNumQuads, CM::UINT32 vertexStride, CM::UINT32 indexStride, CM::UINT32 renderElementIdx) const;
  37. /**
  38. * @copydoc GUIElement::updateRenderElementsInternal()
  39. */
  40. virtual void updateRenderElementsInternal();
  41. /**
  42. * @copydoc GUIElement::updateBounds()
  43. */
  44. virtual void updateClippedBounds();
  45. virtual CM::Vector2I _getTextInputOffset() const;
  46. virtual CM::RectI _getTextInputRect() const;
  47. virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
  48. virtual void _setFocus(bool focus);
  49. virtual GUIContextMenu* getContextMenu() const;
  50. private:
  51. // Sprites
  52. ImageSprite* mImageSprite;
  53. TextSprite* mTextSprite;
  54. bool mIsMultiline;
  55. CM::Vector2I mTextOffset;
  56. bool mHasFocus;
  57. HSpriteTexture mActiveTexture;
  58. IMAGE_SPRITE_DESC mImageDesc;
  59. CM::WString mText;
  60. bool mCaretShown;
  61. bool mSelectionShown;
  62. bool mInputCursorSet;
  63. bool mDragInProgress;
  64. GUIInputBox(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions, bool multiline);
  65. virtual bool mouseEvent(const GUIMouseEvent& ev);
  66. virtual bool textInputEvent(const GUITextInputEvent& ev);
  67. virtual bool commandEvent(const GUICommandEvent& ev);
  68. Sprite* renderElemToSprite(CM::UINT32 renderElemIdx, CM::UINT32& localRenderElemIdx) const;
  69. CM::Vector2I renderElemToOffset(CM::UINT32 renderElemIdx) const;
  70. CM::RectI renderElemToClipRect(CM::UINT32 renderElemIdx) const;
  71. void insertString(CM::UINT32 charIdx, const CM::WString& string);
  72. void insertChar(CM::UINT32 charIdx, CM::UINT32 charCode);
  73. void eraseChar(CM::UINT32 charIdx);
  74. void deleteSelectedText();
  75. CM::WString getSelectedText();
  76. void showCaret();
  77. void hideCaret();
  78. void showSelection(CM::UINT32 anchorCaretPos);
  79. void clearSelection();
  80. void moveSelectionLeft(bool skipNewline);
  81. void moveSelectionRight(bool skipNewline);
  82. void scrollTextToCaret();
  83. void clampScrollToBounds(CM::RectI unclippedTextBounds);
  84. CM::Vector2I getTextOffset() const;
  85. CM::RectI getTextClipRect() const;
  86. TEXT_SPRITE_DESC getTextDesc() const;
  87. void cutText();
  88. void copyText();
  89. void pasteText();
  90. };
  91. }