V-Gears 0
Free Final Fantasy VII engine.
UiTextArea.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#pragma once
17
18#include <OgreHardwareVertexBuffer.h>
19#include <OgreRenderQueueListener.h>
20#include <OgreRoot.h>
21#include <Overlay/OgreUTFString.h>
22#include <tinyxml.h>
23
24#include "UiFont.h"
25#include "UiWidget.h"
26
27class UiSprite;
28
33
38
43
48
53
58
63
68};
69
73struct TextChar{
75 char_code(0),
76 colour(Ogre::ColourValue::White),
77 skip(false),
78 variable(""),
79 variable_len(0),
80 pause_ok(false),
81 pause_time(0.0f),
82 next_page(false),
83 sprite(NULL),
84 sprite_y(0)
85 {}
86
93
97 Ogre::ColourValue colour;
98
102 bool skip;
103
108
112 unsigned int variable_len;
113
118
123
128
133
137 float sprite_y;
138};
139
144
149
153 Ogre::UTFString value;
154};
155
156
163class UiTextArea : public UiWidget{
164
165 public:
166
172 UiTextArea(const Ogre::String& name);
173
181 UiTextArea(const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent);
182
186 virtual ~UiTextArea();
187
193 void Initialise();
194
198 virtual void Update();
199
203 virtual void Render();
204
208 virtual void UpdateTransformation();
209
213 void UpdateGeometry();
214
218 void InputPressed();
219
223 void InputRepeated();
224
229
234
239
243 CENTER
244 };
245
251 void SetTextAlign(const TextAlign align);
252
261 void SetPadding(const float top, const float right, const float bottom, const float left);
262
268 void SetText(const Ogre::UTFString& text);
269
275 void SetText(const char* text) override;
276
282 void SetText(TiXmlNode* text);
283
287 void TextClear();
288
294 void RemoveSpritesFromText(const unsigned int end);
295
301 void SetFont(const Ogre::String& font);
302
308 const UiFont* GetFont() const;
309
316 void SetTextPrintSpeed(const float speed);
317
324 void SetTextScrollTime(const float time);
325
332 void SetVariable(const Ogre::String& name, const Ogre::UTFString& value);
333
341 Ogre::UTFString GetVariable(const Ogre::String& name) const;
342
348 TextState GetTextState() const;
349
357 float GetTextLimit() const;
358
364 unsigned int GetTextSize() const;
365
371 float GetPauseTime() const;
372
373 private:
374
380 float GetTextWidth() const;
381
391 void PrepareTextFromNode(TiXmlNode* node, const Ogre::ColourValue& colour);
392
402 void SetTextFromNode(TiXmlNode* node, const Ogre::ColourValue& colour);
403
410 void PrepareTextFromText(const Ogre::UTFString& text, const Ogre::ColourValue& colour);
411
416
420 void CreateVertexBuffer();
421
425 void DestroyVertexBuffer();
426
430 Ogre::MaterialPtr material_;
431
435 Ogre::SceneManager* scene_manager_;
436
440 Ogre::RenderSystem* render_system_;
441
445 unsigned int max_letters_;
446
450 Ogre::RenderOperation render_operation_;
451
455 Ogre::HardwareVertexBufferSharedPtr vertex_buffer_;
456
461
466
470 std::vector<TextChar> text_;
471
476
481
486
491
495 std::vector<TextVariable> text_variable_;
496
501
506
511
516
520 unsigned int next_page_start_;
521
526
531
536
541
546
551
555 bool timer_;
556
561};
562
TextState
The textarea state.
Definition: UiTextArea.h:32
@ TS_SCROLL_TEXT
The text is scrolling.
Definition: UiTextArea.h:42
@ TS_OVERFLOW
The text is overflowing.
Definition: UiTextArea.h:62
@ TS_NEXT_PAGE
The text is changing pages.
Definition: UiTextArea.h:67
@ TS_PAUSE_OK
The text is paused waiting for input.
Definition: UiTextArea.h:47
@ TS_PAUSE_TIME
The text is paused waiting for time to pass.
Definition: UiTextArea.h:52
@ TS_SHOW_TEXT
The text is displayed.
Definition: UiTextArea.h:37
@ TS_DONE
The textarea is done with.
Definition: UiTextArea.h:57
The UI widgets font.
Definition: UiFont.h:64
A sprite.
Definition: UiSprite.h:26
An ingame textarea.
Definition: UiTextArea.h:163
void InputRepeated()
Handles a key being hold.
Definition: UiTextArea.cpp:195
unsigned int max_letters_
Max letter per textarea.
Definition: UiTextArea.h:445
TextAlign
Text alignment in the text area.
Definition: UiTextArea.h:228
@ CENTER
Horizontally centered text.
Definition: UiTextArea.h:243
@ RIGHT
Right aligned text.
Definition: UiTextArea.h:238
@ LEFT
Left aligned text.
Definition: UiTextArea.h:233
float text_print_speed_mod_
Definition: UiTextArea.h:485
float text_y_offset_target_
Definition: UiTextArea.h:510
TextState text_state_
The state of the text.
Definition: UiTextArea.h:490
std::vector< TextChar > text_
The text.
Definition: UiTextArea.h:470
float padding_right_
The right padding.
Definition: UiTextArea.h:540
void Initialise()
Sets default values for the UiTextArea.
Definition: UiTextArea.cpp:44
virtual void UpdateTransformation()
Updates the UiTextArea.
Definition: UiTextArea.cpp:187
void RemoveSpritesFromText(const unsigned int end)
Removes the prites from the text.
Definition: UiTextArea.cpp:278
float pause_time_
The time to pause the text.
Definition: UiTextArea.h:515
float padding_bottom_
The bottom padding.
Definition: UiTextArea.h:545
void InputPressed()
Handles a keypress.
Definition: UiTextArea.cpp:193
UiFont * font_
The font for the text.
Definition: UiTextArea.h:460
void SetTextAlign(const TextAlign align)
Sets the text alignment in the text area.
Definition: UiTextArea.cpp:197
virtual ~UiTextArea()
Destroys the UiTextArea.
Definition: UiTextArea.cpp:42
const UiFont * GetFont() const
Retrieves the font.
Definition: UiTextArea.cpp:325
float GetTextLimit() const
Gets the text limit.
Definition: UiTextArea.cpp:378
bool next_pressed_
Indicates if the 'next' button has been pressed.
Definition: UiTextArea.h:525
void CreateVertexBuffer()
Creates a vertex buffer for the textarea.
Definition: UiTextArea.cpp:931
void DestroyVertexBuffer()
Destroys a vertex buffer for the textarea.
Definition: UiTextArea.cpp:951
void SetPadding(const float top, const float right, const float bottom, const float left)
Sets the paddings in the text area.
Definition: UiTextArea.cpp:202
unsigned int GetTextSize() const
Gets the text size.
Definition: UiTextArea.cpp:380
int timer_time_
Definition: UiTextArea.h:560
void SetVariable(const Ogre::String &name, const Ogre::UTFString &value)
Sets a variable in the text.
Definition: UiTextArea.cpp:331
void SetText(const Ogre::UTFString &text)
Sets the text from a string.
Definition: UiTextArea.cpp:233
bool next_repeated_
Indicates if the 'next' button is being held down.
Definition: UiTextArea.h:530
Ogre::SceneManager * scene_manager_
The scene manager.
Definition: UiTextArea.h:435
float GetPauseTime() const
Retrieves the pause time of the text.
Definition: UiTextArea.cpp:382
std::vector< TextVariable > text_variable_
Variables in the text.
Definition: UiTextArea.h:495
float text_scroll_time_
Time to scroll the text.
Definition: UiTextArea.h:500
void SetTextFromNode(TiXmlNode *node, const Ogre::ColourValue &colour)
Prepares text from a XML node.
Definition: UiTextArea.cpp:756
Ogre::MaterialPtr material_
Material for the text area.
Definition: UiTextArea.h:430
Ogre::UTFString GetVariable(const Ogre::String &name) const
Gets the value of a variable in the text.
Definition: UiTextArea.cpp:370
void PrepareTextFromText(const Ogre::UTFString &text, const Ogre::ColourValue &colour)
Prepares text from a string.
Definition: UiTextArea.cpp:920
void UpdateGeometry()
Updates the UiTextArea geometry.
Definition: UiTextArea.cpp:384
virtual void Render()
Renders the UiTextArea on the screen.
Definition: UiTextArea.cpp:160
UiTextArea()
Constructor.
float padding_top_
The top padding.
Definition: UiTextArea.h:535
TextState GetTextState() const
Checks the text state.
Definition: UiTextArea.cpp:376
float text_limit_
The text limit.
Definition: UiTextArea.h:475
void TextClear()
Removes the text from the text area.
Definition: UiTextArea.cpp:269
float text_y_offset_
Definition: UiTextArea.h:505
virtual void Update()
Updates the UiTextArea.
Definition: UiTextArea.cpp:73
void SetFont(const Ogre::String &font)
Set the font for the text.
Definition: UiTextArea.cpp:292
void SetTextPrintSpeed(const float speed)
Sets the printing speed.
Definition: UiTextArea.cpp:327
float text_print_speed_
The text printing speed.
Definition: UiTextArea.h:480
Ogre::RenderSystem * render_system_
The render system.
Definition: UiTextArea.h:440
bool timer_
Definition: UiTextArea.h:555
Ogre::HardwareVertexBufferSharedPtr vertex_buffer_
The text area vertext buffer.
Definition: UiTextArea.h:455
void PrepareTextFromNode(TiXmlNode *node, const Ogre::ColourValue &colour)
Prepares text from a XML node.
Definition: UiTextArea.cpp:588
unsigned int next_page_start_
Definition: UiTextArea.h:520
TextAlign text_align_
The text alignment.
Definition: UiTextArea.h:465
float padding_left_
The left padding.
Definition: UiTextArea.h:550
Ogre::RenderOperation render_operation_
The render operation.
Definition: UiTextArea.h:450
float GetTextWidth() const
Retrieves the text width.
Definition: UiTextArea.cpp:573
void SetTextScrollTime(const float time)
Sets the scroll duration.
Definition: UiTextArea.cpp:329
An UI widget.
Definition: UiWidget.h:28
Ogre::String String
Definition: TypeDefine.h:37
A character in a text.
Definition: UiTextArea.h:73
UiSprite * sprite
If the character is a symbol or an image, this is the sprite.
Definition: UiTextArea.h:132
bool skip
Indicates if the character is to be actually printed.
Definition: UiTextArea.h:102
float sprite_y
If the character is a symbol or an image, this is the Y position.
Definition: UiTextArea.h:137
float pause_time
For pause characters, the time.
Definition: UiTextArea.h:122
Ogre::String variable
If the character is a variable, the variable name.
Definition: UiTextArea.h:107
bool pause_ok
Indicates if the OK button has been pressed during a text pause.
Definition: UiTextArea.h:117
bool next_page
Indicates if the character is a new page character.
Definition: UiTextArea.h:127
int char_code
The character code.
Definition: UiTextArea.h:92
unsigned int variable_len
If the character is a variable, the variable length.
Definition: UiTextArea.h:112
Ogre::ColourValue colour
Color for the character.
Definition: UiTextArea.h:97
TextChar()
Definition: UiTextArea.h:74
A variable displayed in a text.
Definition: UiTextArea.h:143
Ogre::String name
The variable name.
Definition: UiTextArea.h:148
Ogre::UTFString value
The variable value, resolved as a string.
Definition: UiTextArea.h:153