BsGUIInputBox.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElement.h"
  4. #include "BsImageSprite.h"
  5. #include "BsTextSprite.h"
  6. #include "BsGUIInputCaret.h"
  7. namespace BansheeEngine
  8. {
  9. enum class SelectionDir
  10. {
  11. Left,
  12. Right
  13. };
  14. class BS_EXPORT GUIInputBox : public GUIElement
  15. {
  16. public:
  17. static const CM::String& getGUITypeName();
  18. static GUIInputBox* create(GUIWidget& parent, bool multiline = false, const GUIElementStyle* style = nullptr);
  19. static GUIInputBox* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, bool multiline = false, const GUIElementStyle* style = nullptr);
  20. protected:
  21. ~GUIInputBox();
  22. /**
  23. * @copydoc GUIElement::getNumRenderElements()
  24. */
  25. virtual CM::UINT32 getNumRenderElements() const;
  26. /**
  27. * @copydoc GUIElement::getMaterial()
  28. */
  29. virtual const CM::HMaterial& 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. virtual CM::UINT32 _getOptimalWidth() const;
  44. virtual CM::UINT32 _getOptimalHeight() const;
  45. virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
  46. virtual void _setFocus(bool focus);
  47. private:
  48. // Sprites
  49. ImageSprite* mImageSprite;
  50. TextSprite* mTextSprite;
  51. CM::Vector<ImageSprite*>::type mSelectionSprites;
  52. GUIInputCaret* mInputCaret;
  53. bool mInputCursorSet;
  54. bool mDragInProgress;
  55. bool mIsMultiline;
  56. CM::Int2 mTextOffset;
  57. IMAGE_SPRITE_DESC mImageDesc;
  58. CM::WString mText;
  59. // Selection & input caret
  60. CM::UINT32 mSelectionStart;
  61. CM::UINT32 mSelectionEnd;
  62. CM::UINT32 mSelectionAnchor;
  63. bool mCaretShown;
  64. bool mSelectionShown;
  65. GUIInputBox(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions, bool multiline);
  66. virtual bool mouseEvent(const GUIMouseEvent& ev);
  67. virtual bool keyEvent(const GUIKeyEvent& ev);
  68. virtual bool commandEvent(const GUICommandEvent& ev);
  69. Sprite* renderElemToSprite(CM::UINT32 renderElemIdx, CM::UINT32& localRenderElemIdx) const;
  70. void showCaret();
  71. void hideCaret();
  72. void scrollTextToCaret();
  73. void showSelection(CM::UINT32 startChar);
  74. void clearSelection();
  75. void moveSelectionLeft(bool skipNewline);
  76. void moveSelectionRight(bool skipnewLine);
  77. void moveSelectionUp();
  78. void moveSelectionDown();
  79. CM::UINT32 getCaretSelectionCharIdx(SelectionDir dir) const;
  80. bool isNewlineChar(CM::UINT32 charIdx) const;
  81. CM::Vector<CM::Rect>::type getSelectionRects() const;
  82. CM::Rect getTextBounds() const;
  83. TEXT_SPRITE_DESC getTextDesc() const;
  84. };
  85. }