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::PaletteGroupMap& palette_groups) {
61 return false;
62 }
64 if (binding.palette_group_name.empty()) {
65 return false;
66 }
67 gfx::PaletteGroup* group =
68 palette_groups.get_group(std::string(binding.palette_group_name));
69 if (group == nullptr || group->size() == 0) {
70 return false;
71 }
72 const size_t resolved_index =
73 binding.default_sub_index < group->size() ? binding.default_sub_index : 0;
74 gfx::SnesPalette* palette = group->mutable_palette(resolved_index);
75 if (palette == nullptr || palette->empty()) {
76 return false;
77 }
78 sheet.SetPalette(*palette);
79 return true;
80}
81
82} // namespace internal
83} // namespace editor
84} // namespace yaze
85
86#endif // YAZE_APP_EDITOR_GRAPHICS_GFX_GROUP_EDITOR_INTERNAL_H_
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:36
static Arena & Get()
Definition arena.cc:21
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
TextureHandle texture() const
Definition bitmap.h:401
BitmapMetadata & metadata()
Definition bitmap.h:391
bool is_active() const
Definition bitmap.h:405
void set_active(bool active)
Definition bitmap.h:407
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
Definition bitmap.cc:384
SDL_Surface * surface() const
Definition bitmap.h:400
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void EnsureSheetTextureQueued(gfx::Bitmap &sheet)
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)
Represents a group of palettes.