yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
pixel_editor_view.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_PIXEL_EDITOR_VIEW_H
2#define YAZE_APP_EDITOR_GRAPHICS_PIXEL_EDITOR_VIEW_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 // WindowContent 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 bool IsVisibleByDefault() const override { return true; }
38 float GetPreferredWidth() const override { return 800.0f; }
39
40 // ==========================================================================
41 // WindowContent Lifecycle
42 // ==========================================================================
43
47 void Initialize();
48
52 void Draw(bool* p_open) override;
53
58 absl::Status Update();
59
60 private:
64 void DrawToolbar();
65
69 void DrawViewControls();
70
74 void DrawCanvas();
75
79 void DrawColorPicker();
80
84 void DrawStatusBar();
85
89 void DrawMiniMap();
90
94 void HandleCanvasInput();
95
99 void ApplyPencil(int x, int y);
100
104 void ApplyBrush(int x, int y);
105
109 void ApplyEraser(int x, int y);
110
114 void ApplyFill(int x, int y);
115
119 void ApplyEyedropper(int x, int y);
120
124 void DrawLine(int x1, int y1, int x2, int y2);
125
129 void DrawRectangle(int x1, int y1, int x2, int y2, bool filled);
130
134 void BeginSelection(int x, int y);
135
139 void UpdateSelection(int x, int y);
140
144 void EndSelection();
145
149 void CopySelection();
150
154 void PasteSelection(int x, int y);
155
160
165
169 void SaveUndoState();
170
175 void FinalizeUndoAction();
176
180 ImVec2 ScreenToPixel(ImVec2 screen_pos);
181
185 ImVec2 PixelToScreen(int x, int y);
186
187 // ==========================================================================
188 // Overlay Drawing
189 // ==========================================================================
190
194 void DrawTransparencyGrid(float canvas_width, float canvas_height);
195
199 void DrawCursorCrosshair();
200
204 void DrawBrushPreview();
205
209 void DrawPixelInfoTooltip(const gfx::Bitmap& sheet);
210
214 void DrawTileHighlight(const gfx::Bitmap& sheet);
215
219 gui::Canvas canvas_{"PixelEditorCanvas", ImVec2(128, 32),
221
222 // Pending before-snapshot for UndoManager integration.
223 // Captured at the start of an edit stroke and consumed when finalized.
224 bool has_pending_undo_ = false;
226 std::vector<uint8_t> pending_undo_before_data_;
227
228 // Mouse tracking for tools
229 bool is_drawing_ = false;
230 ImVec2 last_mouse_pixel_ = {-1, -1};
231 ImVec2 tool_start_pixel_ = {-1, -1};
232
233 // Line/rectangle preview
234 bool show_tool_preview_ = false;
235 ImVec2 preview_end_ = {0, 0};
236
237 // Current cursor position in pixel coords
238 int cursor_x_ = 0;
239 int cursor_y_ = 0;
240 bool cursor_in_canvas_ = false;
241};
242
243} // namespace editor
244} // namespace yaze
245
246#endif // YAZE_APP_EDITOR_GRAPHICS_PIXEL_EDITOR_VIEW_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
Shared state between GraphicsEditor panel components.
Main pixel editing view for graphics sheets.
void ApplyFill(int x, int y)
Apply flood fill starting at position.
float GetPreferredWidth() const override
Get preferred width for this panel (optional)
std::string GetId() const override
Unique identifier for this panel.
int GetPriority() const override
Get display priority for menu ordering.
void DrawBrushPreview()
Draw brush size preview circle.
void DrawCursorCrosshair()
Draw crosshair at cursor position.
absl::Status Update()
Legacy Update method for backward compatibility.
void DrawCanvas()
Draw the main editing canvas.
void ApplyPencil(int x, int y)
Apply pencil tool at position.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
std::vector< uint8_t > pending_undo_before_data_
void FinalizeUndoAction()
Finalize the current undo action by capturing the after-snapshot and pushing a GraphicsPixelEditActio...
void BeginSelection(int x, int y)
Start a new selection.
void HandleCanvasInput()
Handle canvas mouse input for current tool.
void DrawTransparencyGrid(float canvas_width, float canvas_height)
Draw checkerboard pattern for transparent pixels.
void Initialize()
Initialize the view.
PixelEditorView(GraphicsEditorState *state, Rom *rom, UndoManager *undo_manager=nullptr)
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
void ApplyEyedropper(int x, int y)
Apply eyedropper tool at position.
ImVec2 PixelToScreen(int x, int y)
Convert pixel coordinates to screen coordinates.
void DrawPixelInfoTooltip(const gfx::Bitmap &sheet)
Draw tooltip with pixel information.
void FlipSelectionHorizontal()
Flip selection horizontally.
ImVec2 ScreenToPixel(ImVec2 screen_pos)
Convert screen coordinates to pixel coordinates.
void DrawTileHighlight(const gfx::Bitmap &sheet)
Draw a transient highlight for a target tile.
void PasteSelection(int x, int y)
Paste clipboard at position.
void Draw(bool *p_open) override
Draw the pixel editor UI (WindowContent interface)
bool IsVisibleByDefault() const override
Whether this panel should be visible by default.
void DrawLine(int x1, int y1, int x2, int y2)
Draw line from start to end.
std::string GetIcon() const override
Material Design icon for this panel.
void CopySelection()
Copy selection to clipboard.
void UpdateSelection(int x, int y)
Update selection during drag.
void FlipSelectionVertical()
Flip selection vertically.
void DrawToolbar()
Draw the toolbar with tool selection.
void DrawViewControls()
Draw zoom and view controls.
void SaveUndoState()
Save current state for undo (captures before-snapshot)
void DrawRectangle(int x1, int y1, int x2, int y2, bool filled)
Draw rectangle from start to end.
void EndSelection()
Finalize the selection.
void ApplyBrush(int x, int y)
Apply brush tool at position.
void DrawStatusBar()
Draw the status bar with cursor position.
void ApplyEraser(int x, int y)
Apply eraser tool at position.
void DrawColorPicker()
Draw the color palette picker.
void DrawMiniMap()
Draw the mini navigation map.
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:67
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:150
#define ICON_MD_BRUSH
Definition icons.h:325