yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
pixel_editor_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_PIXEL_EDITOR_PANEL_H
2#define YAZE_APP_EDITOR_GRAPHICS_PIXEL_EDITOR_PANEL_H
3
4#include <functional>
5#include <optional>
6
7#include "absl/status/status.h"
13#include "app/gfx/core/bitmap.h"
15#include "app/gui/core/icons.h"
16#include "rom/rom.h"
18
19namespace yaze {
20namespace editor {
21
29 public:
31 UndoManager* undo_manager = nullptr)
32 : state_(state), rom_(rom), undo_manager_(undo_manager) {}
33
34 // ==========================================================================
35 // WindowContent Identity
36 // ==========================================================================
37
38 std::string GetId() const override { return "graphics.pixel_editor"; }
39 std::string GetDisplayName() const override { return "Pixel Editor"; }
40 std::string GetIcon() const override { return ICON_MD_BRUSH; }
41 std::string GetEditorCategory() const override { return "Graphics"; }
42 int GetPriority() const override { return 20; }
43
44 // ==========================================================================
45 // WindowContent Lifecycle
46 // ==========================================================================
47
51 void Initialize();
52
53 void SetRom(Rom* rom) { rom_ = rom; }
54 // The Graphics owner supplies its existing Usage Preview; no second renderer.
55 void SetSourcePreviewCallback(std::function<void()> draw) {
56 draw_source_preview_ = std::move(draw);
57 }
59 void SetScratchCallback(std::function<void()> open) {
60 open_scratch_ = std::move(open);
61 }
62 // Visibility belongs to the workspace manager, including saved layouts.
63 void SetSheetBrowserCallbacks(std::function<bool()> visible,
64 std::function<void(bool)> set_visible) {
65 sheet_browser_visible_ = std::move(visible);
66 set_sheet_browser_visible_ = std::move(set_visible);
67 }
68
72 void Draw(bool* p_open) override;
73
78 absl::Status Update();
79
80 // System clipboard (PNG); Cut/Copy/Paste shortcuts route here through
81 // GraphicsEditor. Copy takes the selection, or the whole sheet.
85
86 bool HasActiveStroke() const { return stroke_.has_value(); }
87 // Explicit navigation commits the current gesture before its target changes.
88 void FinishGesture();
89 // A hidden panel may miss the release frame; button-up still finishes it.
91 void SetHistoryCallbacks(std::function<absl::Status()> undo,
92 std::function<absl::Status()> redo) {
93 undo_ = std::move(undo);
94 redo_ = std::move(redo);
95 }
99
100 private:
101 std::function<absl::Status()> undo_;
102 std::function<absl::Status()> redo_;
103 std::string history_error_;
107 void DrawSourceContext();
108 // A palette-only display copy. Pixel tools still write the session store.
114 std::function<void()> draw_source_preview_;
115 std::function<void()> open_scratch_;
116 std::function<bool()> sheet_browser_visible_;
117 std::function<void(bool)> set_sheet_browser_visible_;
121 void DrawToolbar();
122
126 void DrawViewControls();
127
131 void DrawCanvas();
132
136 void DrawColorPicker();
137
140 int swap_to_id_ = 2;
141 int swap_scope_ = 0;
143
147 void DrawStatusBar();
148
152 void DrawMiniMap();
153
157 void HandleCanvasInput();
158
162 void ApplyPencil(int x, int y);
163
167 void ApplyBrush(int x, int y);
168
172 void ApplyEraser(int x, int y);
173
177 void ApplyFill(int x, int y);
178
182 void ApplyEyedropper(int x, int y);
183
187 void DrawLine(int x1, int y1, int x2, int y2);
188
192 void DrawRectangle(int x1, int y1, int x2, int y2, bool filled);
193
197 void BeginSelection(int x, int y);
198
202 void UpdateSelection(int x, int y);
203
207 void EndSelection();
208
212 void CopySelection();
213
217 void PasteSelection(int x, int y);
218
223
228
233 void BeginStroke();
234
239 void EndStroke();
240
245
247 void ShowStrokeChanges(bool changed);
248
252 ImVec2 ScreenToPixel(ImVec2 screen_pos);
253
257 ImVec2 PixelToScreen(int x, int y);
258
259 // ==========================================================================
260 // Overlay Drawing
261 // ==========================================================================
262
266 void DrawTransparencyGrid(float canvas_width, float canvas_height);
267
271 void DrawCursorCrosshair();
272
276 void DrawBrushPreview();
277
281 void DrawPixelInfoTooltip(const gfx::Bitmap& sheet);
282
286 void DrawTileHighlight(const gfx::Bitmap& sheet);
287
290
294 gui::Canvas canvas_{"PixelEditorCanvas", ImVec2(128, 32),
296
297 // The stroke in progress (mouse-down to mouse-up, or one paste or cut).
298 std::optional<zelda3::GraphicsSheetStore::Edit> stroke_;
299
300 // Mouse tracking for tools
301 bool is_drawing_ = false;
302 ImVec2 last_mouse_pixel_ = {-1, -1};
303 ImVec2 tool_start_pixel_ = {-1, -1};
304
305 // Line/rectangle preview
306 bool show_tool_preview_ = false;
307 ImVec2 preview_end_ = {0, 0};
308
309 // Current cursor position in pixel coords
310 int cursor_x_ = 0;
311 int cursor_y_ = 0;
312 bool cursor_in_canvas_ = false;
313
314 // System clipboard (PNG). Copy takes the selection, or the whole sheet
315 // when nothing is selected. Paste maps the image onto the sheet's colors
316 // and floats it as the selection until committed (Enter, or a click
317 // outside it) or cancelled (Esc); a commit is one undo step.
320 void DrawFloatingPaste();
321 bool HandleFloatingPasteInput(); // true while the float takes the mouse
322 void CommitFloatingPaste();
323 void CancelFloatingPaste();
324 void ClampFloatingPaste();
326 std::string clipboard_status_;
328 bool paste_skip_color0_ = false;
329 bool dragging_paste_ = false;
332
333 // Canvas panning (Hand tool, or the middle mouse button with any tool).
334 bool HandlePanInput();
336 void DrawPixelGrids(float canvas_width, float canvas_height);
337};
338
339} // namespace editor
340} // namespace yaze
341
342#endif // YAZE_APP_EDITOR_GRAPHICS_PIXEL_EDITOR_PANEL_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:52
Shared state between GraphicsEditor panel components.
std::function< absl::Status(const std::vector< size_t > &, const PalettePermutation &)> Apply
Main pixel editing panel for graphics sheets.
std::string GetId() const override
Unique identifier for this panel.
void EndSelection()
Finalize the selection.
PaletteReorderControl palette_reorder_
void SetSheetBrowserCallbacks(std::function< bool()> visible, std::function< void(bool)> set_visible)
void DrawLine(int x1, int y1, int x2, int y2)
Draw line from start to end.
void DrawColorPicker()
Draw the color palette picker.
void ApplyEraser(int x, int y)
Apply eraser tool at position.
std::optional< zelda3::GraphicsSheetStore::Edit > stroke_
void DrawPixelInfoTooltip(const gfx::Bitmap &sheet)
Draw tooltip with pixel information.
void SetHistoryCallbacks(std::function< absl::Status()> undo, std::function< absl::Status()> redo)
void DrawCursorCrosshair()
Draw crosshair at cursor position.
void DrawMiniMap()
Draw the mini navigation map.
void Draw(bool *p_open) override
Draw the pixel editor UI (WindowContent interface)
std::string GetEditorCategory() const override
Editor category this panel belongs to.
void HandleCanvasInput()
Handle canvas mouse input for current tool.
ImVec2 ScreenToPixel(ImVec2 screen_pos)
Convert screen coordinates to pixel coordinates.
std::function< void(bool)> set_sheet_browser_visible_
void DrawBrushPreview()
Draw brush size preview circle.
void ApplyEyedropper(int x, int y)
Apply eyedropper tool at position.
void CopySelection()
Copy selection to clipboard.
void UpdateSelection(int x, int y)
Update selection during drag.
void FlipSelectionVertical()
Flip selection vertically.
void ApplyBrush(int x, int y)
Apply brush tool at position.
void Initialize()
Initialize the panel.
void FlipSelectionHorizontal()
Flip selection horizontally.
void DrawViewControls()
Draw zoom and view controls.
void ApplyPencil(int x, int y)
Apply pencil tool at position.
std::string GetIcon() const override
Material Design icon for this panel.
void DrawToolbar()
Draw the toolbar with tool selection.
absl::Status Update()
Legacy Update method for backward compatibility.
ImVec2 PixelToScreen(int x, int y)
Convert pixel coordinates to screen coordinates.
void BeginSelection(int x, int y)
Start a new selection.
std::function< absl::Status()> redo_
std::function< absl::Status()> undo_
void DrawStatusBar()
Draw the status bar with cursor position.
void SetSourcePreviewCallback(std::function< void()> draw)
void DrawTransparencyGrid(float canvas_width, float canvas_height)
Draw checkerboard pattern for transparent pixels.
void EndStroke()
Ends the stroke: the sheet's store revision changes once and one GraphicsPixelEditAction (the changed...
void BeginStroke()
Starts a stroke on the current sheet. Pixel writes go to the session's GraphicsSheetStore until EndSt...
void DrawTileHighlight(const gfx::Bitmap &sheet)
Draw a transient highlight for a target tile.
std::function< void()> open_scratch_
void DrawPixelGrids(float canvas_width, float canvas_height)
void ShowStrokeChanges(bool changed)
After pixel writes: refresh the Arena copy and mark the sheet modified.
std::function< void()> draw_source_preview_
void ApplyFill(int x, int y)
Apply flood fill starting at position.
void PasteSelection(int x, int y)
Paste clipboard at position.
gfx::SnesPalette DisplayPalette() const
void SetScratchCallback(std::function< void()> open)
void SetPaletteReorderCallback(PaletteReorderControl::Apply apply)
int GetPriority() const override
Get display priority for menu ordering.
std::function< bool()> sheet_browser_visible_
void DrawRectangle(int x1, int y1, int x2, int y2, bool filled)
Draw rectangle from start to end.
PixelEditorPanel(GraphicsEditorState *state, Rom *rom, UndoManager *undo_manager=nullptr)
void DrawCanvas()
Draw the main editing canvas.
PaletteReorderControl::Apply apply_palette_reorder_
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
zelda3::GraphicsSheetStore::Edit * StrokeEdit()
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
One ROM session's graphics sheet pixels, with a revision per sheet.
#define ICON_MD_BRUSH
Definition icons.h:325
std::array< std::array< uint8_t, 3 >, 8 > SheetColors
The 8 colors a 3bpp sheet shows (index 0 is transparent in game).
PixelTool
Pixel editing tool types for the graphics editor.