BsGUIInputTool.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. protected:
  30. CM::Vector2* mQuads;
  31. CM::UINT32 mNumQuads;
  32. TEXT_SPRITE_DESC mTextDesc;
  33. CM::Int2 mTextOffset;
  34. CM::Int2 mClipOffset;
  35. CM::Vector<GUIInputLineDesc>::type mLineDescs;
  36. CM::UINT32 getNumLines() const { return (CM::UINT32)mLineDescs.size(); }
  37. const GUIInputLineDesc& getLineDesc(CM::UINT32 lineIdx) const { return mLineDescs.at(lineIdx); }
  38. CM::UINT32 getLineForChar(CM::UINT32 charIdx, bool newlineCountsOnNextLine = false) const;
  39. CM::Rect getCharRect(CM::UINT32 charIdx) const;
  40. CM::INT32 getCharIdxAtPos(const CM::Int2& pos) const;
  41. /**
  42. * @brief Gets a character index AFTER the input index.
  43. * "Input index" represents the empty areas between the characters. Newline counts as a character.
  44. * (e.g. 0 is before the first character, 1 is after the first character but before the second, etc.)
  45. *
  46. * @note This can return an out of range character index, in case the input index is specified after the last character.
  47. */
  48. CM::UINT32 getCharIdxAtInputIdx(CM::UINT32 inputIdx) const;
  49. };
  50. }