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 58 of file canvas_interaction_handler.h.
|
default |
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().
|
inline |
Set the interaction mode.
Definition at line 70 of file canvas_interaction_handler.h.
References current_mode_.
|
inline |
Definition at line 71 of file canvas_interaction_handler.h.
References current_mode_.
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)
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 36 of file canvas_interaction_handler.cc.
References current_mode_, hover_points_, and mouse_pos_in_canvas_.
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)
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 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().
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 | ||
) |
Draw tilemap painter (preview + interaction)
Definition at line 102 of file canvas_interaction_handler.cc.
References 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::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_.
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_.
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)
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 236 of file canvas_interaction_handler.cc.
References rect_select_active_, selected_points_, selected_tile_pos_, and selected_tiles_.
|
inline |
Get current hover points (for DrawOverlay)
Definition at line 140 of file canvas_interaction_handler.h.
References hover_points_.
|
inline |
Get selected points (for DrawOverlay)
Definition at line 145 of file canvas_interaction_handler.h.
References selected_points_.
|
inline |
Get selected tiles from last rectangle selection.
Definition at line 150 of file canvas_interaction_handler.h.
References selected_tiles_.
|
inline |
Get last drawn tile position.
Definition at line 155 of file canvas_interaction_handler.h.
References drawn_tile_pos_.
|
inline |
Get current mouse position in canvas space.
Definition at line 160 of file canvas_interaction_handler.h.
References mouse_pos_in_canvas_.
void yaze::gui::canvas::CanvasInteractionHandler::ClearState | ( | ) |
Clear all interaction state.
Definition at line 26 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 170 of file canvas_interaction_handler.h.
References rect_select_active_.
|
inline |
Get selected tile position (for single selection)
Definition at line 175 of file canvas_interaction_handler.h.
References selected_tile_pos_.
|
inline |
Set selected tile position.
Definition at line 180 of file canvas_interaction_handler.h.
References selected_tile_pos_.
|
private |
Definition at line 341 of file canvas_interaction_handler.cc.
|
private |
Definition at line 345 of file canvas_interaction_handler.cc.
|
private |
Definition at line 351 of file canvas_interaction_handler.cc.
|
private |
Definition at line 355 of file canvas_interaction_handler.cc.
|
private |
Definition at line 359 of file canvas_interaction_handler.cc.
|
private |
Definition at line 363 of file canvas_interaction_handler.cc.
|
private |
Definition at line 183 of file canvas_interaction_handler.h.
Referenced by Initialize().
|
private |
Definition at line 184 of file canvas_interaction_handler.h.
|
private |
Definition at line 187 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSolidTilePainter(), DrawTilemapPainter(), DrawTilePainter(), DrawTileSelector(), GetHoverPoints(), and Update().
|
private |
Definition at line 188 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), and GetSelectedPoints().
|
private |
Definition at line 189 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), and GetSelectedTiles().
|
private |
Definition at line 190 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSolidTilePainter(), DrawTilemapPainter(), DrawTilePainter(), and GetDrawnTilePosition().
|
private |
Definition at line 191 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSolidTilePainter(), DrawTilemapPainter(), DrawTilePainter(), DrawTileSelector(), GetMousePositionInCanvas(), and Update().
|
private |
Definition at line 192 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), GetSelectedTilePosition(), and SetSelectedTilePosition().
|
private |
Definition at line 193 of file canvas_interaction_handler.h.
Referenced by ClearState(), DrawSelectRect(), and IsRectSelectActive().