From a288dd89337a83b86000e2019d917f6087511ae1 Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 20 Aug 2024 11:05:49 -0400 Subject: [PATCH] add DrawCustomHighlight to Canvas --- src/app/gui/canvas.cc | 26 +++++++++++++++----------- src/app/gui/canvas.h | 1 + 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/app/gui/canvas.cc b/src/app/gui/canvas.cc index 2026e624..eb2050f2 100644 --- a/src/app/gui/canvas.cc +++ b/src/app/gui/canvas.cc @@ -647,6 +647,7 @@ void Canvas::DrawInfoGrid(float grid_step, int tile_id_offset, int label_id) { grid_step *= global_scale_; // Apply global scale to grid step DrawGridLines(grid_step); + DrawCustomHighlight(grid_step); if (enable_custom_labels_) { // Draw the contents of labels on the grid @@ -672,6 +673,19 @@ void Canvas::DrawInfoGrid(float grid_step, int tile_id_offset, int label_id) { } } +void Canvas::DrawCustomHighlight(float grid_step) { + if (highlight_tile_id != -1) { + int tile_x = highlight_tile_id % 8; + int tile_y = highlight_tile_id / 8; + ImVec2 tile_pos(canvas_p0_.x + scrolling_.x + tile_x * grid_step, + canvas_p0_.y + scrolling_.y + tile_y * grid_step); + ImVec2 tile_pos_end(tile_pos.x + grid_step, tile_pos.y + grid_step); + + draw_list_->AddRectFilled(tile_pos, tile_pos_end, + IM_COL32(255, 0, 255, 255)); + } +} + void Canvas::DrawGrid(float grid_step, int tile_id_offset) { // Draw grid + all lines in the canvas draw_list_->PushClipRect(canvas_p0_, canvas_p1_, true); @@ -680,17 +694,7 @@ void Canvas::DrawGrid(float grid_step, int tile_id_offset) { grid_step *= global_scale_; // Apply global scale to grid step DrawGridLines(grid_step); - - if (highlight_tile_id != -1) { - int tile_x = highlight_tile_id % 8; - int tile_y = highlight_tile_id / 8; - ImVec2 tile_pos(canvas_p0_.x + scrolling_.x + tile_x * grid_step, - canvas_p0_.y + scrolling_.y + tile_y * grid_step); - ImVec2 tile_pos_end(tile_pos.x + grid_step, tile_pos.y + grid_step); - - draw_list_->AddRectFilled(tile_pos, tile_pos_end, - IM_COL32(255, 0, 255, 255)); - } + DrawCustomHighlight(grid_step); if (enable_hex_tile_labels_) { // Draw the hex ID of the tile in the center of the tile square diff --git a/src/app/gui/canvas.h b/src/app/gui/canvas.h index 07a5c4f4..f03b29cd 100644 --- a/src/app/gui/canvas.h +++ b/src/app/gui/canvas.h @@ -135,6 +135,7 @@ class Canvas : public SharedRom { canvas_sz_ = canvas_size; custom_canvas_size_ = true; } + void DrawCustomHighlight(float grid_step); bool IsMouseHovering() const { return is_hovered_; } void ZoomIn() { global_scale_ += 0.25f; } void ZoomOut() { global_scale_ -= 0.25f; }