From 56351fb36ffd91e6938eaa7288fbbc9a1b074642 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sat, 27 Aug 2022 22:07:29 -0500 Subject: [PATCH] add DrawBitmap to Canvas class --- src/gui/canvas.cc | 12 +++++++++++- src/gui/canvas.h | 11 ++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/gui/canvas.cc b/src/gui/canvas.cc index c7b237e1..1ac36094 100644 --- a/src/gui/canvas.cc +++ b/src/gui/canvas.cc @@ -5,6 +5,8 @@ #include #include +#include "app/gfx/bitmap.h" + namespace yaze { namespace gui { @@ -21,7 +23,7 @@ void Canvas::DrawBackground(ImVec2 canvas_size) { draw_list_->AddRect(canvas_p0_, canvas_p1_, IM_COL32(255, 255, 255, 255)); } -void Canvas::UpdateContext() { +void Canvas::DrawContextMenu() { // This will catch our interactions const ImGuiIO &io = ImGui::GetIO(); ImGui::InvisibleButton( @@ -68,6 +70,14 @@ void Canvas::UpdateContext() { } } +void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset) { + draw_list_->AddImage( + (void *)bitmap.GetTexture(), + ImVec2(canvas_p0_.x + border_offset, canvas_p0_.y + border_offset), + ImVec2(canvas_p0_.x + (bitmap.GetWidth() * 2), + canvas_p0_.y + (bitmap.GetHeight() * 2))); +} + void Canvas::DrawGrid(float grid_step) { // Draw grid + all lines in the canvas draw_list_->PushClipRect(canvas_p0_, canvas_p1_, true); diff --git a/src/gui/canvas.h b/src/gui/canvas.h index dda7e970..d81de5b5 100644 --- a/src/gui/canvas.h +++ b/src/gui/canvas.h @@ -6,9 +6,13 @@ #include #include +#include "app/gfx/bitmap.h" + namespace yaze { namespace gui { +using app::gfx::Bitmap; + class Canvas { public: Canvas() = default; @@ -16,16 +20,17 @@ class Canvas { : custom_canvas_size_(true), canvas_sz_(canvas_size) {} void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0)); - void UpdateContext(); + void DrawContextMenu(); + void DrawBitmap(const Bitmap& bitmap, int border_offset = 0); void DrawGrid(float grid_step = 64.0f); void DrawOverlay(); // last + auto GetDrawList() const { return draw_list_; } + auto GetZeroPoint() const { return canvas_p0_; } void SetCanvasSize(ImVec2 canvas_size) { canvas_sz_ = canvas_size; custom_canvas_size_ = true; } - auto GetDrawList() const { return draw_list_; } - auto GetZeroPoint() const { return canvas_p0_; } private: bool enable_grid_ = true;