add canvas id and context id to Canvas
This commit is contained in:
@@ -202,9 +202,10 @@ class GraphicsEditor : public SharedRom, public Editor {
|
||||
gui::Canvas import_canvas_;
|
||||
gui::Canvas scr_canvas_;
|
||||
gui::Canvas super_donkey_canvas_;
|
||||
gui::Canvas current_sheet_canvas_{ImVec2(0x80, 0x20),
|
||||
gui::Canvas current_sheet_canvas_{"CurrentSheetCanvas", ImVec2(0x80, 0x20),
|
||||
gui::CanvasGridSize::k8x8};
|
||||
gui::Canvas link_canvas_{
|
||||
"LinkCanvas",
|
||||
ImVec2(core::kTilesheetWidth * 4, core::kTilesheetHeight * 0x10 * 4),
|
||||
gui::CanvasGridSize::k16x16};
|
||||
absl::Status status_;
|
||||
|
||||
@@ -95,18 +95,19 @@ class Tile16Editor : public context::GfxContext, public SharedRom {
|
||||
uint8_t* all_tiles_types_;
|
||||
|
||||
// Tile16 blockset for selecting the tile to edit
|
||||
gui::Canvas blockset_canvas_{ImVec2(0x100, 0x4000),
|
||||
gui::Canvas blockset_canvas_{"blocksetCanvas", ImVec2(0x100, 0x4000),
|
||||
gui::CanvasGridSize::k32x32};
|
||||
gfx::Bitmap* tile16_blockset_bmp_;
|
||||
|
||||
// Canvas for editing the selected tile
|
||||
gui::Canvas tile16_edit_canvas_{ImVec2(0x40, 0x40),
|
||||
gui::Canvas tile16_edit_canvas_{"Tile16EditCanvas", ImVec2(0x40, 0x40),
|
||||
gui::CanvasGridSize::k64x64};
|
||||
gfx::Bitmap* current_tile16_bmp_;
|
||||
gfx::Bitmap* current_tile8_bmp_;
|
||||
|
||||
// Tile8 canvas to get the tile to drawing in the tile16_edit_canvas_
|
||||
gui::Canvas tile8_source_canvas_{
|
||||
"Tile8SourceCanvas",
|
||||
ImVec2(core::kTilesheetWidth * 4, core::kTilesheetHeight * 0x10 * 4),
|
||||
gui::CanvasGridSize::k32x32};
|
||||
gfx::Bitmap current_gfx_bmp_;
|
||||
|
||||
@@ -244,14 +244,15 @@ class OverworldEditor : public Editor,
|
||||
PaletteEditor palette_editor_;
|
||||
zelda3::overworld::Overworld overworld_;
|
||||
|
||||
gui::Canvas ow_map_canvas_{ImVec2(0x200 * 8, 0x200 * 8),
|
||||
gui::Canvas ow_map_canvas_{"owMapCanvas", ImVec2(0x200 * 8, 0x200 * 8),
|
||||
gui::CanvasGridSize::k64x64};
|
||||
gui::Canvas current_gfx_canvas_{ImVec2(0x100 + 1, 0x10 * 0x40 + 1),
|
||||
gui::Canvas current_gfx_canvas_{"customGfxCanvas",
|
||||
ImVec2(0x100 + 1, 0x10 * 0x40 + 1),
|
||||
gui::CanvasGridSize::k32x32};
|
||||
gui::Canvas blockset_canvas_{ImVec2(0x100 + 1, 0x2000 + 1),
|
||||
gui::Canvas blockset_canvas_{"blocksetCanvas", ImVec2(0x100 + 1, 0x2000 + 1),
|
||||
gui::CanvasGridSize::k32x32};
|
||||
gui::Canvas graphics_bin_canvas_{
|
||||
ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1),
|
||||
"graphicsBinCanvas", ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1),
|
||||
gui::CanvasGridSize::k16x16};
|
||||
gui::Canvas properties_canvas_;
|
||||
|
||||
|
||||
@@ -90,7 +90,6 @@ void SpriteEditor::DrawSpriteCanvas() {
|
||||
ImGui::GetContentRegionAvail(), true)) {
|
||||
sprite_canvas_.DrawBackground();
|
||||
sprite_canvas_.DrawContextMenu();
|
||||
// sprite_canvas_.DrawBitmap(oam_bitmap_, 2, 2);
|
||||
sprite_canvas_.DrawGrid();
|
||||
sprite_canvas_.DrawOverlay();
|
||||
|
||||
|
||||
@@ -91,10 +91,11 @@ class SpriteEditor : public SharedRom, public Editor {
|
||||
gui::Bitmap oam_bitmap_; /**< OAM bitmap. */
|
||||
|
||||
gui::Canvas sprite_canvas_{
|
||||
ImVec2(0x200, 0x200), gui::CanvasGridSize::k32x32}; /**< Sprite canvas. */
|
||||
"SpriteCanvas", ImVec2(0x200, 0x200),
|
||||
gui::CanvasGridSize::k32x32}; /**< Sprite canvas. */
|
||||
|
||||
gui::Canvas graphics_sheet_canvas_{
|
||||
ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
|
||||
"GraphicsSheetCanvas", ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
|
||||
gui::CanvasGridSize::k16x16}; /**< Graphics sheet canvas. */
|
||||
|
||||
std::vector<zsprite::ZSprite> custom_sprites_; /**< Sprites. */
|
||||
|
||||
@@ -24,6 +24,8 @@ using ImGui::IsItemHovered;
|
||||
using ImGui::IsMouseClicked;
|
||||
using ImGui::IsMouseDragging;
|
||||
using ImGui::MenuItem;
|
||||
using ImGui::Selectable;
|
||||
using ImGui::Separator;
|
||||
using ImGui::Text;
|
||||
|
||||
constexpr uint32_t kRectangleColor = IM_COL32(32, 32, 32, 255);
|
||||
@@ -66,7 +68,7 @@ void Canvas::DrawBackground(ImVec2 canvas_size, bool can_drag) {
|
||||
draw_list_->AddRect(canvas_p0_, canvas_p1_, kRectangleBorder);
|
||||
|
||||
ImGui::InvisibleButton(
|
||||
"canvas",
|
||||
canvas_id_.c_str(),
|
||||
ImVec2(canvas_sz_.x * global_scale_, canvas_sz_.y * global_scale_),
|
||||
kMouseFlags);
|
||||
|
||||
@@ -99,21 +101,22 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
|
||||
// Context menu (under default mouse threshold)
|
||||
if (ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
enable_context_menu_ && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
||||
ImGui::OpenPopupOnItemClick(context_id_.c_str(),
|
||||
ImGuiPopupFlags_MouseButtonRight);
|
||||
|
||||
// Contents of the Context Menu
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
if (ImGui::BeginPopup(context_id_.c_str())) {
|
||||
if (MenuItem("Reset Position", nullptr, false)) {
|
||||
scrolling_.x = 0;
|
||||
scrolling_.y = 0;
|
||||
}
|
||||
MenuItem("Show Grid", nullptr, &enable_grid_);
|
||||
ImGui::Selectable("Show Position Labels", &enable_hex_tile_labels_);
|
||||
Selectable("Show Position Labels", &enable_hex_tile_labels_);
|
||||
if (BeginMenu("Canvas Properties")) {
|
||||
Text("Canvas Size: %.0f x %.0f", canvas_sz_.x, canvas_sz_.y);
|
||||
Text("Global Scale: %.1f", global_scale_);
|
||||
Text("Mouse Position: %.0f x %.0f", mouse_pos.x, mouse_pos.y);
|
||||
ImGui::EndMenu();
|
||||
EndMenu();
|
||||
}
|
||||
if (bitmap != nullptr) {
|
||||
if (BeginMenu("Bitmap Properties")) {
|
||||
@@ -122,7 +125,7 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
|
||||
absl::StrFormat("%d", bitmap->surface()->pitch).c_str());
|
||||
Text("BitsPerPixel: %d", bitmap->surface()->format->BitsPerPixel);
|
||||
Text("BytesPerPixel: %d", bitmap->surface()->format->BytesPerPixel);
|
||||
ImGui::EndMenu();
|
||||
EndMenu();
|
||||
}
|
||||
}
|
||||
ImGui::Separator();
|
||||
@@ -139,7 +142,7 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
|
||||
if (MenuItem("64x64", nullptr, custom_step_ == 64.0f)) {
|
||||
custom_step_ = 64.0f;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
EndMenu();
|
||||
}
|
||||
// TODO: Add a menu item for selecting the palette
|
||||
|
||||
|
||||
@@ -36,10 +36,14 @@ enum class CanvasGridSize { k8x8, k16x16, k32x32, k64x64 };
|
||||
class Canvas {
|
||||
public:
|
||||
Canvas() = default;
|
||||
explicit Canvas(ImVec2 canvas_size)
|
||||
: custom_canvas_size_(true), canvas_sz_(canvas_size) {}
|
||||
explicit Canvas(ImVec2 canvas_size, CanvasGridSize grid_size)
|
||||
: custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
||||
explicit Canvas(const std::string& id, ImVec2 canvas_size)
|
||||
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
||||
context_id_ = id + "Context";
|
||||
}
|
||||
explicit Canvas(const std::string& id, ImVec2 canvas_size,
|
||||
CanvasGridSize grid_size)
|
||||
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
||||
context_id_ = id + "Context";
|
||||
switch (grid_size) {
|
||||
case CanvasGridSize::k8x8:
|
||||
custom_step_ = 8.0f;
|
||||
@@ -84,7 +88,7 @@ class Canvas {
|
||||
// in the canvas window. Represented and split apart into a grid of tiles.
|
||||
bool DrawTileSelector(int size);
|
||||
|
||||
|
||||
// Draws the selection rectangle when the user is selecting multiple tiles
|
||||
void DrawSelectRect(int current_map, int tile_size = 0x10,
|
||||
float scale = 1.0f);
|
||||
|
||||
@@ -104,9 +108,6 @@ class Canvas {
|
||||
void DrawOutlineWithColor(int x, int y, int w, int h, ImVec4 color);
|
||||
void DrawOutlineWithColor(int x, int y, int w, int h, uint32_t color);
|
||||
|
||||
void DrawSelectRect(int current_map, int tile_size = 0x10,
|
||||
float scale = 1.0f);
|
||||
|
||||
void DrawRect(int x, int y, int w, int h, ImVec4 color);
|
||||
|
||||
void DrawText(std::string text, int x, int y);
|
||||
@@ -197,6 +198,9 @@ class Canvas {
|
||||
int current_labels_ = 0;
|
||||
int highlight_tile_id = -1;
|
||||
|
||||
std::string canvas_id_ = "Canvas";
|
||||
std::string context_id_ = "CanvasContext";
|
||||
|
||||
ImDrawList* draw_list_;
|
||||
ImVector<ImVec2> points_;
|
||||
ImVector<ImVector<std::string>> labels_;
|
||||
|
||||
Reference in New Issue
Block a user