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 // Visibility belongs to the workspace manager, including saved layouts.
60 void SetSheetBrowserCallbacks(std::function<bool()> visible,
61 std::function<void(bool)> set_visible) {
62 sheet_browser_visible_ = std::move(visible);
63 set_sheet_browser_visible_ = std::move(set_visible);
64 }
65
69 void Draw(bool* p_open) override;
70
75 absl::Status Update();
76
77 // System clipboard (PNG); Cut/Copy/Paste shortcuts route here through
78 // GraphicsEditor. Copy takes the selection, or the whole sheet.
82
83 bool HasActiveStroke() const { return stroke_.has_value(); }
84 // Explicit navigation commits the current gesture before its target changes.
85 void FinishGesture();
86 // A hidden panel may miss the release frame; button-up still finishes it.
88 void SetHistoryCallbacks(std::function<absl::Status()> undo,
89 std::function<absl::Status()> redo) {
90 undo_ = std::move(undo);
91 redo_ = std::move(redo);
92 }
96
97 private:
98 std::function<absl::Status()> undo_;
99 std::function<absl::Status()> redo_;
100 std::string history_error_;
104 void DrawSourceContext();
105 // A palette-only display copy. Pixel tools still write the session store.
111 std::function<void()> draw_source_preview_;
112 std::function<bool()> sheet_browser_visible_;
113 std::function<void(bool)> set_sheet_browser_visible_;
117 void DrawToolbar();
118
122 void DrawViewControls();
123
127 void DrawCanvas();
128
132 void DrawColorPicker();
133
137 void DrawStatusBar();
138
142 void DrawMiniMap();
143
147 void HandleCanvasInput();
148
152 void ApplyPencil(int x, int y);
153
157 void ApplyBrush(int x, int y);
158
162 void ApplyEraser(int x, int y);
163
167 void ApplyFill(int x, int y);
168
172 void ApplyEyedropper(int x, int y);
173
177 void DrawLine(int x1, int y1, int x2, int y2);
178
182 void DrawRectangle(int x1, int y1, int x2, int y2, bool filled);
183
187 void BeginSelection(int x, int y);
188
192 void UpdateSelection(int x, int y);
193
197 void EndSelection();
198
202 void CopySelection();
203
207 void PasteSelection(int x, int y);
208
213
218
223 void BeginStroke();
224
229 void EndStroke();
230
235
237 void ShowStrokeChanges(bool changed);
238
242 ImVec2 ScreenToPixel(ImVec2 screen_pos);
243
247 ImVec2 PixelToScreen(int x, int y);
248
249 // ==========================================================================
250 // Overlay Drawing
251 // ==========================================================================
252
256 void DrawTransparencyGrid(float canvas_width, float canvas_height);
257
261 void DrawCursorCrosshair();
262
266 void DrawBrushPreview();
267
271 void DrawPixelInfoTooltip(const gfx::Bitmap& sheet);
272
276 void DrawTileHighlight(const gfx::Bitmap& sheet);
277
280
284 gui::Canvas canvas_{"PixelEditorCanvas", ImVec2(128, 32),
286
287 // The stroke in progress (mouse-down to mouse-up, or one paste or cut).
288 std::optional<zelda3::GraphicsSheetStore::Edit> stroke_;
289
290 // Mouse tracking for tools
291 bool is_drawing_ = false;
292 ImVec2 last_mouse_pixel_ = {-1, -1};
293 ImVec2 tool_start_pixel_ = {-1, -1};
294
295 // Line/rectangle preview
296 bool show_tool_preview_ = false;
297 ImVec2 preview_end_ = {0, 0};
298
299 // Current cursor position in pixel coords
300 int cursor_x_ = 0;
301 int cursor_y_ = 0;
302 bool cursor_in_canvas_ = false;
303
304 // System clipboard (PNG). Copy takes the selection, or the whole sheet
305 // when nothing is selected. Paste maps the image onto the sheet's colors
306 // and floats it as the selection until committed (Enter, or a click
307 // outside it) or cancelled (Esc); a commit is one undo step.
310 void DrawFloatingPaste();
311 bool HandleFloatingPasteInput(); // true while the float takes the mouse
312 void CommitFloatingPaste();
313 void CancelFloatingPaste();
314 void ClampFloatingPaste();
316 std::string clipboard_status_;
318 bool paste_skip_color0_ = false;
319 bool dragging_paste_ = false;
322
323 // Canvas panning (Hand tool, or the middle mouse button with any tool).
324 bool HandlePanInput();
326 void DrawPixelGrids(float canvas_width, float canvas_height);
327};
328
329} // namespace editor
330} // namespace yaze
331
332#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:49
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.
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 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.