BsGUIInputBox.h 3.6 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 ElementType getElementType() const { return ElementType::InputBox; }
  18. virtual CM::Vector2I _getOptimalSize() const;
  19. protected:
  20. GUIInputBox(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions, bool multiline);
  21. virtual ~GUIInputBox();
  22. /**
  23. * @copydoc GUIElement::getNumRenderElements()
  24. */
  25. virtual CM::UINT32 getNumRenderElements() const;
  26. /**
  27. * @copydoc GUIElement::getMaterial()
  28. */
  29. virtual const GUIMaterialInfo& getMaterial(CM::UINT32 renderElementIdx) const;
  30. /**
  31. * @copydoc GUIElement::getNumQuads()
  32. */
  33. virtual CM::UINT32 getNumQuads(CM::UINT32 renderElementIdx) const;
  34. /**
  35. * @copydoc GUIElement::fillBuffer()
  36. */
  37. virtual void fillBuffer(CM::UINT8* vertices, CM::UINT8* uv, CM::UINT32* indices, CM::UINT32 startingQuad,
  38. CM::UINT32 maxNumQuads, CM::UINT32 vertexStride, CM::UINT32 indexStride, CM::UINT32 renderElementIdx) const;
  39. /**
  40. * @copydoc GUIElement::updateRenderElementsInternal()
  41. */
  42. virtual void updateRenderElementsInternal();
  43. /**
  44. * @copydoc GUIElement::updateBounds()
  45. */
  46. virtual void updateClippedBounds();
  47. virtual bool mouseEvent(const GUIMouseEvent& ev);
  48. virtual bool textInputEvent(const GUITextInputEvent& ev);
  49. virtual bool commandEvent(const GUICommandEvent& ev);
  50. virtual CM::Vector2I _getTextInputOffset() const;
  51. virtual CM::RectI _getTextInputRect() const;
  52. virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
  53. virtual GUIContextMenu* getContextMenu() const;
  54. private:
  55. // Sprites
  56. ImageSprite* mImageSprite;
  57. TextSprite* mTextSprite;
  58. bool mIsMultiline;
  59. CM::Vector2I mTextOffset;
  60. bool mHasFocus;
  61. bool mIsMouseOver;
  62. HSpriteTexture mActiveTexture;
  63. IMAGE_SPRITE_DESC mImageDesc;
  64. CM::WString mText;
  65. bool mCaretShown;
  66. bool mSelectionShown;
  67. bool mInputCursorSet;
  68. bool mDragInProgress;
  69. Sprite* renderElemToSprite(CM::UINT32 renderElemIdx, CM::UINT32& localRenderElemIdx) const;
  70. CM::Vector2I renderElemToOffset(CM::UINT32 renderElemIdx) const;
  71. CM::RectI renderElemToClipRect(CM::UINT32 renderElemIdx) const;
  72. void insertString(CM::UINT32 charIdx, const CM::WString& string);
  73. void insertChar(CM::UINT32 charIdx, CM::UINT32 charCode);
  74. void eraseChar(CM::UINT32 charIdx);
  75. void deleteSelectedText();
  76. CM::WString getSelectedText();
  77. void showCaret();
  78. void hideCaret();
  79. void showSelection(CM::UINT32 anchorCaretPos);
  80. void clearSelection();
  81. void moveSelectionLeft(bool skipNewline);
  82. void moveSelectionRight(bool skipNewline);
  83. void scrollTextToCaret();
  84. void clampScrollToBounds(CM::RectI unclippedTextBounds);
  85. CM::Vector2I getTextOffset() const;
  86. CM::RectI getTextClipRect() const;
  87. TEXT_SPRITE_DESC getTextDesc() const;
  88. void cutText();
  89. void copyText();
  90. void pasteText();
  91. };
  92. }