BsGUIInputCaret.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "BsGUIInputTool.h"
  6. #include "BsTextSprite.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup GUI-Internal
  10. * @{
  11. */
  12. /** When paired with a character index determines should the caret be placed before or after it. */
  13. enum CaretPos
  14. {
  15. CARET_BEFORE,
  16. CARET_AFTER
  17. };
  18. /** Helper class for dealing with caret for text input boxes and similar controls. */
  19. class BS_EXPORT GUIInputCaret : public GUIInputTool
  20. {
  21. public:
  22. GUIInputCaret();
  23. ~GUIInputCaret();
  24. /** Returns sprite used for rendering the caret. */
  25. ImageSprite* getSprite() const { return mCaretSprite; }
  26. /** Returns offset relative to parent widget that determines placement of the caret sprite. */
  27. Vector2I getSpriteOffset() const;
  28. /**
  29. * Returns clip rectangle relative to parent GUI element that determines how is caret sprite clipped.
  30. *
  31. * @param[in] parentClipRect Clip rectangle of the parent GUI element. Caret clip rectangle will additionally be
  32. * clipped by this area. Relative to parent element.
  33. */
  34. Rect2I getSpriteClipRect(const Rect2I& parentClipRect) const;
  35. /** Rebuilts internal caret sprite using current properties. */
  36. void updateSprite();
  37. /** Moves caret to the start of text. */
  38. void moveCaretToStart();
  39. /** Moves caret to the end of text. */
  40. void moveCaretToEnd();
  41. /** Moves caret one character to the left, if not at start already. */
  42. void moveCaretLeft();
  43. /** Moves caret one character to the right, if not at end already. */
  44. void moveCaretRight();
  45. /** Moves caret one line up if possible. */
  46. void moveCaretUp();
  47. /** Moves caret one line down if possible. */
  48. void moveCaretDown();
  49. /** Moves caret to the character nearest to the specified position. Position is relative to parent widget. */
  50. void moveCaretToPos(const Vector2I& pos);
  51. /**
  52. * Moves the caret to a specific character index.
  53. *
  54. * @param[in] charIdx Index of the character to move the caret to.
  55. * @param[in] caretPos Whether to place the caret before or after the character.
  56. */
  57. void moveCaretToChar(UINT32 charIdx, CaretPos caretPos);
  58. /** Returns character index after the current caret position. */
  59. UINT32 getCharIdxAtCaretPos() const;
  60. /**
  61. * Returns current caret position, relative to parent widget. Requires you to provide offset to text the caret is
  62. * used for (also relative to parent widget).
  63. */
  64. Vector2I getCaretPosition(const Vector2I& offset) const;
  65. /** Returns height of the caret, in pixels. */
  66. UINT32 getCaretHeight() const;
  67. /** Returns true if the character after the caret is newline. */
  68. bool isCaretAtNewline() const;
  69. /** Returns maximum valid caret index. */
  70. UINT32 getMaxCaretPos() const;
  71. /** Returns current caret index (not equal to character index). */
  72. UINT32 getCaretPos() const { return mCaretPos; }
  73. private:
  74. UINT32 mCaretPos;
  75. ImageSprite* mCaretSprite;
  76. };
  77. /** @} */
  78. }