Manages object selection state and operations for the dungeon editor. More...
#include <object_selection.h>
Public Types | |
| enum class | SelectionMode { Single , Add , Toggle , Rectangle } |
Public Member Functions | |
| ObjectSelection ()=default | |
| void | SelectObject (size_t index, SelectionMode mode=SelectionMode::Single) |
| Select a single object by index. | |
| 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. | |
| void | SelectAll (size_t object_count) |
| Select all objects in the current room. | |
| void | SelectAll (const std::vector< zelda3::RoomObject > &objects) |
| Select all objects in the current room respecting layer filter. | |
| void | ClearSelection () |
| Clear all selections. | |
| bool | IsObjectSelected (size_t index) const |
| Check if an object is selected. | |
| std::vector< size_t > | GetSelectedIndices () const |
| Get all selected object indices. | |
| size_t | GetSelectionCount () const |
| Get the number of selected objects. | |
| bool | HasSelection () const |
| Check if any objects are selected. | |
| std::optional< size_t > | GetPrimarySelection () const |
| Get the primary selected object (first in selection) | |
| void | BeginRectangleSelection (int canvas_x, int canvas_y) |
| Begin a rectangle selection operation. | |
| void | UpdateRectangleSelection (int canvas_x, int canvas_y) |
| Update rectangle selection endpoint. | |
| void | EndRectangleSelection (const std::vector< zelda3::RoomObject > &objects, SelectionMode mode=SelectionMode::Single) |
| Complete rectangle selection operation. | |
| void | CancelRectangleSelection () |
| Cancel rectangle selection without modifying selection. | |
| bool | IsRectangleSelectionActive () const |
| Check if a rectangle selection is in progress. | |
| std::tuple< int, int, int, int > | GetRectangleSelectionBounds () const |
| Get rectangle selection bounds in canvas coordinates. | |
| bool | IsRectangleLargeEnough (int min_pixels) const |
| Check if rectangle selection exceeds a minimum pixel size. | |
| void | DrawSelectionHighlights (gui::Canvas *canvas, const std::vector< zelda3::RoomObject > &objects, std::function< std::tuple< int, int, int, int >(const zelda3::RoomObject &)> bounds_calculator) |
| Draw selection highlights for all selected objects. | |
| void | DrawRectangleSelectionBox (gui::Canvas *canvas) |
| Draw the active rectangle selection box. | |
| ImVec4 | GetLayerTypeColor (const zelda3::RoomObject &object) const |
| Get selection highlight color based on object layer and type. | |
| void | SetSelectionChangedCallback (std::function< void()> callback) |
| Set callback to be invoked when selection changes. | |
| void | SetLayerFilter (int layer) |
| Set the active layer filter for selection. | |
| int | GetLayerFilter () const |
| Get the current active layer filter. | |
| bool | IsLayerEnabled (int layer) const |
| Check if a specific layer is enabled for selection. | |
| bool | IsLayerFilterActive () const |
| Check if layer filtering is active. | |
| const char * | GetLayerFilterName () const |
| Get the name of the current layer filter for display. | |
| bool | IsMaskModeActive () const |
| Check if mask selection mode is active. | |
| bool | PassesLayerFilterForObject (const zelda3::RoomObject &object) const |
| Check if an object passes the current layer filter. | |
| void | SetLayersMerged (bool merged) |
| Set whether layers are currently merged in the room. | |
| bool | AreLayersMerged () const |
| Check if layers are currently merged. | |
Static Public Member Functions | |
| static std::pair< int, int > | RoomToCanvasCoordinates (int room_x, int room_y) |
| Convert room tile coordinates to canvas pixel coordinates. | |
| static std::pair< int, int > | CanvasToRoomCoordinates (int canvas_x, int canvas_y) |
| Convert canvas pixel coordinates to room tile coordinates. | |
| static std::tuple< int, int, int, int > | GetObjectBounds (const zelda3::RoomObject &object) |
| Calculate the bounding box of an object. | |
Static Public Attributes | |
| static constexpr int | kLayerAll = -1 |
| static constexpr int | kMaskLayer |
| static constexpr int | kLayer1 = 0 |
| static constexpr int | kLayer2 = 1 |
| static constexpr int | kLayer3 = 2 |
Private Member Functions | |
| void | NotifySelectionChanged () |
| bool | IsObjectInRectangle (const zelda3::RoomObject &object, int min_x, int min_y, int max_x, int max_y) const |
| bool | PassesLayerFilter (const zelda3::RoomObject &object) const |
Private Attributes | |
| std::set< size_t > | selected_indices_ |
| bool | rectangle_selection_active_ = false |
| int | rect_start_x_ = 0 |
| int | rect_start_y_ = 0 |
| int | rect_end_x_ = 0 |
| int | rect_end_y_ = 0 |
| int | active_layer_filter_ |
| bool | layers_merged_ = false |
| std::function< void()> | selection_changed_callback_ |
Manages object selection state and operations for the dungeon editor.
Provides comprehensive selection functionality including:
Design Philosophy:
Definition at line 35 of file object_selection.h.
|
strong |
| Enumerator | |
|---|---|
| Single | |
| Add | |
| Toggle | |
| Rectangle | |
Definition at line 37 of file object_selection.h.
|
explicitdefault |
| void yaze::editor::ObjectSelection::SelectObject | ( | size_t | index, |
| SelectionMode | mode = SelectionMode::Single ) |
Select a single object by index.
| index | Object index in the room's object list |
| mode | How to modify the selection |
Definition at line 18 of file object_selection.cc.
References Add, LOG_ERROR, NotifySelectionChanged(), Rectangle, selected_indices_, Single, and Toggle.
Referenced by yaze::editor::TileObjectHandler::HandleClick(), yaze::editor::TileObjectHandler::HandleDrag(), and yaze::editor::DungeonObjectInteraction::SetSelectedObjects().

| void yaze::editor::ObjectSelection::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.
| room_min_x | Minimum X coordinate in room tiles |
| room_min_y | Minimum Y coordinate in room tiles |
| room_max_x | Maximum X coordinate in room tiles |
| room_max_y | Maximum Y coordinate in room tiles |
| objects | Object list to select from |
| mode | How to modify the selection |
Definition at line 51 of file object_selection.cc.
References IsObjectInRectangle(), NotifySelectionChanged(), selected_indices_, Single, and Toggle.
Referenced by EndRectangleSelection().

| void yaze::editor::ObjectSelection::SelectAll | ( | size_t | object_count | ) |
Select all objects in the current room.
| object_count | Total number of objects in the room |
Definition at line 85 of file object_selection.cc.
References NotifySelectionChanged(), and selected_indices_.

| void yaze::editor::ObjectSelection::SelectAll | ( | const std::vector< zelda3::RoomObject > & | objects | ) |
Select all objects in the current room respecting layer filter.
| objects | Object list to select from |
Definition at line 93 of file object_selection.cc.
References NotifySelectionChanged(), PassesLayerFilter(), and selected_indices_.

| void yaze::editor::ObjectSelection::ClearSelection | ( | ) |
Clear all selections.
Definition at line 104 of file object_selection.cc.
References NotifySelectionChanged(), and selected_indices_.
Referenced by yaze::editor::InteractionCoordinator::HandleClick(), yaze::editor::TileObjectHandler::HandleDrag(), yaze::editor::InteractionCoordinator::SelectEntity(), and yaze::editor::DungeonObjectInteraction::SetSelectedObjects().

| bool yaze::editor::ObjectSelection::IsObjectSelected | ( | size_t | index | ) | const |
Check if an object is selected.
| index | Object index to check |
Definition at line 113 of file object_selection.cc.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::IsObjectSelected().
| std::vector< size_t > yaze::editor::ObjectSelection::GetSelectedIndices | ( | ) | const |
Get all selected object indices.
Definition at line 117 of file object_selection.cc.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::GetSelectedObjectIndices(), yaze::editor::TileObjectHandler::HandleDrag(), and yaze::editor::TileObjectHandler::HandleMouseWheel().
|
inline |
Get the number of selected objects.
Definition at line 114 of file object_selection.h.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::GetSelectionCount().
|
inline |
Check if any objects are selected.
Definition at line 119 of file object_selection.h.
References selected_indices_.
Referenced by yaze::editor::InteractionCoordinator::HandleDrag(), yaze::editor::DungeonObjectInteraction::HandleLeftClick(), and yaze::editor::DungeonObjectInteraction::IsObjectSelectActive().
| std::optional< size_t > yaze::editor::ObjectSelection::GetPrimarySelection | ( | ) | const |
Get the primary selected object (first in selection)
Definition at line 127 of file object_selection.cc.
References selected_indices_.
| void yaze::editor::ObjectSelection::BeginRectangleSelection | ( | int | canvas_x, |
| int | canvas_y ) |
Begin a rectangle selection operation.
| canvas_x | Starting X position in canvas coordinates |
| canvas_y | Starting Y position in canvas coordinates |
Definition at line 138 of file object_selection.cc.
References rect_end_x_, rect_end_y_, rect_start_x_, rect_start_y_, and rectangle_selection_active_.
Referenced by yaze::editor::TileObjectHandler::BeginMarqueeSelection().
| void yaze::editor::ObjectSelection::UpdateRectangleSelection | ( | int | canvas_x, |
| int | canvas_y ) |
Update rectangle selection endpoint.
| canvas_x | Current X position in canvas coordinates |
| canvas_y | Current Y position in canvas coordinates |
Definition at line 146 of file object_selection.cc.
References LOG_ERROR, rect_end_x_, rect_end_y_, and rectangle_selection_active_.
Referenced by yaze::editor::TileObjectHandler::HandleMarqueeSelection().
| void yaze::editor::ObjectSelection::EndRectangleSelection | ( | const std::vector< zelda3::RoomObject > & | objects, |
| SelectionMode | mode = SelectionMode::Single ) |
Complete rectangle selection operation.
| objects | Object list to select from |
| mode | How to modify the selection |
Definition at line 157 of file object_selection.cc.
References CanvasToRoomCoordinates(), LOG_ERROR, rect_end_x_, rect_end_y_, rect_start_x_, rect_start_y_, rectangle_selection_active_, and SelectObjectsInRect().
Referenced by yaze::editor::TileObjectHandler::HandleMarqueeSelection().

| void yaze::editor::ObjectSelection::CancelRectangleSelection | ( | ) |
Cancel rectangle selection without modifying selection.
Definition at line 178 of file object_selection.cc.
References rectangle_selection_active_.
Referenced by yaze::editor::TileObjectHandler::HandleMarqueeSelection().
|
inline |
Check if a rectangle selection is in progress.
Definition at line 161 of file object_selection.h.
References rectangle_selection_active_.
Referenced by yaze::editor::DungeonObjectInteraction::HandleCanvasMouseInput(), yaze::editor::TileObjectHandler::HandleMarqueeSelection(), and yaze::editor::DungeonObjectInteraction::IsObjectSelectActive().
| std::tuple< int, int, int, int > yaze::editor::ObjectSelection::GetRectangleSelectionBounds | ( | ) | const |
Get rectangle selection bounds in canvas coordinates.
Definition at line 182 of file object_selection.cc.
References rect_end_x_, rect_end_y_, rect_start_x_, and rect_start_y_.
Referenced by DrawRectangleSelectionBox(), and IsRectangleLargeEnough().
| bool yaze::editor::ObjectSelection::IsRectangleLargeEnough | ( | int | min_pixels | ) | const |
Check if rectangle selection exceeds a minimum pixel size.
| min_pixels | Minimum size along either axis in canvas pixels |
Definition at line 191 of file object_selection.cc.
References GetRectangleSelectionBounds(), and rectangle_selection_active_.
Referenced by yaze::editor::TileObjectHandler::HandleMarqueeSelection().

| void yaze::editor::ObjectSelection::DrawSelectionHighlights | ( | gui::Canvas * | canvas, |
| const std::vector< zelda3::RoomObject > & | objects, | ||
| std::function< std::tuple< int, int, int, int >(const zelda3::RoomObject &)> | bounds_calculator ) |
Draw selection highlights for all selected objects.
| canvas | Canvas to draw on |
| objects | Object list for position/size information |
| bounds_calculator | Callback to calculate selection bounds (offset_x, offset_y, width, height) in pixels |
Definition at line 206 of file object_selection.cc.
References GetObjectBounds(), yaze::editor::AgentUI::GetTheme(), yaze::gui::Canvas::global_scale(), RoomToCanvasCoordinates(), selected_indices_, and yaze::gui::Canvas::zero_point().
Referenced by yaze::editor::TileObjectHandler::DrawSelectionHighlight().
| void yaze::editor::ObjectSelection::DrawRectangleSelectionBox | ( | gui::Canvas * | canvas | ) |
Draw the active rectangle selection box.
| canvas | Canvas to draw on |
Definition at line 313 of file object_selection.cc.
References GetRectangleSelectionBounds(), yaze::editor::AgentUI::GetTheme(), yaze::gui::Canvas::global_scale(), rectangle_selection_active_, and yaze::gui::Canvas::zero_point().
Referenced by yaze::editor::TileObjectHandler::HandleMarqueeSelection().

| ImVec4 yaze::editor::ObjectSelection::GetLayerTypeColor | ( | const zelda3::RoomObject & | object | ) | const |
Get selection highlight color based on object layer and type.
| object | The room object to get color for |
Definition at line 301 of file object_selection.cc.
References yaze::editor::AgentUI::GetTheme().

|
inline |
Set callback to be invoked when selection changes.
Definition at line 212 of file object_selection.h.
References selection_changed_callback_.
Referenced by yaze::editor::DungeonObjectInteraction::SetSelectionChangeCallback().
|
inline |
Set the active layer filter for selection.
| layer | Layer to filter by (kLayerAll, kLayer1, kLayer2, kLayer3) |
When a layer filter is active, only objects on that layer can be selected. Use kLayerAll (-1) to disable filtering and select from all layers.
Definition at line 227 of file object_selection.h.
References active_layer_filter_.
Referenced by yaze::editor::DungeonObjectInteraction::SetLayerFilter().
|
inline |
Get the current active layer filter.
Definition at line 233 of file object_selection.h.
References active_layer_filter_.
Referenced by yaze::editor::DungeonObjectInteraction::GetLayerFilter().
|
inline |
Check if a specific layer is enabled for selection.
| layer | Layer to check (0, 1, or 2) |
Definition at line 240 of file object_selection.h.
References active_layer_filter_, and kLayerAll.
|
inline |
Check if layer filtering is active.
Definition at line 248 of file object_selection.h.
References active_layer_filter_, and kLayerAll.
Referenced by yaze::editor::DungeonObjectInteraction::IsLayerFilterActive().
|
inline |
Get the name of the current layer filter for display.
Definition at line 254 of file object_selection.h.
References active_layer_filter_, kLayer1, kLayer2, kLayer3, and kMaskLayer.
Referenced by yaze::editor::DungeonObjectInteraction::GetLayerFilterName().
|
inline |
Check if mask selection mode is active.
Definition at line 273 of file object_selection.h.
References active_layer_filter_, and kMaskLayer.
Referenced by yaze::editor::DungeonObjectInteraction::IsMaskModeActive().
|
inline |
Check if an object passes the current layer filter.
| object | Room object to evaluate |
Definition at line 280 of file object_selection.h.
References PassesLayerFilter().
Referenced by yaze::editor::TileObjectHandler::GetEntityAtPosition().

|
inline |
Set whether layers are currently merged in the room.
When layers are merged, this information helps the UI provide appropriate feedback about which objects can be selected.
Definition at line 290 of file object_selection.h.
References layers_merged_.
Referenced by yaze::editor::DungeonObjectInteraction::SetLayersMerged().
|
inline |
Check if layers are currently merged.
Definition at line 295 of file object_selection.h.
References layers_merged_.
Referenced by yaze::editor::DungeonObjectInteraction::AreLayersMerged().
|
static |
Convert room tile coordinates to canvas pixel coordinates.
| room_x | Room X coordinate (0-63) |
| room_y | Room Y coordinate (0-63) |
Definition at line 348 of file object_selection.cc.
Referenced by DrawSelectionHighlights().
|
static |
Convert canvas pixel coordinates to room tile coordinates.
| canvas_x | Canvas X coordinate (pixels) |
| canvas_y | Canvas Y coordinate (pixels) |
Definition at line 354 of file object_selection.cc.
Referenced by EndRectangleSelection().
|
static |
Calculate the bounding box of an object.
| object | Object to calculate bounds for |
Definition at line 360 of file object_selection.cc.
References yaze::zelda3::DimensionService::Get(), and yaze::zelda3::DimensionService::GetHitTestBounds().
Referenced by DrawSelectionHighlights(), and IsObjectInRectangle().

|
private |
Definition at line 369 of file object_selection.cc.
References selection_changed_callback_.
Referenced by ClearSelection(), SelectAll(), SelectAll(), SelectObject(), and SelectObjectsInRect().
|
private |
Definition at line 375 of file object_selection.cc.
References GetObjectBounds(), and PassesLayerFilter().
Referenced by SelectObjectsInRect().

|
private |
Definition at line 400 of file object_selection.cc.
References active_layer_filter_, kLayer2, kLayerAll, and kMaskLayer.
Referenced by IsObjectInRectangle(), PassesLayerFilterForObject(), and SelectAll().
|
staticconstexpr |
Definition at line 45 of file object_selection.h.
Referenced by IsLayerEnabled(), IsLayerFilterActive(), and PassesLayerFilter().
|
staticconstexpr |
Definition at line 46 of file object_selection.h.
Referenced by GetLayerFilterName(), IsMaskModeActive(), and PassesLayerFilter().
|
staticconstexpr |
Definition at line 48 of file object_selection.h.
Referenced by GetLayerFilterName().
|
staticconstexpr |
Definition at line 49 of file object_selection.h.
Referenced by GetLayerFilterName(), and PassesLayerFilter().
|
staticconstexpr |
Definition at line 50 of file object_selection.h.
Referenced by GetLayerFilterName().
|
private |
Definition at line 329 of file object_selection.h.
Referenced by ClearSelection(), DrawSelectionHighlights(), GetPrimarySelection(), GetSelectedIndices(), GetSelectionCount(), HasSelection(), IsObjectSelected(), SelectAll(), SelectAll(), SelectObject(), and SelectObjectsInRect().
|
private |
Definition at line 332 of file object_selection.h.
Referenced by BeginRectangleSelection(), CancelRectangleSelection(), DrawRectangleSelectionBox(), EndRectangleSelection(), IsRectangleLargeEnough(), IsRectangleSelectionActive(), and UpdateRectangleSelection().
|
private |
Definition at line 333 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), and GetRectangleSelectionBounds().
|
private |
Definition at line 334 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), and GetRectangleSelectionBounds().
|
private |
Definition at line 335 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), GetRectangleSelectionBounds(), and UpdateRectangleSelection().
|
private |
Definition at line 336 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), GetRectangleSelectionBounds(), and UpdateRectangleSelection().
|
private |
Definition at line 339 of file object_selection.h.
Referenced by GetLayerFilter(), GetLayerFilterName(), IsLayerEnabled(), IsLayerFilterActive(), IsMaskModeActive(), PassesLayerFilter(), and SetLayerFilter().
|
private |
Definition at line 341 of file object_selection.h.
Referenced by AreLayersMerged(), and SetLayersMerged().
|
private |
Definition at line 344 of file object_selection.h.
Referenced by NotifySelectionChanged(), and SetSelectionChangedCallback().