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. | |
| 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. | |
| 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. | |
| 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 = -2 |
| 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_ = kLayerAll |
| 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 34 of file object_selection.h.
|
strong |
| Enumerator | |
|---|---|
| Single | |
| Add | |
| Toggle | |
| Rectangle | |
Definition at line 36 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 16 of file object_selection.cc.
References Add, LOG_ERROR, NotifySelectionChanged(), Rectangle, selected_indices_, Single, and Toggle.
Referenced by yaze::editor::DungeonObjectInteraction::BringSelectedForward(), yaze::editor::DungeonObjectInteraction::SendSelectedBackward(), yaze::editor::DungeonObjectInteraction::SendSelectedToBack(), yaze::editor::DungeonObjectInteraction::SendSelectedToFront(), yaze::editor::DungeonObjectInteraction::SetSelectedObjects(), and yaze::editor::DungeonObjectInteraction::TrySelectObjectAtCursor().

| 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 49 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 83 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 91 of file object_selection.cc.
References NotifySelectionChanged(), PassesLayerFilter(), and selected_indices_.

| void yaze::editor::ObjectSelection::ClearSelection | ( | ) |
Clear all selections.
Definition at line 102 of file object_selection.cc.
References NotifySelectionChanged(), and selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::BringSelectedForward(), yaze::editor::DungeonObjectInteraction::ClearSelection(), yaze::editor::DungeonObjectInteraction::HandleCanvasMouseInput(), yaze::editor::DungeonObjectInteraction::HandleDeleteSelected(), yaze::editor::DungeonObjectInteraction::SelectEntity(), yaze::editor::DungeonObjectInteraction::SendSelectedBackward(), yaze::editor::DungeonObjectInteraction::SendSelectedToBack(), yaze::editor::DungeonObjectInteraction::SendSelectedToFront(), yaze::editor::DungeonObjectInteraction::SetSelectedObjects(), and yaze::editor::DungeonObjectInteraction::TrySelectEntityAtCursor().

| bool yaze::editor::ObjectSelection::IsObjectSelected | ( | size_t | index | ) | const |
Check if an object is selected.
| index | Object index to check |
Definition at line 111 of file object_selection.cc.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::DrawHoverHighlight(), yaze::editor::DungeonObjectInteraction::DrawSelectionHighlights(), yaze::editor::DungeonObjectInteraction::HandleScrollWheelResize(), and yaze::editor::DungeonObjectInteraction::IsObjectSelected().
| std::vector< size_t > yaze::editor::ObjectSelection::GetSelectedIndices | ( | ) | const |
Get all selected object indices.
Definition at line 115 of file object_selection.cc.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::BringSelectedForward(), yaze::editor::DungeonObjectInteraction::DrawDragPreview(), yaze::editor::DungeonObjectInteraction::GetSelectedObjectIndices(), yaze::editor::DungeonObjectInteraction::HandleCanvasMouseInput(), yaze::editor::DungeonObjectInteraction::HandleCopySelected(), yaze::editor::DungeonObjectInteraction::HandleDeleteSelected(), yaze::editor::DungeonObjectInteraction::HandleScrollWheelResize(), yaze::editor::DungeonObjectInteraction::SendSelectedBackward(), yaze::editor::DungeonObjectInteraction::SendSelectedToBack(), yaze::editor::DungeonObjectInteraction::SendSelectedToFront(), and yaze::editor::DungeonObjectInteraction::SendSelectedToLayer().
|
inline |
Get the number of selected objects.
Definition at line 112 of file object_selection.h.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::GetSelectionCount().
|
inline |
Check if any objects are selected.
Definition at line 117 of file object_selection.h.
References selected_indices_.
Referenced by yaze::editor::DungeonObjectInteraction::HandleCanvasMouseInput(), yaze::editor::DungeonObjectInteraction::HandleLayerKeyboardShortcuts(), yaze::editor::DungeonObjectInteraction::HandleScrollWheelResize(), 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 125 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 136 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::DungeonObjectInteraction::HandleCanvasMouseInput().
| 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 144 of file object_selection.cc.
References LOG_ERROR, rect_end_x_, rect_end_y_, and rectangle_selection_active_.
Referenced by yaze::editor::DungeonObjectInteraction::DrawObjectSelectRect().
| 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 155 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::DungeonObjectInteraction::DrawObjectSelectRect().

| void yaze::editor::ObjectSelection::CancelRectangleSelection | ( | ) |
Cancel rectangle selection without modifying selection.
Definition at line 176 of file object_selection.cc.
References rectangle_selection_active_.
|
inline |
Check if a rectangle selection is in progress.
Definition at line 160 of file object_selection.h.
References rectangle_selection_active_.
Referenced by yaze::editor::DungeonObjectInteraction::DrawObjectSelectRect(), yaze::editor::DungeonObjectInteraction::DrawSelectBox(), 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 180 of file object_selection.cc.
References rect_end_x_, rect_end_y_, rect_start_x_, and rect_start_y_.
Referenced by DrawRectangleSelectionBox().
| void yaze::editor::ObjectSelection::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.
| canvas | Canvas to draw on |
| objects | Object list for position/size information |
| dimension_calculator | Callback to calculate object dimensions (width, height) in pixels |
Definition at line 193 of file object_selection.cc.
References GetLayerTypeColor(), GetObjectBounds(), yaze::gui::Canvas::global_scale(), RoomToCanvasCoordinates(), selected_indices_, and yaze::gui::Canvas::zero_point().
Referenced by yaze::editor::DungeonObjectInteraction::DrawSelectionHighlights().
| void yaze::editor::ObjectSelection::DrawRectangleSelectionBox | ( | gui::Canvas * | canvas | ) |
Draw the active rectangle selection box.
| canvas | Canvas to draw on |
Definition at line 327 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::DungeonObjectInteraction::DrawObjectSelectRect(), and yaze::editor::DungeonObjectInteraction::DrawSelectBox().

| 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 285 of file object_selection.cc.
References yaze::zelda3::GetObjectSubtype().
Referenced by yaze::editor::DungeonObjectInteraction::DrawHoverHighlight(), and DrawSelectionHighlights().

|
inline |
Set callback to be invoked when selection changes.
Definition at line 205 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 220 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 226 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 233 of file object_selection.h.
References active_layer_filter_, and kLayerAll.
|
inline |
Check if layer filtering is active.
Definition at line 241 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 247 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 261 of file object_selection.h.
References active_layer_filter_, and kMaskLayer.
Referenced by yaze::editor::DungeonObjectInteraction::IsMaskModeActive().
|
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 269 of file object_selection.h.
References layers_merged_.
Referenced by yaze::editor::DungeonObjectInteraction::SetLayersMerged().
|
inline |
Check if layers are currently merged.
Definition at line 274 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 362 of file object_selection.cc.
Referenced by yaze::editor::DungeonObjectInteraction::DrawHoverHighlight(), and 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 368 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 374 of file object_selection.cc.
References yaze::zelda3::ObjectDimensionTable::Get().
Referenced by DrawSelectionHighlights(), and IsObjectInRectangle().

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

|
private |
Definition at line 437 of file object_selection.cc.
References active_layer_filter_, kLayer2, kLayerAll, and kMaskLayer.
Referenced by IsObjectInRectangle(), and SelectAll().
|
staticconstexpr |
Definition at line 44 of file object_selection.h.
Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), IsLayerEnabled(), IsLayerFilterActive(), and PassesLayerFilter().
|
staticconstexpr |
Definition at line 45 of file object_selection.h.
Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), GetLayerFilterName(), IsMaskModeActive(), and PassesLayerFilter().
|
staticconstexpr |
Definition at line 46 of file object_selection.h.
Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), and GetLayerFilterName().
|
staticconstexpr |
Definition at line 47 of file object_selection.h.
Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), GetLayerFilterName(), and PassesLayerFilter().
|
staticconstexpr |
Definition at line 48 of file object_selection.h.
Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), and GetLayerFilterName().
|
private |
Definition at line 307 of file object_selection.h.
Referenced by ClearSelection(), DrawSelectionHighlights(), GetPrimarySelection(), GetSelectedIndices(), GetSelectionCount(), HasSelection(), IsObjectSelected(), SelectAll(), SelectAll(), SelectObject(), and SelectObjectsInRect().
|
private |
Definition at line 310 of file object_selection.h.
Referenced by BeginRectangleSelection(), CancelRectangleSelection(), DrawRectangleSelectionBox(), EndRectangleSelection(), IsRectangleSelectionActive(), and UpdateRectangleSelection().
|
private |
Definition at line 311 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), and GetRectangleSelectionBounds().
|
private |
Definition at line 312 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), and GetRectangleSelectionBounds().
|
private |
Definition at line 313 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), GetRectangleSelectionBounds(), and UpdateRectangleSelection().
|
private |
Definition at line 314 of file object_selection.h.
Referenced by BeginRectangleSelection(), EndRectangleSelection(), GetRectangleSelectionBounds(), and UpdateRectangleSelection().
|
private |
Definition at line 317 of file object_selection.h.
Referenced by GetLayerFilter(), GetLayerFilterName(), IsLayerEnabled(), IsLayerFilterActive(), IsMaskModeActive(), PassesLayerFilter(), and SetLayerFilter().
|
private |
Definition at line 318 of file object_selection.h.
Referenced by AreLayersMerged(), and SetLayersMerged().
|
private |
Definition at line 321 of file object_selection.h.
Referenced by NotifySelectionChanged(), and SetSelectionChangedCallback().