UiTextArea.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef UI_TEXT_AREA_H
  2. #define UI_TEXT_AREA_H
  3. #include <OgreHardwareVertexBuffer.h>
  4. #include <OgreRenderQueueListener.h>
  5. #include <OgreRoot.h>
  6. #include <OgreUTFString.h>
  7. #include <tinyxml/tinyxml.h>
  8. #include "UiFont.h"
  9. #include "UiWidget.h"
  10. struct TextStyle
  11. {
  12. Ogre::ColourValue colour;
  13. };
  14. struct TextBlockData
  15. {
  16. float local_x1;
  17. float local_y1;
  18. int position;
  19. };
  20. class UiTextArea : public UiWidget
  21. {
  22. public:
  23. UiTextArea( const Ogre::String& name );
  24. UiTextArea( const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent );
  25. virtual ~UiTextArea();
  26. void Initialise();
  27. virtual void Update();
  28. virtual void Render();
  29. virtual void UpdateTransformation();
  30. enum TextAlign
  31. {
  32. LEFT,
  33. RIGHT,
  34. CENTER
  35. };
  36. void SetTextAlign( const TextAlign align );
  37. void SetText( const Ogre::UTFString& text );
  38. void SetText( TiXmlNode* text );
  39. void SetFont( const Ogre::String& font );
  40. void UpdateGeometry();
  41. float GetTextLengthFromNode( TiXmlNode* node ) const;
  42. float GetTextLength( const Ogre::UTFString& text ) const;
  43. void SetTextGeometryFromNode( TiXmlNode* node, TextBlockData& data, const TextStyle& style );
  44. void SetTextGeometry( const Ogre::UTFString& text, TextBlockData& data, const TextStyle& style );
  45. private:
  46. UiTextArea();
  47. void CreateVertexBuffer();
  48. void DestroyVertexBuffer();
  49. private:
  50. Ogre::MaterialPtr m_Material;
  51. Ogre::SceneManager* m_SceneManager;
  52. Ogre::RenderSystem* m_RenderSystem;
  53. unsigned int m_MaxLetters;
  54. Ogre::RenderOperation m_RenderOp;
  55. Ogre::HardwareVertexBufferSharedPtr m_VertexBuffer;
  56. UiFont* m_Font;
  57. TextAlign m_TextAlign;
  58. Ogre::UTFString m_Text;
  59. TiXmlNode* m_TextNode;
  60. };
  61. #endif // UI_TEXT_AREA_H