canvas and ow edit changes
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
@@ -63,6 +64,10 @@ void Canvas::DrawContextMenu() {
|
||||
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
||||
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
if (ImGui::MenuItem("Reset Position", nullptr, false)) {
|
||||
scrolling_.x = 0;
|
||||
scrolling_.y = 0;
|
||||
}
|
||||
if (ImGui::MenuItem("Remove all", nullptr, false, points_.Size > 0)) {
|
||||
points_.clear();
|
||||
}
|
||||
@@ -70,6 +75,27 @@ void Canvas::DrawContextMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::DrawTilesFromUser(app::ROM &rom, Bytes &tile,
|
||||
app::gfx::SNESPalette &pal) {
|
||||
ImVec2 draw_tile_outline_pos;
|
||||
|
||||
// Add rectangle
|
||||
if (is_hovered_ && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
draw_tile_outline_pos.x =
|
||||
std::round((double)mouse_pos_in_canvas_.x / 16) * 16;
|
||||
draw_tile_outline_pos.y =
|
||||
std::round((double)mouse_pos_in_canvas_.y / 16) * 16;
|
||||
|
||||
points_.push_back(draw_tile_outline_pos);
|
||||
points_.push_back(
|
||||
ImVec2(draw_tile_outline_pos.x + 16, draw_tile_outline_pos.y + 16));
|
||||
|
||||
changed_tiles_.emplace_back(app::gfx::Bitmap(16, 16, 64, tile.data()));
|
||||
changed_tiles_.back().ApplyPalette(pal);
|
||||
rom.RenderBitmap(&(changed_tiles_.back()));
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset) {
|
||||
draw_list_->AddImage(
|
||||
(void *)bitmap.GetTexture(),
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
@@ -21,6 +22,8 @@ class Canvas {
|
||||
|
||||
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
||||
void DrawContextMenu();
|
||||
void DrawTilesFromUser(app::ROM& rom, Bytes& tile,
|
||||
app::gfx::SNESPalette& pal);
|
||||
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0);
|
||||
void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset);
|
||||
void DrawOutline(int x, int y, int w, int h);
|
||||
@@ -39,6 +42,7 @@ class Canvas {
|
||||
bool enable_grid_ = true;
|
||||
bool enable_context_menu_ = true;
|
||||
bool custom_canvas_size_ = false;
|
||||
bool is_hovered_ = false;
|
||||
|
||||
ImDrawList* draw_list_;
|
||||
ImVector<ImVec2> points_;
|
||||
@@ -46,6 +50,9 @@ class Canvas {
|
||||
ImVec2 canvas_sz_;
|
||||
ImVec2 canvas_p0_;
|
||||
ImVec2 canvas_p1_;
|
||||
ImVec2 mouse_pos_in_canvas_;
|
||||
|
||||
std::vector<app::gfx::Bitmap> changed_tiles_;
|
||||
|
||||
std::string title_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user