Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.blamite
The core library for the Blamite Game Engine.
dynamic_menubar.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
12 #include "version_data.h"
13 
20 {
21 private:
22  int commit_hash_label = 0;
23 
29  void create_menu_item(BlamMenubarItem item)
30  {
31  if (item.type == BlamMenubarItemType::Menu)
32  {
33  if (ImGui::BeginMenu(item.name.c_str()))
34  {
35  for (int i = 0; i < item.items.size(); i++)
36  {
37  create_menu_item(item.items.at(i));
38  }
39 
41  }
42  }
43  else if (item.type == BlamMenubarItemType::MenuItem)
44  {
45  if (ImGui::MenuItem(item.name.c_str(), item.shortcut.c_str(), false, item.enabled))
46  {
48  {
50  }
52  {
54 
55  if (global)
56  {
57  switch (global->type)
58  {
60  {
62  break;
63  }
64  default:
65  {
66  Blam::Logger::LogEvent("only boolean globals can be modified using the menu bar at this time");
67  break;
68  }
69  }
70  }
71  }
72  }
73 
75  {
77  }
78  }
79  else if (item.type == BlamMenubarItemType::Label)
80  {
81  if (item.override_color)
82  {
83  ImVec4 im_color = ImVec4(item.color.GetRedAsFloat(), item.color.GetGreenAsFloat(), item.color.GetBlueAsFloat(), item.color.GetAlphaAsFloat());
84  ImGui::TextColored(im_color, item.variable.c_str());
85  }
86  else
87  {
88  ImGui::Text(item.variable.c_str());
89  }
90  }
91  else if (item.type == BlamMenubarItemType::Separator)
92  {
94  }
95  }
96 
97 public:
102  {
103  show = true;
104  }
105 
109  void Draw()
110  {
111  if (show)
112  {
114  {
116 
117  for (int i = 0; i < menu->items.size(); i++)
118  {
119  create_menu_item(menu->items.at(i));
120  }
121 
122  int label_spacing = 15 * *Blam::Globals::GetGlobalAsFloat("ui_scale_factor");
123 
124  ImGui::SameLine(ImGui::GetWindowWidth() - (commit_hash_label + label_spacing));
126  if (ImGui::IsItemHovered())
127  {
129  ImGui::PushTextWrapPos(450.0f);
130  //ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_title").c_str());
132 
134 
135 #ifdef NON_JENKINS_BUILD
136  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_text_untracked").c_str());
137 #else
138  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_text").c_str());
139 #endif
140 
143  }
144 
145  ImVec2 commit_label_size = ImGui::GetItemRectSize();
146 
147  commit_hash_label = commit_label_size.x;
148 
150  }
151  }
152  }
153 };
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::UI::ImGUI::Widgets::ShowNYITooltip
BLAM void ShowNYITooltip()
Shows a tooltip with the text Not yet implemented upon hovered.
Definition: widgets.cpp:20
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:130
ImGui::EndMenu
IMGUI_API void EndMenu()
Definition: imgui_widgets.cpp:6224
BlamImGuiWindow_DynamicMenuBar::BlamImGuiWindow_DynamicMenuBar
BlamImGuiWindow_DynamicMenuBar()
Initializes data for the legacy menu bar and instructs it to draw as a standard menu rather than the ...
Definition: dynamic_menubar.hpp:101
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:82
logger.h
menubar.h
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
Blam::Globals::UpdateGlobal
BLAM BlamGlobalUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:574
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:403
BlamMenubarItemType::Menu
@ Menu
A submenu within the menu.
engine_text.h
BlamEngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:66
ImGui::BeginMainMenuBar
IMGUI_API bool BeginMainMenuBar()
Definition: imgui_widgets.cpp:5975
console.h
BlamImGuiWindow_DynamicMenuBar
Class for the main ImGUI menu bar.
Definition: dynamic_menubar.hpp:19
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
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
ImGui::MenuItem
IMGUI_API bool MenuItem(const char *label, const char *shortcut=NULL, bool selected=false, bool enabled=true)
Definition: imgui_widgets.cpp:6240
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
BlamImGuiWindow_DynamicMenuBar::Draw
void Draw()
Draws the menu bar contents and current git commit hash.
Definition: dynamic_menubar.hpp:109
BlamEngineGlobal::type
BlamGlobalType type
The type of the global.
Definition: globals.h:56
ImGui::GetItemRectSize
IMGUI_API ImVec2 GetItemRectSize()
Definition: imgui.cpp:4689
BlamMenubarItemType::Label
@ Label
A non-clickable text label.
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
BlamMenubarItemVariableType::Command
@ Command
Indicates the menu item will execute a command upon being clicked.
BlamEngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:54
ImGui::BeginMenu
IMGUI_API bool BeginMenu(const char *label, bool enabled=true)
Definition: imgui_widgets.cpp:6081
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
Blam::Globals::GetGlobal
BLAM BlamEngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:189
engine_definitions.h
Blam::Resources::Console::RunCommandLine
BLAM BlamResult RunCommandLine(std::string command_line)
Executed the provided string as a console command.
Definition: console.cpp:260
Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:34
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.
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
imgui.h
BlamMenubar::items
std::vector< BlamMenubarItem > items
List of all items in this menu.
Definition: menubar.h:84
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
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
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