FuncDoodle
Loading...
Searching...
No Matches
Tool.h
Go to the documentation of this file.
1
17
18#pragma once
19
20#include "Project/Frame.h"
21
22#include "Asset/LoadedAssets.h"
23#include "Keybinds/Keybinds.h"
24#include "UI/Gui.h"
25
26#include "Conf/FuncPCH.h"
27
28namespace FuncDoodle {
40
41 // i really don't like that i have to do this, but i do, because as it is
42 // right now, there is no consistent way to iterate over an enum class,
43 // without adding Start and End members which aren't that clean imo.
45 constexpr std::array<ToolType, 5> ToolTypes{
51 };
52
53 // don't like this either, but i have to do it..
54 // actually i COULD use a constexpr std::unordered_map here but idk
56 constexpr const char* ToolTypeName(ToolType t) {
57 switch (t) {
59 return "Pencil";
61 return "Eraser";
63 return "Bucket";
65 return "Picker";
67 return "Select";
68 }
69 return "Unknown";
70 }
71
72 // also could use a constexpr std::unordered_map here but idk
73 // rather than having 2 unordered_maps it would be better to have one with a
74 // struct that holds both the name and the texid for each tool.
76 constexpr uint32_t ToolTexID(ToolType tool) {
77 switch (tool) {
79 return s_PencilTexId;
81 return s_EraserTexId;
83 return s_BucketTexId;
85 return s_PickerTexId;
87 return s_SelectTexId;
88 }
89 // case ToolType::Text:
90 // btnTexId = s_TextTexId;
91 // break;
92 }
93
94 // hehe get it - tool, tips
95 // lol
96 // (could ALSO use an unordered_map)
97 // (this is old code, ok?)
98 static void Tooltips(ToolType tool, KeybindsRegistry& keys) {
99 switch (tool) {
100 case ToolType::Pencil:
101 if (ImGui::IsItemHovered()) {
102 ImGui::BeginTooltip();
103 ImGui::Text("Pencil (%s)",
104 static_cast<const char*>(keys.Get("pencil")));
105 ImGui::EndTooltip();
106 }
107 break;
108 case ToolType::Eraser:
109 if (ImGui::IsItemHovered()) {
110 ImGui::BeginTooltip();
111 ImGui::Text("Eraser (%s)",
112 static_cast<const char*>(keys.Get("eraser")));
113 ImGui::EndTooltip();
114 }
115 break;
116 case ToolType::Bucket:
117 if (ImGui::IsItemHovered()) {
118 ImGui::BeginTooltip();
119 ImGui::Text("Bucket (%s)",
120 static_cast<const char*>(keys.Get("bucket")));
121 ImGui::EndTooltip();
122 }
123 break;
124 case ToolType::Picker:
125 if (ImGui::IsItemHovered()) {
126 ImGui::BeginTooltip();
127 ImGui::Text("Picker (%s)",
128 static_cast<const char*>(keys.Get("picker")));
129 ImGui::EndTooltip();
130 }
131 break;
132 case ToolType::Select:
133 if (ImGui::IsItemHovered()) {
134 ImGui::BeginTooltip();
135 ImGui::Text("Select (%s)",
136 static_cast<const char*>(keys.Get("select")));
137 ImGui::EndTooltip();
138 }
139 break;
140 }
141 }
142
143 // yea i really have nothing to say about this method idk why i put a
144 // comment here
145 static void ToolKeybindsRegister(KeybindsRegistry& keybinds) {
146 keybinds.Register("pencil", "Pencil tool", "Switches to pencil tool",
147 {false, false, false, ImGuiKey_1});
148 keybinds.Register("eraser", "Eraser tool", "Switches to eraser tool",
149 {false, false, false, ImGuiKey_2});
150 keybinds.Register("bucket", "Bucket tool", "Switches to bucket tool",
151 {false, false, false, ImGuiKey_3});
152 keybinds.Register("picker", "Picker tool", "Switches to picker tool",
153 {false, false, false, ImGuiKey_4});
154 keybinds.Register("select", "Select tool", "Switches to select tool",
155 {false, false, false, ImGuiKey_5});
156 }
157
158 // perhaps use some sorta unordered_map too..?
159 static void ToolKeybinds(ToolType* tool, KeybindsRegistry& keybinds) {
160 if (keybinds.Get("pencil").IsPressed()) {
161 *tool = ToolType::Pencil;
162 }
163 if (keybinds.Get("eraser").IsPressed()) {
164 *tool = ToolType::Eraser;
165 }
166 if (keybinds.Get("bucket").IsPressed()) {
167 *tool = ToolType::Bucket;
168 }
169 if (keybinds.Get("picker").IsPressed()) {
170 *tool = ToolType::Picker;
171 }
172 if (keybinds.Get("select").IsPressed()) {
173 *tool = ToolType::Select;
174 }
175 }
176} // namespace FuncDoodle
Logging system, assertion macros, platform utilities, and build/config macros.
ImGui/OpenGL/GLFW integration utilities and file dialog wrapper.
Keyboard input system including key masks, shortcuts, and keybind registry.
Global handles for textures and audio used across FuncDoodle.
Defines pixel color structures and frame/image data containers.
Stores and persists all keybinds used in FuncDoodle (default + user-defined).
Definition Keybinds.h:262
Shortcut Get(const char *id)
Returns the effective shortcut registered for an identifier.
Definition Keybinds.cc:191
void Register(const char *id, const char *friendlyName, const char *desc, Shortcut shortcut)
Registers a default shortcut for an identifier.
Definition Keybinds.cc:200
The FuncDoodle C++ namespace.
Definition Common.h:12
uint32_t s_BucketTexId
Bucket tool icon texture.
Definition LoadedAssets.cc:13
uint32_t s_PencilTexId
Pencil tool icon texture.
Definition LoadedAssets.cc:10
constexpr const char * ToolTypeName(ToolType t)
Returns the user-facing name of a tool type.
Definition Tool.h:56
static void ToolKeybindsRegister(KeybindsRegistry &keybinds)
Definition Tool.h:145
static void Tooltips(ToolType tool, KeybindsRegistry &keys)
Definition Tool.h:98
static void ToolKeybinds(ToolType *tool, KeybindsRegistry &keybinds)
Definition Tool.h:159
uint32_t s_PickerTexId
Color picker tool icon texture.
Definition LoadedAssets.cc:11
uint32_t s_SelectTexId
Selection tool icon texture.
Definition LoadedAssets.cc:14
ToolType
All available tools in the editor.
Definition Tool.h:33
@ Eraser
Definition Tool.h:35
@ Bucket
Definition Tool.h:36
@ Pencil
Definition Tool.h:34
@ Select
Definition Tool.h:38
@ Picker
Definition Tool.h:37
uint32_t s_EraserTexId
Eraser tool icon texture.
Definition LoadedAssets.cc:12
constexpr uint32_t ToolTexID(ToolType tool)
Returns the toolbar texture ID associated with a tool.
Definition Tool.h:76
constexpr std::array< ToolType, 5 > ToolTypes
Ordered list of tools used for iteration and UI rendering.
Definition Tool.h:45
bool IsPressed() const
Returns whether the full shortcut is active.
Definition Keybinds.cc:178