Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.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 
12 #include "version_data.h"
13 
14 namespace Blam::DebugUI::Widgets
15 {
22  {
23  private:
24  int commit_hash_label = 0;
25 
31  void create_menu_item(BlamMenubarItem item)
32  {
33  if (item.type == BlamMenubarItemType::Menu)
34  {
35  if (ImGui::BeginMenu(item.name.c_str()))
36  {
37  for (int i = 0; i < item.items.size(); i++)
38  {
39  create_menu_item(item.items.at(i));
40  }
41 
43  }
44  }
45  else if (item.type == BlamMenubarItemType::MenuItem)
46  {
47  if (ImGui::MenuItem(item.name.c_str(), item.shortcut.c_str(), false, item.enabled))
48  {
50  {
52  }
54  {
56 
57  if (global)
58  {
59  switch (global->type)
60  {
61  case Blam::Globals::GvarType::Boolean:
62  {
64  break;
65  }
66  default:
67  {
68  Blam::Logger::LogEvent("only boolean globals can be modified using the menu bar at this time");
69  break;
70  }
71  }
72  }
73  }
74  }
75 
77  {
79  }
80  }
81  else if (item.type == BlamMenubarItemType::Label)
82  {
83  if (item.override_color)
84  {
85  ImVec4 im_color = ImVec4(item.color.GetRedAsFloat(), item.color.GetGreenAsFloat(), item.color.GetBlueAsFloat(), item.color.GetAlphaAsFloat());
86  ImGui::TextColored(im_color, item.variable.c_str());
87  }
88  else
89  {
90  ImGui::Text(item.variable.c_str());
91  }
92  }
93  else if (item.type == BlamMenubarItemType::Separator)
94  {
96  }
97  }
98 
99  public:
104  {
105  show = true;
106  }
107 
112  {
113 
114  }
115 
119  void Draw()
120  {
121  if (show)
122  {
124  {
126 
127  for (int i = 0; i < menu->items.size(); i++)
128  {
129  create_menu_item(menu->items.at(i));
130  }
131 
132  int label_spacing = 15 * *Blam::Globals::GetGlobalAsFloat("ui_scale_factor");
133 
134  ImGui::SameLine(ImGui::GetWindowWidth() - (commit_hash_label + label_spacing));
136  if (ImGui::IsItemHovered())
137  {
139  ImGui::PushTextWrapPos(450.0f);
140  //ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_title").c_str());
142 
144 
145 #ifdef NON_JENKINS_BUILD
146  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_text_untracked").c_str());
147 #else
148  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_text").c_str());
149 #endif
150 
153  }
154 
155  ImVec2 commit_label_size = ImGui::GetItemRectSize();
156 
157  commit_hash_label = commit_label_size.x;
158 
160  }
161  }
162  }
163  };
164 }
BlamMenubarItem
Structure representing a menu bar item.
Definition: menubar.h:44
BlamVersionStringDisplayMode::Default
@ Default
Indicates the build string should use the default format.
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:142
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.
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:407
BlamMenubarItemType::Menu
@ Menu
A submenu within the menu.
engine_text.h
ImGui::BeginMainMenuBar
IMGUI_API bool BeginMainMenuBar()
Definition: imgui_widgets.cpp:5975
console.h
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:21
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:103
ImVec2
Definition: imgui.h:179
ImGui::IsItemHovered
IMGUI_API bool IsItemHovered(ImGuiHoveredFlags flags=0)
Definition: imgui.cpp:3061
Blam::EngineDefs::GetVersionBuildString
BLAM std::string GetVersionBuildString(BlamVersionStringDisplayMode display_mode)
Retrieves the build string of the engine.
Definition: engine_definitions.cpp:53
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:64
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:271
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
globals.h
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
engine_definitions.h
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:111
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:119
Blam::Globals::UpdateGlobal
BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:578