yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_scratch_view.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_UI_SCRATCH_GRAPHICS_SCRATCH_VIEW_H_
2#define YAZE_APP_EDITOR_GRAPHICS_UI_SCRATCH_GRAPHICS_SCRATCH_VIEW_H_
3
4#include <functional>
5#include <map>
6#include <optional>
7#include <string>
8#include <tuple>
9
17#include "app/gui/core/icons.h"
18
19namespace yaze::editor {
20
22 std::function<absl::StatusOr<usage_preview::PreviewImage>(
23 const GraphicsScratchAsset&)>;
24
28
29 public:
31 std::string library_path = "");
32 ~GraphicsScratchView() override;
33 std::string GetId() const override { return "graphics.scratch"; }
34 std::string GetDisplayName() const override { return "Graphics Scratch"; }
35 std::string GetIcon() const override { return ICON_MD_BRUSH; }
36 std::string GetEditorCategory() const override { return "Graphics"; }
40 int GetPriority() const override { return 28; }
41 float GetPreferredWidth() const override { return 650; }
42 void Draw(bool* p_open) override;
43 bool HasPendingChanges() const { return dirty_ || stroke_.has_value(); }
44 bool HasActiveStroke() const { return stroke_.has_value(); }
45 absl::Status Flush();
46 void FinishGesture();
47 // These commands are shared by the toolbar and future source navigation.
48 absl::Status CaptureSheet();
49 absl::Status ImportBin(const std::string& path, int bpp, size_t offset,
50 const gfx::SnesPalette& palette = {});
51 absl::Status ApplyToSheet();
52 absl::Status ExportBin(const std::string& path);
53 // One Undo step covers every affected asset; a no-op adds no history.
54 absl::Status SwapColorIds(const std::vector<ScratchColorIdTarget>& targets,
55 const ColorIdPermutation& permutation);
56 const GraphicsScratchLibrary& library() const { return library_; }
57 // Binds a captured source pose to the currently imported asset, never another
58 // library selection. The callback must own its captured input values.
59 void SetAssociatedPreview(std::string label, ScratchPreviewCallback callback);
60 void SetApplyValidator(std::function<absl::Status(uint16_t)> validator) {
61 apply_validator_ = std::move(validator);
62 }
64 std::function<absl::Status(const std::string&)> validator) {
65 export_validator_ = std::move(validator);
66 }
67
68 private:
69 class LibraryEdit;
70 void Load();
71 absl::Status Record(GraphicsScratchLibrary before);
72 absl::Status PrepareCommand();
74 void SetStatus(absl::Status status);
76 void DrawColorIdSwap(const GraphicsScratchAsset& selected);
82 std::optional<GraphicsScratchLibrary> stroke_;
83 uint64_t selected_id_ = 0;
84 std::string path_;
85 std::string loaded_bytes_;
86 bool existed_ = false;
87 bool load_ok_ = false;
88 bool dirty_ = false;
89 std::string error_;
90 std::string asset_name_ = "Untitled sheet";
91 std::string bin_path_;
92 int bpp_ = 4;
93 int bin_offset_ = 0;
94 int color_ = 1;
96 int swap_to_id_ = 2;
97 bool swap_all_at_depth_ = false;
98 float zoom_ = 4;
99 std::function<absl::Status(uint16_t)> apply_validator_;
100 std::function<absl::Status(const std::string&)> export_validator_;
102 std::string preview_label_;
103 std::string preview_error_;
104 uint64_t preview_asset_id_ = 0;
105 std::optional<uint64_t> preview_hash_;
107 gui::Canvas preview_canvas_{"ScratchSourcePreview", ImVec2(256, 256),
109 // Export is an external write, not an Undoable pixel edit. Keep successful
110 // CAS baselines current when an older pixel/history snapshot is restored.
111 std::map<std::tuple<std::string, uint64_t, int>, std::vector<uint8_t>>
113};
114
115// The editor owns scratch state and history targets across Initialize calls.
116// Workspace replacement only replaces this callback, never the document.
118 public:
119 explicit GraphicsScratchWindow(std::function<void()> draw)
120 : draw_(std::move(draw)) {}
121 std::string GetId() const override { return "graphics.scratch"; }
122 std::string GetDisplayName() const override { return "Graphics Scratch"; }
123 std::string GetIcon() const override { return ICON_MD_BRUSH; }
124 std::string GetEditorCategory() const override { return "Graphics"; }
128 int GetPriority() const override { return 28; }
129 float GetPreferredWidth() const override { return 650; }
130 void Draw(bool*) override { draw_(); }
131
132 private:
133 std::function<void()> draw_;
134};
135
136} // namespace yaze::editor
137#endif // YAZE_APP_EDITOR_GRAPHICS_UI_SCRATCH_GRAPHICS_SCRATCH_VIEW_H_
Shared state between GraphicsEditor panel components.
void SetExportValidator(std::function< absl::Status(const std::string &)> validator)
void SetAssociatedPreview(std::string label, ScratchPreviewCallback callback)
std::string GetId() const override
Unique identifier for this panel.
float GetPreferredWidth() const override
Get preferred width for this panel (optional)
void DrawPixels(GraphicsScratchAsset &asset)
void Draw(bool *p_open) override
Draw the panel content.
std::string GetIcon() const override
Material Design icon for this panel.
std::optional< GraphicsScratchLibrary > stroke_
std::function< absl::Status(const std::string &) export_validator_)
void SetApplyValidator(std::function< absl::Status(uint16_t)> validator)
absl::Status ImportBin(const std::string &path, int bpp, size_t offset, const gfx::SnesPalette &palette={})
WindowPresentationPolicy GetPresentationPolicy() const override
How this content is hosted and advertised by workspace chrome.
const GraphicsScratchLibrary & library() const
void DrawColorIdSwap(const GraphicsScratchAsset &selected)
absl::Status SwapColorIds(const std::vector< ScratchColorIdTarget > &targets, const ColorIdPermutation &permutation)
int GetPriority() const override
Get display priority for menu ordering.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
GraphicsScratchView(GraphicsEditorState *state, UndoManager *history, std::string library_path="")
std::optional< uint64_t > preview_hash_
absl::Status Record(GraphicsScratchLibrary before)
absl::Status ExportBin(const std::string &path)
std::map< std::tuple< std::string, uint64_t, int >, std::vector< uint8_t > > published_chunks_
std::function< absl::Status(uint16_t)> apply_validator_
WindowPresentationPolicy GetPresentationPolicy() const override
How this content is hosted and advertised by workspace chrome.
GraphicsScratchWindow(std::function< void()> draw)
float GetPreferredWidth() const override
Get preferred width for this panel (optional)
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
std::string GetIcon() const override
Material Design icon for this panel.
void Draw(bool *) override
Draw the panel content.
int GetPriority() const override
Get display priority for menu ordering.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
std::string GetId() const override
Unique identifier for this panel.
Manages undo/redo stacks for a single editor.
Base interface for all logical window content components.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
#define ICON_MD_BRUSH
Definition icons.h:325
Editors are the view controllers for the application.
std::function< absl::StatusOr< usage_preview::PreviewImage >( const GraphicsScratchAsset &)> ScratchPreviewCallback
static WindowPresentationPolicy OptionalPopOut()