add modified colors section to palette editor

This commit is contained in:
scawful
2024-07-20 09:01:14 -04:00
parent 69a407fee1
commit 577f4e08f0
2 changed files with 40 additions and 4 deletions

View File

@@ -107,6 +107,8 @@ absl::Status PaletteEditor::Update() {
TableHeadersRow(); TableHeadersRow();
TableNextRow(); TableNextRow();
TableNextColumn(); TableNextColumn();
DrawModifiedColors();
DrawCustomPalette(); DrawCustomPalette();
Separator(); Separator();
gui::SnesColorEdit4("Current Color Picker", &current_color_, gui::SnesColorEdit4("Current Color Picker", &current_color_,
@@ -300,10 +302,33 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category, bool right_side) {
return absl::OkStatus(); return absl::OkStatus();
} }
void PaletteEditor::DrawModifiedColors() {
if (BeginChild("ModifiedColors", ImVec2(0, 100), true,
ImGuiWindowFlags_HorizontalScrollbar)) {
for (int i = 0; i < history_.size(); i++) {
PushID(i);
gui::SnesColorEdit4("Original ", &history_.GetOriginalColor(i),
ImGuiColorEditFlags_NoInputs);
SameLine(0.0f, GetStyle().ItemSpacing.y);
gui::SnesColorEdit4("Modified ", &history_.GetModifiedColor(i),
ImGuiColorEditFlags_NoInputs);
PopID();
}
}
EndChild();
}
absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i, absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i,
int j, int n) { int j, int n) {
auto col = gfx::ToFloatArray(palette[n]); auto col = gfx::ToFloatArray(palette[n]);
gui::SnesColorEdit4("Edit Color", &palette[n], kColorPopupFlags); auto original_color = palette[n];
if (gui::SnesColorEdit4("Edit Color", &palette[n], kColorPopupFlags)) {
history_.RecordChange(/*group_name=*/std::string(kPaletteGroupNames[i]),
/*palette_index=*/j, /*color_index=*/n,
original_color, palette[n]);
palette[n].set_modified(true);
}
if (Button("Copy as..", ImVec2(-1, 0))) OpenPopup("Copy"); if (Button("Copy as..", ImVec2(-1, 0))) OpenPopup("Copy");
if (BeginPopup("Copy")) { if (BeginPopup("Copy")) {
int cr = F32_TO_INT8_SAT(col[0]); int cr = F32_TO_INT8_SAT(col[0]);

View File

@@ -46,9 +46,9 @@ class PaletteEditorHistory {
} }
// Restore the original color // Restore the original color
gfx::SnesColor GetOriginalColor(const std::string& groupName, gfx::SnesColor RestoreOriginalColor(const std::string& groupName,
size_t paletteIndex, size_t paletteIndex,
size_t colorIndex) const { size_t colorIndex) const {
for (const auto& change : recentChanges) { for (const auto& change : recentChanges) {
if (change.group_name == groupName && if (change.group_name == groupName &&
change.palette_index == paletteIndex && change.palette_index == paletteIndex &&
@@ -61,6 +61,15 @@ class PaletteEditorHistory {
return gfx::SnesColor(); return gfx::SnesColor();
} }
auto size() const { return recentChanges.size(); }
gfx::SnesColor& GetModifiedColor(size_t index) {
return recentChanges[index].new_color;
}
gfx::SnesColor& GetOriginalColor(size_t index) {
return recentChanges[index].original_color;
}
private: private:
std::deque<PaletteChange> recentChanges; std::deque<PaletteChange> recentChanges;
static const size_t maxHistorySize = 50; // or any other number you deem fit static const size_t maxHistorySize = 50; // or any other number you deem fit
@@ -96,6 +105,8 @@ class PaletteEditor : public SharedRom, public Editor {
void DrawCustomPalette(); void DrawCustomPalette();
void DrawModifiedColors();
private: private:
absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n); absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n);
absl::Status InitializeSavedPalette(const gfx::SnesPalette& palette) { absl::Status InitializeSavedPalette(const gfx::SnesPalette& palette) {