From 585413e6d63fe202ea21b3fc3a03c5a29442171e Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 9 Jul 2023 10:35:44 -0400 Subject: [PATCH] Add DrawBitmapTable to Canvas class --- src/app/gui/canvas.cc | 14 ++++++++++++++ src/app/gui/canvas.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/app/gui/canvas.cc b/src/app/gui/canvas.cc index 29d03f15..a8f0685a 100644 --- a/src/app/gui/canvas.cc +++ b/src/app/gui/canvas.cc @@ -163,6 +163,20 @@ void Canvas::DrawBitmap(const Bitmap &bitmap, int x_offset, int y_offset) { canvas_p0_.y + y_offset + scrolling_.y + (bitmap.GetHeight()))); } +// TODO: Add parameters for sizing and positioning +void Canvas::DrawBitmapTable(const BitmapTable gfx_bin) { + for (const auto &[key, value] : gfx_bin) { + int offset = 0x40 * (key + 1); + int top_left_y = canvas_p0_.y + 2; + if (key >= 1) { + top_left_y = canvas_p0_.y + 0x40 * key; + } + draw_list_->AddImage((void *)value.GetTexture(), + ImVec2(canvas_p0_.x + 2, top_left_y), + ImVec2(canvas_p0_.x + 0x100, canvas_p0_.y + offset)); + } +} + void Canvas::DrawOutline(int x, int y, int w, int h) { ImVec2 origin(canvas_p0_.x + scrolling_.x + x, canvas_p0_.y + scrolling_.y + y); diff --git a/src/app/gui/canvas.h b/src/app/gui/canvas.h index 0503c22b..a23c1eaf 100644 --- a/src/app/gui/canvas.h +++ b/src/app/gui/canvas.h @@ -13,6 +13,7 @@ namespace yaze { namespace gui { using app::gfx::Bitmap; +using app::gfx::BitmapTable; class Canvas { public: @@ -29,6 +30,7 @@ class Canvas { void DrawBitmap(const Bitmap& bitmap, int border_offset = 0, bool ready = true); void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset); + void DrawBitmapTable(const BitmapTable gfx_bin); void DrawOutline(int x, int y, int w, int h); void DrawRect(int x, int y, int w, int h, ImVec4 color); void DrawText(std::string text, int x, int y);