yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_editor_state.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_GRAPHICS_EDITOR_STATE_H
2#define YAZE_APP_EDITOR_GRAPHICS_GRAPHICS_EDITOR_STATE_H
3
4#include <cstdint>
5#include <functional>
6#include <set>
7#include <string>
8#include <vector>
9
10#include "app/gfx/core/bitmap.h"
12#include "imgui/imgui.h"
13
14namespace yaze {
15namespace editor {
16
20enum class PixelTool {
21 kSelect, // Rectangle selection
22 kLasso, // Freeform selection
23 kPencil, // Single pixel drawing
24 kBrush, // Multi-pixel brush
25 kEraser, // Set pixels to transparent (index 0)
26 kFill, // Flood fill
27 kLine, // Line drawing
28 kRectangle, // Rectangle outline/fill
29 kEyedropper, // Color picker from canvas
30};
31
36 std::vector<uint8_t> pixel_data; // Copied pixel indices
37 gfx::SnesPalette palette; // Associated palette
38 int x = 0; // Selection origin X
39 int y = 0; // Selection origin Y
40 int width = 0; // Selection width
41 int height = 0; // Selection height
42 bool is_active = false; // Whether selection exists
43 bool is_floating = false; // Floating vs committed
44
45 void Clear() {
46 pixel_data.clear();
47 x = y = width = height = 0;
48 is_active = false;
49 is_floating = false;
50 }
51};
52
57 uint16_t sheet_id = 0;
58 uint16_t tile_index = 0;
59 double start_time = 0.0;
60 double duration = 0.0;
61 bool active = false;
62 std::string label;
63
64 void Clear() {
65 active = false;
66 label.clear();
67 duration = 0.0;
68 start_time = 0.0;
69 }
70};
71
72
82 public:
83 // --- Current Selection ---
84 uint16_t current_sheet_id = 0;
85 std::set<uint16_t> open_sheets;
86 std::set<uint16_t> selected_sheets; // Multi-select support
87
88 // --- Editing State ---
90 uint8_t current_color_index = 1; // Palette index (0 = transparent)
91 ImVec4 current_color; // RGBA for display
92 uint8_t brush_size = 1; // 1-8 pixel brush
93 bool fill_contiguous = true; // Fill tool: contiguous only
94
95 // --- View State ---
96 float zoom_level = 4.0f; // 1x to 16x
97 bool show_grid = true; // 8x8 tile grid
98 bool show_tile_boundaries = true; // 16x16 tile boundaries
99 ImVec2 pan_offset = {0, 0}; // Canvas pan offset
100
101 // --- Overlay State (for enhanced UX) ---
102 bool show_cursor_crosshair = true; // Crosshair at cursor position
103 bool show_brush_preview = true; // Preview circle for brush/eraser
104 bool show_transparency_grid = true; // Checkerboard for transparent pixels
105 bool show_pixel_info_tooltip = true; // Tooltip with pixel info on hover
106
107 // --- Palette State ---
109 uint64_t palette_index = 0;
110 uint64_t sub_palette_index = 0;
111 bool refresh_graphics = false;
112
113 // --- Selection State ---
115 ImVec2 selection_start; // Drag start point
116 bool is_selecting = false; // Currently drawing selection
117 TileHighlight tile_highlight; // Active tile focus hint
118
119 // --- Modified Sheets Tracking ---
120 std::set<uint16_t> modified_sheets;
121
122 // --- Callbacks for cross-panel communication ---
123 std::function<void(uint16_t)> on_sheet_selected;
124 std::function<void()> on_palette_changed;
125 std::function<void()> on_tool_changed;
126 std::function<void(uint16_t)> on_sheet_modified;
127
128 // --- Methods ---
129
133 void MarkSheetModified(uint16_t sheet_id) {
134 modified_sheets.insert(sheet_id);
135 if (on_sheet_modified) {
136 on_sheet_modified(sheet_id);
137 }
138 }
139
144
148 void ClearModifiedSheets(const std::set<uint16_t>& sheet_ids) {
149 for (auto sheet_id : sheet_ids) {
150 modified_sheets.erase(sheet_id);
151 }
152 }
153
157 bool HasUnsavedChanges() const { return !modified_sheets.empty(); }
158
162 void SelectSheet(uint16_t sheet_id) {
163 current_sheet_id = sheet_id;
164 open_sheets.insert(sheet_id);
165 if (on_sheet_selected) {
166 on_sheet_selected(sheet_id);
167 }
168 }
169
173 void HighlightTile(uint16_t sheet_id, uint16_t tile_index,
174 const std::string& label = "",
175 double duration_secs = 3.0) {
176 tile_highlight.sheet_id = sheet_id;
177 tile_highlight.tile_index = tile_index;
178 tile_highlight.label = label;
179 tile_highlight.start_time = ImGui::GetTime();
180 tile_highlight.duration = duration_secs;
181 tile_highlight.active = true;
182 }
183
187 void CloseSheet(uint16_t sheet_id) { open_sheets.erase(sheet_id); }
188
192 void SetTool(PixelTool tool) {
193 current_tool = tool;
194 if (on_tool_changed) {
196 }
197 }
198
202 void SetZoom(float zoom) {
203 zoom_level = std::clamp(zoom, 1.0f, 16.0f);
204 }
205
206 void ZoomIn() { SetZoom(zoom_level + 1.0f); }
207 void ZoomOut() { SetZoom(zoom_level - 1.0f); }
208
212 const char* GetToolName() const {
213 switch (current_tool) {
214 case PixelTool::kSelect: return "Select";
215 case PixelTool::kLasso: return "Lasso";
216 case PixelTool::kPencil: return "Pencil";
217 case PixelTool::kBrush: return "Brush";
218 case PixelTool::kEraser: return "Eraser";
219 case PixelTool::kFill: return "Fill";
220 case PixelTool::kLine: return "Line";
221 case PixelTool::kRectangle: return "Rectangle";
222 case PixelTool::kEyedropper: return "Eyedropper";
223 default: return "Unknown";
224 }
225 }
226};
227
228} // namespace editor
229} // namespace yaze
230
231#endif // YAZE_APP_EDITOR_GRAPHICS_GRAPHICS_EDITOR_STATE_H
Shared state between GraphicsEditor panel components.
std::function< void(uint16_t)> on_sheet_modified
void MarkSheetModified(uint16_t sheet_id)
Mark a sheet as modified for save tracking.
void HighlightTile(uint16_t sheet_id, uint16_t tile_index, const std::string &label="", double duration_secs=3.0)
Highlight a tile in the current sheet for quick visual focus.
void SetZoom(float zoom)
Set zoom level with clamping.
std::function< void(uint16_t)> on_sheet_selected
const char * GetToolName() const
Get tool name for status display.
bool HasUnsavedChanges() const
Check if any sheets have unsaved changes.
void SelectSheet(uint16_t sheet_id)
Select a sheet for editing.
void CloseSheet(uint16_t sheet_id)
Close a sheet tab.
void SetTool(PixelTool tool)
Set the current editing tool.
void ClearModifiedSheets()
Clear modification tracking (after save)
void ClearModifiedSheets(const std::set< uint16_t > &sheet_ids)
Clear specific sheets from modification tracking.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
PixelTool
Pixel editing tool types for the graphics editor.
Selection data for copy/paste operations.
std::vector< uint8_t > pixel_data
Transient highlight for focusing a tile in the pixel editor.