V-Gears 0
Free Final Fantasy VII engine.
UiWidget.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 <OgreColourValue.h>
19#include <OgreString.h>
20#include <Ogre.h>
21#include <vector>
22#include "ScriptManager.h"
23#include "UiAnimation.h"
24
29
30 public:
31
37 UiWidget(const Ogre::String& name);
38
46 UiWidget(const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent);
47
51 virtual ~UiWidget();
52
58 void Initialise();
59
63 virtual void Update();
64
70 void OnResize();
71
75 virtual void Render();
76
82 void SetVisible(const bool visible);
83
89 bool IsVisible() const;
90
96 const Ogre::String& GetName() const;
97
103 void AddChild(UiWidget* widget);
104
112 UiWidget* GetChild(const Ogre::String& name);
113
121 UiWidget* GetChild(const unsigned int id);
122
128 unsigned int GetNumberOfChildren();
129
133 void RemoveAllChildren();
134
140 void AddAnimation(UiAnimation* animation);
141
148
155
164 void PlayAnimation(
165 const Ogre::String& animation, UiAnimation::State state,
166 const float start, const float end
167 );
168
178 void ScriptPlayAnimation(const char* name);
179
187 void ScriptPlayAnimationStop(const char* name);
188
196 void ScriptPlayAnimation(const char* name, const float start, const float end);
197
208 void ScriptPlayAnimationStop(const char* name, const float start, const float end);
209
215 void ScriptSetDefaultAnimation(const char* animation);
216
224
232
236 virtual void UpdateTransformation();
237
241 enum Align{
242
247
252
256 CENTER
257 };
258
263
268
273
277 MIDDLE
278 };
279
285 void SetAlign(const UiWidget::Align align);
286
292 void SetVerticalAlign(const UiWidget::VerticalAlign valign);
293
299 float GetFinalZ() const;
300
306 Ogre::Vector2 GetFinalOrigin() const;
307
315 Ogre::Vector2 GetFinalTranslate() const;
316
322 Ogre::Vector2 GetFinalSize() const;
323
329 Ogre::Vector2 GetFinalScale() const;
330
337 Ogre::Vector4 GetFinalScissor(bool& scissor) const;
338
344 float GetFinalRotation() const;
345
352 void SetOriginX(const float percent, const float x);
353
360 void SetOriginY(const float percent, const float y);
361
368 void SetX(const float percent, const float x);
369
376 void GetX(float& percent, float& x);
377
384 void SetY(const float percent, const float y);
385
392 void GetY(float& percent, float& y);
393
399 void SetZ(const float z);
400
407 void SetWidth(const float percent, const float width);
408
415 void GetWidth(float& percent, float& width);
416
423 void SetHeight(const float percent, const float height);
424
431 void GetHeight(float& percent, float& height);
432
438 void SetScale(const Ogre::Vector2& scale);
439
445 void SetRotation(const float degree);
446
459 void SetScissorArea(
460 const float percent_x1, const float x1, const float percent_y1, const float y1,
461 const float percent_x2, const float x2, const float percent_y2, const float y2
462 );
463
469 void SetGlobalScissor(const bool global);
470
478 void SetColour(const float r, const float g, const float b);
479
498 void SetColours(
499 const float r1, const float g1, const float b1,
500 const float r2, const float g2, const float b2,
501 const float r3, const float g3, const float b3,
502 const float r4, const float g4, const float b4
503 );
504
510 void SetAlpha(const float a);
511
519 virtual void SetText(const char* text);
520
528 virtual void SetImage(const char* image);
529
537 float ScriptGetWidth();
538
546 void ScriptSetWidth(float width);
547
555 float ScriptGetHeight();
556
564 void ScriptSetHeight(float height);
565
566 protected:
567
572
577
582
586 std::vector<UiWidget*> children_;
587
594
601
606
610 Ogre::ColourValue colour_1_;
611
615 Ogre::ColourValue colour_2_;
616
620 Ogre::ColourValue colour_3_;
621
625 Ogre::ColourValue colour_4_;
626
631
636
641
645 Ogre::Vector2 final_origin_;
646
652 Ogre::Vector2 final_translate_;
653
657 float final_z_;
658
662 Ogre::Vector2 final_size_;
663
667 Ogre::Vector2 final_scale_;
668
673
678
683
688
693
698
702 float x_;
703
708
712 float y_;
713
717 float z_;
718
723
727 float width_;
728
733
737 float height_;
738
742 Ogre::Vector2 scale_;
743
748
753
758
763
768
773
778
783
788
793
798
803
808
813
818
823
828
834 std::vector<ScriptId> animation_sync_;
835
840
845
850
854 std::vector<UiAnimation*> animations_;
855
856 private:
857
862};
863
uint16 a
Alpha component.
Definition: TxzFileSerializer.h:19
uint16 b
Blue component.
Definition: TxzFileSerializer.h:14
uint16 g
Green component.
Definition: TxzFileSerializer.h:9
uint16 r
Red component.
Definition: TxzFileSerializer.h:4
An UI element animation.
Definition: UiAnimation.h:59
State
Animation state.
Definition: UiAnimation.h:79
An UI widget.
Definition: UiWidget.h:28
void SetHeight(const float percent, const float height)
Sets the height the widget.
Definition: UiWidget.cpp:509
void AddChild(UiWidget *widget)
Add other widget as the widget's child.
Definition: UiWidget.cpp:228
void ScriptSetHeight(float height)
Sets the absolute height of the widget.
Definition: UiWidget.cpp:591
float final_rotation_
Final rotation after a transformation.
Definition: UiWidget.h:672
float x_
The widget X coordinate.
Definition: UiWidget.h:702
void OnResize()
Handles resizing events.
Definition: UiWidget.cpp:210
UiWidget * GetChild(const Ogre::String &name)
Retrieves a children by name.
Definition: UiWidget.cpp:230
float scissor_x_bottom_
Definition: UiWidget.h:792
float scissor_y_percent_right_
Definition: UiWidget.h:817
void SetRotation(const float degree)
Sets the widget rotation.
Definition: UiWidget.cpp:525
virtual void SetImage(const char *image)
Sets the text of the widget.
Definition: UiWidget.cpp:580
Ogre::Vector2 GetFinalSize() const
Retrieves the final size of the widget after a transformation.
Definition: UiWidget.cpp:444
void SetVisible(const bool visible)
Toggles the widget visibility.
Definition: UiWidget.cpp:222
void SetVerticalAlign(const UiWidget::VerticalAlign valign)
Sets the widget vertical alignment.
Definition: UiWidget.cpp:436
virtual void Update()
Updates the widget status.
Definition: UiWidget.cpp:102
virtual void UpdateTransformation()
Recalculates the widget geometry.
Definition: UiWidget.cpp:306
void RemoveAllChildren()
Removes all children widgets.
Definition: UiWidget.cpp:243
float origin_y_percent_
Definition: UiWidget.h:687
void SetGlobalScissor(const bool global)
Definition: UiWidget.cpp:546
int scissor_bottom_
Definition: UiWidget.h:782
void GetX(float &percent, float &x)
Retrieves the X coordinate for the widget.
Definition: UiWidget.cpp:477
Ogre::ColourValue colour_2_
Top-right corner colour.
Definition: UiWidget.h:615
void SetZ(const float z)
Sets the widget Z-index.
Definition: UiWidget.cpp:493
std::vector< UiAnimation * > animations_
The list of animations.
Definition: UiWidget.h:854
VerticalAlign
Vertical alignment of the widget.
Definition: UiWidget.h:262
@ BOTTOM
Bottom alignment.
Definition: UiWidget.h:272
@ TOP
Top alignment.
Definition: UiWidget.h:267
@ MIDDLE
Centered vertically.
Definition: UiWidget.h:277
Align align_
The vertical alignment.
Definition: UiWidget.h:630
bool local_scissor_
Definition: UiWidget.h:757
Ogre::Vector2 final_scale_
Final scale after a transformation.
Definition: UiWidget.h:667
Ogre::String animation_default_
The name of the default animation.
Definition: UiWidget.h:844
Ogre::ColourValue colour_3_
Bottom-right corner colour.
Definition: UiWidget.h:620
VerticalAlign vertical_align_
The evrtical alignment.
Definition: UiWidget.h:635
void ScriptSetDefaultAnimation(const char *animation)
Sets the default animation for the widget.
Definition: UiWidget.cpp:290
float ScriptGetWidth()
Retrieves the absolute width of the widget.
Definition: UiWidget.cpp:582
float scissor_y_right_
Definition: UiWidget.h:822
float scissor_x_percent_top_
Definition: UiWidget.h:772
void SetWidth(const float percent, const float width)
Sets the width the widget.
Definition: UiWidget.cpp:498
float origin_x_
The origin X coordinate.
Definition: UiWidget.h:682
bool IsVisible() const
Checks the widget visibility.
Definition: UiWidget.cpp:224
float y_
The widget Y coordinate.
Definition: UiWidget.h:712
float height_
The widget height.
Definition: UiWidget.h:737
Ogre::Vector2 final_size_
Final size after a transformation.
Definition: UiWidget.h:662
float GetFinalZ() const
Retrieves the final Z-index of the widget after a transformation.
Definition: UiWidget.cpp:438
void GetWidth(float &percent, float &width)
Retrieves the width of the widget.
Definition: UiWidget.cpp:504
float scissor_x_percent_bottom_
Definition: UiWidget.h:787
bool update_transformation_
Indicates if the widget is marked as transformed.
Definition: UiWidget.h:640
UiAnimation::State GetAnimationState() const
Retrieves the current animation state.
Ogre::Vector2 GetFinalOrigin() const
Retrieves the coordinates of the widget after a transformation.
Definition: UiWidget.cpp:440
void SetScissorArea(const float percent_x1, const float x1, const float percent_y1, const float y1, const float percent_x2, const float x2, const float percent_y2, const float y2)
Sets the widget scissor area.
Definition: UiWidget.cpp:530
UiWidget * parent_
The parent widget.
Definition: UiWidget.h:581
Ogre::ColourValue colour_4_
Bottom-left corner colour.
Definition: UiWidget.h:625
float screen_height_
Height, in game screen units.
Definition: UiWidget.h:600
int scissor_top_
Definition: UiWidget.h:767
float width_
The widget width.
Definition: UiWidget.h:727
virtual void SetText(const char *text)
Sets the text of the widget.
Definition: UiWidget.cpp:578
const Ogre::String & GetName() const
Retrieves the widget name.
Definition: UiWidget.cpp:226
Ogre::Vector2 final_translate_
Final translation after a transformation.
Definition: UiWidget.h:652
Ogre::Vector2 scale_
The widget scale.
Definition: UiWidget.h:742
Ogre::Vector4 GetFinalScissor(bool &scissor) const
Retrieves the final scissor of the widget after a transformation.
Definition: UiWidget.cpp:448
float final_z_
Final Z-index after a transformation.
Definition: UiWidget.h:657
bool scissor_
Definition: UiWidget.h:752
Ogre::ColourValue colour_1_
Top-left corner colour.
Definition: UiWidget.h:610
Ogre::String path_name_
Definition: UiWidget.h:576
void ScriptPlayAnimationStop(const char *name)
Plays an animation.
Definition: UiWidget.cpp:278
UiAnimation::State animation_state_
The current animation state.
Definition: UiWidget.h:839
bool global_scissor_
Definition: UiWidget.h:762
float rotation_
The widget rotation.
Definition: UiWidget.h:747
void ScriptPlayAnimation(const char *name)
Plays an animation.
Definition: UiWidget.cpp:274
void AddAnimation(UiAnimation *animation)
Adds an animation to the widget.
Definition: UiWidget.cpp:248
float width_percent_
Definition: UiWidget.h:722
unsigned int GetNumberOfChildren()
Counts the widget's children.
Definition: UiWidget.cpp:241
int ScriptAnimationSync()
Synchronizes an animation.
Definition: UiWidget.cpp:295
void SetAlign(const UiWidget::Align align)
Sets the widget horizontal alignment.
Definition: UiWidget.cpp:434
Ogre::Vector2 GetFinalScale() const
Retrieves the final scale of the widget after a transformation.
Definition: UiWidget.cpp:446
Ogre::Vector2 GetFinalTranslate() const
Retrieves the final translation of the widget after a transformation.
Definition: UiWidget.cpp:442
int scissor_left_
Definition: UiWidget.h:797
void ScriptSetWidth(float width)
Sets the absolute width of the widget.
Definition: UiWidget.cpp:584
std::vector< UiWidget * > children_
The list of children widgets.
Definition: UiWidget.h:586
float z_
The widget Z coordinate.
Definition: UiWidget.h:717
float animation_end_time_
Time for the current animation to end.
Definition: UiWidget.h:849
float height_percent_
Definition: UiWidget.h:732
Align
Horizontal alignment of the widget.
Definition: UiWidget.h:241
@ LEFT
Left alignment.
Definition: UiWidget.h:246
@ RIGHT
Right alignment.
Definition: UiWidget.h:251
@ CENTER
Centered horizontally.
Definition: UiWidget.h:256
void SetOriginY(const float percent, const float y)
Sets the Y coordinate origin for the widget.
Definition: UiWidget.cpp:465
void SetColours(const float r1, const float g1, const float b1, const float r2, const float g2, const float b2, const float r3, const float g3, const float b3, const float r4, const float g4, const float b4)
Sets the widget colour.
Definition: UiWidget.cpp:559
void SetAlpha(const float a)
Sets the widget transparency.
Definition: UiWidget.cpp:570
void GetHeight(float &percent, float &height)
Retrieves the height of the widget.
Definition: UiWidget.cpp:515
void Initialise()
Initializes the widget.
Definition: UiWidget.cpp:48
float x_percent_
Definition: UiWidget.h:697
UiAnimation * animation_current_
The current animation.
Definition: UiWidget.h:827
void SetOriginX(const float percent, const float x)
Sets the X coordinate origin for the widget.
Definition: UiWidget.cpp:459
float origin_x_percent_
Definition: UiWidget.h:677
virtual void Render()
Renders the widget and it's children.
Definition: UiWidget.cpp:218
float origin_y_
The origin Y coordinate.
Definition: UiWidget.h:692
float scissor_y_percent_left_
Definition: UiWidget.h:802
float scissor_x_top_
Definition: UiWidget.h:777
void SetUpdateTransformation()
Marks the widget as transformed.
Definition: UiWidget.cpp:301
float ScriptGetHeight()
Retrieves the absolute height of the widget.
Definition: UiWidget.cpp:589
void SetScale(const Ogre::Vector2 &scale)
Sets the widget scale.
Definition: UiWidget.cpp:520
std::vector< ScriptId > animation_sync_
The animation stack.
Definition: UiWidget.h:834
int scissor_right_
Definition: UiWidget.h:812
void SetY(const float percent, const float y)
Sets the Y coordinate for the widget.
Definition: UiWidget.cpp:482
void PlayAnimation(const Ogre::String &animation, UiAnimation::State state, const float start, const float end)
Plays an animation.
Definition: UiWidget.cpp:255
const Ogre::String & GetCurrentAnimationName() const
Retrieves the current animation name.
Definition: UiWidget.cpp:250
void GetY(float &percent, float &y)
Retrieves the Y coordinate for the widget.
Definition: UiWidget.cpp:488
void SetColour(const float r, const float g, const float b)
Sets the widget colour.
Definition: UiWidget.cpp:551
float y_percent_
Definition: UiWidget.h:707
float scissor_y_left_
Definition: UiWidget.h:807
void SetX(const float percent, const float x)
Sets the X coordinate for the widget.
Definition: UiWidget.cpp:471
UiWidget()
Constructor.
bool visible_
Indicates if the widget is visible.
Definition: UiWidget.h:605
Ogre::String name_
The widget name.
Definition: UiWidget.h:571
float screen_width_
Width, in game screen units.
Definition: UiWidget.h:593
float GetFinalRotation() const
Retrieves the final rotation of the widget.
Definition: UiWidget.cpp:457
Ogre::Vector2 final_origin_
Final origin point after a transformation.
Definition: UiWidget.h:645
virtual ~UiWidget()
Destructor.
Definition: UiWidget.cpp:42
Ogre::String String
Definition: TypeDefine.h:37