From 01b8441573c2782a2dbe8664f0114b78ab60cced Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 14 Jul 2024 19:34:33 -0400 Subject: [PATCH] fix palette update pointer semantics --- src/app/editor/modules/gfx_group_editor.cc | 18 +++++++++-------- src/app/editor/modules/palette_editor.cc | 18 ++++++----------- src/app/gfx/bitmap.cc | 23 +++++++++++----------- src/app/gfx/snes_color.h | 6 +++--- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/app/editor/modules/gfx_group_editor.cc b/src/app/editor/modules/gfx_group_editor.cc index 1e0375e0..5373691d 100644 --- a/src/app/editor/modules/gfx_group_editor.cc +++ b/src/app/editor/modules/gfx_group_editor.cc @@ -71,13 +71,6 @@ absl::Status GfxGroupEditor::Update() { } if (ImGui::BeginTabItem("Palettes")) { - gui::InputHexByte("Selected Paletteset", &selected_paletteset_); - if (selected_paletteset_ >= 71) { - selected_paletteset_ = 71; - } - rom()->resource_label()->SelectableLabelWithNameEdit( - false, "paletteset", "0x" + std::to_string(selected_paletteset_), - "Paletteset " + std::to_string(selected_paletteset_)); DrawPaletteViewer(); ImGui::EndTabItem(); } @@ -227,6 +220,7 @@ void DrawPaletteFromPaletteGroup(gfx::SnesPalette &palette) { auto popup_id = absl::StrCat("Palette", n); // Small icon of the color in the palette + if (gui::SnesColorButton(popup_id, palette[n], ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | @@ -239,6 +233,14 @@ void DrawPaletteFromPaletteGroup(gfx::SnesPalette &palette) { } // namespace void GfxGroupEditor::DrawPaletteViewer() { + gui::InputHexByte("Selected Paletteset", &selected_paletteset_); + if (selected_paletteset_ >= 71) { + selected_paletteset_ = 71; + } + rom()->resource_label()->SelectableLabelWithNameEdit( + false, "paletteset", "0x" + std::to_string(selected_paletteset_), + "Paletteset " + std::to_string(selected_paletteset_)); + uint8_t &dungeon_main_palette_val = rom()->paletteset_ids[selected_paletteset_][0]; uint8_t &dungeon_spr_pal_1_val = @@ -248,7 +250,7 @@ void GfxGroupEditor::DrawPaletteViewer() { uint8_t &dungeon_spr_pal_3_val = rom()->paletteset_ids[selected_paletteset_][3]; - gui::InputHexByte("Dungeon Main", &selected_paletteset_); + gui::InputHexByte("Dungeon Main", &dungeon_main_palette_val); rom()->resource_label()->SelectableLabelWithNameEdit( false, kPaletteGroupNames[PaletteCategory::kDungeons].data(), diff --git a/src/app/editor/modules/palette_editor.cc b/src/app/editor/modules/palette_editor.cc index c6991f3b..586ece7e 100644 --- a/src/app/editor/modules/palette_editor.cc +++ b/src/app/editor/modules/palette_editor.cc @@ -95,7 +95,7 @@ absl::Status PaletteEditor::Update() { TableHeadersRow(); TableNextRow(); TableNextColumn(); - if (gui::SnesColorEdit4("Color Picker", current_color_, + if (gui::SnesColorEdit4("Color Picker", ¤t_color_, ImGuiColorEditFlags_NoAlpha)) { // TODO: Implement new update color function } @@ -204,13 +204,13 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { } auto palette_group_name = kPaletteGroupNames[category]; - gfx::PaletteGroup palette_group = - *rom()->palette_group().get_group(palette_group_name.data()); - const auto size = palette_group.size(); + gfx::PaletteGroup* palette_group = + rom()->mutable_palette_group()->get_group(palette_group_name.data()); + const auto size = palette_group->size(); static bool edit_color = false; for (int j = 0; j < size; j++) { - gfx::SnesPalette* palette = palette_group.mutable_palette(j); + gfx::SnesPalette* palette = palette_group->mutable_palette(j); auto pal_size = palette->size(); for (int n = 0; n < pal_size; n++) { @@ -230,12 +230,6 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { if (BeginPopupContextItem(popup_id.c_str())) { RETURN_IF_ERROR(HandleColorPopup(*palette, category, j, n)) } - - // if (gui::SnesColorEdit4(popup_id.c_str(), (*palette)[n], - // palette_button_flags)) { - // EditColorInPalette(*palette, n); - // } - PopID(); } SameLine(); @@ -249,7 +243,7 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n) { auto col = gfx::ToFloatArray(palette[n]); - if (gui::SnesColorEdit4("Edit Color", palette[n], color_popup_flags)) { + if (gui::SnesColorEdit4("Edit Color", &palette[n], color_popup_flags)) { // TODO: Implement new update color function } diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index 4a202982..af5ffa76 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -201,6 +201,7 @@ void Bitmap::Create(int width, int height, int depth, const Bytes &data) { SDL_Surface_Deleter()); surface_->pixels = pixel_data_; GrayscalePalette(surface_->format->palette); + active_ = true; } void Bitmap::CreateTexture(SDL_Renderer *renderer) { @@ -312,17 +313,17 @@ absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) { for (int i = 0; i < palette.size(); ++i) { ASSIGN_OR_RETURN(gfx::SnesColor pal_color, palette.GetColor(i)); - if (pal_color.is_transparent()) { - sdlPalette->colors[i].r = 0; - sdlPalette->colors[i].g = 0; - sdlPalette->colors[i].b = 0; - sdlPalette->colors[i].a = 0; - } else { - sdlPalette->colors[i].r = pal_color.rgb().x; - sdlPalette->colors[i].g = pal_color.rgb().y; - sdlPalette->colors[i].b = pal_color.rgb().z; - sdlPalette->colors[i].a = pal_color.rgb().w; - } + // if (pal_color.is_transparent()) { + // sdlPalette->colors[i].r = 0; + // sdlPalette->colors[i].g = 0; + // sdlPalette->colors[i].b = 0; + // sdlPalette->colors[i].a = 0; + // } else { + sdlPalette->colors[i].r = pal_color.rgb().x; + sdlPalette->colors[i].g = pal_color.rgb().y; + sdlPalette->colors[i].b = pal_color.rgb().z; + sdlPalette->colors[i].a = pal_color.rgb().w; + // } } SDL_LockSurface(surface_.get()); diff --git a/src/app/gfx/snes_color.h b/src/app/gfx/snes_color.h index 5923d27b..c1719a02 100644 --- a/src/app/gfx/snes_color.h +++ b/src/app/gfx/snes_color.h @@ -31,10 +31,10 @@ std::vector Convert(const std::vector& palette); /** * @brief SNES Color container - * - * Used for displaying the color to the screen and writing + * + * Used for displaying the color to the screen and writing * the color to the Rom file in the correct format. - * + * * SNES colors may be represented in one of three formats: * - Color data from the rom in a snes_color struct * - Color data for displaying to the UI via ImVec4