Editor namespace housekeeping, Canvas expansion

This commit is contained in:
Justin Scofield
2022-07-19 20:21:32 -04:00
parent 86150f82bd
commit 7a795fd75d
7 changed files with 44 additions and 230 deletions

View File

@@ -282,65 +282,26 @@ void OverworldEditor::DrawTile16Selector() const {
draw_list->PopClipRect();
}
void OverworldEditor::DrawTile8Selector() const {
static ImVec2 scrolling(0.0f, 0.0f);
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
auto canvas_sz = ImVec2(256 + 1, kNumSheetsToLoad * 64 + 1);
auto canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
// Draw border and background color
const ImGuiIO &io = ImGui::GetIO();
ImDrawList *draw_list = ImGui::GetWindowDrawList();
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
// This will catch our interactions
ImGui::InvisibleButton(
"Tile8SelectorCanvas", canvas_sz,
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
const ImVec2 origin(canvas_p0.x + scrolling.x,
canvas_p0.y + scrolling.y); // Lock scrolled origin
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
io.MousePos.y - origin.y);
// Context menu (under default mouse threshold)
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
if (drag_delta.x == 0.0f && drag_delta.y == 0.0f)
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
if (ImGui::BeginPopup("context")) {
ImGui::EndPopup();
}
void OverworldEditor::DrawTile8Selector() {
graphics_bin_canvas_.DrawBackground(
ImVec2(256 + 1, kNumSheetsToLoad * 64 + 1));
graphics_bin_canvas_.UpdateContext();
graphics_bin_canvas_.DrawGrid(16.0f);
if (all_gfx_loaded_) {
for (const auto &[key, value] : graphics_bin_) {
int offset = 64 * (key + 1);
int top_left_y = canvas_p0.y + 2;
int top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 2;
if (key >= 1) {
top_left_y = canvas_p0.y + 64 * key;
top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 64 * key;
}
draw_list->AddImage((void *)value.GetTexture(),
ImVec2(canvas_p0.x + 2, top_left_y),
ImVec2(canvas_p0.x + 256, canvas_p0.y + offset));
graphics_bin_canvas_.GetDrawList()->AddImage(
(void *)value.GetTexture(),
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 2, top_left_y),
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 256,
graphics_bin_canvas_.GetZeroPoint().y + offset));
}
}
// Draw grid + all lines in the canvas
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
if (opt_enable_grid) {
const float GRID_STEP = 16.0f;
for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x;
x += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y),
ImVec2(canvas_p0.x + x, canvas_p1.y),
IM_COL32(200, 200, 200, 40));
for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y;
y += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y),
ImVec2(canvas_p1.x, canvas_p0.y + y),
IM_COL32(200, 200, 200, 40));
}
draw_list->PopClipRect();
graphics_bin_canvas_.DrawOverlay();
}
void OverworldEditor::DrawPseudoVRAM() {
@@ -354,9 +315,12 @@ void OverworldEditor::DrawPseudoVRAM() {
pseudo_vram_canvas_.DrawBackground();
pseudo_vram_canvas_.UpdateContext();
pseudo_vram_canvas_.DrawGrid();
// draw_list->AddImage((void *)rom_.GetVRAM().GetTileset(0).GetTexture(),
// ImVec2(canvas_p0.x + 2, canvas_p0.y + 2),
// ImVec2(canvas_p0.x + 256, canvas_p0.y + 64));
pseudo_vram_canvas_.GetDrawList()->AddImage(
(void *)rom_.GetVRAM().GetTileset(0).GetTexture(),
ImVec2(pseudo_vram_canvas_.GetZeroPoint().x + 2,
pseudo_vram_canvas_.GetZeroPoint().y + 2),
ImVec2(pseudo_vram_canvas_.GetZeroPoint().x + 256,
pseudo_vram_canvas_.GetZeroPoint().y + 64));
pseudo_vram_canvas_.DrawOverlay();
}