yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
object_selection.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_OBJECT_SELECTION_H
2#define YAZE_APP_EDITOR_DUNGEON_OBJECT_SELECTION_H
3
4#include <cstdint>
5#include <functional>
6#include <set>
7#include <vector>
8
10#include "imgui/imgui.h"
12#include "zelda3/dungeon/room.h"
14
15namespace yaze {
16namespace editor {
17
35 public:
36 enum class SelectionMode {
37 Single, // Replace selection with single object
38 Add, // Add to existing selection (Shift)
39 Toggle, // Toggle object in selection (Ctrl)
40 Rectangle, // Rectangle drag selection
41 };
42
43 // Layer filter constants
44 static constexpr int kLayerAll = -1; // Select from all layers
45 static constexpr int kMaskLayer = -2; // Mask mode: only BG2/Layer 1 objects (overlays)
46 static constexpr int kLayer1 = 0; // BG1 (Layer 0)
47 static constexpr int kLayer2 = 1; // BG2 (Layer 1) - overlay objects
48 static constexpr int kLayer3 = 2; // BG3 (Layer 2)
49
50 explicit ObjectSelection() = default;
51
52 // ============================================================================
53 // Selection Operations
54 // ============================================================================
55
61 void SelectObject(size_t index, SelectionMode mode = SelectionMode::Single);
62
72 void SelectObjectsInRect(int room_min_x, int room_min_y, int room_max_x,
73 int room_max_y,
74 const std::vector<zelda3::RoomObject>& objects,
76
83 void SelectAll(size_t object_count);
84
89 void SelectAll(const std::vector<zelda3::RoomObject>& objects);
90
94 void ClearSelection();
95
101 bool IsObjectSelected(size_t index) const;
102
107 std::vector<size_t> GetSelectedIndices() const;
108
112 size_t GetSelectionCount() const { return selected_indices_.size(); }
113
117 bool HasSelection() const { return !selected_indices_.empty(); }
118
123 std::optional<size_t> GetPrimarySelection() const;
124
125 // ============================================================================
126 // Rectangle Selection State
127 // ============================================================================
128
134 void BeginRectangleSelection(int canvas_x, int canvas_y);
135
141 void UpdateRectangleSelection(int canvas_x, int canvas_y);
142
149 const std::vector<zelda3::RoomObject>& objects,
151
156
163
168 std::tuple<int, int, int, int> GetRectangleSelectionBounds() const;
169
170 // ============================================================================
171 // Visual Rendering
172 // ============================================================================
173
181 gui::Canvas* canvas, const std::vector<zelda3::RoomObject>& objects,
182 std::function<std::pair<int, int>(const zelda3::RoomObject&)>
183 dimension_calculator);
184
190
196 ImVec4 GetLayerTypeColor(const zelda3::RoomObject& object) const;
197
198 // ============================================================================
199 // Callbacks
200 // ============================================================================
201
205 void SetSelectionChangedCallback(std::function<void()> callback) {
206 selection_changed_callback_ = std::move(callback);
207 }
208
209 // ============================================================================
210 // Layer Filtering
211 // ============================================================================
212
220 void SetLayerFilter(int layer) { active_layer_filter_ = layer; }
221
226 int GetLayerFilter() const { return active_layer_filter_; }
227
233 bool IsLayerEnabled(int layer) const {
235 }
236
242
247 const char* GetLayerFilterName() const {
248 switch (active_layer_filter_) {
249 case kMaskLayer: return "Mask Mode (BG2 Overlays)";
250 case kLayer1: return "Layer 1 (BG1)";
251 case kLayer2: return "Layer 2 (BG2)";
252 case kLayer3: return "Layer 3 (BG3)";
253 default: return "All Layers";
254 }
255 }
256
262
269 void SetLayersMerged(bool merged) { layers_merged_ = merged; }
270
274 bool AreLayersMerged() const { return layers_merged_; }
275
276 // ============================================================================
277 // Utility Functions
278 // ============================================================================
279
286 static std::pair<int, int> RoomToCanvasCoordinates(int room_x, int room_y);
287
294 static std::pair<int, int> CanvasToRoomCoordinates(int canvas_x,
295 int canvas_y);
296
302 static std::tuple<int, int, int, int> GetObjectBounds(
303 const zelda3::RoomObject& object);
304
305 private:
306 // Selection state
307 std::set<size_t> selected_indices_; // Using set for fast lookup and auto-sort
308
309 // Rectangle selection state
313 int rect_end_x_ = 0;
314 int rect_end_y_ = 0;
315
316 // Layer filtering state
317 int active_layer_filter_ = kLayerAll; // -1 = all layers, 0/1/2 = specific layer
318 bool layers_merged_ = false; // Whether room has merged layers
319
320 // Callbacks
321 std::function<void()> selection_changed_callback_;
322
323 // Helper functions
325 bool IsObjectInRectangle(const zelda3::RoomObject& object, int min_x,
326 int min_y, int max_x, int max_y) const;
327 bool PassesLayerFilter(const zelda3::RoomObject& object) const;
328};
329
330} // namespace editor
331} // namespace yaze
332
333#endif // YAZE_APP_EDITOR_DUNGEON_OBJECT_SELECTION_H
Manages object selection state and operations for the dungeon editor.
void SetSelectionChangedCallback(std::function< void()> callback)
Set callback to be invoked when selection changes.
bool IsObjectInRectangle(const zelda3::RoomObject &object, int min_x, int min_y, int max_x, int max_y) const
std::tuple< int, int, int, int > GetRectangleSelectionBounds() const
Get rectangle selection bounds in canvas coordinates.
bool IsMaskModeActive() const
Check if mask selection mode is active.
bool IsRectangleSelectionActive() const
Check if a rectangle selection is in progress.
void UpdateRectangleSelection(int canvas_x, int canvas_y)
Update rectangle selection endpoint.
static std::pair< int, int > RoomToCanvasCoordinates(int room_x, int room_y)
Convert room tile coordinates to canvas pixel coordinates.
int GetLayerFilter() const
Get the current active layer filter.
std::function< void()> selection_changed_callback_
static constexpr int kMaskLayer
bool IsObjectSelected(size_t index) const
Check if an object is selected.
std::set< size_t > selected_indices_
std::vector< size_t > GetSelectedIndices() const
Get all selected object indices.
static std::tuple< int, int, int, int > GetObjectBounds(const zelda3::RoomObject &object)
Calculate the bounding box of an object.
bool AreLayersMerged() const
Check if layers are currently merged.
void SelectAll(size_t object_count)
Select all objects in the current room.
static std::pair< int, int > CanvasToRoomCoordinates(int canvas_x, int canvas_y)
Convert canvas pixel coordinates to room tile coordinates.
size_t GetSelectionCount() const
Get the number of selected objects.
void SelectObject(size_t index, SelectionMode mode=SelectionMode::Single)
Select a single object by index.
void ClearSelection()
Clear all selections.
void EndRectangleSelection(const std::vector< zelda3::RoomObject > &objects, SelectionMode mode=SelectionMode::Single)
Complete rectangle selection operation.
void BeginRectangleSelection(int canvas_x, int canvas_y)
Begin a rectangle selection operation.
bool PassesLayerFilter(const zelda3::RoomObject &object) const
void DrawSelectionHighlights(gui::Canvas *canvas, const std::vector< zelda3::RoomObject > &objects, std::function< std::pair< int, int >(const zelda3::RoomObject &)> dimension_calculator)
Draw selection highlights for all selected objects.
const char * GetLayerFilterName() const
Get the name of the current layer filter for display.
ImVec4 GetLayerTypeColor(const zelda3::RoomObject &object) const
Get selection highlight color based on object layer and type.
void SetLayersMerged(bool merged)
Set whether layers are currently merged in the room.
static constexpr int kLayerAll
void SetLayerFilter(int layer)
Set the active layer filter for selection.
bool IsLayerFilterActive() const
Check if layer filtering is active.
void CancelRectangleSelection()
Cancel rectangle selection without modifying selection.
std::optional< size_t > GetPrimarySelection() const
Get the primary selected object (first in selection)
void DrawRectangleSelectionBox(gui::Canvas *canvas)
Draw the active rectangle selection box.
bool IsLayerEnabled(int layer) const
Check if a specific layer is enabled for selection.
void SelectObjectsInRect(int room_min_x, int room_min_y, int room_max_x, int room_max_y, const std::vector< zelda3::RoomObject > &objects, SelectionMode mode=SelectionMode::Single)
Select multiple objects within a rectangle.
bool HasSelection() const
Check if any objects are selected.
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:150