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"
14#include "app/gui/canvas.h"
15#include "app/gui/color.h"
16#include "app/gui/icons.h"
17#include "app/gui/input.h"
19#include "app/gui/style.h"
20#include "app/rom.h"
21#include "imgui/imgui.h"
22#include "imgui/misc/cpp/imgui_stdlib.h"
23#include "imgui_memory_editor.h"
24
25namespace yaze {
26namespace app {
27namespace editor {
28
29using core::Renderer;
30
32using ImGui::Button;
33using ImGui::InputInt;
34using ImGui::InputText;
35using ImGui::SameLine;
36using ImGui::TableNextColumn;
37
38constexpr ImGuiTableFlags kGfxEditTableFlags =
39 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
40 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable |
41 ImGuiTableFlags_SizingFixedFit;
42
43absl::Status GraphicsEditor::Update() {
44 if (ImGui::BeginTabBar("##TabBar")) {
46 TAB_ITEM("Sheet Browser")
47 if (asset_browser_.Initialized == false) {
48 asset_browser_.Initialize(rom()->gfx_sheets());
49 }
50 asset_browser_.Draw(rom()->gfx_sheets());
54 ImGui::EndTabBar();
55 }
57 return absl::OkStatus();
58}
59
61 if (ImGui::BeginTabItem("Sheet Editor")) {
62 if (ImGui::BeginTable("##GfxEditTable", 3, kGfxEditTableFlags,
63 ImVec2(0, 0))) {
64 for (const auto& name :
65 {"Tilesheets", "Current Graphics", "Palette Controls"})
66 ImGui::TableSetupColumn(name);
67
68 ImGui::TableHeadersRow();
69
72
74 if (rom()->is_loaded()) {
77 }
78
80 if (rom()->is_loaded()) {
82 }
83 }
84 ImGui::EndTable();
85
86 ImGui::EndTabItem();
87 }
88 return absl::OkStatus();
89}
90
92 if (ImGui::BeginTable("##GfxEditToolset", 9, ImGuiTableFlags_SizingFixedFit,
93 ImVec2(0, 0))) {
94 for (const auto& name :
95 {"Select", "Pencil", "Fill", "Copy Sheet", "Paste Sheet", "Zoom Out",
96 "Zoom In", "Current Color", "Tile Size"})
97 ImGui::TableSetupColumn(name);
98
99 TableNextColumn();
100 if (Button(ICON_MD_SELECT_ALL)) {
102 }
103
104 TableNextColumn();
105 if (Button(ICON_MD_DRAW)) {
107 }
108 HOVER_HINT("Draw with current color");
109
110 TableNextColumn();
111 if (Button(ICON_MD_FORMAT_COLOR_FILL)) {
113 }
114 HOVER_HINT("Fill with current color");
115
116 TableNextColumn();
117 if (Button(ICON_MD_CONTENT_COPY)) {
118 std::vector<uint8_t> png_data =
119 rom()->gfx_sheets().at(current_sheet_).GetPngData();
121 }
122 HOVER_HINT("Copy to Clipboard");
123
124 TableNextColumn();
125 if (Button(ICON_MD_CONTENT_PASTE)) {
126 std::vector<uint8_t> png_data;
127 int width, height;
128 core::GetImageFromClipboard(png_data, width, height);
129 if (png_data.size() > 0) {
130 rom()
131 ->mutable_gfx_sheets()
132 ->at(current_sheet_)
133 .Create(width, height, 8, png_data);
135 &rom()->mutable_gfx_sheets()->at(current_sheet_));
136 }
137 }
138 HOVER_HINT("Paste from Clipboard");
139
140 TableNextColumn();
141 if (Button(ICON_MD_ZOOM_OUT)) {
142 if (current_scale_ >= 0.0f) {
143 current_scale_ -= 1.0f;
144 }
145 }
146
147 TableNextColumn();
148 if (Button(ICON_MD_ZOOM_IN)) {
149 if (current_scale_ <= 16.0f) {
150 current_scale_ += 1.0f;
151 }
152 }
153
154 TableNextColumn();
155 auto bitmap = rom()->gfx_sheets()[current_sheet_];
156 auto palette = bitmap.palette();
157 for (int i = 0; i < 8; i++) {
158 ImGui::SameLine();
159 auto color =
160 ImVec4(palette[i].rgb().x / 255.0f, palette[i].rgb().y / 255.0f,
161 palette[i].rgb().z / 255.0f, 255.0f);
162 if (ImGui::ColorButton(absl::StrFormat("Palette Color %d", i).c_str(),
163 color)) {
164 current_color_ = color;
165 }
166 }
167
168 TableNextColumn();
169 gui::InputHexByte("Tile Size", &tile_size_);
170
171 ImGui::EndTable();
172 }
173}
174
176 ImGui::BeginChild(
177 "##GfxEditChild", ImVec2(0, 0), true,
178 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysVerticalScrollbar);
179 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
180 // TODO: Update the interaction for multi select on sheets
181 static ImGuiSelectionBasicStorage selection;
182 ImGuiMultiSelectFlags flags =
183 ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d;
184 ImGuiMultiSelectIO* ms_io =
185 ImGui::BeginMultiSelect(flags, selection.Size, kNumGfxSheets);
186 selection.ApplyRequests(ms_io);
187 ImGuiListClipper clipper;
188 clipper.Begin(kNumGfxSheets);
189 if (ms_io->RangeSrcItem != -1)
190 clipper.IncludeItemByIndex(
191 (int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped.
192
193 int key = 0;
194 for (auto& value : rom()->gfx_sheets()) {
195 ImGui::BeginChild(absl::StrFormat("##GfxSheet%02X", key).c_str(),
196 ImVec2(0x100 + 1, 0x40 + 1), true,
197 ImGuiWindowFlags_NoDecoration);
198 ImGui::PopStyleVar();
199
200 graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 0x40 + 1));
202 if (value.is_active()) {
203 auto texture = value.texture();
205 (ImTextureID)(intptr_t)texture,
206 ImVec2(graphics_bin_canvas_.zero_point().x + 2,
209 value.width() * sheet_scale_,
211 value.height() * sheet_scale_));
212
213 if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
214 current_sheet_ = key;
215 open_sheets_.insert(key);
216 }
217
218 // Add a slightly transparent rectangle behind the text
219 ImVec2 text_pos(graphics_bin_canvas_.zero_point().x + 2,
221 ImVec2 text_size =
222 ImGui::CalcTextSize(absl::StrFormat("%02X", key).c_str());
223 ImVec2 rent_min(text_pos.x, text_pos.y);
224 ImVec2 rent_max(text_pos.x + text_size.x, text_pos.y + text_size.y);
225
226 graphics_bin_canvas_.draw_list()->AddRectFilled(rent_min, rent_max,
227 IM_COL32(0, 125, 0, 128));
228
230 text_pos, IM_COL32(125, 255, 125, 255),
231 absl::StrFormat("%02X", key).c_str());
232
233 key++;
234 }
237
238 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
239 ImGui::EndChild();
240 }
241 ImGui::PopStyleVar();
242 ms_io = ImGui::EndMultiSelect();
243 selection.ApplyRequests(ms_io);
244 ImGui::EndChild();
245 return absl::OkStatus();
246}
247
249 static int next_tab_id = 0;
250 constexpr ImGuiTabBarFlags kGfxEditTabBarFlags =
251 ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
252 ImGuiTabBarFlags_FittingPolicyResizeDown |
253 ImGuiTabBarFlags_TabListPopupButton;
254
255 if (ImGui::BeginTabBar("##GfxEditTabBar", kGfxEditTabBarFlags)) {
256 if (ImGui::TabItemButton(ICON_MD_ADD, ImGuiTabItemFlags_Trailing |
257 ImGuiTabItemFlags_NoTooltip)) {
258 open_sheets_.insert(next_tab_id++);
259 }
260
261 for (auto& sheet_id : open_sheets_) {
262 bool open = true;
263 if (ImGui::BeginTabItem(absl::StrFormat("%d", sheet_id).c_str(), &open,
264 ImGuiTabItemFlags_None)) {
265 current_sheet_ = sheet_id;
266 if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
267 release_queue_.push(sheet_id);
268 }
269 if (ImGui::IsItemHovered()) {
270 if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
271 release_queue_.push(sheet_id);
272 child_window_sheets_.insert(sheet_id);
273 }
274 }
275
276 const auto child_id =
277 absl::StrFormat("##GfxEditPaletteChildWindow%d", sheet_id);
278 ImGui::BeginChild(child_id.c_str(), ImVec2(0, 0), true,
279 ImGuiWindowFlags_NoDecoration |
280 ImGuiWindowFlags_AlwaysVerticalScrollbar |
281 ImGuiWindowFlags_AlwaysHorizontalScrollbar);
282
283 gfx::Bitmap& current_bitmap = rom()->mutable_gfx_sheets()->at(sheet_id);
284
285 auto draw_tile_event = [&]() {
288 Renderer::GetInstance().UpdateBitmap(&current_bitmap);
289 };
290
292 rom()->mutable_gfx_sheets()->at(sheet_id), current_color_,
293 draw_tile_event, tile_size_, current_scale_);
294
295 ImGui::EndChild();
296 ImGui::EndTabItem();
297 }
298
299 if (!open) release_queue_.push(sheet_id);
300 }
301
302 ImGui::EndTabBar();
303 }
304
305 // Release any tabs that were closed
306 while (!release_queue_.empty()) {
307 auto sheet_id = release_queue_.top();
308 open_sheets_.erase(sheet_id);
309 release_queue_.pop();
310 }
311
312 // Draw any child windows that were created
313 if (!child_window_sheets_.empty()) {
314 int id_to_release = -1;
315 for (const auto& id : child_window_sheets_) {
316 bool active = true;
317 ImGui::SetNextWindowPos(ImGui::GetIO().MousePos, ImGuiCond_Once);
318 ImGui::SetNextWindowSize(ImVec2(0x100 + 1 * 16, 0x40 + 1 * 16),
319 ImGuiCond_Once);
320 ImGui::Begin(absl::StrFormat("##GfxEditPaletteChildWindow%d", id).c_str(),
321 &active, ImGuiWindowFlags_AlwaysUseWindowPadding);
322 current_sheet_ = id;
323 // ImVec2(0x100, 0x40),
325 rom()->mutable_gfx_sheets()->at(id), current_color_,
326 [&]() {
327
328 },
330 ImGui::End();
331
332 if (active == false) {
333 id_to_release = id;
334 }
335 }
336 if (id_to_release != -1) {
337 child_window_sheets_.erase(id_to_release);
338 }
339 }
340
341 return absl::OkStatus();
342}
343
345 if (rom()->is_loaded()) {
346 auto palette_group = *rom()->palette_group().get_group(
347 kPaletteGroupAddressesKeys[edit_palette_group_name_index_]);
348 auto palette = palette_group.palette(edit_palette_index_);
349 gui::TextWithSeparators("ROM Palette");
350 ImGui::SetNextItemWidth(100.f);
351 ImGui::Combo("Palette Group", (int*)&edit_palette_group_name_index_,
352 kPaletteGroupAddressesKeys,
353 IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
354 ImGui::SetNextItemWidth(100.f);
355 gui::InputHex("Palette Group Index", &edit_palette_index_);
356
358 palette);
359
360 if (refresh_graphics_ && !open_sheets_.empty()) {
362 rom()
363 ->mutable_gfx_sheets()
364 ->data()[current_sheet_]
365 .ApplyPaletteWithTransparent(palette, edit_palette_sub_index_));
367 &rom()->mutable_gfx_sheets()->data()[current_sheet_]);
368 refresh_graphics_ = false;
369 }
370 }
371 return absl::OkStatus();
372}
373
375 TAB_ITEM("Player Animations")
376
377 if (ImGui::BeginTable("##PlayerAnimationTable", 3, kGfxEditTableFlags,
378 ImVec2(0, 0))) {
379 for (const auto& name : {"Canvas", "Animation Steps", "Properties"})
380 ImGui::TableSetupColumn(name);
381
382 ImGui::TableHeadersRow();
383
384 NEXT_COLUMN();
386 link_canvas_.DrawGrid(16.0f);
387
388 int i = 0;
389 for (auto link_sheet : *rom()->mutable_link_graphics()) {
390 int x_offset = 0;
391 int y_offset = gfx::kTilesheetHeight * i * 4;
392 link_canvas_.DrawContextMenu(&link_sheet);
393 link_canvas_.DrawBitmap(link_sheet, x_offset, y_offset, 4);
394 i++;
395 }
398
399 NEXT_COLUMN();
400 ImGui::Text("Placeholder");
401
402 NEXT_COLUMN();
403 if (ImGui::Button("Load Link Graphics (Experimental)")) {
404 if (rom()->is_loaded()) {
405 // Load Links graphics from the ROM
406 RETURN_IF_ERROR(rom()->LoadLinkGraphics());
407
408 // Split it into the pose data frames
409 // Create an animation step display for the poses
410 // Allow the user to modify the frames used in an anim step
411 // LinkOAM_AnimationSteps:
412 // #_0D85FB
413 }
414 }
415 }
416 ImGui::EndTable();
417
419 return absl::OkStatus();
420}
421
423 TAB_ITEM("Prototype")
424
426
428 ImGui::Begin("Memory Editor", &open_memory_editor_);
430 ImGui::End();
431 }
432
433 constexpr ImGuiTableFlags kGfxEditFlags = ImGuiTableFlags_Reorderable |
434 ImGuiTableFlags_Resizable |
435 ImGuiTableFlags_SizingStretchSame;
436
437 BEGIN_TABLE("#gfxEditTable", 4, kGfxEditFlags)
438 SETUP_COLUMN("File Import (BIN, CGX, ROM)")
439 SETUP_COLUMN("Palette (COL)")
440 ImGui::TableSetupColumn("Tilemaps and Objects (SCR, PNL, OBJ)",
441 ImGuiTableColumnFlags_WidthFixed);
442 SETUP_COLUMN("Graphics Preview")
444 NEXT_COLUMN() {
449 }
450
452
455 scr_loaded_, false, 0);
457
459 if (super_donkey_) {
460 // TODO: Implement the Super Donkey 1 graphics decompression
461 // if (refresh_graphics_) {
462 // for (int i = 0; i < kNumGfxSheets; i++) {
463 // status_ = graphics_bin_[i].ApplyPalette(
464 // col_file_palette_group_[current_palette_index_]);
465 // Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]);
466 // }
467 // refresh_graphics_ = false;
468 // }
469 // Load the full graphics space from `super_donkey_1.bin`
470 // gui::GraphicsBinCanvasPipeline(0x100, 0x40, 0x20, num_sheets_to_load_, 3,
471 // super_donkey_, graphics_bin_);
472 } else if (cgx_loaded_ && col_file_) {
473 // Load the CGX graphics
475 cgx_loaded_, true, 5);
476 } else {
477 // Load the BIN/Clipboard Graphics
479 gfx_loaded_, true, 2);
480 }
481 END_TABLE()
482
484 return absl::OkStatus();
485}
486
488 static constexpr absl::string_view kGfxToolsetColumnNames[] = {
489 "#memoryEditor",
490 "##separator_gfx1",
491 };
492
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 =
716 std::vector<uint8_t>(text, text + strlen(text));
717 ImGui::MemFree((void*)text);
718 status_ = temp_rom_.LoadFromBytes(clipboard_data);
719 is_open_ = true;
720 open_memory_editor_ = true;
721 }
722 }
725 gui::InputHex("Num Sheets", &num_sheets_to_load_);
726
727 if (Button("Decompress Clipboard Data")) {
728 if (temp_rom_.is_loaded()) {
729 status_ = DecompressImportData(0x40000);
730 } else {
731 status_ = absl::InvalidArgumentError(
732 "Please paste data into the clipboard before "
733 "decompressing.");
734 }
735 }
736
737 return absl::OkStatus();
738}
739
741 gui::TextWithSeparators("Experimental");
742 if (Button("Decompress Super Donkey Full")) {
743 if (strlen(file_path_) > 0) {
745 } else {
746 return absl::InvalidArgumentError(
747 "Please select `super_donkey_1.bin` before "
748 "importing.");
749 }
750 }
751 ImGui::SetItemTooltip(
752 "Requires `super_donkey_1.bin` to be imported under the "
753 "BIN import section.");
754 return absl::OkStatus();
755}
756
758 std::string title = "Memory Editor";
759 if (is_open_) {
760 static MemoryEditor mem_edit;
761 mem_edit.DrawWindow(title.c_str(), temp_rom_.data(), temp_rom_.size());
762 }
763 return absl::OkStatus();
764}
765
769
770 auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
772 converted_sheet);
773
774 if (rom()->is_loaded()) {
775 auto palette_group = rom()->palette_group().overworld_animated;
776 z3_rom_palette_ = palette_group[current_palette_];
777 if (col_file_) {
779 } else {
781 }
782 }
783
785 gfx_loaded_ = true;
786
787 return absl::OkStatus();
788}
789
791 int i = 0;
792 for (const auto& offset : kSuperDonkeyTiles) {
793 int offset_value =
794 std::stoi(offset, nullptr, 16); // convert hex string to int
796 auto decompressed_data,
797 gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
798 auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
800 gfx::kTilesheetDepth, converted_sheet);
801 if (col_file_) {
802 status_ = gfx_sheets_[i].ApplyPalette(
804 } else {
805 // ROM palette
806
807 auto palette_group = rom()->palette_group().get_group(
808 kPaletteGroupAddressesKeys[current_palette_]);
809 z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
810 status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_);
811 }
812
814 i++;
815 }
816
817 for (const auto& offset : kSuperDonkeySprites) {
818 int offset_value =
819 std::stoi(offset, nullptr, 16); // convert hex string to int
821 auto decompressed_data,
822 gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
823 auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
825 gfx::kTilesheetDepth, converted_sheet);
826 if (col_file_) {
827 status_ = gfx_sheets_[i].ApplyPalette(
829 } else {
830 // ROM palette
831 auto palette_group = rom()->palette_group().get_group(
832 kPaletteGroupAddressesKeys[current_palette_]);
833 z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
834 status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_);
835 }
836
838 i++;
839 }
840 super_donkey_ = true;
842
843 return absl::OkStatus();
844}
845
846} // namespace editor
847} // namespace app
848} // namespace yaze
auto size() const
Definition rom.h:460
bool is_loaded() const
Definition rom.h:448
auto data()
Definition rom.h:463
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:168
absl::Status LoadFromBytes(const std::vector< uint8_t > &data)
Definition rom.cc:266
void UpdateBitmap(gfx::Bitmap *bitmap)
Used to update a bitmap on the screen.
Definition renderer.h:56
static Renderer & GetInstance()
Definition renderer.h:27
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:49
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:67
auto at(int i) const
Definition bitmap.h:185
absl::Status ApplyPalette(const SnesPalette &palette)
Copy color data from the SnesPalette into the SDL_Palette.
Definition bitmap.cc:327
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:230
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:66
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
Definition canvas.cc:686
auto draw_list() const
Definition canvas.h:156
void DrawTileOnBitmap(int tile_size, gfx::Bitmap *bitmap, ImVec4 color)
Definition canvas.cc:319
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
Definition canvas.cc:461
auto zero_point() const
Definition canvas.h:157
void UpdateColorPainter(gfx::Bitmap &bitmap, const ImVec4 &color, const std::function< void()> &event, int tile_size, float scale=1.0f)
Definition canvas.cc:44
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
Definition canvas.cc:101
#define SETUP_COLUMN(l)
Definition constants.h:21
#define END_TABLE()
Definition constants.h:29
#define TABLE_HEADERS()
Definition constants.h:23
#define BEGIN_TABLE(l, n, f)
Definition constants.h:20
#define RETURN_IF_ERROR(expression)
Definition constants.h:62
#define END_TAB_ITEM()
Definition constants.h:5
#define NEXT_COLUMN()
Definition constants.h:27
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition constants.h:70
#define CLEAR_AND_RETURN_STATUS(status)
Definition constants.h:105
#define TEXT_COLUMN(w)
Definition constants.h:16
#define TAB_ITEM(w)
Definition constants.h:4
#define HOVER_HINT(string)
Definition constants.h:33
#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
const std::string kSuperDonkeyTiles[]
constexpr ImGuiTableFlags kGfxEditTableFlags
const std::string kSuperDonkeySprites[]
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:45
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:18
std::vector< uint8_t > SnesTo8bppSheet(const std::vector< uint8_t > &sheet, int bpp, int num_sheets)
Definition snes_tile.cc:152
constexpr int kTilesheetWidth
Definition snes_tile.h:16
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:17
constexpr const char * kPaletteGroupAddressesKeys[]
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:175
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:142
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:266
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:424
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:832
constexpr uint32_t kNumGfxSheets
Definition rom.h:116
Definition common.cc:22
void Draw(const std::array< gfx::Bitmap, kNumGfxSheets > &bmp_manager)
void Initialize(const std::array< gfx::Bitmap, kNumGfxSheets > &bmp_manager)