载入中...
搜索中...
未找到
EditorToolbar.cpp
浏览该文件的文档.
2
3#include "common/Exception.h"
4
5namespace eve::editor {
6
8 tools_.clear();
9 active_.clear();
10}
11
12int EditorToolbar::findIndex(const std::string &id) const {
13 for (int i = 0; i < static_cast<int>(tools_.size()); ++i) {
14 if (tools_[i].id == id) return i;
15 }
16 return -1;
17}
18
19void EditorToolbar::addTool(const std::string &id, const std::string &label) {
20 if (id.empty()) throw Exception("EditorToolbar::addTool: empty id");
21 if (findIndex(id) >= 0) throw Exception("EditorToolbar::addTool: duplicate id");
22 tools_.push_back(Tool{id, label, "", ""});
23 if (active_.empty()) active_ = id;
24}
25
26void EditorToolbar::setIcon(const std::string &id, const std::string &icon) {
27 int i = findIndex(id);
28 if (i < 0) throw Exception("EditorToolbar::setIcon: unknown id");
29 tools_[i].icon = icon;
30}
31
32void EditorToolbar::setShortcut(const std::string &id, const std::string &key) {
33 int i = findIndex(id);
34 if (i < 0) throw Exception("EditorToolbar::setShortcut: unknown id");
35 tools_[i].shortcut = key;
36}
37
38bool EditorToolbar::setActive(const std::string &id) {
39 if (findIndex(id) < 0) return false;
40 active_ = id;
41 return true;
42}
43
44bool EditorToolbar::matchShortcut(const std::string &key) {
45 for (const auto &t : tools_) {
46 if (!t.shortcut.empty() && t.shortcut == key) {
47 active_ = t.id;
48 return true;
49 }
50 }
51 return false;
52}
53
54std::string EditorToolbar::getToolId(int index) const {
55 if (index < 0 || index >= static_cast<int>(tools_.size()))
56 throw Exception("EditorToolbar::getToolId: bad index");
57 return tools_[index].id;
58}
59
60std::string EditorToolbar::getToolLabel(int index) const {
61 if (index < 0 || index >= static_cast<int>(tools_.size()))
62 throw Exception("EditorToolbar::getToolLabel: bad index");
63 return tools_[index].label;
64}
65
66std::string EditorToolbar::getToolIcon(int index) const {
67 if (index < 0 || index >= static_cast<int>(tools_.size()))
68 throw Exception("EditorToolbar::getToolIcon: bad index");
69 return tools_[index].icon;
70}
71
72std::string EditorToolbar::getToolShortcut(int index) const {
73 if (index < 0 || index >= static_cast<int>(tools_.size()))
74 throw Exception("EditorToolbar::getToolShortcut: bad index");
75 return tools_[index].shortcut;
76}
77
78} // namespace eve::editor
std::string label
std::uint32_t key
Icon icon
Definition Icons.cpp:11
std::string id
Definition PlayHost.cpp:108
float t
uint32_t index
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
std::string getToolLabel(int index) const
Returns the tool label.
std::string getToolId(int index) const
Returns the tool id.
void setIcon(const std::string &id, const std::string &icon)
Assigns a backend-neutral semantic icon name to an existing tool.
void addTool(const std::string &id, const std::string &label)
Adds tool.
bool setActive(const std::string &id)
Sets the active.
void setShortcut(const std::string &id, const std::string &key)
Sets the shortcut.
std::string getToolShortcut(int index) const
Returns the tool shortcut.
bool matchShortcut(const std::string &key)
Match shortcut.
std::string getToolIcon(int index) const
Returns the tool's semantic icon name.