yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_editor.cc
Go to the documentation of this file.
1#include "graphics_editor.h"
2
3#include "ImGuiFileDialog/ImGuiFileDialog.h"
4#include "absl/status/status.h"
5#include "absl/status/statusor.h"
9#include "app/gfx/bitmap.h"
10#include "app/gfx/compression.h"
11#include "app/gfx/scad_format.h"
13#include "app/gfx/snes_tile.h"
15#include "app/gui/canvas.h"
16#include "app/gui/color.h"
17#include "app/gui/input.h"
18#include "app/gui/style.h"
19#include "app/rom.h"
20#include "imgui/imgui.h"
21#include "imgui/misc/cpp/imgui_stdlib.h"
22#include "imgui_memory_editor.h"
23
24namespace yaze {
25namespace app {
26namespace editor {
27
28using core::Renderer;
29
31using ImGui::Button;
32using ImGui::InputInt;
33using ImGui::InputText;
34using ImGui::SameLine;
35using ImGui::TableNextColumn;
36
37static constexpr absl::string_view kGfxToolsetColumnNames[] = {
38 "#memoryEditor",
39 "##separator_gfx1",
40};
41
42constexpr ImGuiTableFlags kGfxEditTableFlags =
43 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
44 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable |
45 ImGuiTableFlags_SizingFixedFit;
46
47constexpr ImGuiTabBarFlags kGfxEditTabBarFlags =
48 ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
49 ImGuiTabBarFlags_FittingPolicyResizeDown |
50 ImGuiTabBarFlags_TabListPopupButton;
51
52constexpr ImGuiTableFlags kGfxEditFlags = ImGuiTableFlags_Reorderable |
53 ImGuiTableFlags_Resizable |
54 ImGuiTableFlags_SizingStretchSame;
55
56absl::Status GraphicsEditor::Update() {
57 TAB_BAR("##TabBar")
59 TAB_ITEM("Sheet Browser")
60 if (asset_browser_.Initialized == false) {
61 asset_browser_.Initialize(rom()->gfx_sheets());
62 }
63 asset_browser_.Draw(rom()->gfx_sheets());
64
70 return absl::OkStatus();
71}
72
74 TAB_ITEM("Sheet Editor")
75
76 if (ImGui::BeginTable("##GfxEditTable", 3, kGfxEditTableFlags,
77 ImVec2(0, 0))) {
78 for (const auto& name :
79 {"Tilesheets", "Current Graphics", "Palette Controls"})
80 ImGui::TableSetupColumn(name);
81
82 ImGui::TableHeadersRow();
83
86
88 if (rom()->is_loaded()) {
91 }
92
94 if (rom()->is_loaded()) {
96 }
97 }
98 ImGui::EndTable();
99
101 return absl::OkStatus();
102}
103
105 if (ImGui::BeginTable("##GfxEditToolset", 9, ImGuiTableFlags_SizingFixedFit,
106 ImVec2(0, 0))) {
107 for (const auto& name :
108 {"Select", "Pencil", "Fill", "Copy Sheet", "Paste Sheet", "Zoom Out",
109 "Zoom In", "Current Color", "Tile Size"})
110 ImGui::TableSetupColumn(name);
111
112 TableNextColumn();
113 if (Button(ICON_MD_SELECT_ALL)) {
115 }
116
117 TableNextColumn();
118 if (Button(ICON_MD_DRAW)) {
120 }
121 HOVER_HINT("Draw with current color");
122
123 TableNextColumn();
124 if (Button(ICON_MD_FORMAT_COLOR_FILL)) {
126 }
127 HOVER_HINT("Fill with current color");
128
129 TableNextColumn();
130 if (Button(ICON_MD_CONTENT_COPY)) {
131 std::vector<uint8_t> png_data =
132 rom()->gfx_sheets().at(current_sheet_).GetPngData();
134 }
135 HOVER_HINT("Copy to Clipboard");
136
137 TableNextColumn();
138 if (Button(ICON_MD_CONTENT_PASTE)) {
139 std::vector<uint8_t> png_data;
140 int width, height;
141 core::GetImageFromClipboard(png_data, width, height);
142 if (png_data.size() > 0) {
143 rom()
144 ->mutable_gfx_sheets()
145 ->at(current_sheet_)
146 .Create(width, height, 8, png_data);
148 &rom()->mutable_gfx_sheets()->at(current_sheet_));
149 }
150 }
151 HOVER_HINT("Paste from Clipboard");
152
153 TableNextColumn();
154 if (Button(ICON_MD_ZOOM_OUT)) {
155 if (current_scale_ >= 0.0f) {
156 current_scale_ -= 1.0f;
157 }
158 }
159
160 TableNextColumn();
161 if (Button(ICON_MD_ZOOM_IN)) {
162 if (current_scale_ <= 16.0f) {
163 current_scale_ += 1.0f;
164 }
165 }
166
167 TableNextColumn();
168 auto bitmap = rom()->gfx_sheets()[current_sheet_];
169 auto palette = bitmap.palette();
170 for (int i = 0; i < 8; i++) {
171 ImGui::SameLine();
172 auto color =
173 ImVec4(palette[i].rgb().x / 255.0f, palette[i].rgb().y / 255.0f,
174 palette[i].rgb().z / 255.0f, 255.0f);
175 if (ImGui::ColorButton(absl::StrFormat("Palette Color %d", i).c_str(),
176 color)) {
177 current_color_ = color;
178 }
179 }
180
181 TableNextColumn();
182 gui::InputHexByte("Tile Size", &tile_size_);
183
184 ImGui::EndTable();
185 }
186}
187
189 ImGui::BeginChild(
190 "##GfxEditChild", ImVec2(0, 0), true,
191 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysVerticalScrollbar);
192 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
193 // TODO: Update the interaction for multi select on sheets
194 static ImGuiSelectionBasicStorage selection;
195 ImGuiMultiSelectFlags flags =
196 ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d;
197 ImGuiMultiSelectIO* ms_io =
198 ImGui::BeginMultiSelect(flags, selection.Size, kNumGfxSheets);
199 selection.ApplyRequests(ms_io);
200 ImGuiListClipper clipper;
201 clipper.Begin(kNumGfxSheets);
202 if (ms_io->RangeSrcItem != -1)
203 clipper.IncludeItemByIndex(
204 (int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped.
205
206 int key = 0;
207 for (auto& value : rom()->gfx_sheets()) {
208 ImGui::BeginChild(absl::StrFormat("##GfxSheet%02X", key).c_str(),
209 ImVec2(0x100 + 1, 0x40 + 1), true,
210 ImGuiWindowFlags_NoDecoration);
211 ImGui::PopStyleVar();
212
213 graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 0x40 + 1));
215 if (value.is_active()) {
216 auto texture = value.texture();
218 (void*)texture,
219 ImVec2(graphics_bin_canvas_.zero_point().x + 2,
222 value.width() * sheet_scale_,
224 value.height() * sheet_scale_));
225
226 if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
227 current_sheet_ = key;
228 open_sheets_.insert(key);
229 }
230
231 // Add a slightly transparent rectangle behind the text
232 ImVec2 text_pos(graphics_bin_canvas_.zero_point().x + 2,
234 ImVec2 text_size =
235 ImGui::CalcTextSize(absl::StrFormat("%02X", key).c_str());
236 ImVec2 rent_min(text_pos.x, text_pos.y);
237 ImVec2 rent_max(text_pos.x + text_size.x, text_pos.y + text_size.y);
238
239 graphics_bin_canvas_.draw_list()->AddRectFilled(rent_min, rent_max,
240 IM_COL32(0, 125, 0, 128));
241
243 text_pos, IM_COL32(125, 255, 125, 255),
244 absl::StrFormat("%02X", key).c_str());
245
246 key++;
247 }
250
251 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
252 ImGui::EndChild();
253 }
254 ImGui::PopStyleVar();
255 ms_io = ImGui::EndMultiSelect();
256 selection.ApplyRequests(ms_io);
257 ImGui::EndChild();
258 return absl::OkStatus();
259}
260
262 static int next_tab_id = 0;
263
264 if (ImGui::BeginTabBar("##GfxEditTabBar", kGfxEditTabBarFlags)) {
265 if (ImGui::TabItemButton(ICON_MD_ADD, ImGuiTabItemFlags_Trailing |
266 ImGuiTabItemFlags_NoTooltip)) {
267 open_sheets_.insert(next_tab_id++);
268 }
269
270 for (auto& sheet_id : open_sheets_) {
271 bool open = true;
272 if (ImGui::BeginTabItem(absl::StrFormat("%d", sheet_id).c_str(), &open,
273 ImGuiTabItemFlags_None)) {
274 current_sheet_ = sheet_id;
275 if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
276 release_queue_.push(sheet_id);
277 }
278 if (ImGui::IsItemHovered()) {
279 if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
280 release_queue_.push(sheet_id);
281 child_window_sheets_.insert(sheet_id);
282 }
283 }
284
285 const auto child_id =
286 absl::StrFormat("##GfxEditPaletteChildWindow%d", sheet_id);
287 ImGui::BeginChild(child_id.c_str(), ImVec2(0, 0), true,
288 ImGuiWindowFlags_NoDecoration |
289 ImGuiWindowFlags_AlwaysVerticalScrollbar |
290 ImGuiWindowFlags_AlwaysHorizontalScrollbar);
291
292 gfx::Bitmap& current_bitmap = rom()->mutable_gfx_sheets()->at(sheet_id);
293
294 auto draw_tile_event = [&]() {
297 Renderer::GetInstance().UpdateBitmap(&current_bitmap, true);
298 };
299
301 rom()->mutable_gfx_sheets()->at(sheet_id), current_color_,
302 draw_tile_event, tile_size_, current_scale_);
303
304 ImGui::EndChild();
305 ImGui::EndTabItem();
306 }
307
308 if (!open) release_queue_.push(sheet_id);
309 }
310
311 ImGui::EndTabBar();
312 }
313
314 // Release any tabs that were closed
315 while (!release_queue_.empty()) {
316 auto sheet_id = release_queue_.top();
317 open_sheets_.erase(sheet_id);
318 release_queue_.pop();
319 }
320
321 // Draw any child windows that were created
322 if (!child_window_sheets_.empty()) {
323 int id_to_release = -1;
324 for (const auto& id : child_window_sheets_) {
325 bool active = true;
326 ImGui::SetNextWindowPos(ImGui::GetIO().MousePos, ImGuiCond_Once);
327 ImGui::SetNextWindowSize(ImVec2(0x100 + 1 * 16, 0x40 + 1 * 16),
328 ImGuiCond_Once);
329 ImGui::Begin(absl::StrFormat("##GfxEditPaletteChildWindow%d", id).c_str(),
330 &active, ImGuiWindowFlags_AlwaysUseWindowPadding);
331 current_sheet_ = id;
332 // ImVec2(0x100, 0x40),
334 rom()->mutable_gfx_sheets()->at(id), current_color_,
335 [&]() {
336
337 },
339 ImGui::End();
340
341 if (active == false) {
342 id_to_release = id;
343 }
344 }
345 if (id_to_release != -1) {
346 child_window_sheets_.erase(id_to_release);
347 }
348 }
349
350 return absl::OkStatus();
351}
352
354 if (rom()->is_loaded()) {
355 auto palette_group = *rom()->palette_group().get_group(
356 kPaletteGroupAddressesKeys[edit_palette_group_name_index_]);
357 auto palette = palette_group.palette(edit_palette_index_);
358 gui::TextWithSeparators("ROM Palette");
359 ImGui::SetNextItemWidth(100.f);
360 ImGui::Combo("Palette Group", (int*)&edit_palette_group_name_index_,
361 kPaletteGroupAddressesKeys,
362 IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
363 ImGui::SetNextItemWidth(100.f);
364 gui::InputHex("Palette Group Index", &edit_palette_index_);
365
367 palette);
368
369 if (refresh_graphics_ && !open_sheets_.empty()) {
371 rom()
372 ->mutable_gfx_sheets()
373 ->data()[current_sheet_]
374 .ApplyPaletteWithTransparent(palette, edit_palette_sub_index_));
376 &rom()->mutable_gfx_sheets()->data()[current_sheet_], true);
377 refresh_graphics_ = false;
378 }
379 }
380 return absl::OkStatus();
381}
382
384 TAB_ITEM("Player Animations")
385
386 if (ImGui::BeginTable("##PlayerAnimationTable", 3, kGfxEditTableFlags,
387 ImVec2(0, 0))) {
388 for (const auto& name : {"Canvas", "Animation Steps", "Properties"})
389 ImGui::TableSetupColumn(name);
390
391 ImGui::TableHeadersRow();
392
393 NEXT_COLUMN();
395 link_canvas_.DrawGrid(16.0f);
396
397 int i = 0;
398 for (auto link_sheet : *rom()->mutable_link_graphics()) {
399 int x_offset = 0;
400 int y_offset = gfx::kTilesheetHeight * i * 4;
401 link_canvas_.DrawContextMenu(&link_sheet);
402 link_canvas_.DrawBitmap(link_sheet, x_offset, y_offset, 4);
403 i++;
404 }
407
408 NEXT_COLUMN();
409 ImGui::Text("Placeholder");
410
411 NEXT_COLUMN();
412 if (ImGui::Button("Load Link Graphics (Experimental)")) {
413 if (rom()->is_loaded()) {
414 // Load Links graphics from the ROM
415 RETURN_IF_ERROR(rom()->LoadLinkGraphics());
416
417 // Split it into the pose data frames
418 // Create an animation step display for the poses
419 // Allow the user to modify the frames used in an anim step
420 // LinkOAM_AnimationSteps:
421 // #_0D85FB
422 }
423 }
424 }
425 ImGui::EndTable();
426
428 return absl::OkStatus();
429}
430
432 TAB_ITEM("Prototype")
433
435
437 ImGui::Begin("Memory Editor", &open_memory_editor_);
439 ImGui::End();
440 }
441
442 BEGIN_TABLE("#gfxEditTable", 4, kGfxEditFlags)
443 SETUP_COLUMN("File Import (BIN, CGX, ROM)")
444 SETUP_COLUMN("Palette (COL)")
445 ImGui::TableSetupColumn("Tilemaps and Objects (SCR, PNL, OBJ)",
446 ImGuiTableColumnFlags_WidthFixed);
447 SETUP_COLUMN("Graphics Preview")
449 NEXT_COLUMN() {
454 }
455
457
460 scr_loaded_, false, 0);
462
464 if (super_donkey_) {
465 // TODO: Implement the Super Donkey 1 graphics decompression
466 // if (refresh_graphics_) {
467 // for (int i = 0; i < kNumGfxSheets; i++) {
468 // status_ = graphics_bin_[i].ApplyPalette(
469 // col_file_palette_group_[current_palette_index_]);
470 // Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]);
471 // }
472 // refresh_graphics_ = false;
473 // }
474 // Load the full graphics space from `super_donkey_1.bin`
475 // gui::GraphicsBinCanvasPipeline(0x100, 0x40, 0x20, num_sheets_to_load_, 3,
476 // super_donkey_, graphics_bin_);
477 } else if (cgx_loaded_ && col_file_) {
478 // Load the CGX graphics
480 cgx_loaded_, true, 5);
481 } else {
482 // Load the BIN/Clipboard Graphics
484 gfx_loaded_, true, 2);
485 }
486 END_TABLE()
487
489 return absl::OkStatus();
490}
491
493 if (ImGui::BeginTable("GraphicsToolset", 2, ImGuiTableFlags_SizingFixedFit,
494 ImVec2(0, 0))) {
495 for (const auto& name : kGfxToolsetColumnNames)
496 ImGui::TableSetupColumn(name.data());
497
498 TableNextColumn();
499 if (Button(ICON_MD_MEMORY)) {
500 if (!open_memory_editor_) {
501 open_memory_editor_ = true;
502 } else {
503 open_memory_editor_ = false;
504 }
505 }
506
507 TEXT_COLUMN("Open Memory Editor") // Separator
508
509 ImGui::EndTable();
510 }
511 return absl::OkStatus();
512}
513
515 gui::TextWithSeparators("Cgx Import");
516 InputInt("BPP", &current_bpp_);
517
518 InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_));
519 SameLine();
520
521 gui::FileDialogPipeline("ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [this]() {
522 strncpy(cgx_file_path_,
523 ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
524 sizeof(cgx_file_path_));
525 strncpy(cgx_file_name_,
526 ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
527 sizeof(cgx_file_name_));
528 is_open_ = true;
529 cgx_loaded_ = true;
530 });
531
532 if (ImGui::Button("Copy CGX Path")) {
533 ImGui::SetClipboardText(cgx_file_path_);
534 }
535
536 if (ImGui::Button("Load CGX Data")) {
539
540 cgx_bitmap_.Create(0x80, 0x200, 8, decoded_cgx_);
541 if (col_file_) {
544 }
545 }
546
547 return absl::OkStatus();
548}
549
551 InputText("##ScrFile", scr_file_name_, sizeof(scr_file_name_));
552
554 "ImportScrKey", ".SCR,.scr,.BAK\0", "Open SCR", [this]() {
555 strncpy(scr_file_path_,
556 ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
557 sizeof(scr_file_path_));
558 strncpy(scr_file_name_,
559 ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
560 sizeof(scr_file_name_));
561 is_open_ = true;
562 scr_loaded_ = true;
563 });
564
565 InputInt("SCR Mod", &scr_mod_value_);
566
567 if (ImGui::Button("Load Scr Data")) {
568 status_ =
570
571 decoded_scr_data_.resize(0x100 * 0x100);
574
575 scr_bitmap_.Create(0x100, 0x100, 8, decoded_scr_data_);
576 if (scr_loaded_) {
579 }
580 }
581
582 return absl::OkStatus();
583}
584
586 gui::TextWithSeparators("COL Import");
587 InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
588 SameLine();
589
591 "ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [this]() {
592 strncpy(col_file_path_,
593 ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
594 sizeof(col_file_path_));
595 strncpy(col_file_name_,
596 ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
597 sizeof(col_file_name_));
599 /*z3_load=*/false);
600 auto col_data_ = gfx::GetColFileData(temp_rom_.data());
601 if (col_file_palette_group_.size() != 0) {
603 }
604 auto col_file_palette_group_status =
606 if (col_file_palette_group_status.ok()) {
607 col_file_palette_group_ = col_file_palette_group_status.value();
608 }
610
611 // gigaleak dev format based code
613 col_file_ = true;
614 is_open_ = true;
615 });
616
617 if (ImGui::Button("Copy Col Path")) {
618 ImGui::SetClipboardText(col_file_path_);
619 }
620
621 if (rom()->is_loaded()) {
622 gui::TextWithSeparators("ROM Palette");
623 gui::InputHex("Palette Index", &current_palette_index_);
624 ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
625 IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
626 }
627
628 if (col_file_palette_.size() != 0) {
631 }
632
633 return absl::OkStatus();
634}
635
637 gui::TextWithSeparators("OBJ Import");
638
639 InputText("##ObjFile", obj_file_path_, sizeof(obj_file_path_));
640 SameLine();
641
643 "ImportObjKey", ".obj,.OBJ,.bak,.BAK\0", "Open OBJ", [this]() {
644 strncpy(file_path_,
645 ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
646 sizeof(file_path_));
648 is_open_ = true;
649 });
650
651 return absl::OkStatus();
652}
653
655 gui::TextWithSeparators("Tilemap Import");
656
657 InputText("##TMapFile", tilemap_file_path_, sizeof(tilemap_file_path_));
658 SameLine();
659
661 "ImportTilemapKey", ".DAT,.dat,.BIN,.bin,.hex,.HEX\0", "Open Tilemap",
662 [this]() {
663 strncpy(tilemap_file_path_,
664 ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
665 sizeof(tilemap_file_path_));
667
668 // Extract the high and low bytes from the file.
669 auto decomp_sheet = gfx::lc_lz2::DecompressV2(
671 tilemap_loaded_ = true;
672 is_open_ = true;
673 });
674
675 return absl::OkStatus();
676}
677
679 gui::TextWithSeparators("BIN Import");
680
681 InputText("##ROMFile", file_path_, sizeof(file_path_));
682 SameLine();
683
684 gui::FileDialogPipeline("ImportDlgKey", ".bin,.hex\0", "Open BIN", [this]() {
685 strncpy(file_path_, ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
686 sizeof(file_path_));
688 is_open_ = true;
689 });
690
691 if (Button("Copy File Path")) {
692 ImGui::SetClipboardText(file_path_);
693 }
694
695 gui::InputHex("BIN Offset", &current_offset_);
696 gui::InputHex("BIN Size", &bin_size_);
697
698 if (Button("Decompress BIN")) {
699 if (strlen(file_path_) > 0) {
701 } else {
702 return absl::InvalidArgumentError(
703 "Please select a file before importing.");
704 }
705 }
706
707 return absl::OkStatus();
708}
709
711 gui::TextWithSeparators("Clipboard Import");
712 if (Button("Paste From Clipboard")) {
713 const char* text = ImGui::GetClipboardText();
714 if (text) {
715 const auto clipboard_data = std::vector<uint8_t>(text, text + strlen(text));
716 ImGui::MemFree((void*)text);
717 status_ = temp_rom_.LoadFromBytes(clipboard_data);
718 is_open_ = true;
719 open_memory_editor_ = true;
720 }
721 }
724 gui::InputHex("Num Sheets", &num_sheets_to_load_);
725
726 if (Button("Decompress Clipboard Data")) {
727 if (temp_rom_.is_loaded()) {
728 status_ = DecompressImportData(0x40000);
729 } else {
730 status_ = absl::InvalidArgumentError(
731 "Please paste data into the clipboard before "
732 "decompressing.");
733 }
734 }
735
736 return absl::OkStatus();
737}
738
740 gui::TextWithSeparators("Experimental");
741 if (Button("Decompress Super Donkey Full")) {
742 if (strlen(file_path_) > 0) {
744 } else {
745 return absl::InvalidArgumentError(
746 "Please select `super_donkey_1.bin` before "
747 "importing.");
748 }
749 }
750 ImGui::SetItemTooltip(
751 "Requires `super_donkey_1.bin` to be imported under the "
752 "BIN import section.");
753 return absl::OkStatus();
754}
755
757 std::string title = "Memory Editor";
758 if (is_open_) {
759 static MemoryEditor mem_edit;
760 mem_edit.DrawWindow(title.c_str(), temp_rom_.data(), temp_rom_.size());
761 }
762 return absl::OkStatus();
763}
764
768
769 auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
771 converted_sheet);
772
773 if (rom()->is_loaded()) {
774 auto palette_group = rom()->palette_group().overworld_animated;
775 z3_rom_palette_ = palette_group[current_palette_];
776 if (col_file_) {
778 } else {
780 }
781 }
782
784 gfx_loaded_ = true;
785
786 return absl::OkStatus();
787}
788
790 int i = 0;
791 for (const auto& offset : kSuperDonkeyTiles) {
792 int offset_value =
793 std::stoi(offset, nullptr, 16); // convert hex string to int
795 auto decompressed_data,
796 gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
797 auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
799 gfx::kTilesheetDepth, converted_sheet);
800 if (col_file_) {
801 status_ = gfx_sheets_[i].ApplyPalette(
803 } else {
804 // ROM palette
805
806 auto palette_group = rom()->palette_group().get_group(
807 kPaletteGroupAddressesKeys[current_palette_]);
808 z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
809 status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_);
810 }
811
813 i++;
814 }
815
816 for (const auto& offset : kSuperDonkeySprites) {
817 int offset_value =
818 std::stoi(offset, nullptr, 16); // convert hex string to int
820 auto decompressed_data,
821 gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
822 auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
824 gfx::kTilesheetDepth, converted_sheet);
825 if (col_file_) {
826 status_ = gfx_sheets_[i].ApplyPalette(
828 } else {
829 // ROM palette
830 auto palette_group = rom()->palette_group().get_group(
831 kPaletteGroupAddressesKeys[current_palette_]);
832 z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
833 status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_);
834 }
835
837 i++;
838 }
839 super_donkey_ = true;
841
842 return absl::OkStatus();
843}
844
845} // namespace editor
846} // namespace app
847} // namespace yaze
auto size() const
Definition rom.h:467
bool is_loaded() const
Definition rom.h:455
auto data()
Definition rom.h:470
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:142
absl::Status LoadFromBytes(const std::vector< uint8_t > &data)
Definition rom.cc:243
static Renderer & GetInstance()
Definition renderer.h:30
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:52
void UpdateBitmap(gfx::Bitmap *bitmap, bool use_sdl_update=false)
Used to update a bitmap on the screen.
Definition renderer.h:63
absl::Status DecompressImportData(int size)
std::set< uint16_t > child_window_sheets_
std::array< gfx::Bitmap, kNumGfxSheets > gfx_sheets_
gui::GfxSheetAssetBrowser asset_browser_
std::vector< SDL_Color > decoded_col_
std::vector< uint8_t > extra_cgx_data_
std::vector< uint8_t > decoded_scr_data_
std::vector< uint8_t > decoded_cgx_
std::vector< uint8_t > import_data_
std::stack< uint16_t > release_queue_
Represents a bitmap image.
Definition bitmap.h:70
auto at(int i) const
Definition bitmap.h:192
absl::Status ApplyPalette(const SnesPalette &palette)
Copy color data from the SnesPalette into the SDL_Palette.
Definition bitmap.cc:346
void Create(int width, int height, int depth, const std::vector< uint8_t > &data)
Creates a bitmap object with the provided graphical data.
Definition bitmap.cc:232
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), bool drag=false)
Definition canvas.cc:69
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
Definition canvas.cc:689
auto draw_list() const
Definition canvas.h:146
void DrawTileOnBitmap(int tile_size, gfx::Bitmap *bitmap, ImVec4 color)
Definition canvas.cc:322
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
Definition canvas.cc:464
auto zero_point() const
Definition canvas.h:147
void UpdateColorPainter(gfx::Bitmap &bitmap, const ImVec4 &color, const std::function< void()> &event, int tile_size, float scale=1.0f)
Definition canvas.cc:47
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
Definition canvas.cc:104
#define SETUP_COLUMN(l)
Definition constants.h:28
#define TAB_BAR(w)
Definition constants.h:6
#define END_TAB_BAR()
Definition constants.h:7
#define END_TABLE()
Definition constants.h:36
#define TABLE_HEADERS()
Definition constants.h:30
#define BEGIN_TABLE(l, n, f)
Definition constants.h:27
#define RETURN_IF_ERROR(expression)
Definition constants.h:69
#define END_TAB_ITEM()
Definition constants.h:12
#define NEXT_COLUMN()
Definition constants.h:34
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition constants.h:77
#define CLEAR_AND_RETURN_STATUS(status)
Definition constants.h:112
#define TEXT_COLUMN(w)
Definition constants.h:23
#define TAB_ITEM(w)
Definition constants.h:11
#define HOVER_HINT(string)
Definition constants.h:40
#define ICON_MD_MEMORY
Definition icons.h:1193
#define ICON_MD_DRAW
Definition icons.h:623
#define ICON_MD_ZOOM_OUT
Definition icons.h:2191
#define ICON_MD_FORMAT_COLOR_FILL
Definition icons.h:828
#define ICON_MD_CONTENT_PASTE
Definition icons.h:465
#define ICON_MD_ADD
Definition icons.h:84
#define ICON_MD_ZOOM_IN
Definition icons.h:2189
#define ICON_MD_SELECT_ALL
Definition icons.h:1678
#define ICON_MD_CONTENT_COPY
Definition icons.h:463
void CopyImageToClipboard(const std::vector< uint8_t > &data)
Definition clipboard.cc:10
void GetImageFromClipboard(std::vector< uint8_t > &data, int &width, int &height)
Definition clipboard.cc:11
constexpr ImGuiTabBarFlags kGfxEditTabBarFlags
const std::string kSuperDonkeyTiles[]
constexpr ImGuiTableFlags kGfxEditTableFlags
const std::string kSuperDonkeySprites[]
constexpr ImGuiTableFlags kGfxEditFlags
absl::StatusOr< std::vector< uint8_t > > DecompressV2(const uchar *data, int offset, int size, int mode)
Decompresses a buffer of data using the LC_LZ2 algorithm.
constexpr int kNintendoMode1
Definition compression.h:46
absl::Status LoadCgx(uint8_t bpp, std::string_view filename, std::vector< uint8_t > &cgx_data, std::vector< uint8_t > &cgx_loaded, std::vector< uint8_t > &cgx_header)
Load Cgx file (graphical content)
std::vector< SDL_Color > DecodeColFile(const std::string_view filename)
Decode color file.
absl::Status LoadScr(std::string_view filename, uint8_t input_value, std::vector< uint8_t > &map_data)
Load Scr file (screen data)
absl::Status DrawScrWithCgx(uint8_t bpp, std::vector< uint8_t > &map_data, std::vector< uint8_t > &map_bitmap_data, std::vector< uint8_t > &cgx_loaded)
Draw screen tilemap with graphical data.
constexpr int kTilesheetDepth
Definition snes_tile.h:16
constexpr int kTilesheetWidth
Definition snes_tile.h:14
std::vector< uint8_t > SnesTo8bppSheet(const std::vector< uint8_t > &sheet, int bpp)
Definition snes_tile.cc:152
std::vector< SnesColor > GetColFileData(uint8_t *data)
Definition snes_color.cc:90
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromColFile(std::vector< SnesColor > &palette_rows)
constexpr int kTilesheetHeight
Definition snes_tile.h:15
constexpr const char * kPaletteGroupAddressesKeys[]
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:176
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:143
void SelectablePalettePipeline(uint64_t &palette_id, bool &refresh_graphics, gfx::SnesPalette &palette)
Definition color.cc:129
void FileDialogPipeline(absl::string_view display_key, absl::string_view file_extensions, std::optional< absl::string_view > button_text, std::function< void()> callback)
Definition input.cc:253
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:416
void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap, int width, int height, int tile_size, bool is_loaded, bool scrollbar, int canvas_id)
Definition canvas.cc:834
constexpr uint32_t kNumGfxSheets
Definition rom.h:126
Definition common.cc:21
void Draw(const std::array< gfx::Bitmap, kNumGfxSheets > &bmp_manager)
void Initialize(const std::array< gfx::Bitmap, kNumGfxSheets > &bmp_manager)