From 0460a6f638cd4b78720203324cf1c80bbb10e52b Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 27 Sep 2025 18:40:03 -0400 Subject: [PATCH] Refactor tile selection logic in Tile16Editor for improved accuracy - Simplified tile selection detection by integrating it with the tile selector drawing method. - Enhanced click position calculations to use dynamic grid step values, improving responsiveness to different grid sizes. - Rearranged drawing calls for better organization and clarity in the UpdateBlockset method. --- src/app/editor/overworld/tile16_editor.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/app/editor/overworld/tile16_editor.cc b/src/app/editor/overworld/tile16_editor.cc index 3b72997e..d52cfe8d 100644 --- a/src/app/editor/overworld/tile16_editor.cc +++ b/src/app/editor/overworld/tile16_editor.cc @@ -277,20 +277,14 @@ absl::Status Tile16Editor::UpdateBlockset() { gui::EndPadding(); blockset_canvas_.DrawContextMenu(); - blockset_canvas_.DrawTileSelector(32); - blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 0, true, 2.0f); - blockset_canvas_.DrawGrid(); - blockset_canvas_.DrawOverlay(); - EndChild(); - - // Improved blockset tile selection detection - if (blockset_canvas_.WasClicked() || blockset_canvas_.WasDoubleClicked()) { + if (blockset_canvas_.DrawTileSelector(32)) { auto tile_pos = blockset_canvas_.GetLastClickPosition(); - int clicked_x = static_cast(tile_pos.x / 32); - int clicked_y = static_cast(tile_pos.y / 32); + int clicked_x = + static_cast(tile_pos.x / blockset_canvas_.GetGridStep()); + int clicked_y = + static_cast(tile_pos.y / blockset_canvas_.GetGridStep()); int selected_tile = clicked_x + (clicked_y * 8); // 8 tiles per row in blockset - if (selected_tile != current_tile16_ && selected_tile >= 0 && selected_tile < 512) { RETURN_IF_ERROR(SetCurrentTile(selected_tile)); @@ -298,6 +292,10 @@ absl::Status Tile16Editor::UpdateBlockset() { selected_tile, clicked_x, clicked_y); } } + blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 0, true, 2.0f); + blockset_canvas_.DrawGrid(); + blockset_canvas_.DrawOverlay(); + EndChild(); return absl::OkStatus(); }