yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
gfx_group_editor_internal.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_GFX_GROUP_EDITOR_INTERNAL_H_
2#define YAZE_APP_EDITOR_GRAPHICS_GFX_GROUP_EDITOR_INTERNAL_H_
3
4#include <string>
5
11
12namespace yaze {
13namespace editor {
14namespace internal {
15
16// Ensure a graphics sheet bitmap is ready for canvas rendering.
17//
18// Sheets are seeded by GameData::LoadGraphics into Arena::gfx_sheets_, but
19// nothing in the GfxGroupEditor draw path queues a CREATE for the underlying
20// SDL texture. RenderBitmapOnCanvas (canvas_rendering.cc) silently returns
21// when !is_active() || !texture(), so sheets render blank until something
22// else (e.g. opening Graphics Editor) seeds the textures.
23//
24// Behavior:
25// * Bitmap with no surface -> no-op.
26// * Surface present, !is_active() -> mark active.
27// * Surface present, no texture -> queue CREATE on Arena.
28// * Surface and texture both set -> no-op.
29//
30// Safe to call every frame; the Arena's CREATE branch checks for an existing
31// texture before allocating, so re-queuing is harmless.
33 if (sheet.surface() == nullptr) {
34 return;
35 }
36 if (!sheet.is_active()) {
37 sheet.set_active(true);
38 }
39 if (sheet.texture() == nullptr) {
42 }
43 // Sheets shown in the gfx-group viewers are read-only previews. Marking
44 // the purpose lets later passes (and ad-hoc inspectors) tell preview
45 // bitmaps apart from editable scratchpads without consulting the caller.
47}
48
49// Apply the role-default palette to a sheet bitmap. Looks up the binding via
50// sheet_role_palette_table and resolves it against the provided palette
51// groups. Returns true if a palette was applied, false otherwise.
52//
53// No-op (returns false) when:
54// * role is kUnclassified
55// * the role's palette group cannot be resolved (palette data not loaded
56// yet, or unknown group name)
57// * the binding's sub_index is out of range for the resolved group
59 gfx::SheetRole role, gfx::PaletteGroupMap& palette_groups) {
61 return nullptr;
62 const auto binding = gfx::DefaultBindingFor(role);
63 if (binding.palette_group_name.empty())
64 return nullptr;
65 auto* group =
66 palette_groups.get_group(std::string(binding.palette_group_name));
67 if (group == nullptr || group->size() == 0)
68 return nullptr;
69 const size_t index =
70 binding.default_sub_index < group->size() ? binding.default_sub_index : 0;
71 const auto* palette = group->mutable_palette(index);
72 return palette && !palette->empty() ? palette : nullptr;
73}
74
76 gfx::PaletteGroupMap& palette_groups) {
77 const auto* palette = ResolveRoleDefaultPalette(role, palette_groups);
78 if (!palette)
79 return false;
80 sheet.SetPalette(*palette);
81 return true;
82}
83
84// A view owns its palette and texture; Arena sheets remain source data.
85inline void SyncSheetPreview(const gfx::Bitmap& source,
86 const gfx::SnesPalette& palette,
87 gfx::Bitmap& preview) {
88 if (!source.surface())
89 return;
90 const bool pixels_changed =
91 !preview.surface() || preview.width() != source.width() ||
92 preview.height() != source.height() ||
93 preview.depth() != source.depth() || preview.vector() != source.vector();
94 const bool palette_changed = !(preview.palette() == palette);
95 if (pixels_changed) {
96 preview.Create(source.width(), source.height(), source.depth(),
97 source.vector());
98 }
99 if (pixels_changed || palette_changed)
100 preview.SetPalette(palette);
102 if (preview.texture() && (pixels_changed || palette_changed)) {
103 preview.UpdateTexture();
104 }
105}
106
107} // namespace internal
108} // namespace editor
109} // namespace yaze
110
111#endif // YAZE_APP_EDITOR_GRAPHICS_GFX_GROUP_EDITOR_INTERNAL_H_
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:39
static Arena & Get()
Definition arena.cc:24
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
const SnesPalette & palette() const
Definition bitmap.h:393
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
Definition bitmap.cc:198
TextureHandle texture() const
Definition bitmap.h:410
const std::vector< uint8_t > & vector() const
Definition bitmap.h:411
BitmapMetadata & metadata()
Definition bitmap.h:395
bool is_active() const
Definition bitmap.h:414
void set_active(bool active)
Definition bitmap.h:416
int height() const
Definition bitmap.h:399
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
Definition bitmap.cc:452
int width() const
Definition bitmap.h:398
int depth() const
Definition bitmap.h:400
SDL_Surface * surface() const
Definition bitmap.h:409
void UpdateTexture()
Updates the underlying SDL_Texture when it already exists.
Definition bitmap.cc:301
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void EnsureSheetTextureQueued(gfx::Bitmap &sheet)
const gfx::SnesPalette * ResolveRoleDefaultPalette(gfx::SheetRole role, gfx::PaletteGroupMap &palette_groups)
void SyncSheetPreview(const gfx::Bitmap &source, const gfx::SnesPalette &palette, gfx::Bitmap &preview)
bool ApplyRoleDefaultPalette(gfx::Bitmap &sheet, gfx::SheetRole role, gfx::PaletteGroupMap &palette_groups)
SheetRolePaletteBinding DefaultBindingFor(SheetRole role)
Represents a mapping of palette groups.
PaletteGroup * get_group(const std::string &group_name)