add DrawBitmap to Canvas class
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "app/gfx/bitmap.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
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));
|
draw_list_->AddRect(canvas_p0_, canvas_p1_, IM_COL32(255, 255, 255, 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::UpdateContext() {
|
void Canvas::DrawContextMenu() {
|
||||||
// This will catch our interactions
|
// This will catch our interactions
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
ImGui::InvisibleButton(
|
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) {
|
void Canvas::DrawGrid(float grid_step) {
|
||||||
// Draw grid + all lines in the canvas
|
// Draw grid + all lines in the canvas
|
||||||
draw_list_->PushClipRect(canvas_p0_, canvas_p1_, true);
|
draw_list_->PushClipRect(canvas_p0_, canvas_p1_, true);
|
||||||
|
|||||||
@@ -6,9 +6,13 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "app/gfx/bitmap.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
|
using app::gfx::Bitmap;
|
||||||
|
|
||||||
class Canvas {
|
class Canvas {
|
||||||
public:
|
public:
|
||||||
Canvas() = default;
|
Canvas() = default;
|
||||||
@@ -16,16 +20,17 @@ class Canvas {
|
|||||||
: custom_canvas_size_(true), canvas_sz_(canvas_size) {}
|
: custom_canvas_size_(true), canvas_sz_(canvas_size) {}
|
||||||
|
|
||||||
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
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 DrawGrid(float grid_step = 64.0f);
|
||||||
void DrawOverlay(); // last
|
void DrawOverlay(); // last
|
||||||
|
|
||||||
|
auto GetDrawList() const { return draw_list_; }
|
||||||
|
auto GetZeroPoint() const { return canvas_p0_; }
|
||||||
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;
|
||||||
}
|
}
|
||||||
auto GetDrawList() const { return draw_list_; }
|
|
||||||
auto GetZeroPoint() const { return canvas_p0_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool enable_grid_ = true;
|
bool enable_grid_ = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user