remove unused canvas update routines

This commit is contained in:
scawful
2024-07-18 22:58:26 -04:00
parent 9cee1ec75c
commit 2ff79816ee
2 changed files with 56 additions and 41 deletions

View File

@@ -18,20 +18,6 @@ constexpr uint32_t kRectangleBorder = IM_COL32(255, 255, 255, 255);
constexpr ImGuiButtonFlags kMouseFlags = constexpr ImGuiButtonFlags kMouseFlags =
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight; ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight;
void Canvas::Update(const gfx::Bitmap &bitmap, ImVec2 bg_size, int tile_size,
float scale, float grid_size) {
if (scale != 1.0f) {
bg_size.x *= scale / 2;
bg_size.y *= scale / 2;
}
DrawBackground(bg_size);
DrawContextMenu();
DrawTileSelector(tile_size);
DrawBitmap(bitmap, 2, scale);
DrawGrid(grid_size);
DrawOverlay();
}
void Canvas::UpdateColorPainter(gfx::Bitmap &bitmap, const ImVec4 &color, void Canvas::UpdateColorPainter(gfx::Bitmap &bitmap, const ImVec4 &color,
const std::function<void()> &event, const std::function<void()> &event,
int tile_size, float scale) { int tile_size, float scale) {
@@ -46,15 +32,6 @@ void Canvas::UpdateColorPainter(gfx::Bitmap &bitmap, const ImVec4 &color,
DrawOverlay(); DrawOverlay();
} }
void Canvas::UpdateEvent(const std::function<void()> &event, ImVec2 bg_size,
int tile_size, float scale, float grid_size) {
DrawBackground(bg_size);
DrawContextMenu();
event();
DrawGrid(grid_size);
DrawOverlay();
}
void Canvas::UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale, void Canvas::UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale,
float grid_size) { float grid_size) {
enable_custom_labels_ = true; enable_custom_labels_ = true;
@@ -694,6 +671,48 @@ void Canvas::DrawOverlay() {
draw_list_->PopClipRect(); draw_list_->PopClipRect();
} }
void Canvas::DrawLayeredElements() {
// Based on ImGui demo, should be adapted to use for OAM
ImDrawList *draw_list = ImGui::GetWindowDrawList();
{
ImGui::Text("Blue shape is drawn first: appears in back");
ImGui::Text("Red shape is drawn after: appears in front");
ImVec2 p0 = ImGui::GetCursorScreenPos();
draw_list->AddRectFilled(ImVec2(p0.x, p0.y), ImVec2(p0.x + 50, p0.y + 50),
IM_COL32(0, 0, 255, 255)); // Blue
draw_list->AddRectFilled(ImVec2(p0.x + 25, p0.y + 25),
ImVec2(p0.x + 75, p0.y + 75),
IM_COL32(255, 0, 0, 255)); // Red
ImGui::Dummy(ImVec2(75, 75));
}
ImGui::Separator();
{
ImGui::Text("Blue shape is drawn first, into channel 1: appears in front");
ImGui::Text("Red shape is drawn after, into channel 0: appears in back");
ImVec2 p1 = ImGui::GetCursorScreenPos();
// Create 2 channels and draw a Blue shape THEN a Red shape.
// You can create any number of channels. Tables API use 1 channel per
// column in order to better batch draw calls.
draw_list->ChannelsSplit(2);
draw_list->ChannelsSetCurrent(1);
draw_list->AddRectFilled(ImVec2(p1.x, p1.y), ImVec2(p1.x + 50, p1.y + 50),
IM_COL32(0, 0, 255, 255)); // Blue
draw_list->ChannelsSetCurrent(0);
draw_list->AddRectFilled(ImVec2(p1.x + 25, p1.y + 25),
ImVec2(p1.x + 75, p1.y + 75),
IM_COL32(255, 0, 0, 255)); // Red
// Flatten/reorder channels. Red shape is in channel 0 and it appears
// below the Blue shape in channel 1. This works by copying draw indices
// only (vertices are not copied).
draw_list->ChannelsMerge();
ImGui::Dummy(ImVec2(75, 75));
ImGui::Text(
"After reordering, contents of channel 0 appears below channel 1.");
}
}
} // namespace gui } // namespace gui
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -56,16 +56,10 @@ class Canvas {
} }
} }
void Update(const gfx::Bitmap& bitmap, ImVec2 bg_size, int tile_size,
float scale = 1.0f, float grid_size = 64.0f);
void UpdateColorPainter(gfx::Bitmap& bitmap, const ImVec4& color, void UpdateColorPainter(gfx::Bitmap& bitmap, const ImVec4& color,
const std::function<void()>& event, int tile_size, const std::function<void()>& event, int tile_size,
float scale = 1.0f); float scale = 1.0f);
void UpdateEvent(const std::function<void()>& event, ImVec2 bg_size,
int tile_size, float scale = 1.0f, float grid_size = 64.0f);
void UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale = 1.0f, void UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale = 1.0f,
float grid_size = 64.0f); float grid_size = 64.0f);
@@ -116,6 +110,20 @@ class Canvas {
void DrawGridLines(float grid_step); void DrawGridLines(float grid_step);
void DrawGrid(float grid_step = 64.0f, int tile_id_offset = 8); void DrawGrid(float grid_step = 64.0f, int tile_id_offset = 8);
void DrawOverlay(); // last void DrawOverlay(); // last
void DrawLayeredElements();
int GetTileIdFromMousePos() {
int x = mouse_pos_in_canvas_.x;
int y = mouse_pos_in_canvas_.y;
int num_columns = canvas_sz_.x / custom_step_;
int num_rows = canvas_sz_.y / custom_step_;
int tile_id = (x / custom_step_) + (y / custom_step_) * num_columns;
if (tile_id >= num_columns * num_rows) {
tile_id = -1; // Invalid tile ID
}
return tile_id;
}
void SetCanvasSize(ImVec2 canvas_size) { void SetCanvasSize(ImVec2 canvas_size) {
canvas_sz_ = canvas_size; canvas_sz_ = canvas_size;
custom_canvas_size_ = true; custom_canvas_size_ = true;
@@ -158,18 +166,6 @@ class Canvas {
return &labels_[i]; return &labels_[i];
} }
int GetTileIdFromMousePos() {
int x = mouse_pos_in_canvas_.x;
int y = mouse_pos_in_canvas_.y;
int num_columns = width() / custom_step_;
int num_rows = height() / custom_step_;
int tile_id = (x / custom_step_) + (y / custom_step_) * num_columns;
if (tile_id >= num_columns * num_rows) {
tile_id = -1; // Invalid tile ID
}
return tile_id;
}
auto set_current_labels(int i) { current_labels_ = i; } auto set_current_labels(int i) { current_labels_ = i; }
auto set_highlight_tile_id(int i) { highlight_tile_id = i; } auto set_highlight_tile_id(int i) { highlight_tile_id = i; }