* feat(editor): 新增编辑器构件模块(gizmo / 笔刷 / UI 壳) 引擎不内置完整 3D 或地图编辑器,改为提供可组装构件: TransformGizmo + GizmoManager(平移/旋转/缩放/包围盒)、 TileBuffer + Brush(paint/erase/fill/line/rect/stamp)、 以及 Toolbar / Inspector / Dock / History 辅助快速搭建编辑器 UI。 参考 Three.js、Babylon.js、ImGuizmo、Unity GridBrush 与 Godot 插件 API。 Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * docs(editor): 标记编辑器模块 Phase A 已实现 Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * fix(editor): avoid CHECK(unique_ptr) so zeroerr can compile tests zeroerr's CHECK copies the expression for printing; unique_ptr is non-copyable and broke unit_test on Linux/macOS/Windows. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#include "editor/EditorToolbar.h"
|
|
|
|
#include "common/Exception.h"
|
|
|
|
namespace eve::editor {
|
|
|
|
void EditorToolbar::clear() {
|
|
tools_.clear();
|
|
active_.clear();
|
|
}
|
|
|
|
int EditorToolbar::findIndex(const std::string &id) const {
|
|
for (int i = 0; i < static_cast<int>(tools_.size()); ++i) {
|
|
if (tools_[i].id == id) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void EditorToolbar::addTool(const std::string &id, const std::string &label) {
|
|
if (id.empty()) throw Exception("EditorToolbar::addTool: empty id");
|
|
if (findIndex(id) >= 0) throw Exception("EditorToolbar::addTool: duplicate id");
|
|
tools_.push_back(Tool{id, label, ""});
|
|
if (active_.empty()) active_ = id;
|
|
}
|
|
|
|
void EditorToolbar::setShortcut(const std::string &id, const std::string &key) {
|
|
int i = findIndex(id);
|
|
if (i < 0) throw Exception("EditorToolbar::setShortcut: unknown id");
|
|
tools_[i].shortcut = key;
|
|
}
|
|
|
|
bool EditorToolbar::setActive(const std::string &id) {
|
|
if (findIndex(id) < 0) return false;
|
|
active_ = id;
|
|
return true;
|
|
}
|
|
|
|
bool EditorToolbar::matchShortcut(const std::string &key) {
|
|
for (const auto &t : tools_) {
|
|
if (!t.shortcut.empty() && t.shortcut == key) {
|
|
active_ = t.id;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::string EditorToolbar::getToolId(int index) const {
|
|
if (index < 0 || index >= static_cast<int>(tools_.size()))
|
|
throw Exception("EditorToolbar::getToolId: bad index");
|
|
return tools_[index].id;
|
|
}
|
|
|
|
std::string EditorToolbar::getToolLabel(int index) const {
|
|
if (index < 0 || index >= static_cast<int>(tools_.size()))
|
|
throw Exception("EditorToolbar::getToolLabel: bad index");
|
|
return tools_[index].label;
|
|
}
|
|
|
|
std::string EditorToolbar::getToolShortcut(int index) const {
|
|
if (index < 0 || index >= static_cast<int>(tools_.size()))
|
|
throw Exception("EditorToolbar::getToolShortcut: bad index");
|
|
return tools_[index].shortcut;
|
|
}
|
|
|
|
} // namespace eve::editor
|