BsGUIInputTool.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsTextSprite.h"
  4. namespace BansheeEngine
  5. {
  6. class BS_EXPORT GUIInputLineDesc
  7. {
  8. public:
  9. GUIInputLineDesc(CM::UINT32 startChar, CM::UINT32 endChar, CM::UINT32 lineHeight, CM::INT32 lineYStart, bool includesNewline);
  10. CM::UINT32 getEndChar(bool includeNewline = true) const;
  11. CM::UINT32 getStartChar() const { return mStartChar; }
  12. CM::UINT32 getLineHeight() const { return mLineHeight; }
  13. CM::INT32 getLineYStart() const { return mLineYStart; }
  14. bool isNewline(CM::UINT32 charIdx) const;
  15. bool hasNewlineChar() const { return mIncludesNewline; }
  16. private:
  17. CM::UINT32 mStartChar;
  18. CM::UINT32 mEndChar;
  19. CM::UINT32 mLineHeight;
  20. CM::INT32 mLineYStart;
  21. bool mIncludesNewline;
  22. };
  23. class BS_EXPORT GUIInputTool
  24. {
  25. public:
  26. GUIInputTool(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);
  27. ~GUIInputTool();
  28. void updateText(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);
  29. /**
  30. * @note "Input index" represents the empty areas between the characters.
  31. */
  32. bool isNewlineBefore(CM::UINT32 inputIdx);
  33. /**
  34. * @note "Input index" represents the empty areas between the characters.
  35. */
  36. bool isNewlineAfter(CM::UINT32 inputIdx);
  37. protected:
  38. CM::Vector2* mQuads;
  39. CM::UINT32 mNumQuads;
  40. TEXT_SPRITE_DESC mTextDesc;
  41. CM::Int2 mTextOffset;
  42. CM::Int2 mClipOffset;
  43. CM::Vector<GUIInputLineDesc>::type mLineDescs;
  44. CM::UINT32 getNumLines() const { return (CM::UINT32)mLineDescs.size(); }
  45. const GUIInputLineDesc& getLineDesc(CM::UINT32 lineIdx) const { return mLineDescs.at(lineIdx); }
  46. CM::UINT32 getLineForChar(CM::UINT32 charIdx, bool newlineCountsOnNextLine = false) const;
  47. CM::Rect getCharRect(CM::UINT32 charIdx) const;
  48. CM::INT32 getCharIdxAtPos(const CM::Int2& pos) const;
  49. /**
  50. * @brief Gets a character index AFTER the input index.
  51. * "Input index" represents the empty areas between the characters. Newline counts as a character.
  52. * (e.g. 0 is before the first character, 1 is after the first character but before the second, etc.)
  53. *
  54. * @note This can return an out of range character index, in case the input index is specified after the last character.
  55. */
  56. CM::UINT32 getCharIdxAtInputIdx(CM::UINT32 inputIdx) const;
  57. bool isNewlineChar(CM::UINT32 charIdx) const;
  58. };
  59. }