yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
base_entity_handler.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_INTERACTION_BASE_ENTITY_HANDLER_H_
2#define YAZE_APP_EDITOR_DUNGEON_INTERACTION_BASE_ENTITY_HANDLER_H_
3
4#include <optional>
5#include <utility>
6
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace editor {
13
25 public:
26 virtual ~BaseEntityHandler() = default;
27
34 void SetContext(InteractionContext* ctx) { ctx_ = ctx; }
35
39 InteractionContext* context() const { return ctx_; }
40
41 // ========================================================================
42 // Placement Lifecycle
43 // ========================================================================
44
51 virtual void BeginPlacement() = 0;
52
59 virtual void CancelPlacement() = 0;
60
64 virtual bool IsPlacementActive() const = 0;
65
66 // ========================================================================
67 // Mouse Interaction
68 // ========================================================================
69
77 virtual bool HandleClick(int canvas_x, int canvas_y) = 0;
78
85 virtual void HandleDrag(ImVec2 current_pos, ImVec2 delta) = 0;
86
92 virtual void HandleRelease() = 0;
93
94 // ========================================================================
95 // Rendering
96 // ========================================================================
97
104 virtual void DrawGhostPreview() = 0;
105
111 virtual void DrawSelectionHighlight() = 0;
112
113 // ========================================================================
114 // Hit Testing
115 // ========================================================================
116
124 virtual std::optional<size_t> GetEntityAtPosition(int canvas_x,
125 int canvas_y) const = 0;
126
127 protected:
129
130 // ========================================================================
131 // Helper Methods (available to all derived handlers)
132 // ========================================================================
133
137 std::pair<int, int> RoomToCanvas(int room_x, int room_y) const {
138 return dungeon_coords::RoomToCanvas(room_x, room_y);
139 }
140
144 std::pair<int, int> CanvasToRoom(int canvas_x, int canvas_y) const {
145 return dungeon_coords::CanvasToRoom(canvas_x, canvas_y);
146 }
147
151 bool IsWithinBounds(int canvas_x, int canvas_y) const {
152 return dungeon_coords::IsWithinBounds(canvas_x, canvas_y);
153 }
154
158 ImVec2 GetCanvasZeroPoint() const {
159 if (!ctx_ || !ctx_->canvas) return ImVec2(0, 0);
160 return ctx_->canvas->zero_point();
161 }
162
166 float GetCanvasScale() const {
167 if (!ctx_ || !ctx_->canvas) return 1.0f;
168 float scale = ctx_->canvas->global_scale();
169 return scale > 0.0f ? scale : 1.0f;
170 }
171
175 bool HasValidContext() const { return ctx_ && ctx_->IsValid(); }
176
181 return ctx_ ? ctx_->GetCurrentRoom() : nullptr;
182 }
183};
184
185} // namespace editor
186} // namespace yaze
187
188#endif // YAZE_APP_EDITOR_DUNGEON_INTERACTION_BASE_ENTITY_HANDLER_H_
Abstract base class for entity interaction handlers.
virtual void HandleRelease()=0
Handle mouse release.
virtual bool IsPlacementActive() const =0
Check if placement mode is active.
virtual void BeginPlacement()=0
Begin placement mode.
InteractionContext * context() const
Get the interaction context.
virtual void HandleDrag(ImVec2 current_pos, ImVec2 delta)=0
Handle mouse drag.
virtual bool HandleClick(int canvas_x, int canvas_y)=0
Handle mouse click at canvas position.
virtual void DrawSelectionHighlight()=0
Draw selection highlight for selected entities.
virtual void DrawGhostPreview()=0
Draw ghost preview during placement.
std::pair< int, int > CanvasToRoom(int canvas_x, int canvas_y) const
Convert canvas pixel coordinates to room tile coordinates.
bool IsWithinBounds(int canvas_x, int canvas_y) const
Check if coordinates are within room bounds.
virtual void CancelPlacement()=0
Cancel current placement.
float GetCanvasScale() const
Get canvas global scale.
zelda3::Room * GetCurrentRoom() const
Get current room (convenience method)
virtual ~BaseEntityHandler()=default
bool HasValidContext() const
Check if context is valid.
std::pair< int, int > RoomToCanvas(int room_x, int room_y) const
Convert room tile coordinates to canvas pixel coordinates.
ImVec2 GetCanvasZeroPoint() const
Get canvas zero point (for screen coordinate conversion)
virtual std::optional< size_t > GetEntityAtPosition(int canvas_x, int canvas_y) const =0
Get entity at canvas position.
void SetContext(InteractionContext *ctx)
Set the interaction context.
auto global_scale() const
Definition canvas.h:494
auto zero_point() const
Definition canvas.h:443
std::pair< int, int > RoomToCanvas(int room_x, int room_y)
Convert room tile coordinates to canvas pixel coordinates.
bool IsWithinBounds(int canvas_x, int canvas_y, int margin=0)
Check if coordinates are within room bounds.
std::pair< int, int > CanvasToRoom(int canvas_x, int canvas_y)
Convert canvas pixel coordinates to room tile coordinates.
Shared context for all interaction handlers.
bool IsValid() const
Check if context has required dependencies.
zelda3::Room * GetCurrentRoom() const
Get pointer to current room.