BsGUIInputSelection.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisites.h"
  5. #include "GUI/BsGUIInputTool.h"
  6. #include "2D/BsTextSprite.h"
  7. namespace bs
  8. {
  9. /** @addtogroup GUI-Internal
  10. * @{
  11. */
  12. /** Helper class for dealing with text selection for text input boxes and similar controls. */
  13. class BS_EXPORT GUIInputSelection : public GUIInputTool
  14. {
  15. public:
  16. GUIInputSelection();
  17. ~GUIInputSelection();
  18. /** Returns sprites representing the currently selected areas. */
  19. const Vector<ImageSprite*>& getSprites() const { return mSprites; }
  20. /** Returns how much to offset the sprite with the specified index, relative to the parent widget. */
  21. Vector2I getSelectionSpriteOffset(UINT32 spriteIdx) const;
  22. /**
  23. * Returns clip rectangle relative to parent GUI element for the sprite with the specified index.
  24. *
  25. * @param[in] spriteIdx Index of the sprite to retrieve the clip rectangle for.
  26. * @param[in] parentClipRect Clip rectangle of the parent GUI element. Selection clip rectangle will
  27. * additionally be clipped by this area. Relative to parent element.
  28. */
  29. Rect2I getSelectionSpriteClipRect(UINT32 spriteIdx, const Rect2I& parentClipRect) const;
  30. /** Recreates the selection clip sprites. */
  31. void updateSprite();
  32. /**
  33. * Shows the selection using the specified anchor. By default this will select 0 characters so you must manually
  34. * move the selection using moveSelectionToCaret() before anything is considered selected.
  35. *
  36. * @param[in] anchorCaretPos Anchor position which to initially select. Anchor position determines selection
  37. * area behavior when the input caret moves (determines whether left or right side of
  38. * the selection will move with the caret).
  39. */
  40. void showSelection(UINT32 anchorCaretPos);
  41. /** Clears the currently active selection. */
  42. void clearSelection();
  43. /**
  44. * Moves the selection to caret. Selected area will be from the anchor provided in showSelection() to the caret
  45. * position provided here.
  46. */
  47. void moveSelectionToCaret(UINT32 caretPos);
  48. /** Checks is anything selected. */
  49. bool isSelectionEmpty() const;
  50. /** Selects all available text. */
  51. void selectAll();
  52. /**
  53. * Starts selection drag at the specified caret position. Call selectionDragUpdate() and selectionDragEnd() as the
  54. * drag operation progresses.
  55. */
  56. void selectionDragStart(UINT32 caretPos);
  57. /** Updates selection drag at the specified caret position. */
  58. void selectionDragUpdate(UINT32 caretPos);
  59. /** Stops selection drag. */
  60. void selectionDragEnd();
  61. /** Gets caret index of selection start. */
  62. UINT32 getSelectionStart() const { return mSelectionStart; }
  63. /** Gets caret index of selection end. */
  64. UINT32 getSelectionEnd() const { return mSelectionEnd; }
  65. private:
  66. /** Returns rectangles describing the currently selected areas. Rectangles are relative to parent GUI element. */
  67. Vector<Rect2I> getSelectionRects() const;
  68. private:
  69. UINT32 mSelectionStart;
  70. UINT32 mSelectionEnd;
  71. UINT32 mSelectionAnchor;
  72. UINT32 mSelectionDragAnchor;
  73. Vector<Rect2I> mSelectionRects;
  74. Vector<ImageSprite*> mSprites;
  75. };
  76. /** @} */
  77. }