载入中...
搜索中...
未找到
EditorTool.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
7
8#include <memory>
9#include <string>
10
11namespace eve::editor {
12
13class EditorSession;
14class EditorTransactions;
15class IEditCommand;
16class IEditorOverlay;
17class IEditorInspector;
18
22 enum class Phase { Down, Move, Up, Cancel };
23
25 int pointerId = 0;
26 int button = 0;
27 float x = 0.f;
28 float y = 0.f;
29 float z = 0.f;
30 float deltaX = 0.f;
31 float deltaY = 0.f;
32 float deltaZ = 0.f;
33 float pressure = 1.f;
34 bool shift = false;
35 bool control = false;
36 bool alt = false;
37};
38
41 std::string key;
42 bool pressed = false;
43 bool repeated = false;
44 bool shift = false;
45 bool control = false;
46 bool alt = false;
47};
48
51 bool handled = false;
52 bool capturePointer = false;
53 bool releasePointer = false;
54
56 static ToolResponse ignored() { return {}; }
58 static ToolResponse consumed() { return {true, false, false}; }
60 static ToolResponse capture() { return {true, true, false}; }
62 static ToolResponse release() { return {true, false, true}; }
63};
64
72public:
74 explicit EditorContext(EditorSession* session = nullptr) : session_(session) {}
75
77 EditorSession* session() const { return session_; }
79 IEditableTarget* target() const;
81 EditorTransactions& transactions() const;
83 bool execute(std::unique_ptr<IEditCommand> command) const;
85 [[nodiscard]] Result<void> executeChecked(std::unique_ptr<IEditCommand> command) const;
86
88 template <typename Capability>
90 Capability* targetCapability() const;
91
92private:
93 friend class EditorSession;
94 EditorSession* session_ = nullptr;
95};
96
99 std::string id;
100 std::string label;
101 std::string shortcut;
102};
103
111public:
113 virtual ~IEditorTool() = default;
114
116 virtual const ToolDescriptor& descriptor() const = 0;
117
119 virtual void activate(EditorContext& context) { (void)context; }
121 virtual void deactivate(EditorContext& context) { (void)context; }
122
125 (void)context;
126 (void)event;
128 return ToolResponse::ignored();
129 }
130
133 (void)context;
134 (void)event;
136 return ToolResponse::ignored();
137 }
138
140 virtual void update(EditorContext& context, float dt) {
141 (void)context;
142 (void)dt;
143 }
144
147 (void)context;
148 (void)overlay;
149 }
150
152 virtual void inspect(EditorContext& context, IEditorInspector& inspector) {
153 (void)context;
154 (void)inspector;
155 }
156
158 virtual void cancel(EditorContext& context) { (void)context; }
159};
160
161} // namespace eve::editor
162
163namespace eve::editor {
164
165template <typename Capability>
170 return current ? current->query<Capability>() : nullptr;
171}
172
173} // namespace eve::editor
LogicalId target
#define EVENGINE_API_ORCHESTRATION
Definition Export.h:111
double current
std::optional< InteractionSession > session
Definition Tactics.cpp:39
const VegetationPresetContext & context
Move-only operation result carrying either a value or Status.
Definition Result.h:155
IEditableTarget public API.
Context supplied by EditorSession to tools.
Definition EditorTool.h:71
Capability * targetCapability() const
Query a capability from the current target.
Definition EditorTool.h:168
EditorContext(EditorSession *session=nullptr)
Editor context.
Definition EditorTool.h:74
IEditableTarget * target() const
Target currently bound to the session.
EditorSession * session() const
Session currently dispatching the tool callback.
Definition EditorTool.h:77
Hosts interchangeable editor tools and routes their lifecycle/input.
Executes, groups, rolls back and replays arbitrary edit commands.
UI-independent property editor used by tools to expose settings.
Sink implemented by a 2D or 3D viewport to render tool feedback.
Protocol implemented by every editor tool.
Definition EditorTool.h:110
virtual void update(EditorContext &context, float dt)
Per-frame hook for an active tool.
Definition EditorTool.h:140
virtual void inspect(EditorContext &context, IEditorInspector &inspector)
Expose configurable settings through a host-provided inspector.
Definition EditorTool.h:152
virtual void drawOverlay(EditorContext &context, IEditorOverlay &overlay)
Emit renderer-independent feedback for the active viewport.
Definition EditorTool.h:146
virtual void deactivate(EditorContext &context)
Called exactly once before this tool stops being active.
Definition EditorTool.h:121
virtual ToolResponse pointerEvent(EditorContext &context, const EditorPointerEvent &event)
Handle normalized pointer input.
Definition EditorTool.h:124
virtual ~IEditorTool()=default
Releases IEditorTool resources.
virtual ToolResponse keyEvent(EditorContext &context, const EditorKeyEvent &event)
Handle normalized keyboard input.
Definition EditorTool.h:132
virtual void activate(EditorContext &context)
Called exactly once when this tool becomes active.
Definition EditorTool.h:119
virtual void cancel(EditorContext &context)
Cancel the active gesture while keeping the tool selected.
Definition EditorTool.h:158
virtual const ToolDescriptor & descriptor() const =0
Stable tool identity and presentation metadata.
Keyboard input normalized by the editor host.
Definition EditorTool.h:40
Pointer input normalized by an editor viewport adapter.
Definition EditorTool.h:20
UI-facing metadata supplied by a tool implementation.
Definition EditorTool.h:98
Result returned by a tool after processing input.
Definition EditorTool.h:50
static ToolResponse ignored()
Ignored.
Definition EditorTool.h:56
static ToolResponse capture()
Capture.
Definition EditorTool.h:60
static ToolResponse release()
Release.
Definition EditorTool.h:62
static ToolResponse consumed()
Consumed.
Definition EditorTool.h:58