fix palette update pointer semantics

This commit is contained in:
scawful
2024-07-14 19:34:33 -04:00
parent abbef06142
commit 01b8441573
4 changed files with 31 additions and 34 deletions

View File

@@ -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(),

View File

@@ -95,7 +95,7 @@ absl::Status PaletteEditor::Update() {
TableHeadersRow();
TableNextRow();
TableNextColumn();
if (gui::SnesColorEdit4("Color Picker", current_color_,
if (gui::SnesColorEdit4("Color Picker", &current_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
}

View File

@@ -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());

View File

@@ -31,10 +31,10 @@ std::vector<char> Convert(const std::vector<snes_color>& 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