UiTextArea.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. class UiSprite;
  11. enum TextState
  12. {
  13. TS_SHOW_TEXT,
  14. TS_SCROLL_TEXT,
  15. TS_PAUSE_OK,
  16. TS_PAUSE_TIME,
  17. TS_DONE,
  18. TS_OVERFLOW,
  19. TS_NEXT_PAGE,
  20. };
  21. struct TextChar
  22. {
  23. TextChar():
  24. char_code( 0 ),
  25. colour( Ogre::ColourValue::White ),
  26. skip( false ),
  27. variable( "" ),
  28. variable_len( 0 ),
  29. pause_ok( false ),
  30. pause_time( 0.0f ),
  31. next_page( false ),
  32. sprite( NULL ),
  33. sprite_y( 0 )
  34. {
  35. }
  36. int char_code;
  37. Ogre::ColourValue colour;
  38. bool skip;
  39. Ogre::String variable;
  40. unsigned int variable_len;
  41. bool pause_ok;
  42. float pause_time;
  43. bool next_page;
  44. UiSprite* sprite;
  45. float sprite_y;
  46. };
  47. struct TextVariable
  48. {
  49. Ogre::String name;
  50. Ogre::UTFString value;
  51. };
  52. class UiTextArea : public UiWidget
  53. {
  54. public:
  55. UiTextArea( const Ogre::String& name );
  56. UiTextArea( const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent );
  57. virtual ~UiTextArea();
  58. void Initialise();
  59. virtual void Update();
  60. virtual void Render();
  61. virtual void UpdateTransformation();
  62. void UpdateGeometry();
  63. void InputPressed();
  64. void InputRepeated();
  65. enum TextAlign
  66. {
  67. LEFT,
  68. RIGHT,
  69. CENTER
  70. };
  71. void SetTextAlign( const TextAlign align );
  72. void SetPadding( const float top, const float right, const float bottom, const float left );
  73. void SetText( const Ogre::UTFString& text );
  74. void SetText( TiXmlNode* text );
  75. void TextClear();
  76. void RemoveSpritesFromText( const unsigned int end );
  77. void SetFont( const Ogre::String& font );
  78. const UiFont* GetFont() const;
  79. void SetTextPrintSpeed( const float speed );
  80. void SetTextScrollTime( const float time );
  81. void SetVariable( const Ogre::String& name, const Ogre::UTFString& value );
  82. Ogre::UTFString GetVariable( const Ogre::String& name ) const;
  83. TextState GetTextState() const;
  84. float GetTextLimit() const;
  85. unsigned int GetTextSize() const;
  86. float GetPauseTime() const;
  87. private:
  88. float GetTextWidth() const;
  89. void PrepareTextFromNode( TiXmlNode* node, const Ogre::ColourValue& colour );
  90. void PrepareTextFromText( const Ogre::UTFString& text, const Ogre::ColourValue& colour );
  91. UiTextArea();
  92. void CreateVertexBuffer();
  93. void DestroyVertexBuffer();
  94. private:
  95. Ogre::MaterialPtr m_Material;
  96. Ogre::SceneManager* m_SceneManager;
  97. Ogre::RenderSystem* m_RenderSystem;
  98. unsigned int m_MaxLetters;
  99. Ogre::RenderOperation m_RenderOp;
  100. Ogre::HardwareVertexBufferSharedPtr m_VertexBuffer;
  101. UiFont* m_Font;
  102. TextAlign m_TextAlign;
  103. std::vector< TextChar > m_Text;
  104. float m_TextLimit;
  105. float m_TextPrintSpeed;
  106. float m_TextPrintSpeedMod;
  107. TextState m_TextState;
  108. std::vector< TextVariable > m_TextVariable;
  109. float m_TextScrollTime;
  110. float m_TextYOffset;
  111. float m_TextYOffsetTarget;
  112. float m_PauseTime;
  113. unsigned int m_NextPageStart;
  114. bool m_NextPressed;
  115. bool m_NextRepeated;
  116. float m_PaddingTop;
  117. float m_PaddingRight;
  118. float m_PaddingBottom;
  119. float m_PaddingLeft;
  120. bool m_Timer;
  121. int m_TimerTime;
  122. };
  123. #endif // UI_TEXT_AREA_H