yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gui::canvas::CanvasInteractionHandler Class Reference

Handles all tile-based interactions for Canvas. More...

#include <canvas_interaction_handler.h>

Public Member Functions

 CanvasInteractionHandler ()=default
 
void Initialize (const std::string &canvas_id)
 Initialize the interaction handler.
 
void SetMode (TileInteractionMode mode)
 Set the interaction mode.
 
TileInteractionMode GetMode () const
 
TileInteractionResult Update (ImVec2 canvas_p0, ImVec2 scrolling, float global_scale, float tile_size, ImVec2 canvas_size, bool is_hovered)
 Update interaction state (call once per frame)
 
bool DrawTilePainter (const gfx::Bitmap &bitmap, ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, float global_scale, float tile_size, bool is_hovered)
 Draw tile painter (preview + interaction)
 
bool DrawTilemapPainter (gfx::Tilemap &tilemap, int current_tile, ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, float global_scale, bool is_hovered)
 Draw tilemap painter (preview + interaction)
 
bool DrawSolidTilePainter (const ImVec4 &color, ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, float global_scale, float tile_size, bool is_hovered)
 Draw solid color painter.
 
bool DrawTileSelector (ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, float tile_size, bool is_hovered)
 Draw tile selector (single tile selection)
 
bool DrawSelectRect (int current_map, ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, float global_scale, float tile_size, bool is_hovered)
 Draw rectangle selector (multi-tile selection)
 
const ImVector< ImVec2 > & GetHoverPoints () const
 Get current hover points (for DrawOverlay)
 
const ImVector< ImVec2 > & GetSelectedPoints () const
 Get selected points (for DrawOverlay)
 
const std::vector< ImVec2 > & GetSelectedTiles () const
 Get selected tiles from last rectangle selection.
 
ImVec2 GetDrawnTilePosition () const
 Get last drawn tile position.
 
ImVec2 GetMousePositionInCanvas () const
 Get current mouse position in canvas space.
 
void ClearState ()
 Clear all interaction state.
 
bool IsRectSelectActive () const
 Check if rectangle selection is active.
 
ImVec2 GetSelectedTilePosition () const
 Get selected tile position (for single selection)
 
void SetSelectedTilePosition (ImVec2 pos)
 Set selected tile position.
 

Private Member Functions

ImVec2 AlignPosToGrid (ImVec2 pos, float grid_step)
 
ImVec2 GetMousePosition (ImVec2 canvas_p0, ImVec2 scrolling)
 
bool IsMouseClicked (ImGuiMouseButton button)
 
bool IsMouseDoubleClicked (ImGuiMouseButton button)
 
bool IsMouseDragging (ImGuiMouseButton button)
 
bool IsMouseReleased (ImGuiMouseButton button)
 

Private Attributes

std::string canvas_id_
 
TileInteractionMode current_mode_ = TileInteractionMode::kNone
 
ImVector< ImVec2 > hover_points_
 
ImVector< ImVec2 > selected_points_
 
std::vector< ImVec2 > selected_tiles_
 
ImVec2 drawn_tile_pos_ = ImVec2(-1, -1)
 
ImVec2 mouse_pos_in_canvas_ = ImVec2(0, 0)
 
ImVec2 selected_tile_pos_ = ImVec2(-1, -1)
 
bool rect_select_active_ = false
 

Detailed Description

Handles all tile-based interactions for Canvas.

Consolidates tile painting, selection, and multi-selection logic that was previously scattered across Canvas methods. Provides a unified interface for common tile interaction patterns.

Key Features:

  • Single tile painting with preview
  • Drag painting for continuous tile placement
  • Single tile selection
  • Rectangle selection for multi-tile operations
  • Color painting mode
  • Grid-aligned positioning
  • Hover preview

Definition at line 58 of file canvas_interaction_handler.h.

Constructor & Destructor Documentation

◆ CanvasInteractionHandler()

yaze::gui::canvas::CanvasInteractionHandler::CanvasInteractionHandler ( )
default

Member Function Documentation

◆ Initialize()

void yaze::gui::canvas::CanvasInteractionHandler::Initialize ( const std::string &  canvas_id)

Initialize the interaction handler.

Definition at line 21 of file canvas_interaction_handler.cc.

References canvas_id_, and ClearState().

Referenced by yaze::gui::Canvas::InitializeDefaults().

Here is the call graph for this function:

◆ SetMode()

void yaze::gui::canvas::CanvasInteractionHandler::SetMode ( TileInteractionMode  mode)
inline

Set the interaction mode.

Definition at line 70 of file canvas_interaction_handler.h.

References current_mode_.

◆ GetMode()

TileInteractionMode yaze::gui::canvas::CanvasInteractionHandler::GetMode ( ) const
inline

Definition at line 71 of file canvas_interaction_handler.h.

References current_mode_.

◆ Update()

TileInteractionResult yaze::gui::canvas::CanvasInteractionHandler::Update ( ImVec2  canvas_p0,
ImVec2  scrolling,
float  global_scale,
float  tile_size,
ImVec2  canvas_size,
bool  is_hovered 
)

Update interaction state (call once per frame)

Parameters
canvas_p0Canvas top-left screen position
scrollingCanvas scroll offset
global_scaleCanvas zoom scale
tile_sizeLogical tile size
canvas_sizeCanvas dimensions
is_hoveredWhether mouse is over canvas
Returns
Interaction result for this frame

Definition at line 36 of file canvas_interaction_handler.cc.

References current_mode_, hover_points_, and mouse_pos_in_canvas_.

◆ DrawTilePainter()

bool yaze::gui::canvas::CanvasInteractionHandler::DrawTilePainter ( const gfx::Bitmap bitmap,
ImDrawList *  draw_list,
ImVec2  canvas_p0,
ImVec2  scrolling,
float  global_scale,
float  tile_size,
bool  is_hovered 
)

Draw tile painter (preview + interaction)

Parameters
bitmapTile bitmap to paint
draw_listImGui draw list
canvas_p0Canvas top-left position
scrollingCanvas scroll offset
global_scaleCanvas zoom scale
tile_sizeLogical tile size
is_hoveredWhether mouse is over canvas
Returns
True if tile was painted

Definition at line 58 of file canvas_interaction_handler.cc.

References drawn_tile_pos_, hover_points_, yaze::gfx::Bitmap::is_active(), mouse_pos_in_canvas_, and yaze::gfx::Bitmap::texture().

Here is the call graph for this function:

◆ DrawTilemapPainter()

bool yaze::gui::canvas::CanvasInteractionHandler::DrawTilemapPainter ( gfx::Tilemap tilemap,
int  current_tile,
ImDrawList *  draw_list,
ImVec2  canvas_p0,
ImVec2  scrolling,
float  global_scale,
bool  is_hovered 
)

◆ DrawSolidTilePainter()

bool yaze::gui::canvas::CanvasInteractionHandler::DrawSolidTilePainter ( const ImVec4 &  color,
ImDrawList *  draw_list,
ImVec2  canvas_p0,
ImVec2  scrolling,
float  global_scale,
float  tile_size,
bool  is_hovered 
)

Draw solid color painter.

Definition at line 163 of file canvas_interaction_handler.cc.

References drawn_tile_pos_, hover_points_, and mouse_pos_in_canvas_.

◆ DrawTileSelector()

bool yaze::gui::canvas::CanvasInteractionHandler::DrawTileSelector ( ImDrawList *  draw_list,
ImVec2  canvas_p0,
ImVec2  scrolling,
float  tile_size,
bool  is_hovered 
)

Draw tile selector (single tile selection)

Definition at line 212 of file canvas_interaction_handler.cc.

References hover_points_, and mouse_pos_in_canvas_.

◆ DrawSelectRect()

bool yaze::gui::canvas::CanvasInteractionHandler::DrawSelectRect ( int  current_map,
ImDrawList *  draw_list,
ImVec2  canvas_p0,
ImVec2  scrolling,
float  global_scale,
float  tile_size,
bool  is_hovered 
)

Draw rectangle selector (multi-tile selection)

Parameters
current_mapMap ID for coordinate calculation
draw_listImGui draw list
canvas_p0Canvas position
scrollingScroll offset
global_scaleZoom scale
tile_sizeTile size
is_hoveredWhether mouse is over canvas
Returns
True if selection was made

Definition at line 236 of file canvas_interaction_handler.cc.

References rect_select_active_, selected_points_, selected_tile_pos_, and selected_tiles_.

◆ GetHoverPoints()

const ImVector< ImVec2 > & yaze::gui::canvas::CanvasInteractionHandler::GetHoverPoints ( ) const
inline

Get current hover points (for DrawOverlay)

Definition at line 140 of file canvas_interaction_handler.h.

References hover_points_.

◆ GetSelectedPoints()

const ImVector< ImVec2 > & yaze::gui::canvas::CanvasInteractionHandler::GetSelectedPoints ( ) const
inline

Get selected points (for DrawOverlay)

Definition at line 145 of file canvas_interaction_handler.h.

References selected_points_.

◆ GetSelectedTiles()

const std::vector< ImVec2 > & yaze::gui::canvas::CanvasInteractionHandler::GetSelectedTiles ( ) const
inline

Get selected tiles from last rectangle selection.

Definition at line 150 of file canvas_interaction_handler.h.

References selected_tiles_.

◆ GetDrawnTilePosition()

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::GetDrawnTilePosition ( ) const
inline

Get last drawn tile position.

Definition at line 155 of file canvas_interaction_handler.h.

References drawn_tile_pos_.

◆ GetMousePositionInCanvas()

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::GetMousePositionInCanvas ( ) const
inline

Get current mouse position in canvas space.

Definition at line 160 of file canvas_interaction_handler.h.

References mouse_pos_in_canvas_.

◆ ClearState()

void yaze::gui::canvas::CanvasInteractionHandler::ClearState ( )

◆ IsRectSelectActive()

bool yaze::gui::canvas::CanvasInteractionHandler::IsRectSelectActive ( ) const
inline

Check if rectangle selection is active.

Definition at line 170 of file canvas_interaction_handler.h.

References rect_select_active_.

◆ GetSelectedTilePosition()

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::GetSelectedTilePosition ( ) const
inline

Get selected tile position (for single selection)

Definition at line 175 of file canvas_interaction_handler.h.

References selected_tile_pos_.

◆ SetSelectedTilePosition()

void yaze::gui::canvas::CanvasInteractionHandler::SetSelectedTilePosition ( ImVec2  pos)
inline

Set selected tile position.

Definition at line 180 of file canvas_interaction_handler.h.

References selected_tile_pos_.

◆ AlignPosToGrid()

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::AlignPosToGrid ( ImVec2  pos,
float  grid_step 
)
private

Definition at line 341 of file canvas_interaction_handler.cc.

◆ GetMousePosition()

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::GetMousePosition ( ImVec2  canvas_p0,
ImVec2  scrolling 
)
private

Definition at line 345 of file canvas_interaction_handler.cc.

◆ IsMouseClicked()

bool yaze::gui::canvas::CanvasInteractionHandler::IsMouseClicked ( ImGuiMouseButton  button)
private

Definition at line 351 of file canvas_interaction_handler.cc.

◆ IsMouseDoubleClicked()

bool yaze::gui::canvas::CanvasInteractionHandler::IsMouseDoubleClicked ( ImGuiMouseButton  button)
private

Definition at line 355 of file canvas_interaction_handler.cc.

◆ IsMouseDragging()

bool yaze::gui::canvas::CanvasInteractionHandler::IsMouseDragging ( ImGuiMouseButton  button)
private

Definition at line 359 of file canvas_interaction_handler.cc.

◆ IsMouseReleased()

bool yaze::gui::canvas::CanvasInteractionHandler::IsMouseReleased ( ImGuiMouseButton  button)
private

Definition at line 363 of file canvas_interaction_handler.cc.

Member Data Documentation

◆ canvas_id_

std::string yaze::gui::canvas::CanvasInteractionHandler::canvas_id_
private

Definition at line 183 of file canvas_interaction_handler.h.

Referenced by Initialize().

◆ current_mode_

TileInteractionMode yaze::gui::canvas::CanvasInteractionHandler::current_mode_ = TileInteractionMode::kNone
private

Definition at line 184 of file canvas_interaction_handler.h.

Referenced by GetMode(), SetMode(), and Update().

◆ hover_points_

ImVector<ImVec2> yaze::gui::canvas::CanvasInteractionHandler::hover_points_
private

◆ selected_points_

ImVector<ImVec2> yaze::gui::canvas::CanvasInteractionHandler::selected_points_
private

Definition at line 188 of file canvas_interaction_handler.h.

Referenced by ClearState(), DrawSelectRect(), and GetSelectedPoints().

◆ selected_tiles_

std::vector<ImVec2> yaze::gui::canvas::CanvasInteractionHandler::selected_tiles_
private

Definition at line 189 of file canvas_interaction_handler.h.

Referenced by ClearState(), DrawSelectRect(), and GetSelectedTiles().

◆ drawn_tile_pos_

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::drawn_tile_pos_ = ImVec2(-1, -1)
private

◆ mouse_pos_in_canvas_

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::mouse_pos_in_canvas_ = ImVec2(0, 0)
private

◆ selected_tile_pos_

ImVec2 yaze::gui::canvas::CanvasInteractionHandler::selected_tile_pos_ = ImVec2(-1, -1)
private

◆ rect_select_active_

bool yaze::gui::canvas::CanvasInteractionHandler::rect_select_active_ = false
private

Definition at line 193 of file canvas_interaction_handler.h.

Referenced by ClearState(), DrawSelectRect(), and IsRectSelectActive().


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