Fix PaletteGroup display color math
This commit is contained in:
@@ -43,9 +43,38 @@ absl::Status PaletteEditor::Update() {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::EditColorInPalette(gfx::SNESPalette& palette, int index) {
|
||||||
|
if (index >= palette.size()) {
|
||||||
|
// Handle error: the index is out of bounds
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the current color
|
||||||
|
auto currentColor = palette.GetColor(index).GetRGB();
|
||||||
|
if (ImGui::ColorPicker4("Color Picker", (float*)¤tColor)) {
|
||||||
|
// The color was modified, update it in the palette
|
||||||
|
palette(index, currentColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::ResetColorToOriginal(
|
||||||
|
gfx::SNESPalette& palette, int index,
|
||||||
|
const gfx::SNESPalette& originalPalette) {
|
||||||
|
if (index >= palette.size() || index >= originalPalette.size()) {
|
||||||
|
// Handle error: the index is out of bounds
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto originalColor = originalPalette.GetColor(index).GetRGB();
|
||||||
|
palette(index, originalColor);
|
||||||
|
}
|
||||||
|
|
||||||
absl::Status PaletteEditor::DrawPaletteGroup(int i) {
|
absl::Status PaletteEditor::DrawPaletteGroup(int i) {
|
||||||
auto size = rom()->GetPaletteGroup(kPaletteGroupNames[i].data()).size();
|
auto size = rom()->GetPaletteGroup(kPaletteGroupNames[i].data()).size();
|
||||||
auto palettes = rom()->GetPaletteGroup(kPaletteGroupNames[i].data());
|
auto palettes = rom()->GetPaletteGroup(kPaletteGroupNames[i].data());
|
||||||
|
if (static bool init = false; !init) {
|
||||||
|
InitializeSavedPalette(palettes[0]);
|
||||||
|
}
|
||||||
for (int j = 0; j < size; j++) {
|
for (int j = 0; j < size; j++) {
|
||||||
ImGui::Text("%d", j);
|
ImGui::Text("%d", j);
|
||||||
|
|
||||||
@@ -58,14 +87,16 @@ absl::Status PaletteEditor::DrawPaletteGroup(int i) {
|
|||||||
|
|
||||||
std::string popupId = kPaletteCategoryNames[i].data() +
|
std::string popupId = kPaletteCategoryNames[i].data() +
|
||||||
std::to_string(j) + "_" + std::to_string(n);
|
std::to_string(j) + "_" + std::to_string(n);
|
||||||
if (ImGui::ColorButton(popupId.c_str(), palette[n].GetRGB(),
|
if (ImGui::ColorButton(
|
||||||
palette_button_flags)) {
|
popupId.c_str(),
|
||||||
static auto float_array = gfx::ToFloatArray(palette[n]);
|
ImVec4(palette[n].GetRGB().x / 255, palette[n].GetRGB().y / 255,
|
||||||
if (ImGui::ColorEdit4(popupId.c_str(), float_array.data(),
|
palette[n].GetRGB().z / 255, palette[n].GetRGB().w / 255),
|
||||||
palette_button_flags))
|
palette_button_flags)) {
|
||||||
current_color_ = ImVec4(palette[n].GetRGB().x, palette[n].GetRGB().y,
|
if (ImGui::ColorEdit4(popupId.c_str(),
|
||||||
palette[n].GetRGB().z,
|
gfx::ToFloatArray(palette[n]).data(),
|
||||||
palette[n].GetRGB().w); // Prese rve alpha!
|
palette_button_flags)) {
|
||||||
|
EditColorInPalette(palette, n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::BeginPopupContextItem(popupId.c_str())) {
|
if (ImGui::BeginPopupContextItem(popupId.c_str())) {
|
||||||
@@ -111,12 +142,7 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
|
|||||||
// Generate a default palette. The palette will persist and can be edited.
|
// Generate a default palette. The palette will persist and can be edited.
|
||||||
static bool init = false;
|
static bool init = false;
|
||||||
if (loaded && !init) {
|
if (loaded && !init) {
|
||||||
for (int n = 0; n < palette.size(); n++) {
|
InitializeSavedPalette(palette);
|
||||||
saved_palette_[n].x = palette.GetColor(n).GetRGB().x / 255;
|
|
||||||
saved_palette_[n].y = palette.GetColor(n).GetRGB().y / 255;
|
|
||||||
saved_palette_[n].z = palette.GetColor(n).GetRGB().z / 255;
|
|
||||||
saved_palette_[n].w = 255; // Alpha
|
|
||||||
}
|
|
||||||
init = true;
|
init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,12 +214,7 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
|
|||||||
void PaletteEditor::DrawPortablePalette(gfx::SNESPalette& palette) {
|
void PaletteEditor::DrawPortablePalette(gfx::SNESPalette& palette) {
|
||||||
static bool init = false;
|
static bool init = false;
|
||||||
if (!init) {
|
if (!init) {
|
||||||
for (int n = 0; n < palette.size(); n++) {
|
InitializeSavedPalette(palette);
|
||||||
saved_palette_[n].x = palette.GetColor(n).GetRGB().x / 255;
|
|
||||||
saved_palette_[n].y = palette.GetColor(n).GetRGB().y / 255;
|
|
||||||
saved_palette_[n].z = palette.GetColor(n).GetRGB().z / 255;
|
|
||||||
saved_palette_[n].w = 255; // Alpha
|
|
||||||
}
|
|
||||||
init = true;
|
init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
@@ -26,9 +28,21 @@ static constexpr absl::string_view kPaletteGroupNames[] = {
|
|||||||
"ow_aux", "global_sprites", "dungeon_main", "ow_mini_map",
|
"ow_aux", "global_sprites", "dungeon_main", "ow_mini_map",
|
||||||
"ow_mini_map", "3d_object", "3d_object"};
|
"ow_mini_map", "3d_object", "3d_object"};
|
||||||
|
|
||||||
|
struct PaletteChange {
|
||||||
|
std::string groupName;
|
||||||
|
size_t paletteIndex;
|
||||||
|
size_t colorIndex;
|
||||||
|
gfx::SNESColor originalColor;
|
||||||
|
};
|
||||||
|
|
||||||
class PaletteEditor : public SharedROM {
|
class PaletteEditor : public SharedROM {
|
||||||
public:
|
public:
|
||||||
absl::Status Update();
|
absl::Status Update();
|
||||||
|
|
||||||
|
void EditColorInPalette(gfx::SNESPalette& palette, int index);
|
||||||
|
void ResetColorToOriginal(gfx::SNESPalette& palette, int index,
|
||||||
|
const gfx::SNESPalette& originalPalette);
|
||||||
|
|
||||||
void DisplayPalette(gfx::SNESPalette& palette, bool loaded);
|
void DisplayPalette(gfx::SNESPalette& palette, bool loaded);
|
||||||
|
|
||||||
void DrawPortablePalette(gfx::SNESPalette& palette);
|
void DrawPortablePalette(gfx::SNESPalette& palette);
|
||||||
@@ -36,6 +50,18 @@ class PaletteEditor : public SharedROM {
|
|||||||
private:
|
private:
|
||||||
absl::Status DrawPaletteGroup(int i);
|
absl::Status DrawPaletteGroup(int i);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void InitializeSavedPalette(const gfx::SNESPalette& palette) {
|
||||||
|
for (int n = 0; n < palette.size(); n++) {
|
||||||
|
saved_palette_[n].x = palette.GetColor(n).GetRGB().x / 255;
|
||||||
|
saved_palette_[n].y = palette.GetColor(n).GetRGB().y / 255;
|
||||||
|
saved_palette_[n].z = palette.GetColor(n).GetRGB().z / 255;
|
||||||
|
saved_palette_[n].w = 255; // Alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stack<PaletteChange> changeHistory;
|
||||||
|
|
||||||
ImVec4 saved_palette_[256] = {};
|
ImVec4 saved_palette_[256] = {};
|
||||||
ImVec4 current_color_;
|
ImVec4 current_color_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user