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 "absl/status/status.h"
10#include "app/gui/core/icons.h"
11#include "rom/rom.h"
12
13namespace yaze {
14namespace editor {
15
23 public:
25 UndoManager* undo_manager = nullptr)
26 : state_(state), rom_(rom), undo_manager_(undo_manager) {}
27
28 // ==========================================================================
29 // EditorPanel Identity
30 // ==========================================================================
31
32 std::string GetId() const override { return "graphics.pixel_editor"; }
33 std::string GetDisplayName() const override { return "Pixel Editor"; }
34 std::string GetIcon() const override { return ICON_MD_BRUSH; }
35 std::string GetEditorCategory() const override { return "Graphics"; }
36 int GetPriority() const override { return 20; }
37
38 // ==========================================================================
39 // EditorPanel Lifecycle
40 // ==========================================================================
41
45 void Initialize();
46
50 void Draw(bool* p_open) override;
51
56 absl::Status Update();
57
58 private:
62 void DrawToolbar();
63
67 void DrawViewControls();
68
72 void DrawCanvas();
73
77 void DrawColorPicker();
78
82 void DrawStatusBar();
83
87 void DrawMiniMap();
88
92 void HandleCanvasInput();
93
97 void ApplyPencil(int x, int y);
98
102 void ApplyBrush(int x, int y);
103
107 void ApplyEraser(int x, int y);
108
112 void ApplyFill(int x, int y);
113
117 void ApplyEyedropper(int x, int y);
118
122 void DrawLine(int x1, int y1, int x2, int y2);
123
127 void DrawRectangle(int x1, int y1, int x2, int y2, bool filled);
128
132 void BeginSelection(int x, int y);
133
137 void UpdateSelection(int x, int y);
138
142 void EndSelection();
143
147 void CopySelection();
148
152 void PasteSelection(int x, int y);
153
158
163
167 void SaveUndoState();
168
173 void FinalizeUndoAction();
174
178 ImVec2 ScreenToPixel(ImVec2 screen_pos);
179
183 ImVec2 PixelToScreen(int x, int y);
184
185 // ==========================================================================
186 // Overlay Drawing
187 // ==========================================================================
188
192 void DrawTransparencyGrid(float canvas_width, float canvas_height);
193
197 void DrawCursorCrosshair();
198
202 void DrawBrushPreview();
203
207 void DrawPixelInfoTooltip(const gfx::Bitmap& sheet);
208
212 void DrawTileHighlight(const gfx::Bitmap& sheet);
213
217 gui::Canvas canvas_{"PixelEditorCanvas", ImVec2(128, 32),
219
220 // Pending before-snapshot for UndoManager integration.
221 // Captured at the start of an edit stroke and consumed when finalized.
222 bool has_pending_undo_ = false;
224 std::vector<uint8_t> pending_undo_before_data_;
225
226 // Mouse tracking for tools
227 bool is_drawing_ = false;
228 ImVec2 last_mouse_pixel_ = {-1, -1};
229 ImVec2 tool_start_pixel_ = {-1, -1};
230
231 // Line/rectangle preview
232 bool show_tool_preview_ = false;
233 ImVec2 preview_end_ = {0, 0};
234
235 // Current cursor position in pixel coords
236 int cursor_x_ = 0;
237 int cursor_y_ = 0;
238 bool cursor_in_canvas_ = false;
239};
240
241} // namespace editor
242} // namespace yaze
243
244#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:28
Base interface for all logical panel components.
Shared state between GraphicsEditor panel components.
Main pixel editing panel for graphics sheets.
std::string GetId() const override
Unique identifier for this panel.
void EndSelection()
Finalize the selection.
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.
void DrawPixelInfoTooltip(const gfx::Bitmap &sheet)
Draw tooltip with pixel information.
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 (EditorPanel 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.
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.
void DrawStatusBar()
Draw the status bar with cursor position.
void DrawTransparencyGrid(float canvas_width, float canvas_height)
Draw checkerboard pattern for transparent pixels.
void DrawTileHighlight(const gfx::Bitmap &sheet)
Draw a transient highlight for a target tile.
void ApplyFill(int x, int y)
Apply flood fill starting at position.
void PasteSelection(int x, int y)
Paste clipboard at position.
int GetPriority() const override
Get display priority for menu ordering.
void DrawRectangle(int x1, int y1, int x2, int y2, bool filled)
Draw rectangle from start to end.
void FinalizeUndoAction()
Finalize the current undo action by capturing the after-snapshot and pushing a GraphicsPixelEditActio...
PixelEditorPanel(GraphicsEditorState *state, Rom *rom, UndoManager *undo_manager=nullptr)
void DrawCanvas()
Draw the main editing canvas.
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
std::vector< uint8_t > pending_undo_before_data_
void SaveUndoState()
Save current state for undo (captures before-snapshot)
Manages undo/redo stacks for a single editor.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:150
#define ICON_MD_BRUSH
Definition icons.h:325