CgxViewer updates
This commit is contained in:
@@ -29,6 +29,7 @@ absl::Status GraphicsEditor::Update() {
|
||||
NEXT_COLUMN()
|
||||
|
||||
status_ = DrawFileImport();
|
||||
status_ = DrawExperimentalFeatures();
|
||||
status_ = DrawPaletteControls();
|
||||
|
||||
NEXT_COLUMN()
|
||||
@@ -51,10 +52,10 @@ absl::Status GraphicsEditor::DrawFileImport() {
|
||||
|
||||
gui::TextWithSeparators("File Import");
|
||||
|
||||
ImGui::InputText("File", file_path_, sizeof(file_path_));
|
||||
ImGui::InputText("##ROMFile", file_path_, sizeof(file_path_));
|
||||
ImGui::SameLine();
|
||||
// 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",
|
||||
".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");
|
||||
RETURN_IF_ERROR(DrawClipboardImport())
|
||||
|
||||
@@ -108,12 +100,12 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
||||
ImGui::Combo("Palette", ¤t_palette_, 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();
|
||||
// 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",
|
||||
".col\0", ".");
|
||||
".col", ".");
|
||||
}
|
||||
|
||||
if (ImGuiFileDialog::Instance()->Display("ImportColKey")) {
|
||||
@@ -121,6 +113,9 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
||||
strncpy(col_file_path_,
|
||||
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
|
||||
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))
|
||||
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
|
||||
col_file_palette_ = gfx::SNESPalette(col_data_);
|
||||
@@ -131,6 +126,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
||||
}
|
||||
|
||||
if (col_file_palette_.size() != 0) {
|
||||
ImGuiFileDialog::Instance()->prDrawFileListView(ImVec2(0, 200));
|
||||
palette_editor_.DrawPortablePalette(col_file_palette_);
|
||||
}
|
||||
|
||||
@@ -153,11 +149,24 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
|
||||
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() {
|
||||
std::string title = "Memory Editor";
|
||||
if (is_open_) {
|
||||
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();
|
||||
}
|
||||
@@ -177,31 +186,6 @@ absl::Status GraphicsEditor::DrawDecompressedData() {
|
||||
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() {
|
||||
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
|
||||
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||
@@ -230,6 +214,30 @@ absl::Status GraphicsEditor::DrawGraphicsBin() {
|
||||
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() {
|
||||
if (rom_.isLoaded()) {
|
||||
auto palette_group =
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "app/gui/canvas.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/viewer/cgx_viewer.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
@@ -60,13 +61,13 @@ class GraphicsEditor {
|
||||
absl::Status DrawFileImport();
|
||||
absl::Status DrawPaletteControls();
|
||||
absl::Status DrawClipboardImport();
|
||||
absl::Status DrawExperimentalFeatures();
|
||||
absl::Status DrawMemoryEditor();
|
||||
absl::Status DrawDecompressedData();
|
||||
absl::Status DrawGraphicsBin();
|
||||
|
||||
absl::Status DecompressImportData(int size);
|
||||
|
||||
absl::Status DrawGraphicsBin();
|
||||
|
||||
absl::Status DecompressSuperDonkey();
|
||||
|
||||
int current_offset_ = 0;
|
||||
@@ -80,6 +81,7 @@ class GraphicsEditor {
|
||||
bool col_file_ = false;
|
||||
char file_path_[256] = "";
|
||||
char col_file_path_[256] = "";
|
||||
char col_file_name_[256] = "";
|
||||
|
||||
ROM rom_;
|
||||
ROM temp_rom_;
|
||||
@@ -98,6 +100,8 @@ class GraphicsEditor {
|
||||
gfx::SNESPalette palette_;
|
||||
gfx::SNESPalette col_file_palette_;
|
||||
|
||||
viewer::CgxViewer cgx_viewer_;
|
||||
|
||||
absl::Status status_;
|
||||
};
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ void PaletteEditor::DrawPortablePalette(gfx::SNESPalette& palette) {
|
||||
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,
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
||||
ImGui::BeginGroup(); // Lock X position
|
||||
|
||||
@@ -15,44 +15,32 @@ namespace viewer {
|
||||
void CgxViewer::Update() {
|
||||
static int current_bpp = 1;
|
||||
// ImGui::Combo("BPP", current_bpp, "0\0 1\0 2\0 3\0", 4, 4);
|
||||
LoadColFile();
|
||||
LoadGfx(current_bpp);
|
||||
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) {
|
||||
unsigned char* ptr = rawData.data();
|
||||
|
||||
for (int i = 0; i < 0x40000; i++) {
|
||||
ptr[i] = 0;
|
||||
rawData[i] = 0;
|
||||
}
|
||||
raw_data_.malloc(0x40000);
|
||||
all_tiles_data_.malloc(0x40000);
|
||||
|
||||
std::ifstream fs(pathfile, std::ios::binary);
|
||||
std::vector<unsigned char> data((std::istreambuf_iterator<char>(fs)),
|
||||
std::istreambuf_iterator<char>());
|
||||
fs.close();
|
||||
|
||||
int matchingPos = -1;
|
||||
std::vector<unsigned char> matched_bytes;
|
||||
int matching_position = -1;
|
||||
bool matched = false;
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
if (matched) {
|
||||
break;
|
||||
}
|
||||
rawData[i] = data[i];
|
||||
for (int j = 0; j < matchBytes.size(); j++) {
|
||||
if (data[i + j] == matchBytes[j]) {
|
||||
if (j == matchBytes.size() - 1) {
|
||||
matchingPos = i;
|
||||
|
||||
raw_data_[i] = data[i];
|
||||
for (int j = 0; j < matched_bytes.size(); j++) {
|
||||
if (data[i + j] == matched_bytes[j]) {
|
||||
if (j == matched_bytes.size() - 1) {
|
||||
matching_position = i;
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
@@ -62,46 +50,34 @@ void CgxViewer::LoadCgx(std::string pathfile) {
|
||||
}
|
||||
}
|
||||
|
||||
char buffer[10];
|
||||
sprintf(buffer, "%X4", matchingPos);
|
||||
label1_text = "CGX In Folder L : " + std::string(buffer);
|
||||
label1_text = absl::StrCat("CGX In Folder L : ",
|
||||
absl::StrFormat("%X4", matching_position));
|
||||
LoadGfx(current_selection_);
|
||||
}
|
||||
|
||||
struct GFX_Class {
|
||||
unsigned char* indexedPointer;
|
||||
} GFX;
|
||||
struct PictureBox_Class {
|
||||
void (*Refresh)();
|
||||
} pictureBox1;
|
||||
|
||||
void CgxViewer::LoadGfx(int comboBpp) {
|
||||
if (comboBpp == 0) {
|
||||
void CgxViewer::LoadGfx(int combo_bpp) {
|
||||
if (combo_bpp == 0) {
|
||||
bpp_ = 4;
|
||||
} else if (comboBpp == 1) {
|
||||
} else if (combo_bpp == 1) {
|
||||
bpp_ = 2;
|
||||
} else if (comboBpp == 2) {
|
||||
} else if (combo_bpp == 2) {
|
||||
bpp_ = 8;
|
||||
} else if (comboBpp == 3) {
|
||||
} else if (combo_bpp == 3) {
|
||||
bpp_ = 40;
|
||||
unsigned char* ptr = GFX.indexedPointer;
|
||||
for (int i = 0; i < rawData.size(); i++) {
|
||||
ptr[i] = rawData[i];
|
||||
for (int i = 0; i < raw_data_.size(); i++) {
|
||||
all_tiles_data_[i] = raw_data_[i];
|
||||
}
|
||||
// Refresh palettes and "picture box" aka canvas
|
||||
RefreshPalettes();
|
||||
pictureBox1.Refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char* ptr = GFX.indexedPointer;
|
||||
Bytes rawBytes; // rawData.data()
|
||||
std::vector<unsigned char> dd = gfx::SnesTo8bppSheet(rawBytes, bpp_);
|
||||
for (int i = 0; i < dd.size(); i++) {
|
||||
ptr[i] = dd[i];
|
||||
Bytes decomp_sheet = gfx::SnesTo8bppSheet(raw_data_.vector(), bpp_);
|
||||
for (int i = 0; i < decomp_sheet.size(); i++) {
|
||||
all_tiles_data_[i] = decomp_sheet[i];
|
||||
}
|
||||
|
||||
RefreshPalettes();
|
||||
pictureBox1.Refresh();
|
||||
}
|
||||
|
||||
void CgxViewer::LoadScr() {}
|
||||
|
||||
@@ -18,20 +18,18 @@ class CgxViewer {
|
||||
void Update();
|
||||
|
||||
private:
|
||||
void LoadColFile();
|
||||
|
||||
void LoadCgx(std::string pathfile);
|
||||
void LoadGfx(int comboBpp);
|
||||
void LoadScr();
|
||||
|
||||
void RefreshPalettes();
|
||||
|
||||
std::vector<unsigned char> matchBytes; // Assuming it's a vector of bytes.
|
||||
std::string label1_text;
|
||||
|
||||
int bpp_;
|
||||
int current_selection_;
|
||||
ROM rawData;
|
||||
ROM all_tiles_data_;
|
||||
ROM raw_data_;
|
||||
};
|
||||
|
||||
} // namespace viewer
|
||||
|
||||
Reference in New Issue
Block a user