yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
palette_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_PALETTE_EDITOR_H
2#define YAZE_APP_EDITOR_PALETTE_EDITOR_H
3
4#include <deque>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
10#include "app/editor/editor.h"
12#include "app/gfx/snes_color.h"
13#include "app/rom.h"
14#include "imgui/imgui.h"
15
16namespace yaze {
17namespace app {
18namespace editor {
19
20namespace palette_internal {
28
30 public:
31 void RecordChange(const std::string& group_name, size_t palette_index,
32 size_t color_index, const gfx::SnesColor& original_color,
33 const gfx::SnesColor& new_color) {
34 if (recent_changes_.size() >= kMaxHistorySize) {
35 recent_changes_.pop_front();
36 }
37
38 recent_changes_.push_back(
39 {group_name, palette_index, color_index, original_color, new_color});
40 }
41
42 gfx::SnesColor RestoreOriginalColor(const std::string& group_name,
43 size_t palette_index,
44 size_t color_index) const {
45 for (const auto& change : recent_changes_) {
46 if (change.group_name == group_name &&
47 change.palette_index == palette_index &&
48 change.color_index == color_index) {
49 return change.original_color;
50 }
51 }
52 return gfx::SnesColor();
53 }
54
55 auto size() const { return recent_changes_.size(); }
56
58 return recent_changes_[index].new_color;
59 }
61 return recent_changes_[index].original_color;
62 }
63
64 const std::deque<PaletteChange>& GetRecentChanges() const {
65 return recent_changes_;
66 }
67
68 private:
69 std::deque<PaletteChange> recent_changes_;
70 static const size_t kMaxHistorySize = 50;
71};
72} // namespace palette_internal
73
74absl::Status DisplayPalette(gfx::SnesPalette& palette, bool loaded);
75
80class PaletteEditor : public SharedRom, public Editor {
81 public:
86
87 absl::Status Update() override;
88
89 absl::Status Cut() override { return absl::OkStatus(); }
90 absl::Status Copy() override { return absl::OkStatus(); }
91 absl::Status Paste() override { return absl::OkStatus(); }
92 absl::Status Undo() override { return absl::OkStatus(); }
93 absl::Status Redo() override { return absl::OkStatus(); }
94 absl::Status Find() override { return absl::OkStatus(); }
95
97
98 absl::Status EditColorInPalette(gfx::SnesPalette& palette, int index);
99 absl::Status ResetColorToOriginal(gfx::SnesPalette& palette, int index,
100 const gfx::SnesPalette& originalPalette);
101 absl::Status DrawPaletteGroup(int category, bool right_side = false);
102
103 void DrawCustomPalette();
104
105 void DrawModifiedColors();
106
107 private:
108 absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n);
109
110 absl::Status status_;
112
114
115 std::vector<gfx::SnesColor> custom_palette_;
116
117 ImVec4 saved_palette_[256] = {};
118
120};
121
122} // namespace editor
123} // namespace app
124} // namespace yaze
125
126#endif
A class to hold a shared pointer to a Rom object.
Definition rom.h:576
Interface for editor classes.
Definition editor.h:54
Manage graphics group configurations in a Rom.
Allows the user to view and edit in game palettes.
absl::Status ResetColorToOriginal(gfx::SnesPalette &palette, int index, const gfx::SnesPalette &originalPalette)
absl::Status Update() override
absl::Status Cut() override
absl::Status Copy() override
absl::Status Redo() override
absl::Status HandleColorPopup(gfx::SnesPalette &palette, int i, int j, int n)
std::vector< gfx::SnesColor > custom_palette_
absl::Status Find() override
absl::Status Paste() override
absl::Status EditColorInPalette(gfx::SnesPalette &palette, int index)
absl::Status DrawPaletteGroup(int category, bool right_side=false)
absl::Status Undo() override
palette_internal::PaletteEditorHistory history_
void RecordChange(const std::string &group_name, size_t palette_index, size_t color_index, const gfx::SnesColor &original_color, const gfx::SnesColor &new_color)
gfx::SnesColor RestoreOriginalColor(const std::string &group_name, size_t palette_index, size_t color_index) const
const std::deque< PaletteChange > & GetRecentChanges() const
SNES Color container.
Definition snes_color.h:39
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
absl::Status DisplayPalette(gfx::SnesPalette &palette, bool loaded)
Definition common.cc:22