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 "Util/MacroUtils.h"
27
28#include <functional>
29
30namespace FuncDoodle {
42
43 // i really don't like that i have to do this, but i do, because as it is
44 // right now, there is no consistent way to iterate over an enum class,
45 // without adding Start and End members which aren't that clean imo.
47 constexpr std::array<ToolType, 5> ToolTypes{
53 };
54
55 // don't like this either, but i have to do it..
56 // actually i COULD use a constexpr std::unordered_map here but idk
58 constexpr const char* ToolTypeName(ToolType t) {
59 switch (t) {
61 return "Pencil";
63 return "Eraser";
65 return "Bucket";
67 return "Picker";
69 return "Select";
70 }
71 return "Unknown";
72 }
73
74 // also could use a constexpr std::unordered_map here but idk
75 // rather than having 2 unordered_maps it would be better to have one with a
76 // struct that holds both the name and the texid for each tool.
78 constexpr uint32_t ToolTexID(ToolType tool) {
79 switch (tool) {
81 return s_PencilTexId;
83 return s_EraserTexId;
85 return s_BucketTexId;
87 return s_PickerTexId;
89 return s_SelectTexId;
90 }
91 // case ToolType::Text:
92 // btnTexId = s_TextTexId;
93 // break;
94 }
95
96 // hehe get it - tool, tips
97 // lol
98 // (could ALSO use an unordered_map)
99 // (this is old code, ok?)
100 static void Tooltips(ToolType tool) {
101 switch (tool) {
102 case ToolType::Pencil:
103 if (ImGui::IsItemHovered()) {
104 ImGui::BeginTooltip();
105 ImGui::Text("Pencil (1)");
106 ImGui::EndTooltip();
107 }
108 break;
109 case ToolType::Eraser:
110 if (ImGui::IsItemHovered()) {
111 ImGui::BeginTooltip();
112 ImGui::Text("Eraser (2)");
113 ImGui::EndTooltip();
114 }
115 break;
116 case ToolType::Bucket:
117 if (ImGui::IsItemHovered()) {
118 ImGui::BeginTooltip();
119 ImGui::Text("Bucket (3)");
120 ImGui::EndTooltip();
121 }
122 break;
123 case ToolType::Picker:
124 if (ImGui::IsItemHovered()) {
125 ImGui::BeginTooltip();
126 ImGui::Text("Picker (4)");
127 ImGui::EndTooltip();
128 }
129 break;
130 case ToolType::Select:
131 if (ImGui::IsItemHovered()) {
132 ImGui::BeginTooltip();
133 ImGui::Text("Select (5)");
134 ImGui::EndTooltip();
135 }
136 break;
137 }
138 }
139
140 // yea i really have nothing to say about this method idk why i put a
141 // comment here
142 static void ToolKeybindsRegister(KeybindsRegistry& keybinds) {
143 keybinds.Register("pencil", {false, false, false, ImGuiKey_1});
144 keybinds.Register("eraser", {false, false, false, ImGuiKey_2});
145 keybinds.Register("bucket", {false, false, false, ImGuiKey_3});
146 keybinds.Register("picker", {false, false, false, ImGuiKey_4});
147 keybinds.Register("select", {false, false, false, ImGuiKey_5});
148 }
149
150 // perhaps use some sorta unordered_map too..?
151 static void ToolKeybinds(ToolType* tool, KeybindsRegistry& keybinds) {
152 if (keybinds.Get("pencil").IsPressed()) {
153 *tool = ToolType::Pencil;
154 }
155 if (keybinds.Get("eraser").IsPressed()) {
156 *tool = ToolType::Eraser;
157 }
158 if (keybinds.Get("bucket").IsPressed()) {
159 *tool = ToolType::Bucket;
160 }
161 if (keybinds.Get("picker").IsPressed()) {
162 *tool = ToolType::Picker;
163 }
164 if (keybinds.Get("select").IsPressed()) {
165 *tool = ToolType::Select;
166 }
167 }
168} // namespace FuncDoodle
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.
Logging system, assertion macros, platform utilities, and build/config macros.
Defines pixel color structures and frame/image data containers.
Stores and persists all keybinds used in FuncDoodle (default + user-defined).
Definition Keybinds.h:250
Shortcut Get(const char *id)
Returns the effective shortcut registered for an identifier.
Definition Keybinds.cc:191
void Register(const char *id, 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
static void Tooltips(ToolType tool)
Definition Tool.h:100
constexpr const char * ToolTypeName(ToolType t)
Returns the user-facing name of a tool type.
Definition Tool.h:58
static void ToolKeybindsRegister(KeybindsRegistry &keybinds)
Definition Tool.h:142
static void ToolKeybinds(ToolType *tool, KeybindsRegistry &keybinds)
Definition Tool.h:151
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:35
@ Eraser
Definition Tool.h:37
@ Bucket
Definition Tool.h:38
@ Pencil
Definition Tool.h:36
@ Select
Definition Tool.h:40
@ Picker
Definition Tool.h:39
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:78
constexpr std::array< ToolType, 5 > ToolTypes
Ordered list of tools used for iteration and UI rendering.
Definition Tool.h:47
bool IsPressed() const
Returns whether the full shortcut is active.
Definition Keybinds.cc:178