UiTextArea.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <Overlay/OgreUTFString.h>
  7. #include <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. /**
  53. * An ingame textarea.
  54. *
  55. * It may be any window used to represent text: a diaog window, a menu panel,
  56. * a choice selection...
  57. */
  58. class UiTextArea : public UiWidget
  59. {
  60. public:
  61. /**
  62. * Creates a UiTextArea.
  63. *
  64. * @param name[name] Name for the textarea.
  65. */
  66. UiTextArea( const Ogre::String& name );
  67. /**
  68. * Creates a UiTextArea.
  69. *
  70. * @param name[in] Name for the textarea.
  71. * @param path_name[in] Path for the widget.
  72. * @param parent[in] Poinbter to the widget that will parent the UiTextArea.
  73. */
  74. UiTextArea( const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent );
  75. /**
  76. * Destroys the UiTextArea.
  77. */
  78. virtual ~UiTextArea();
  79. /**
  80. * Sets default values for the UiTextArea.
  81. *
  82. * It's automatically called when the UiTextArea is created.
  83. */
  84. void Initialise();
  85. /**
  86. * Updates the UiTextArea.
  87. */
  88. virtual void Update();
  89. /**
  90. * Renders the UiTextArea on the screen.
  91. */
  92. virtual void Render();
  93. /**
  94. *
  95. */
  96. virtual void UpdateTransformation();
  97. void UpdateGeometry();
  98. void InputPressed();
  99. void InputRepeated();
  100. enum TextAlign
  101. {
  102. LEFT,
  103. RIGHT,
  104. CENTER
  105. };
  106. void SetTextAlign( const TextAlign align );
  107. void SetPadding( const float top, const float right, const float bottom, const float left );
  108. void SetText( const Ogre::UTFString& text );
  109. void SetText( TiXmlNode* text );
  110. void TextClear();
  111. void RemoveSpritesFromText( const unsigned int end );
  112. void SetFont( const Ogre::String& font );
  113. const UiFont* GetFont() const;
  114. void SetTextPrintSpeed( const float speed );
  115. void SetTextScrollTime( const float time );
  116. void SetVariable( const Ogre::String& name, const Ogre::UTFString& value );
  117. Ogre::UTFString GetVariable( const Ogre::String& name ) const;
  118. TextState GetTextState() const;
  119. float GetTextLimit() const;
  120. unsigned int GetTextSize() const;
  121. float GetPauseTime() const;
  122. private:
  123. float GetTextWidth() const;
  124. void PrepareTextFromNode( TiXmlNode* node, const Ogre::ColourValue& colour );
  125. void PrepareTextFromText( const Ogre::UTFString& text, const Ogre::ColourValue& colour );
  126. UiTextArea();
  127. void CreateVertexBuffer();
  128. void DestroyVertexBuffer();
  129. private:
  130. Ogre::MaterialPtr m_Material;
  131. Ogre::SceneManager* m_SceneManager;
  132. Ogre::RenderSystem* m_RenderSystem;
  133. unsigned int m_MaxLetters;
  134. Ogre::RenderOperation m_RenderOp;
  135. Ogre::HardwareVertexBufferSharedPtr m_VertexBuffer;
  136. UiFont* m_Font;
  137. TextAlign m_TextAlign;
  138. std::vector< TextChar > m_Text;
  139. float m_TextLimit;
  140. float m_TextPrintSpeed;
  141. float m_TextPrintSpeedMod;
  142. TextState m_TextState;
  143. std::vector< TextVariable > m_TextVariable;
  144. float m_TextScrollTime;
  145. float m_TextYOffset;
  146. float m_TextYOffsetTarget;
  147. float m_PauseTime;
  148. unsigned int m_NextPageStart;
  149. bool m_NextPressed;
  150. bool m_NextRepeated;
  151. float m_PaddingTop;
  152. float m_PaddingRight;
  153. float m_PaddingBottom;
  154. float m_PaddingLeft;
  155. bool m_Timer;
  156. int m_TimerTime;
  157. };
  158. #endif // UI_TEXT_AREA_H