Cgx to gfx::Bitmap pipeline in GraphicsEditor

This commit is contained in:
Justin Scofield
2023-08-01 22:02:58 -04:00
parent 952ce1e3dc
commit 09d76f5f5d
5 changed files with 126 additions and 28 deletions

View File

@@ -21,23 +21,33 @@ namespace app {
namespace editor {
absl::Status GraphicsEditor::Update() {
RETURN_IF_ERROR(DrawToolset())
if (open_memory_editor_) {
ImGui::Begin("Memory Editor", &open_memory_editor_);
RETURN_IF_ERROR(DrawMemoryEditor())
ImGui::End();
}
BEGIN_TABLE("#gfxEditTable", 3, kGfxEditFlags)
SETUP_COLUMN("Graphics Manager")
SETUP_COLUMN("Memory Editor")
SETUP_COLUMN("Graphics (BIN, CGX, SCR)")
SETUP_COLUMN("Palette (COL)")
SETUP_COLUMN("Preview")
TABLE_HEADERS()
NEXT_COLUMN()
status_ = DrawCgxImport();
status_ = DrawFileImport();
status_ = DrawExperimentalFeatures();
status_ = DrawPaletteControls();
NEXT_COLUMN()
RETURN_IF_ERROR(DrawMemoryEditor())
status_ = DrawPaletteControls();
NEXT_COLUMN()
if (super_donkey_) {
status_ = DrawGraphicsBin();
} else if (cgx_loaded_ && col_file_) {
status_ = DrawCgxViewer();
} else {
status_ = DrawDecompressedData();
}
@@ -47,17 +57,72 @@ absl::Status GraphicsEditor::Update() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawToolset() {
if (ImGui::BeginTable("GraphicsToolset", 2, ImGuiTableFlags_SizingFixedFit,
ImVec2(0, 0))) {
for (const auto& name : kGfxToolsetColumnNames)
ImGui::TableSetupColumn(name.data());
ImGui::TableNextColumn();
if (ImGui::Button(ICON_MD_MEMORY)) {
open_memory_editor_ = true;
}
TEXT_COLUMN("Open Memory Editor") // Separator
ImGui::EndTable();
}
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawCgxImport() {
gui::TextWithSeparators("Cgx Import");
ImGui::InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_));
ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Open CGX")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportCgxKey", "Choose File",
".CGX,.cgx\0", ".");
}
if (ImGuiFileDialog::Instance()->Display("ImportCgxKey")) {
if (ImGuiFileDialog::Instance()->IsOk()) {
strncpy(cgx_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(cgx_file_path_));
strncpy(cgx_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(cgx_file_name_));
RETURN_IF_ERROR(temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false))
cgx_viewer_.LoadCgx(temp_rom_);
auto all_tiles_data = cgx_viewer_.GetCgxData();
cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth,
all_tiles_data.data(), all_tiles_data.size());
rom_.RenderBitmap(&cgx_bitmap_);
is_open_ = true;
cgx_loaded_ = true;
}
ImGuiFileDialog::Instance()->Close();
}
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawFileImport() {
static int size = 0;
gui::TextWithSeparators("File Import");
gui::TextWithSeparators("Clipboard Import");
RETURN_IF_ERROR(DrawClipboardImport())
gui::TextWithSeparators("BIN Import");
ImGui::InputText("##ROMFile", file_path_, sizeof(file_path_));
ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Open BIN")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File",
".bin\0.hex\0", ".");
".bin,.hex\0", ".");
}
// Draw the file dialog
@@ -78,7 +143,7 @@ absl::Status GraphicsEditor::DrawFileImport() {
gui::InputHex("Offset", &current_offset_);
gui::InputHex("Size ", &size);
if (ImGui::Button("Import")) {
if (ImGui::Button("BIN Import")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressImportData(size))
} else {
@@ -87,25 +152,17 @@ absl::Status GraphicsEditor::DrawFileImport() {
}
}
gui::TextWithSeparators("Clipboard Import");
RETURN_IF_ERROR(DrawClipboardImport())
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawPaletteControls() {
gui::TextWithSeparators("Palette");
gui::InputHex("Palette Index", &current_palette_index_);
ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
gui::TextWithSeparators("COL Import");
ImGui::InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
ImGui::SameLine();
if (ImGui::Button("Open COL")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportColKey", "Choose File",
".col", ".");
".COL,.col", ".");
}
if (ImGuiFileDialog::Instance()->Display("ImportColKey")) {
@@ -121,10 +178,22 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
col_file_palette_ = gfx::SNESPalette(col_data_);
col_file_ = true;
is_open_ = true;
if (cgx_loaded_) {
cgx_bitmap_.ApplyPalette(col_file_palette_);
rom_.RenderBitmap(&cgx_bitmap_);
}
}
ImGuiFileDialog::Instance()->Close();
}
if (rom_.isLoaded()) {
gui::TextWithSeparators("ROM Palette");
gui::InputHex("Palette Index", &current_palette_index_);
ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
}
if (col_file_palette_.size() != 0) {
ImGuiFileDialog::Instance()->prDrawFileListView(ImVec2(0, 200));
palette_editor_.DrawPortablePalette(col_file_palette_);
@@ -143,6 +212,7 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
ImGui::MemFree((void*)text);
RETURN_IF_ERROR(temp_rom_.LoadFromBytes(clipboard_data))
is_open_ = true;
open_memory_editor_ = true;
}
}
@@ -171,6 +241,21 @@ absl::Status GraphicsEditor::DrawMemoryEditor() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawCgxViewer() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)5);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
import_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
import_canvas_.DrawContextMenu();
import_canvas_.DrawBitmap(cgx_bitmap_, 2, cgx_loaded_);
import_canvas_.DrawTileSelector(32);
import_canvas_.DrawGrid(32.0f);
import_canvas_.DrawOverlay();
}
ImGui::EndChild();
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawDecompressedData() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)2);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,