CgxViewer updates

This commit is contained in:
scawful
2023-08-01 20:15:15 -04:00
parent fd3a61a437
commit 952ce1e3dc
5 changed files with 81 additions and 95 deletions

View File

@@ -29,6 +29,7 @@ absl::Status GraphicsEditor::Update() {
NEXT_COLUMN() NEXT_COLUMN()
status_ = DrawFileImport(); status_ = DrawFileImport();
status_ = DrawExperimentalFeatures();
status_ = DrawPaletteControls(); status_ = DrawPaletteControls();
NEXT_COLUMN() NEXT_COLUMN()
@@ -51,10 +52,10 @@ absl::Status GraphicsEditor::DrawFileImport() {
gui::TextWithSeparators("File Import"); gui::TextWithSeparators("File Import");
ImGui::InputText("File", file_path_, sizeof(file_path_)); ImGui::InputText("##ROMFile", file_path_, sizeof(file_path_));
ImGui::SameLine(); ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button // Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Browse")) { if (ImGui::Button("Open BIN")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File", ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File",
".bin\0.hex\0", "."); ".bin\0.hex\0", ".");
} }
@@ -86,15 +87,6 @@ absl::Status GraphicsEditor::DrawFileImport() {
} }
} }
if (ImGui::Button("Import Super Donkey Full")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressSuperDonkey())
} else {
return absl::InvalidArgumentError(
"Please select `super_donkey_1.bin` before importing.");
}
}
gui::TextWithSeparators("Clipboard Import"); gui::TextWithSeparators("Clipboard Import");
RETURN_IF_ERROR(DrawClipboardImport()) RETURN_IF_ERROR(DrawClipboardImport())
@@ -108,12 +100,12 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys, ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(kPaletteGroupAddressesKeys)); IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
ImGui::InputText("COL File", col_file_path_, sizeof(col_file_path_)); ImGui::InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
ImGui::SameLine(); ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Browse")) { if (ImGui::Button("Open COL")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportColKey", "Choose File", ImGuiFileDialog::Instance()->OpenDialog("ImportColKey", "Choose File",
".col\0", "."); ".col", ".");
} }
if (ImGuiFileDialog::Instance()->Display("ImportColKey")) { if (ImGuiFileDialog::Instance()->Display("ImportColKey")) {
@@ -121,6 +113,9 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
strncpy(col_file_path_, strncpy(col_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(), ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(col_file_path_)); sizeof(col_file_path_));
strncpy(col_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(col_file_name_));
RETURN_IF_ERROR(temp_rom_.LoadFromFile(col_file_path_, /*z3_load=*/false)) RETURN_IF_ERROR(temp_rom_.LoadFromFile(col_file_path_, /*z3_load=*/false))
auto col_data_ = gfx::GetColFileData(temp_rom_.data()); auto col_data_ = gfx::GetColFileData(temp_rom_.data());
col_file_palette_ = gfx::SNESPalette(col_data_); col_file_palette_ = gfx::SNESPalette(col_data_);
@@ -131,6 +126,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
} }
if (col_file_palette_.size() != 0) { if (col_file_palette_.size() != 0) {
ImGuiFileDialog::Instance()->prDrawFileListView(ImVec2(0, 200));
palette_editor_.DrawPortablePalette(col_file_palette_); palette_editor_.DrawPortablePalette(col_file_palette_);
} }
@@ -153,11 +149,24 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
return absl::OkStatus(); return absl::OkStatus();
} }
absl::Status GraphicsEditor::DrawExperimentalFeatures() {
gui::TextWithSeparators("Experimental");
if (ImGui::Button("Import Super Donkey Full")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressSuperDonkey())
} else {
return absl::InvalidArgumentError(
"Please select `super_donkey_1.bin` before importing.");
}
}
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawMemoryEditor() { absl::Status GraphicsEditor::DrawMemoryEditor() {
std::string title = "Memory Editor"; std::string title = "Memory Editor";
if (is_open_) { if (is_open_) {
static MemoryEditor mem_edit; static MemoryEditor mem_edit;
mem_edit.DrawContents(temp_rom_.data(), temp_rom_.size()); mem_edit.DrawWindow(title.c_str(), temp_rom_.data(), temp_rom_.size());
} }
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -177,31 +186,6 @@ absl::Status GraphicsEditor::DrawDecompressedData() {
return absl::OkStatus(); return absl::OkStatus();
} }
absl::Status GraphicsEditor::DecompressImportData(int size) {
ASSIGN_OR_RETURN(import_data_, gfx::lc_lz2::DecompressV2(
temp_rom_.data(), current_offset_, size))
std::cout << "Size of import data " << import_data_.size() << std::endl;
auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
bitmap_.Create(core::kTilesheetWidth, 0x2000, core::kTilesheetDepth,
converted_sheet.data(), size);
if (rom_.isLoaded()) {
auto palette_group = rom_.GetPaletteGroup("ow_main");
palette_ = palette_group.palettes[current_palette_];
if (col_file_) {
bitmap_.ApplyPalette(col_file_palette_);
} else {
bitmap_.ApplyPalette(palette_);
}
}
rom_.RenderBitmap(&bitmap_);
gfx_loaded_ = true;
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawGraphicsBin() { absl::Status GraphicsEditor::DrawGraphicsBin() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3); if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
@@ -230,6 +214,30 @@ absl::Status GraphicsEditor::DrawGraphicsBin() {
return absl::OkStatus(); return absl::OkStatus();
} }
absl::Status GraphicsEditor::DecompressImportData(int size) {
ASSIGN_OR_RETURN(import_data_, gfx::lc_lz2::DecompressV2(
temp_rom_.data(), current_offset_, size))
auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
bitmap_.Create(core::kTilesheetWidth, 0x2000, core::kTilesheetDepth,
converted_sheet.data(), size);
if (rom_.isLoaded()) {
auto palette_group = rom_.GetPaletteGroup("ow_main");
palette_ = palette_group.palettes[current_palette_];
if (col_file_) {
bitmap_.ApplyPalette(col_file_palette_);
} else {
bitmap_.ApplyPalette(palette_);
}
}
rom_.RenderBitmap(&bitmap_);
gfx_loaded_ = true;
return absl::OkStatus();
}
absl::Status GraphicsEditor::DecompressSuperDonkey() { absl::Status GraphicsEditor::DecompressSuperDonkey() {
if (rom_.isLoaded()) { if (rom_.isLoaded()) {
auto palette_group = auto palette_group =

View File

@@ -14,6 +14,7 @@
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/rom.h" #include "app/rom.h"
#include "app/viewer/cgx_viewer.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -60,13 +61,13 @@ class GraphicsEditor {
absl::Status DrawFileImport(); absl::Status DrawFileImport();
absl::Status DrawPaletteControls(); absl::Status DrawPaletteControls();
absl::Status DrawClipboardImport(); absl::Status DrawClipboardImport();
absl::Status DrawExperimentalFeatures();
absl::Status DrawMemoryEditor(); absl::Status DrawMemoryEditor();
absl::Status DrawDecompressedData(); absl::Status DrawDecompressedData();
absl::Status DrawGraphicsBin();
absl::Status DecompressImportData(int size); absl::Status DecompressImportData(int size);
absl::Status DrawGraphicsBin();
absl::Status DecompressSuperDonkey(); absl::Status DecompressSuperDonkey();
int current_offset_ = 0; int current_offset_ = 0;
@@ -80,6 +81,7 @@ class GraphicsEditor {
bool col_file_ = false; bool col_file_ = false;
char file_path_[256] = ""; char file_path_[256] = "";
char col_file_path_[256] = ""; char col_file_path_[256] = "";
char col_file_name_[256] = "";
ROM rom_; ROM rom_;
ROM temp_rom_; ROM temp_rom_;
@@ -98,6 +100,8 @@ class GraphicsEditor {
gfx::SNESPalette palette_; gfx::SNESPalette palette_;
gfx::SNESPalette col_file_palette_; gfx::SNESPalette col_file_palette_;
viewer::CgxViewer cgx_viewer_;
absl::Status status_; absl::Status status_;
}; };

View File

@@ -202,7 +202,7 @@ void PaletteEditor::DrawPortablePalette(gfx::SNESPalette& palette) {
init = true; init = true;
} }
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3); if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)100);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) { ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
ImGui::BeginGroup(); // Lock X position ImGui::BeginGroup(); // Lock X position

View File

@@ -15,44 +15,32 @@ namespace viewer {
void CgxViewer::Update() { void CgxViewer::Update() {
static int current_bpp = 1; static int current_bpp = 1;
// ImGui::Combo("BPP", current_bpp, "0\0 1\0 2\0 3\0", 4, 4); // ImGui::Combo("BPP", current_bpp, "0\0 1\0 2\0 3\0", 4, 4);
LoadColFile();
LoadGfx(current_bpp); LoadGfx(current_bpp);
LoadScr(); LoadScr();
} }
void CgxViewer::LoadColFile() {
uchar data[512];
std::vector<gfx::SNESColor> colors;
for (int i = 0; i < 512; i += 2) {
colors[i / 2] = gfx::GetCgxColor((short)((data[i + 1] << 8) + data[i]));
}
}
void CgxViewer::LoadCgx(std::string pathfile) { void CgxViewer::LoadCgx(std::string pathfile) {
unsigned char* ptr = rawData.data(); raw_data_.malloc(0x40000);
all_tiles_data_.malloc(0x40000);
for (int i = 0; i < 0x40000; i++) {
ptr[i] = 0;
rawData[i] = 0;
}
std::ifstream fs(pathfile, std::ios::binary); std::ifstream fs(pathfile, std::ios::binary);
std::vector<unsigned char> data((std::istreambuf_iterator<char>(fs)), std::vector<unsigned char> data((std::istreambuf_iterator<char>(fs)),
std::istreambuf_iterator<char>()); std::istreambuf_iterator<char>());
fs.close(); fs.close();
int matchingPos = -1; std::vector<unsigned char> matched_bytes;
int matching_position = -1;
bool matched = false; bool matched = false;
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
if (matched) { if (matched) {
break; break;
} }
rawData[i] = data[i];
for (int j = 0; j < matchBytes.size(); j++) { raw_data_[i] = data[i];
if (data[i + j] == matchBytes[j]) { for (int j = 0; j < matched_bytes.size(); j++) {
if (j == matchBytes.size() - 1) { if (data[i + j] == matched_bytes[j]) {
matchingPos = i; if (j == matched_bytes.size() - 1) {
matching_position = i;
matched = true; matched = true;
break; break;
} }
@@ -62,46 +50,34 @@ void CgxViewer::LoadCgx(std::string pathfile) {
} }
} }
char buffer[10]; label1_text = absl::StrCat("CGX In Folder L : ",
sprintf(buffer, "%X4", matchingPos); absl::StrFormat("%X4", matching_position));
label1_text = "CGX In Folder L : " + std::string(buffer);
LoadGfx(current_selection_); LoadGfx(current_selection_);
} }
struct GFX_Class { void CgxViewer::LoadGfx(int combo_bpp) {
unsigned char* indexedPointer; if (combo_bpp == 0) {
} GFX;
struct PictureBox_Class {
void (*Refresh)();
} pictureBox1;
void CgxViewer::LoadGfx(int comboBpp) {
if (comboBpp == 0) {
bpp_ = 4; bpp_ = 4;
} else if (comboBpp == 1) { } else if (combo_bpp == 1) {
bpp_ = 2; bpp_ = 2;
} else if (comboBpp == 2) { } else if (combo_bpp == 2) {
bpp_ = 8; bpp_ = 8;
} else if (comboBpp == 3) { } else if (combo_bpp == 3) {
bpp_ = 40; bpp_ = 40;
unsigned char* ptr = GFX.indexedPointer; for (int i = 0; i < raw_data_.size(); i++) {
for (int i = 0; i < rawData.size(); i++) { all_tiles_data_[i] = raw_data_[i];
ptr[i] = rawData[i];
} }
// Refresh palettes and "picture box" aka canvas
RefreshPalettes(); RefreshPalettes();
pictureBox1.Refresh();
return; return;
} }
unsigned char* ptr = GFX.indexedPointer; Bytes decomp_sheet = gfx::SnesTo8bppSheet(raw_data_.vector(), bpp_);
Bytes rawBytes; // rawData.data() for (int i = 0; i < decomp_sheet.size(); i++) {
std::vector<unsigned char> dd = gfx::SnesTo8bppSheet(rawBytes, bpp_); all_tiles_data_[i] = decomp_sheet[i];
for (int i = 0; i < dd.size(); i++) {
ptr[i] = dd[i];
} }
RefreshPalettes(); RefreshPalettes();
pictureBox1.Refresh();
} }
void CgxViewer::LoadScr() {} void CgxViewer::LoadScr() {}

View File

@@ -18,20 +18,18 @@ class CgxViewer {
void Update(); void Update();
private: private:
void LoadColFile();
void LoadCgx(std::string pathfile); void LoadCgx(std::string pathfile);
void LoadGfx(int comboBpp); void LoadGfx(int comboBpp);
void LoadScr(); void LoadScr();
void RefreshPalettes(); void RefreshPalettes();
std::vector<unsigned char> matchBytes; // Assuming it's a vector of bytes.
std::string label1_text; std::string label1_text;
int bpp_; int bpp_;
int current_selection_; int current_selection_;
ROM rawData; ROM all_tiles_data_;
ROM raw_data_;
}; };
} // namespace viewer } // namespace viewer