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 |
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:
Definition at line 57 of file canvas_interaction_handler.h.
|
default |
| void yaze::gui::CanvasInteractionHandler::Initialize | ( | const std::string & | canvas_id | ) |
Initialize the interaction handler.
Definition at line 20 of file canvas_interaction_handler.cc.
References canvas_id_, and ClearState().
Referenced by yaze::gui::Canvas::InitializeDefaults().

|
inline |
Set the interaction mode.
Definition at line 69 of file canvas_interaction_handler.h.
References current_mode_.
|
inline |
Definition at line 70 of file canvas_interaction_handler.h.
References current_mode_.
| TileInteractionResult yaze::gui::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)
| canvas_p0 | Canvas top-left screen position |
| scrolling | Canvas scroll offset |
| global_scale | Canvas zoom scale |
| tile_size | Logical tile size |
| canvas_size | Canvas dimensions |
| is_hovered | Whether mouse is over canvas |
Definition at line 35 of file canvas_interaction_handler.cc.
References current_mode_, hover_points_, and mouse_pos_in_canvas_.
| bool yaze::gui::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)
| bitmap | Tile bitmap to paint |
| draw_list | ImGui draw list |
| canvas_p0 | Canvas top-left position |
| scrolling | Canvas scroll offset |
| global_scale | Canvas zoom scale |
| tile_size | Logical tile size |
| is_hovered | Whether mouse is over canvas |
Definition at line 57 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().

| bool yaze::gui::CanvasInteractionHandler::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)
Definition at line 101 of file canvas_interaction_handler.cc.
References yaze::gui::AlignToGrid(), yaze::gfx::Tilemap::atlas, drawn_tile_pos_, yaze::gfx::Bitmap::height(), hover_points_, yaze::gfx::Bitmap::is_active(), mouse_pos_in_canvas_, yaze::gfx::Bitmap::texture(), yaze::gfx::Tilemap::tile_size, yaze::gfx::Bitmap::width(), yaze::gfx::Pair::x, and yaze::gfx::Pair::y.
| bool yaze::gui::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 162 of file canvas_interaction_handler.cc.
References yaze::gui::AlignToGrid(), drawn_tile_pos_, hover_points_, and mouse_pos_in_canvas_.

| bool yaze::gui::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 211 of file canvas_interaction_handler.cc.
References hover_points_, and mouse_pos_in_canvas_.
| bool yaze::gui::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)
| current_map | Map ID for coordinate calculation |
| draw_list | ImGui draw list |
| canvas_p0 | Canvas position |
| scrolling | Scroll offset |
| global_scale | Zoom scale |
| tile_size | Tile size |
| is_hovered | Whether mouse is over canvas |
Definition at line 235 of file canvas_interaction_handler.cc.
References yaze::gui::CanvasGeometry::canvas_p0, yaze::gui::CanvasGeometry::canvas_sz, yaze::gui::HandleRectangleSelection(), rect_select_active_, yaze::gui::CanvasGeometry::scaled_size, yaze::gui::CanvasGeometry::scrolling, selected_points_, selected_tile_pos_, and selected_tiles_.

|
inline |
Get current hover points (for DrawOverlay)
Definition at line 139 of file canvas_interaction_handler.h.
References hover_points_.
|
inline |
Get selected points (for DrawOverlay)
Definition at line 144 of file canvas_interaction_handler.h.
References selected_points_.
|
inline |
Get selected tiles from last rectangle selection.
Definition at line 149 of file canvas_interaction_handler.h.
References selected_tiles_.
|
inline |
Get last drawn tile position.
Definition at line 154 of file canvas_interaction_handler.h.
References drawn_tile_pos_.
|
inline |
Get current mouse position in canvas space.
Definition at line 159 of file canvas_interaction_handler.h.
References mouse_pos_in_canvas_.
| void yaze::gui::CanvasInteractionHandler::ClearState | ( | ) |
Clear all interaction state.
Definition at line 25 of file canvas_interaction_handler.cc.
References drawn_tile_pos_, hover_points_, mouse_pos_in_canvas_, rect_select_active_, selected_points_, selected_tile_pos_, and selected_tiles_.
Referenced by Initialize().
|
inline |
Check if rectangle selection is active.
Definition at line 169 of file canvas_interaction_handler.h.
References rect_select_active_.
|
inline |
Get selected tile position (for single selection)
Definition at line 174 of file canvas_interaction_handler.h.
References selected_tile_pos_.
|
inline |
Set selected tile position.
Definition at line 179 of file canvas_interaction_handler.h.
References selected_tile_pos_.
|
private |
Definition at line 278 of file canvas_interaction_handler.cc.
|
private |
Definition at line 282 of file canvas_interaction_handler.cc.
|
private |
Definition at line 288 of file canvas_interaction_handler.cc.
|
private |
Definition at line 292 of file canvas_interaction_handler.cc.
|
private |
Definition at line 296 of file canvas_interaction_handler.cc.
|
private |
Definition at line 300 of file canvas_interaction_handler.cc.
|
private |
Definition at line 182 of file canvas_interaction_handler.h.
Referenced by Initialize().
|
private |
Definition at line 183 of file canvas_interaction_handler.h.
|
private |
Definition at line 186 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSolidTilePainter(), DrawTilemapPainter(), DrawTilePainter(), DrawTileSelector(), GetHoverPoints(), and Update().
|
private |
Definition at line 187 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), and GetSelectedPoints().
|
private |
Definition at line 188 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), and GetSelectedTiles().
|
private |
Definition at line 189 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSolidTilePainter(), DrawTilemapPainter(), DrawTilePainter(), and GetDrawnTilePosition().
|
private |
Definition at line 190 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSolidTilePainter(), DrawTilemapPainter(), DrawTilePainter(), DrawTileSelector(), GetMousePositionInCanvas(), and Update().
|
private |
Definition at line 191 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), GetSelectedTilePosition(), and SetSelectedTilePosition().
|
private |
Definition at line 192 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), and IsRectSelectActive().