|
1 | 1 | #include "MeshCraft/Application/MeshCraftApplication.hpp" |
| 2 | +#include "MeshCraft/Application/UI/Toolbar.hpp" |
2 | 3 | #include "MeshCraft/MeshCraftPrivate.hpp" |
3 | 4 |
|
4 | 5 | #include <imgui.h> |
@@ -40,47 +41,12 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW) |
40 | 41 | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoScrollbar | |
41 | 42 | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings); |
42 | 43 |
|
43 | | - // Tool buttons |
44 | | - struct { ActiveTool tool; const char* label; ImVec4 col; } toolBtns[] = { |
45 | | - { ActiveTool::Select, "Select [Q]", ImVec4(0.31f,0.59f,0.82f,1.f) }, |
46 | | - { ActiveTool::Move, "Move [G]", ImVec4(0.22f,0.74f,0.39f,1.f) }, |
47 | | - { ActiveTool::Rotate, "Rotate [R]", ImVec4(0.80f,0.65f,0.22f,1.f) }, |
48 | | - { ActiveTool::Scale, "Scale [S]", ImVec4(0.82f,0.29f,0.29f,1.f) }, |
49 | | - { ActiveTool::Measure, "Ruler", ImVec4(0.60f,0.82f,0.82f,1.f) }, |
| 44 | + UI::ToolbarToolsContext toolsContext{ |
| 45 | + .activeTool = activeTool_, |
| 46 | + .selectTool = [this](ActiveTool tool) { activeTool_ = tool; updateWindowTitle(); }, |
| 47 | + .addPrimitive = [this](Mc3::ObjectType type) { addPrimitive(type); }, |
50 | 48 | }; |
51 | | - for (auto& tb : toolBtns) { |
52 | | - bool active = (activeTool_ == tb.tool); |
53 | | - if (active) ImGui::PushStyleColor(ImGuiCol_Button, tb.col); |
54 | | - if (ImGui::Button(tb.label, ImVec2(84, 30))) { activeTool_ = tb.tool; updateWindowTitle(); } |
55 | | - if (active) ImGui::PopStyleColor(); |
56 | | - ImGui::SameLine(); |
57 | | - } |
58 | | - |
59 | | - ImGui::TextDisabled("|"); |
60 | | - ImGui::SameLine(); |
61 | | - |
62 | | - // Add primitive buttons |
63 | | - struct { Mc3::ObjectType type; const char* label; ImVec4 col; } addBtns[] = { |
64 | | - { Mc3::ObjectType::Box, "+Box", ImVec4(0.82f,0.47f,0.22f,1.f) }, |
65 | | - { Mc3::ObjectType::Sphere, "+Sph", ImVec4(0.22f,0.47f,0.82f,1.f) }, |
66 | | - { Mc3::ObjectType::Cylinder, "+Cyl", ImVec4(0.22f,0.73f,0.39f,1.f) }, |
67 | | - { Mc3::ObjectType::Cone, "+Con", ImVec4(0.73f,0.22f,0.73f,1.f) }, |
68 | | - { Mc3::ObjectType::Plane, "+Pln", ImVec4(0.80f,0.80f,0.22f,1.f) }, |
69 | | - { Mc3::ObjectType::Torus, "+Tor", ImVec4(0.22f,0.70f,0.80f,1.f) }, |
70 | | - { Mc3::ObjectType::Capsule, "+Cap", ImVec4(0.70f,0.35f,0.70f,1.f) }, |
71 | | - { Mc3::ObjectType::Disk, "+Dsk", ImVec4(0.80f,0.65f,0.20f,1.f) }, |
72 | | - { Mc3::ObjectType::Grid, "+Grd", ImVec4(0.30f,0.65f,0.50f,1.f) }, |
73 | | - { Mc3::ObjectType::IcoSphere,"+Ico", ImVec4(0.25f,0.55f,0.80f,1.f) }, |
74 | | - }; |
75 | | - for (auto& ab : addBtns) { |
76 | | - ImGui::PushStyleColor(ImGuiCol_Button, ab.col); |
77 | | - if (ImGui::Button(ab.label, ImVec2(40, 30))) addPrimitive(ab.type); |
78 | | - ImGui::PopStyleColor(); |
79 | | - ImGui::SameLine(); |
80 | | - } |
81 | | - |
82 | | - ImGui::TextDisabled("|"); |
83 | | - ImGui::SameLine(); |
| 49 | + UI::Toolbar::drawTools(toolsContext); |
84 | 50 |
|
85 | 51 | // Local/World space toggle for gizmo |
86 | 52 | { |
@@ -250,3 +216,47 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW) |
250 | 216 |
|
251 | 217 |
|
252 | 218 | } // namespace MeshCraft::Application |
| 219 | + |
| 220 | +namespace MeshCraft::Application::UI { |
| 221 | + |
| 222 | +void Toolbar::drawTools(ToolbarToolsContext& context) { |
| 223 | + struct { ActiveTool tool; const char* label; ImVec4 color; } tools[] = { |
| 224 | + {ActiveTool::Select, "Select [Q]", {0.31f, 0.59f, 0.82f, 1.f}}, |
| 225 | + {ActiveTool::Move, "Move [G]", {0.22f, 0.74f, 0.39f, 1.f}}, |
| 226 | + {ActiveTool::Rotate, "Rotate [R]", {0.80f, 0.65f, 0.22f, 1.f}}, |
| 227 | + {ActiveTool::Scale, "Scale [S]", {0.82f, 0.29f, 0.29f, 1.f}}, |
| 228 | + {ActiveTool::Measure, "Ruler", {0.60f, 0.82f, 0.82f, 1.f}}, |
| 229 | + }; |
| 230 | + for (const auto& tool : tools) { |
| 231 | + const bool active = context.activeTool == tool.tool; |
| 232 | + if (active) ImGui::PushStyleColor(ImGuiCol_Button, tool.color); |
| 233 | + if (ImGui::Button(tool.label, ImVec2(84, 30))) context.selectTool(tool.tool); |
| 234 | + if (active) ImGui::PopStyleColor(); |
| 235 | + ImGui::SameLine(); |
| 236 | + } |
| 237 | + ImGui::TextDisabled("|"); |
| 238 | + ImGui::SameLine(); |
| 239 | + |
| 240 | + struct { Mc3::ObjectType type; const char* label; ImVec4 color; } primitives[] = { |
| 241 | + {Mc3::ObjectType::Box, "+Box", {0.82f, 0.47f, 0.22f, 1.f}}, |
| 242 | + {Mc3::ObjectType::Sphere, "+Sph", {0.22f, 0.47f, 0.82f, 1.f}}, |
| 243 | + {Mc3::ObjectType::Cylinder, "+Cyl", {0.22f, 0.73f, 0.39f, 1.f}}, |
| 244 | + {Mc3::ObjectType::Cone, "+Con", {0.73f, 0.22f, 0.73f, 1.f}}, |
| 245 | + {Mc3::ObjectType::Plane, "+Pln", {0.80f, 0.80f, 0.22f, 1.f}}, |
| 246 | + {Mc3::ObjectType::Torus, "+Tor", {0.22f, 0.70f, 0.80f, 1.f}}, |
| 247 | + {Mc3::ObjectType::Capsule, "+Cap", {0.70f, 0.35f, 0.70f, 1.f}}, |
| 248 | + {Mc3::ObjectType::Disk, "+Dsk", {0.80f, 0.65f, 0.20f, 1.f}}, |
| 249 | + {Mc3::ObjectType::Grid, "+Grd", {0.30f, 0.65f, 0.50f, 1.f}}, |
| 250 | + {Mc3::ObjectType::IcoSphere, "+Ico", {0.25f, 0.55f, 0.80f, 1.f}}, |
| 251 | + }; |
| 252 | + for (const auto& primitive : primitives) { |
| 253 | + ImGui::PushStyleColor(ImGuiCol_Button, primitive.color); |
| 254 | + if (ImGui::Button(primitive.label, ImVec2(40, 30))) context.addPrimitive(primitive.type); |
| 255 | + ImGui::PopStyleColor(); |
| 256 | + ImGui::SameLine(); |
| 257 | + } |
| 258 | + ImGui::TextDisabled("|"); |
| 259 | + ImGui::SameLine(); |
| 260 | +} |
| 261 | + |
| 262 | +} // namespace MeshCraft::Application::UI |
0 commit comments