Elaztek Developer Hub
Blamite Game Engine - blam!  00346.12.11.21.0529.blamite
The core library for the Blamite Game Engine.
dynamic_menubar.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../debug_ui.h"
4 
11 #include "version_data.h"
12 
13 namespace Blam::DebugUI::Widgets
14 {
21  {
22  private:
23  int commit_hash_label = 0;
24 
30  void create_menu_item(BlamMenubarItem item)
31  {
32  if (item.type == BlamMenubarItemType::Menu)
33  {
34  if (ImGui::BeginMenu(item.name.c_str()))
35  {
36  for (int i = 0; i < item.items.size(); i++)
37  {
38  create_menu_item(item.items.at(i));
39  }
40 
42  }
43  }
44  else if (item.type == BlamMenubarItemType::MenuItem)
45  {
46  if (ImGui::MenuItem(item.name.c_str(), item.shortcut.c_str(), false, item.enabled))
47  {
49  {
51  }
53  {
55 
56  if (global)
57  {
58  switch (global->type)
59  {
60  case Blam::Globals::GvarType::Boolean:
61  {
63  break;
64  }
65  default:
66  {
67  Blam::Logger::LogEvent("only boolean globals can be modified using the menu bar at this time");
68  break;
69  }
70  }
71  }
72  }
73  }
74 
76  {
78  }
79  }
80  else if (item.type == BlamMenubarItemType::Label)
81  {
82  if (item.override_color)
83  {
84  ImVec4 im_color = ImVec4(item.color.GetRedAsFloat(), item.color.GetGreenAsFloat(), item.color.GetBlueAsFloat(), item.color.GetAlphaAsFloat());
85  ImGui::TextColored(im_color, item.variable.c_str());
86  }
87  else
88  {
89  ImGui::Text(item.variable.c_str());
90  }
91  }
92  else if (item.type == BlamMenubarItemType::Separator)
93  {
95  }
96  }
97 
98  public:
103  {
104  show = true;
105  }
106 
111  {
112 
113  }
114 
118  void Draw()
119  {
120  if (show)
121  {
123  {
125 
126  for (int i = 0; i < menu->items.size(); i++)
127  {
128  create_menu_item(menu->items.at(i));
129  }
130 
131  ImGui::SameLine(ImGui::GetWindowWidth() - (commit_hash_label + 15));
133  if (ImGui::IsItemHovered())
134  {
136  ImGui::PushTextWrapPos(450.0f);
137  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_title").c_str());
138 
140 
141  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_text").c_str());
142 
143 
146  }
147 
148  ImVec2 commit_label_size = ImGui::GetItemRectSize();
149 
150  commit_hash_label = commit_label_size.x;
151 
153  }
154  }
155  }
156  };
157 }
BlamMenubarItem
Structure representing a menu bar item.
Definition: menubar.h:44
BlamMenubarItem::override_color
bool override_color
Whether or not the label has a custom color set.
Definition: menubar.h:56
BlamMenubarItem::variable
std::string variable
The item variable. Will either be the command to run upon clicking, or the label text.
Definition: menubar.h:50
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:141
Blam::Globals::GetGlobal
BLAM EngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:193
ImGui::EndMenu
IMGUI_API void EndMenu()
Definition: imgui_widgets.cpp:6224
BlamMenubarItem::color
BlamColor color
The color of the label.
Definition: menubar.h:55
ImGui::BeginTooltip
IMGUI_API void BeginTooltip()
Definition: imgui.cpp:7362
ImGui::EndMainMenuBar
IMGUI_API void EndMainMenuBar()
Definition: imgui_widgets.cpp:5995
BlamMenubar
Structure representing the menu bar.
Definition: menubar.h:79
logger.h
menubar.h
version_data.h
ImVec4
Definition: imgui.h:192
BlamMenubarItemType::Separator
@ Separator
A separator item.
console.h
BlamMenubarItemType::Menu
@ Menu
A submenu within the menu.
engine_text.h
ImGui::BeginMainMenuBar
IMGUI_API bool BeginMainMenuBar()
Definition: imgui_widgets.cpp:5975
ImVec2::x
float x
Definition: imgui.h:181
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:7147
BlamMenubarItem::enabled
bool enabled
Whether or not this menu item is enabled and can be clicked.
Definition: menubar.h:53
Blam::DebugUI::Widgets::DynamicMenuBar
Class for the main ImGUI menu bar.
Definition: dynamic_menubar.hpp:20
ImGui::MenuItem
IMGUI_API bool MenuItem(const char *label, const char *shortcut=NULL, bool selected=false, bool enabled=true)
Definition: imgui_widgets.cpp:6240
Blam::DebugUI::Widgets::DynamicMenuBar::DynamicMenuBar
DynamicMenuBar()
Initializes data for the legacy menu bar and instructs it to draw as a standard menu rather than the ...
Definition: dynamic_menubar.hpp:102
ImVec2
Definition: imgui.h:179
ImGui::IsItemHovered
IMGUI_API bool IsItemHovered(ImGuiHoveredFlags flags=0)
Definition: imgui.cpp:3061
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:64
globals.h
ImGui::GetItemRectSize
IMGUI_API ImVec2 GetItemRectSize()
Definition: imgui.cpp:4689
BlamMenubarItemType::Label
@ Label
A non-clickable text label.
Blam::Resources::Console::RunCommandLine
BLAM HRESULT RunCommandLine(std::string command_line)
Executed the provided string as a console command.
Definition: console.cpp:268
widgets.h
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
ImGui::PopTextWrapPos
IMGUI_API void PopTextWrapPos()
Definition: imgui.cpp:6313
ImGui::EndTooltip
IMGUI_API void EndTooltip()
Definition: imgui.cpp:7402
Blam::DebugUI::ImGUIDrawingGroup::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: debug_ui.h:362
BlamMenubarItemVariableType::Command
@ Command
Indicates the menu item will execute a command upon being clicked.
ImGui::BeginMenu
IMGUI_API bool BeginMenu(const char *label, bool enabled=true)
Definition: imgui_widgets.cpp:6081
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
BlamMenubarItem::type
BlamMenubarItemType type
The type of this menu item.
Definition: menubar.h:46
BlamMenubarItemVariableType::Unimplemented
@ Unimplemented
Indicates the menu item is a placeholder item intended for future use.
CURRENT_COMMIT
#define CURRENT_COMMIT
Definition: version_data.h:14
Blam::Settings::Menubar::GetMenuBar
BLAM BlamMenubar * GetMenuBar()
Retrieves the menu bar data.
Definition: menubar.cpp:370
BlamMenubarItem::shortcut
std::string shortcut
The menu item shortcut label. Cosmetic only.
Definition: menubar.h:51
BlamMenubarItem::items
std::vector< BlamMenubarItem > items
List of all child items in this submenu.
Definition: menubar.h:58
BlamMenubarItem::var_type
BlamMenubarItemVariableType var_type
The type of variable the menu item uses.
Definition: menubar.h:47
BlamMenubarItemType::MenuItem
@ MenuItem
A standard menu item.
Blam::DebugUI::Widgets::ShowNYITooltip
BLAM void ShowNYITooltip()
Shows a tooltip with the text Not yet implemented upon hovered.
Definition: widgets.cpp:20
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
BlamMenubar::items
std::vector< BlamMenubarItem > items
List of all items in this menu.
Definition: menubar.h:81
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
BlamMenubarItem::name
std::string name
The item name.
Definition: menubar.h:49
ImGui::TextUnformatted
IMGUI_API void TextUnformatted(const char *text, const char *text_end=NULL)
Definition: imgui_widgets.cpp:233
Blam::DebugUI::Widgets
Namespace containing general-purpose widgets used in multiple ImGUI drawing groups/windows.
Definition: devtools_bar.hpp:10
BlamMenubarItemVariableType::Global
@ Global
Indicates the menu item will modify an engine global.
ImGui::PushTextWrapPos
IMGUI_API void PushTextWrapPos(float wrap_local_pos_x=0.0f)
Definition: imgui.cpp:6306
ImGui::GetWindowWidth
IMGUI_API float GetWindowWidth()
Definition: imgui.cpp:6580
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:66
ImGui::TextColored
IMGUI_API void TextColored(const ImVec4 &col, const char *fmt,...) IM_FMTARGS(2)
Definition: imgui_widgets.cpp:257
ImGui::TextDisabled
IMGUI_API void TextDisabled(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:272
Blam::DebugUI::Widgets::DynamicMenuBar::~DynamicMenuBar
~DynamicMenuBar()
Cleans up the legacy menu bar data.
Definition: dynamic_menubar.hpp:110
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:76
Blam::DebugUI::Widgets::DynamicMenuBar::Draw
void Draw()
Draws the menu bar contents and current git commit hash.
Definition: dynamic_menubar.hpp:118
Blam::Globals::UpdateGlobal
BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:578