17 if (!group || selection.
palette < 0 || selection.
palette >= group->size()) {
18 return absl::InvalidArgumentError(
"Preview palette is unavailable");
20 const auto& palette = group->palette_ref(selection.
palette);
25 if (selection.
row < 0 || selection.
row >= rows) {
26 return absl::InvalidArgumentError(
"Preview palette row is unavailable");
28 const size_t offset = selection.
row * layout.colors_per_row +
29 (layout.has_explicit_transparent ? 1 : 0);
30 const size_t length = std::min<size_t>(
32 layout.colors_per_row - (layout.has_explicit_transparent ? 1 : 0),
33 palette.size() - offset));
34 std::vector<gfx::SnesColor> colors(8,
gfx::SnesColor(uint16_t{0}));
35 colors[0].set_transparent(
true);
36 for (
size_t i = 0; i < length; ++i) {
37 colors[i + 1] = palette[offset + i];
38 colors[i + 1].set_transparent(
false);
41 static_cast<int>(group->size()), rows};
46 std::optional<GraphicsPaletteSelection> selection) {
49 sheet >= arena.gfx_sheets().size()) {
50 return absl::FailedPreconditionError(
"This ROM's graphics are not active");
52 auto& bitmap = arena.mutable_gfx_sheets()->at(sheet);
54 if (!bitmap.is_active() || !current) {
55 return absl::FailedPreconditionError(
"This sheet has no display palette");
58 std::vector<SDL_Color> colors;
63 return resolved.status();
65 for (
size_t i = 0; i < resolved->colors.size(); ++i) {
66 const auto rgb = resolved->colors[i].rgb();
67 colors.push_back({
static_cast<Uint8
>(rgb.x),
static_cast<Uint8
>(rgb.y),
68 static_cast<Uint8
>(rgb.z),
69 static_cast<Uint8
>(i == 0 ? 0 : 255)});
75 return absl::FailedPreconditionError(
"Loaded colors are unavailable");
77 colors.assign(loaded->colors,
78 loaded->colors + std::min(8, loaded->ncolors));
80 bool changed = current->ncolors <
static_cast<int>(colors.size());
81 for (
size_t i = 0; !changed && i < colors.size(); ++i) {
82 const auto& a = colors[i];
83 const auto& b = current->colors[i];
84 changed = a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
87 bitmap.SetPalette(colors);
88 arena.NotifySheetModified(sheet);
95 return absl::OkStatus();
100 std::optional<GraphicsPaletteSelection> selection) {
103 return absl::FailedPreconditionError(
"This ROM's graphics are not active");
106 const auto resolved =
108 if (!resolved.ok()) {
109 return resolved.status();
117 return absl::OkStatus();
125 const auto revision = manager.ColorRevision(state.
game_data);
126 if (context.refresh_palettes && context.palette_revision != revision) {
127 const auto status = context.refresh_palettes(context);
128 context.palette_error = status.ok() ?
"" : std::string(status.message());
129 context.palette_revision = revision;
Shared state between GraphicsEditor panel components.
std::map< uint16_t, GraphicsPaletteSelection > preview_palettes
std::optional< GraphicsEditContext > source_context
std::optional< GraphicsPaletteSelection > browser_palette
zelda3::GameData * game_data
const void * gfx_sheets_owner() const
static PaletteManager & Get()
Get the singleton instance.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
int GetPaletteRowCount(std::size_t palette_size, int colors_per_row)
PaletteRowLayout GetPaletteRowLayout(std::string_view group_name, std::size_t palette_size)
Editors are the view controllers for the application.
absl::Status SetGraphicsPreviewPalette(GraphicsEditorState &state, uint16_t sheet, std::optional< GraphicsPaletteSelection > selection)
absl::Status SetGraphicsPreviewPaletteForAllSheets(GraphicsEditorState &state, std::optional< GraphicsPaletteSelection > selection)
absl::StatusOr< GraphicsPalettePreview > ResolveGraphicsPreviewPalette(zelda3::GameData &data, const GraphicsPaletteSelection &selection)
void RefreshGraphicsPreviewPalettes(GraphicsEditorState &state)
constexpr uint32_t kNumGfxSheets
SDL2/SDL3 compatibility layer.
PaletteGroup * get_group(const std::string &group_name)
gfx::PaletteGroupMap palette_groups
std::array< gfx::Bitmap, kNumGfxSheets > gfx_bitmaps