yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::ObjectSelection Class Reference

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_
 

Detailed Description

Manages object selection state and operations for the dungeon editor.

Provides comprehensive selection functionality including:

  • Single selection (click)
  • Multi-selection (Shift+click, Ctrl+click)
  • Rectangle selection (drag)
  • Select all (Ctrl+A)
  • Selection highlighting and visual feedback
  • Layer-aware selection with filter toggles

Design Philosophy:

  • Single Responsibility: Only manages selection state and operations
  • Composable: Can be used by DungeonObjectInteraction for interaction logic
  • Testable: Pure functions for selection logic where possible

Definition at line 34 of file object_selection.h.

Member Enumeration Documentation

◆ SelectionMode

Enumerator
Single 
Add 
Toggle 
Rectangle 

Definition at line 36 of file object_selection.h.

Constructor & Destructor Documentation

◆ ObjectSelection()

yaze::editor::ObjectSelection::ObjectSelection ( )
explicitdefault

Member Function Documentation

◆ SelectObject()

◆ SelectObjectsInRect()

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.

Parameters
room_min_xMinimum X coordinate in room tiles
room_min_yMinimum Y coordinate in room tiles
room_max_xMaximum X coordinate in room tiles
room_max_yMaximum Y coordinate in room tiles
objectsObject list to select from
modeHow to modify the selection

Definition at line 49 of file object_selection.cc.

References IsObjectInRectangle(), NotifySelectionChanged(), selected_indices_, Single, and Toggle.

Referenced by EndRectangleSelection().

Here is the call graph for this function:

◆ SelectAll() [1/2]

void yaze::editor::ObjectSelection::SelectAll ( size_t object_count)

Select all objects in the current room.

Parameters
object_countTotal number of objects in the room
Note
This version doesn't respect layer filtering - use the overload with objects list for layer-aware selection

Definition at line 83 of file object_selection.cc.

References NotifySelectionChanged(), and selected_indices_.

Here is the call graph for this function:

◆ SelectAll() [2/2]

void yaze::editor::ObjectSelection::SelectAll ( const std::vector< zelda3::RoomObject > & objects)

Select all objects in the current room respecting layer filter.

Parameters
objectsObject list to select from

Definition at line 91 of file object_selection.cc.

References NotifySelectionChanged(), PassesLayerFilter(), and selected_indices_.

Here is the call graph for this function:

◆ ClearSelection()

◆ IsObjectSelected()

bool yaze::editor::ObjectSelection::IsObjectSelected ( size_t index) const

◆ GetSelectedIndices()

◆ GetSelectionCount()

size_t yaze::editor::ObjectSelection::GetSelectionCount ( ) const
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().

◆ HasSelection()

◆ GetPrimarySelection()

std::optional< size_t > yaze::editor::ObjectSelection::GetPrimarySelection ( ) const

Get the primary selected object (first in selection)

Returns
Index of primary object, or nullopt if none selected

Definition at line 125 of file object_selection.cc.

References selected_indices_.

◆ BeginRectangleSelection()

void yaze::editor::ObjectSelection::BeginRectangleSelection ( int canvas_x,
int canvas_y )

Begin a rectangle selection operation.

Parameters
canvas_xStarting X position in canvas coordinates
canvas_yStarting 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().

◆ UpdateRectangleSelection()

void yaze::editor::ObjectSelection::UpdateRectangleSelection ( int canvas_x,
int canvas_y )

Update rectangle selection endpoint.

Parameters
canvas_xCurrent X position in canvas coordinates
canvas_yCurrent 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().

◆ EndRectangleSelection()

void yaze::editor::ObjectSelection::EndRectangleSelection ( const std::vector< zelda3::RoomObject > & objects,
SelectionMode mode = SelectionMode::Single )

Complete rectangle selection operation.

Parameters
objectsObject list to select from
modeHow 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().

Here is the call graph for this function:

◆ CancelRectangleSelection()

void yaze::editor::ObjectSelection::CancelRectangleSelection ( )

Cancel rectangle selection without modifying selection.

Definition at line 176 of file object_selection.cc.

References rectangle_selection_active_.

◆ IsRectangleSelectionActive()

bool yaze::editor::ObjectSelection::IsRectangleSelectionActive ( ) const
inline

◆ GetRectangleSelectionBounds()

std::tuple< int, int, int, int > yaze::editor::ObjectSelection::GetRectangleSelectionBounds ( ) const

Get rectangle selection bounds in canvas coordinates.

Returns
{min_x, min_y, max_x, max_y}

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().

◆ DrawSelectionHighlights()

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.

Parameters
canvasCanvas to draw on
objectsObject list for position/size information
dimension_calculatorCallback 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().

◆ DrawRectangleSelectionBox()

void yaze::editor::ObjectSelection::DrawRectangleSelectionBox ( gui::Canvas * canvas)

Draw the active rectangle selection box.

Parameters
canvasCanvas 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().

Here is the call graph for this function:

◆ GetLayerTypeColor()

ImVec4 yaze::editor::ObjectSelection::GetLayerTypeColor ( const zelda3::RoomObject & object) const

Get selection highlight color based on object layer and type.

Parameters
objectThe room object to get color for
Returns
Color as ImVec4 (Layer 0=Cyan, Layer 1=Orange, Layer 2=Magenta)

Definition at line 285 of file object_selection.cc.

References yaze::zelda3::GetObjectSubtype().

Referenced by yaze::editor::DungeonObjectInteraction::DrawHoverHighlight(), and DrawSelectionHighlights().

Here is the call graph for this function:

◆ SetSelectionChangedCallback()

void yaze::editor::ObjectSelection::SetSelectionChangedCallback ( std::function< void()> callback)
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().

◆ SetLayerFilter()

void yaze::editor::ObjectSelection::SetLayerFilter ( int layer)
inline

Set the active layer filter for selection.

Parameters
layerLayer 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().

◆ GetLayerFilter()

int yaze::editor::ObjectSelection::GetLayerFilter ( ) const
inline

Get the current active layer filter.

Returns
Current layer filter value

Definition at line 226 of file object_selection.h.

References active_layer_filter_.

Referenced by yaze::editor::DungeonObjectInteraction::GetLayerFilter().

◆ IsLayerEnabled()

bool yaze::editor::ObjectSelection::IsLayerEnabled ( int layer) const
inline

Check if a specific layer is enabled for selection.

Parameters
layerLayer to check (0, 1, or 2)
Returns
true if objects on this layer can be selected

Definition at line 233 of file object_selection.h.

References active_layer_filter_, and kLayerAll.

◆ IsLayerFilterActive()

bool yaze::editor::ObjectSelection::IsLayerFilterActive ( ) const
inline

Check if layer filtering is active.

Returns
true if filtering to a specific layer

Definition at line 241 of file object_selection.h.

References active_layer_filter_, and kLayerAll.

Referenced by yaze::editor::DungeonObjectInteraction::IsLayerFilterActive().

◆ GetLayerFilterName()

const char * yaze::editor::ObjectSelection::GetLayerFilterName ( ) const
inline

Get the name of the current layer filter for display.

Returns
Human-readable layer name

Definition at line 247 of file object_selection.h.

References active_layer_filter_, kLayer1, kLayer2, kLayer3, and kMaskLayer.

Referenced by yaze::editor::DungeonObjectInteraction::GetLayerFilterName().

◆ IsMaskModeActive()

bool yaze::editor::ObjectSelection::IsMaskModeActive ( ) const
inline

Check if mask selection mode is active.

Returns
true if only BG2/Layer 1 objects can be selected

Definition at line 261 of file object_selection.h.

References active_layer_filter_, and kMaskLayer.

Referenced by yaze::editor::DungeonObjectInteraction::IsMaskModeActive().

◆ SetLayersMerged()

void yaze::editor::ObjectSelection::SetLayersMerged ( bool merged)
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().

◆ AreLayersMerged()

bool yaze::editor::ObjectSelection::AreLayersMerged ( ) const
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().

◆ RoomToCanvasCoordinates()

std::pair< int, int > yaze::editor::ObjectSelection::RoomToCanvasCoordinates ( int room_x,
int room_y )
static

Convert room tile coordinates to canvas pixel coordinates.

Parameters
room_xRoom X coordinate (0-63)
room_yRoom Y coordinate (0-63)
Returns
{canvas_x, canvas_y} in unscaled pixels

Definition at line 362 of file object_selection.cc.

Referenced by yaze::editor::DungeonObjectInteraction::DrawHoverHighlight(), and DrawSelectionHighlights().

◆ CanvasToRoomCoordinates()

std::pair< int, int > yaze::editor::ObjectSelection::CanvasToRoomCoordinates ( int canvas_x,
int canvas_y )
static

Convert canvas pixel coordinates to room tile coordinates.

Parameters
canvas_xCanvas X coordinate (pixels)
canvas_yCanvas Y coordinate (pixels)
Returns
{room_x, room_y} in tiles (0-63)

Definition at line 368 of file object_selection.cc.

Referenced by EndRectangleSelection().

◆ GetObjectBounds()

std::tuple< int, int, int, int > yaze::editor::ObjectSelection::GetObjectBounds ( const zelda3::RoomObject & object)
static

Calculate the bounding box of an object.

Parameters
objectObject to calculate bounds for
Returns
{x, y, width, height} in room tiles

Definition at line 374 of file object_selection.cc.

References yaze::zelda3::ObjectDimensionTable::Get().

Referenced by DrawSelectionHighlights(), and IsObjectInRectangle().

Here is the call graph for this function:

◆ NotifySelectionChanged()

void yaze::editor::ObjectSelection::NotifySelectionChanged ( )
private

◆ IsObjectInRectangle()

bool yaze::editor::ObjectSelection::IsObjectInRectangle ( const zelda3::RoomObject & object,
int min_x,
int min_y,
int max_x,
int max_y ) const
private

Definition at line 412 of file object_selection.cc.

References GetObjectBounds(), and PassesLayerFilter().

Referenced by SelectObjectsInRect().

Here is the call graph for this function:

◆ PassesLayerFilter()

bool yaze::editor::ObjectSelection::PassesLayerFilter ( const zelda3::RoomObject & object) const
private

Definition at line 437 of file object_selection.cc.

References active_layer_filter_, kLayer2, kLayerAll, and kMaskLayer.

Referenced by IsObjectInRectangle(), and SelectAll().

Member Data Documentation

◆ kLayerAll

constexpr int yaze::editor::ObjectSelection::kLayerAll = -1
staticconstexpr

◆ kMaskLayer

constexpr int yaze::editor::ObjectSelection::kMaskLayer = -2
staticconstexpr

◆ kLayer1

constexpr int yaze::editor::ObjectSelection::kLayer1 = 0
staticconstexpr

◆ kLayer2

constexpr int yaze::editor::ObjectSelection::kLayer2 = 1
staticconstexpr

◆ kLayer3

constexpr int yaze::editor::ObjectSelection::kLayer3 = 2
staticconstexpr

◆ selected_indices_

std::set<size_t> yaze::editor::ObjectSelection::selected_indices_
private

◆ rectangle_selection_active_

bool yaze::editor::ObjectSelection::rectangle_selection_active_ = false
private

◆ rect_start_x_

int yaze::editor::ObjectSelection::rect_start_x_ = 0
private

◆ rect_start_y_

int yaze::editor::ObjectSelection::rect_start_y_ = 0
private

◆ rect_end_x_

int yaze::editor::ObjectSelection::rect_end_x_ = 0
private

◆ rect_end_y_

int yaze::editor::ObjectSelection::rect_end_y_ = 0
private

◆ active_layer_filter_

int yaze::editor::ObjectSelection::active_layer_filter_ = kLayerAll
private

◆ layers_merged_

bool yaze::editor::ObjectSelection::layers_merged_ = false
private

Definition at line 318 of file object_selection.h.

Referenced by AreLayersMerged(), and SetLayersMerged().

◆ selection_changed_callback_

std::function<void()> yaze::editor::ObjectSelection::selection_changed_callback_
private

Definition at line 321 of file object_selection.h.

Referenced by NotifySelectionChanged(), and SetSelectionChangedCallback().


The documentation for this class was generated from the following files: