Elaztek Developer Hub
Blamite Game Engine - blam!  00388.06.24.23.2301.blamite
The core library for the Blamite Game Engine.
ui.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Strings/components/resources/color/BlamColor.h>
6 #include <OGRE/Overlay/OgreTextAreaOverlayElement.h>
7 #include <OGRE/Overlay/OgreOverlayContainer.h>
8 #include <OGRE/Overlay/OgrePanelOverlayElement.h>
9 #include <OGRE/Overlay/OgreOverlay.h>
10 #include <vector>
11 #include <string>
12 
13 #ifndef BLAM
14 #define BLAM
15 #endif
16 
17 class BlamUIWidget_Group;
18 
20 {
21  class BlamUIEditor;
22 }
23 
29 enum class BlamWidgetAnchor
30 {
31  TopCenter,
32  Center,
33  BottomCenter,
34 
35  TopLeft,
36  CenterLeft,
37  BottomLeft,
38 
39  TopRight,
40  CenterRight,
41  BottomRight,
42 
43  TopFill,
44  LeftFill,
45  RightFill,
46  BottomFill,
47  Fill
48 };
49 
53 enum class BlamWidgetType
54 {
57  //Basic_Line,
58  Text,
59  Group,
60 
61  Console,
62  UIDCypher,
65 
67 };
68 
70 {
71 private:
74 
75  void ShowAnchorChangeButton(BlamWidgetAnchor new_anchor, int height_mul, int width_mul, bool text_multiline);
76 
77 protected:
78  BlamVector2 position_absolute = { 0, 0 };
79  BlamVector2 size_absolute = { 100, 100 };
80 
81 public:
82  std::string display_name = "unnamed";
83  std::string description = "";
84 
85  BlamVector2 position = { 0, 0 };
86  BlamVector2 size = { 100, 100 };
87  float rotation = 0.0f;
88  bool hidden = false;
89 
91 
94  virtual ~BlamUIWidget() {};
95 
96  virtual void Draw() {};
97  virtual void ShowImGuiPropertyEditor();
98  virtual void UpdateMetrics() {};
99 
101 
102  virtual void RefreshRelativePosition();
103  void RefreshRelativePosition(int viewport_width, int viewport_height, BlamVector2 initial_position);
104 
105  void SetSize(BlamVector2 new_size);
106  void SetPosition(BlamVector2 new_position);
107  void SetRotation(float new_rotation);
108  void SetAnchorPosition(BlamWidgetAnchor new_anchor_position);
109 
110  BlamVector2 GetAbsolutePosition();
111 };
112 
114 {
115 private:
116  Blam::DebugUI::Windows::BlamUIEditor* editor_window = nullptr;
117 
118 public:
119  std::vector<BlamUIWidget*> children = std::vector<BlamUIWidget*>();
120 
123 
124  void Draw();
127 
128  void ShowImGuiEditorWindow();
129 };
130 
132 {
133 private:
134  Ogre::v1::Overlay* container = nullptr;
135  Ogre::v1::PanelOverlayElement* panel = nullptr;
136  bool last_hide_state = false;
137 
138 public:
139  bool auto_update = false;
140  BlamColor color = BlamColor(255, 255, 255);
141 
144 
145  void Draw();
147  void UpdateMetrics() override;
148 };
149 
151 {
152 private:
153  Ogre::v1::TextAreaOverlayElement* text_element = nullptr;
154  Ogre::v1::TextAreaOverlayElement* text_element_shadow = nullptr;
155  Ogre::v1::Overlay* container = nullptr;
156  Ogre::v1::PanelOverlayElement* panel = nullptr;
157 
158  std::string previous_text = "";
159  bool last_hide_state = false;
160 
161 public:
162  bool auto_update = false;
163  bool auto_scale_shadow = true;
165  BlamVector2 shadow_offset = { 1, 1 };
166  BlamColor color = BlamColor(255, 255, 255);
167  BlamColor shadow_color = BlamColor(0, 0, 0);
168  std::string font_name = "fixedsys";
169 
170  std::string text = "blam!";
171 
174 
175  void Draw();
177  void UpdateMetrics() override;
178 };
179 
183 namespace Blam::UI
184 {
185  BLAM bool Initialize();
186  BLAM void Render();
187  BLAM void Shutdown();
188 
190 
191  BLAM std::string GetWidgetAnchorLabel(BlamWidgetAnchor anchor_position);
192 }
BlamUIWidget::hidden
bool hidden
Definition: ui.h:88
ui.h
BlamWidgetAnchor::LeftFill
@ LeftFill
The widget will fill the left of the screen, while width is left unchanged.
BlamUIWidget_BasicRectangle::UpdateMetrics
void UpdateMetrics() override
Definition: BlamUIWidget_BasicRectangle.cpp:82
BlamUIWidget::BlamUIWidget
BlamUIWidget(BlamWidgetType type)
Definition: BlamUIWidget.cpp:35
BlamWidgetAnchor::BottomRight
@ BottomRight
The widget will be placed at the bottom-right of the screen.
BlamWidgetAnchor::CenterLeft
@ CenterLeft
The widget will be placed at the center-left of the screen.
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:142
uid_cypher.h
BlamUIWidget_Text::font_name
std::string font_name
Definition: ui.h:168
BlamUIWidget_Group
Definition: ui.h:113
BlamWidgetAnchor::CenterRight
@ CenterRight
The widget will be placed at the center-right of the screen.
BlamUIWidget::position
BlamVector2 position
Definition: ui.h:85
Blam::UI::GetWidgetAnchorLabel
BLAM std::string GetWidgetAnchorLabel(BlamWidgetAnchor anchor_position)
Definition: ui.cpp:75
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
BlamUIWidget_BasicRectangle::Draw
void Draw()
Definition: BlamUIWidget_BasicRectangle.cpp:38
logger.h
Blam::UI::GetUIRoot
BLAM BlamUIWidget_Group * GetUIRoot()
Definition: ui.cpp:70
BlamRendering::GetCurrentRenderingEngine
BLAM BlamRenderingEngine GetCurrentRenderingEngine()
Retrieves the current rendering engine being used.
Definition: rendering_abstraction.cpp:104
BlamWidgetAnchor::BottomFill
@ BottomFill
The widget will fill the bottom of the screen, while height is left unchanged.
BlamUIWidget_Text::ShowImGuiPropertyEditor
void ShowImGuiPropertyEditor()
Definition: BlamUIWidget_Text.cpp:91
BlamUIWidget::parent
BlamUIWidget_Group * parent
Definition: ui.h:90
BlamUIWidget::rotation
float rotation
Definition: ui.h:87
BlamUIWidget_Group::RefreshRelativePosition
void RefreshRelativePosition()
Definition: BlamUIWidget_Group.cpp:75
BlamUIWidget_Text::character_height
int character_height
Definition: ui.h:164
BlamUIWidget_Text::shadow_offset
BlamVector2 shadow_offset
Definition: ui.h:165
imgui.h
BlamWidgetType::Text
@ Text
A text object, used to show text on-screen.
console.h
BlamWidgetType::Basic_Rectangle
@ Basic_Rectangle
A basic filled rectangle.
OGRE
@ OGRE
Definition: rendering.h:35
BlamWidgetType::Basic_Ellipse
@ Basic_Ellipse
A basic filled ellipse.
ImGui::InputText
IMGUI_API bool InputText(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3068
world.h
BlamVersionStringDisplayMode::Console
@ Console
Indicates the build string should be formatted for the in-game console.
BlamUIWidget_Group::ShowImGuiEditorWindow
void ShowImGuiEditorWindow()
Definition: BlamUIWidget_Group.cpp:90
BlamWidgetAnchor::Center
@ Center
The widget will be placed at the center of the screen.
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:407
BlamUIWidget::GetType
BlamWidgetType GetType()
Definition: BlamUIWidget.cpp:147
imgui_stdlib.h
BlamUIWidget::size
BlamVector2 size
Definition: ui.h:86
BlamWidgetAnchor::TopCenter
@ TopCenter
The widget will be placed at the top-center of the screen.
rendering.h
BlamUIWidget::Draw
virtual void Draw()
Definition: ui.h:96
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:7147
BlamRendering::BGFX::GetRenderHeight
BLAM int GetRenderHeight()
Definition: bgfx.cpp:190
BlamUIWidget::~BlamUIWidget
virtual ~BlamUIWidget()
Definition: ui.h:94
BlamWidgetType::UIDCypher
@ UIDCypher
Special widget. Used for the user ID cypher.
BlamUIWidget_Text::Draw
void Draw()
Definition: BlamUIWidget_Text.cpp:59
ImVec2
Definition: imgui.h:179
Blam::UI
Namespace containing functions relating to the Blamite UI system.
Definition: ui.h:183
BlamWidgetAnchor::Fill
@ Fill
The widget will fill the entire screen.
BlamUIWidget_Group::~BlamUIWidget_Group
~BlamUIWidget_Group()
Definition: BlamUIWidget_Group.cpp:13
BlamUIWidget_Text::~BlamUIWidget_Text
~BlamUIWidget_Text()
Definition: BlamUIWidget_Text.cpp:44
ImGui::DragFloat
IMGUI_API bool DragFloat(const char *label, float *v, float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2164
BlamUIWidget::SetPosition
void SetPosition(BlamVector2 new_position)
Definition: BlamUIWidget.cpp:297
BlamUIWidget::ShowImGuiPropertyEditor
virtual void ShowImGuiPropertyEditor()
Definition: BlamUIWidget.cpp:57
BlamUIWidget_Text::UpdateMetrics
void UpdateMetrics() override
Definition: BlamUIWidget_Text.cpp:117
ImGui::DragFloat2
IMGUI_API bool DragFloat2(const char *label, float v[2], float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2169
BlamUIWidget_Group::children
std::vector< BlamUIWidget * > children
Definition: ui.h:119
BlamUIWidget_FramerateDisplay
Definition: BlamUIWidget_FramerateDisplay.h:9
BlamUIWidget::display_name
std::string display_name
Definition: ui.h:82
globals.h
BlamUIWidget_Text::color
BlamColor color
Definition: ui.h:166
Blam::UI::Render
BLAM void Render()
Definition: ui.cpp:47
BlamUIWidget::SetSize
void SetSize(BlamVector2 new_size)
Definition: BlamUIWidget.cpp:290
BlamUIWidget_BasicRectangle::ShowImGuiPropertyEditor
void ShowImGuiPropertyEditor()
Definition: BlamUIWidget_BasicRectangle.cpp:66
BlamWidgetAnchor::TopLeft
@ TopLeft
The widget will be placed at the top-left of the screen.
Blam::UI::Shutdown
BLAM void Shutdown()
Definition: ui.cpp:61
BlamUIWidget_BasicRectangle::auto_update
bool auto_update
Definition: ui.h:139
ImGui::BeginCombo
IMGUI_API bool BeginCombo(const char *label, const char *preview_value, ImGuiComboFlags flags=0)
Definition: imgui_widgets.cpp:1416
BlamUIWidget::UpdateMetrics
virtual void UpdateMetrics()
Definition: ui.h:98
BlamPluginFieldType::Unspecified
@ Unspecified
BlamUIWidget_Text::auto_update
bool auto_update
Definition: ui.h:162
BlamUIWidget_FramerateDisplay.h
BlamWidgetAnchor
BlamWidgetAnchor
Enumerator listing possible widget anchor positions.
Definition: ui.h:29
BlamRendering::OGRE::GetRenderHeight
BLAM int GetRenderHeight()
Definition: ogre.cpp:312
BlamWidgetAnchor::BottomLeft
@ BottomLeft
The widget will be placed at the bottom-left of the screen.
BlamUIWidget_BasicRectangle
Definition: ui.h:131
BlamUIWidget_Group::Draw
void Draw()
Definition: BlamUIWidget_Group.cpp:28
Blam::DebugUI::Windows::BlamUIEditor
Class for the Blam UI Editor debug utility.
Definition: blam_ui_editor.hpp:13
BlamUIWidget_Text::BlamUIWidget_Text
BlamUIWidget_Text(BlamUIWidget_Group *_parent)
Definition: BlamUIWidget_Text.cpp:15
BlamUIWidget
Definition: ui.h:69
BlamUIWidget_UserIDCypher
UI widget for the user ID cypher display.
Definition: uid_cypher.h:21
BLAM
#define BLAM
Definition: ui.h:14
ImGui::InputTextMultiline
IMGUI_API bool InputTextMultiline(const char *label, char *buf, size_t buf_size, const ImVec2 &size=ImVec2(0, 0), ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3074
ImGui::EndCombo
IMGUI_API void EndCombo()
Definition: imgui_widgets.cpp:1522
ui_root
BlamUIWidget_Group * ui_root
The UI root widget.
Definition: ui.cpp:10
BlamWidgetType::CoordinatesDisplay
@ CoordinatesDisplay
Special widget. Used for the coordinates display.
BlamUIWidget_Text::text
std::string text
Definition: ui.h:170
BlamRendering::BGFX::GetRenderWidth
BLAM int GetRenderWidth()
Definition: bgfx.cpp:185
BlamUIWidget::RefreshRelativePosition
virtual void RefreshRelativePosition()
Definition: BlamUIWidget.cpp:152
BlamWidgetType::Group
@ Group
A group widget, which can be used to contain any number of other widgets.
BlamUIWidget::description
std::string description
Definition: ui.h:83
BlamWidgetAnchor::TopFill
@ TopFill
The widget will fill the top of the screen, while height is left unchanged.
draw_fail_message_shown
bool draw_fail_message_shown
Whether or not the "draw failure" message has been displayed. Used to prevent spamming the log if the...
Definition: ui.cpp:11
BlamUIWidget_Text::shadow_color
BlamColor shadow_color
Definition: ui.h:167
BlamRendering::OGRE::GetRenderWidth
BLAM int GetRenderWidth()
Definition: ogre.cpp:307
BlamWidgetType::FramerateDisplay
@ FramerateDisplay
Special widget. Used for the framerate display.
BlamUIWidget_Console
Class for the console UI widget.
Definition: console.h:48
BlamUIWidget_Group::ShowImGuiPropertyEditor
void ShowImGuiPropertyEditor()
Definition: BlamUIWidget_Group.cpp:42
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
BlamUIWidget_CoordinatesDisplay
Definition: BlamUIWidget_CoordinatesDisplay.h:9
BlamWidgetType
BlamWidgetType
Enumerator listing possible UI widget types.
Definition: ui.h:53
BlamUIWidget_CoordinatesDisplay.h
Blam::UI::Initialize
BLAM bool Initialize()
Definition: ui.cpp:13
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: ui.h:19
BlamUIWidget_BasicRectangle::color
BlamColor color
Definition: ui.h:140
BlamUIWidget_Group::BlamUIWidget_Group
BlamUIWidget_Group(BlamUIWidget_Group *_parent)
Definition: BlamUIWidget_Group.cpp:8
BlamUIWidget::position_absolute
BlamVector2 position_absolute
Definition: ui.h:78
BlamWidgetAnchor::RightFill
@ RightFill
The widget will fill the right of the screen, while width is left unchanged.
BlamUIWidget::size_absolute
BlamVector2 size_absolute
Definition: ui.h:79
BlamUIWidget_Text::auto_scale_shadow
bool auto_scale_shadow
Definition: ui.h:163
BGFX
@ BGFX
Definition: rendering.h:34
BlamUIWidget_BasicRectangle::BlamUIWidget_BasicRectangle
BlamUIWidget_BasicRectangle(BlamUIWidget_Group *_parent)
Definition: BlamUIWidget_BasicRectangle.cpp:12
BlamWidgetAnchor::BottomCenter
@ BottomCenter
The widget will be placed at the bottom-center of the screen.
BlamWidgetAnchor::TopRight
@ TopRight
The widget will be placed at the top-right of the screen.
BlamUIWidget_BasicRectangle::~BlamUIWidget_BasicRectangle
~BlamUIWidget_BasicRectangle()
Definition: BlamUIWidget_BasicRectangle.cpp:27
BlamWidgetType::Unspecified
@ Unspecified
Indicates the widget is of an unspecified type. Will only appear when a widget is improperly construc...
ImGui::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:644
BlamUIWidget::GetAbsolutePosition
BlamVector2 GetAbsolutePosition()
Definition: BlamUIWidget.cpp:316
BlamUIWidget_Text
Definition: ui.h:150
BlamUIWidget::SetAnchorPosition
void SetAnchorPosition(BlamWidgetAnchor new_anchor_position)
Definition: BlamUIWidget.cpp:310
BlamUIWidget::SetRotation
void SetRotation(float new_rotation)
Definition: BlamUIWidget.cpp:304