yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
core_events.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_EVENTS_CORE_EVENTS_H_
2#define YAZE_APP_EDITOR_EVENTS_CORE_EVENTS_H_
3
4#include <cstddef>
5#include <string>
6#include <vector>
7
9
10namespace yaze {
11class Rom;
12
13namespace editor {
14
15class RomSession;
16
17// =============================================================================
18// ROM Lifecycle Events
19// =============================================================================
20
27struct RomLoadedEvent : public Event {
28 Rom* rom = nullptr;
29 std::string filename;
30 size_t session_id = 0;
31
32 static RomLoadedEvent Create(Rom* r, const std::string& file,
33 size_t session) {
35 e.rom = r;
36 e.filename = file;
37 e.session_id = session;
38 return e;
39 }
40};
41
47struct RomUnloadedEvent : public Event {
48 size_t session_id = 0;
49
50 static RomUnloadedEvent Create(size_t session) {
52 e.session_id = session;
53 return e;
54 }
55};
56
63struct RomModifiedEvent : public Event {
64 Rom* rom = nullptr;
65 uint32_t address = 0;
66 size_t byte_count = 0;
67 size_t session_id = 0;
68
69 static RomModifiedEvent Create(Rom* r, size_t session, uint32_t addr = 0,
70 size_t bytes = 0) {
72 e.rom = r;
73 e.session_id = session;
74 e.address = addr;
75 e.byte_count = bytes;
76 return e;
77 }
78};
79
80// =============================================================================
81// Session Lifecycle Events
82// =============================================================================
83
89struct SessionSwitchedEvent : public Event {
90 size_t old_index = 0;
91 size_t new_index = 0;
92 RomSession* session = nullptr;
93 bool transient = false;
94
95 static SessionSwitchedEvent Create(size_t old_idx, size_t new_idx,
96 RomSession* sess,
97 bool is_transient = false) {
99 e.old_index = old_idx;
100 e.new_index = new_idx;
101 e.session = sess;
102 e.transient = is_transient;
103 return e;
104 }
105};
106
110struct SessionCreatedEvent : public Event {
111 size_t index = 0;
112 RomSession* session = nullptr;
113
114 static SessionCreatedEvent Create(size_t idx, RomSession* sess) {
116 e.index = idx;
117 e.session = sess;
118 return e;
119 }
120};
121
125struct SessionClosedEvent : public Event {
126 size_t index = 0;
127
128 static SessionClosedEvent Create(size_t idx) {
130 e.index = idx;
131 return e;
132 }
133};
134
135// =============================================================================
136// Editor State Events
137// =============================================================================
138
142struct EditorSwitchedEvent : public Event {
143 int editor_type = 0; // EditorType enum value
144 void* editor = nullptr;
145
146 static EditorSwitchedEvent Create(int type, void* ed) {
148 e.editor_type = type;
149 e.editor = ed;
150 return e;
151 }
152};
153
154// =============================================================================
155// UI State Events
156// =============================================================================
157
165 std::string
166 source; // Source editor: "overworld", "dungeon", "graphics", etc.
167 std::vector<int>
168 selected_ids; // IDs of selected items (tiles, rooms, sprites, etc.)
169 int primary_id = -1; // Primary selection (first or focused item)
170 size_t session_id = 0;
171
172 static SelectionChangedEvent Create(const std::string& src,
173 const std::vector<int>& ids,
174 size_t session = 0) {
176 e.source = src;
177 e.selected_ids = ids;
178 e.primary_id = ids.empty() ? -1 : ids.front();
179 e.session_id = session;
180 return e;
181 }
182
183 static SelectionChangedEvent CreateSingle(const std::string& src, int id,
184 size_t session = 0) {
186 e.source = src;
187 e.selected_ids = {id};
188 e.primary_id = id;
189 e.session_id = session;
190 return e;
191 }
192
193 static SelectionChangedEvent CreateEmpty(const std::string& src,
194 size_t session = 0) {
196 e.source = src;
197 e.selected_ids = {};
198 e.primary_id = -1;
199 e.session_id = session;
200 return e;
201 }
202
203 bool IsEmpty() const { return selected_ids.empty(); }
204 size_t Count() const { return selected_ids.size(); }
205};
206
214 std::string panel_id; // Panel identifier (may be session-prefixed)
215 std::string base_panel_id; // Base panel ID without session prefix
216 std::string category; // Panel category ("Dungeon", "Overworld", etc.)
217 bool visible = false; // New visibility state
218 size_t session_id = 0;
219
220 static PanelVisibilityChangedEvent Create(const std::string& id,
221 const std::string& base_id,
222 const std::string& cat, bool vis,
223 size_t session = 0) {
225 e.panel_id = id;
226 e.base_panel_id = base_id;
227 e.category = cat;
228 e.visible = vis;
229 e.session_id = session;
230 return e;
231 }
232};
233
239struct ZoomChangedEvent : public Event {
240 std::string
241 source; // Source canvas: "overworld_canvas", "dungeon_canvas", etc.
242 float old_zoom = 1.0f; // Previous zoom level
243 float new_zoom = 1.0f; // New zoom level
244 size_t session_id = 0;
245
246 static ZoomChangedEvent Create(const std::string& src, float old_z,
247 float new_z, size_t session = 0) {
249 e.source = src;
250 e.old_zoom = old_z;
251 e.new_zoom = new_z;
252 e.session_id = session;
253 return e;
254 }
255
256 float GetZoomDelta() const { return new_zoom - old_zoom; }
257 float GetZoomRatio() const {
258 return old_zoom > 0.0f ? new_zoom / old_zoom : 1.0f;
259 }
260 bool IsZoomIn() const { return new_zoom > old_zoom; }
261 bool IsZoomOut() const { return new_zoom < old_zoom; }
262};
263
264// =============================================================================
265// Navigation Request Events (cross-editor navigation)
266// =============================================================================
267
275 int room_id = -1;
276 size_t session_id = 0;
277
278 static JumpToRoomRequestEvent Create(int room, size_t session = 0) {
280 e.room_id = room;
281 e.session_id = session;
282 return e;
283 }
284};
285
293 int map_id = -1;
294 size_t session_id = 0;
295
296 static JumpToMapRequestEvent Create(int map, size_t session = 0) {
298 e.map_id = map;
299 e.session_id = session;
300 return e;
301 }
302};
303
311 int message_id = -1;
312 size_t session_id = 0;
313
314 static JumpToMessageRequestEvent Create(int message, size_t session = 0) {
316 e.message_id = message;
317 e.session_id = session;
318 return e;
319 }
320};
321
331 std::string symbol;
332 size_t session_id = 0;
333
335 size_t session = 0) {
337 e.symbol = std::move(sym);
338 e.session_id = session;
339 return e;
340 }
341};
342
343// =============================================================================
344// UI Action Request Events (activity bar, menus, shortcuts)
345// =============================================================================
346
371
373 size_t session_id = 0;
374
375 static UIActionRequestEvent Create(Action act, size_t session = 0) {
377 e.action = act;
378 e.session_id = session;
379 return e;
380 }
381
382 // Convenience factory methods
383 static UIActionRequestEvent ShowEmulator(size_t session = 0) {
384 return Create(Action::kShowEmulator, session);
385 }
386 static UIActionRequestEvent ShowSettings(size_t session = 0) {
387 return Create(Action::kShowSettings, session);
388 }
389 static UIActionRequestEvent ShowCommandPalette(size_t session = 0) {
390 return Create(Action::kShowCommandPalette, session);
391 }
392 static UIActionRequestEvent ShowAgentChatSidebar(size_t session = 0) {
393 return Create(Action::kShowAgentChatSidebar, session);
394 }
397 }
398 static UIActionRequestEvent OpenRom(size_t session = 0) {
399 return Create(Action::kOpenRom, session);
400 }
401 static UIActionRequestEvent SaveRom(size_t session = 0) {
402 return Create(Action::kSaveRom, session);
403 }
404 static UIActionRequestEvent Undo(size_t session = 0) {
405 return Create(Action::kUndo, session);
406 }
407 static UIActionRequestEvent Redo(size_t session = 0) {
408 return Create(Action::kRedo, session);
409 }
410};
411
418 bool sidebar_visible = false;
419 bool panel_expanded = false;
420
421 static SidebarStateChangedEvent Create(bool visible, bool expanded) {
423 e.sidebar_visible = visible;
424 e.panel_expanded = expanded;
425 return e;
426 }
427};
428
429// =============================================================================
430// Frame Lifecycle Events (for deferred action consolidation)
431// =============================================================================
432
438struct FrameBeginEvent : public Event {
439 float delta_time = 0.0f;
440
441 static FrameBeginEvent Create(float dt) {
443 e.delta_time = dt;
444 return e;
445 }
446};
447
453struct FrameGuiBeginEvent : public Event {
454 float delta_time = 0.0f;
455
456 static FrameGuiBeginEvent Create(float dt) {
458 e.delta_time = dt;
459 return e;
460 }
461};
462
468struct FrameEndEvent : public Event {
469 float delta_time = 0.0f;
470
471 static FrameEndEvent Create(float dt) {
473 e.delta_time = dt;
474 return e;
475 }
476};
477
478} // namespace editor
479} // namespace yaze
480
481#endif // YAZE_APP_EDITOR_EVENTS_CORE_EVENTS_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
Published when the active editor changes.
static EditorSwitchedEvent Create(int type, void *ed)
Published at the beginning of each frame (pre-ImGui).
static FrameBeginEvent Create(float dt)
Published at the end of each frame.
static FrameEndEvent Create(float dt)
Published after ImGui::NewFrame and dockspace creation.
static FrameGuiBeginEvent Create(float dt)
Request to navigate to an assembly symbol definition.
static JumpToAssemblySymbolRequestEvent Create(std::string sym, size_t session=0)
Request to navigate to a specific overworld map.
static JumpToMapRequestEvent Create(int map, size_t session=0)
Request to navigate to a specific message ID.
static JumpToMessageRequestEvent Create(int message, size_t session=0)
Request to navigate to a specific dungeon room.
static JumpToRoomRequestEvent Create(int room, size_t session=0)
Published when panel visibility changes.
static PanelVisibilityChangedEvent Create(const std::string &id, const std::string &base_id, const std::string &cat, bool vis, size_t session=0)
Published when a ROM is successfully loaded into a session.
Definition core_events.h:27
static RomLoadedEvent Create(Rom *r, const std::string &file, size_t session)
Definition core_events.h:32
Published when ROM data is modified.
Definition core_events.h:63
static RomModifiedEvent Create(Rom *r, size_t session, uint32_t addr=0, size_t bytes=0)
Definition core_events.h:69
Represents a single session, containing a ROM and its associated editors.
Published when a ROM is unloaded from a session.
Definition core_events.h:47
static RomUnloadedEvent Create(size_t session)
Definition core_events.h:50
Published when selection changes in any editor.
static SelectionChangedEvent Create(const std::string &src, const std::vector< int > &ids, size_t session=0)
static SelectionChangedEvent CreateSingle(const std::string &src, int id, size_t session=0)
static SelectionChangedEvent CreateEmpty(const std::string &src, size_t session=0)
Published when a session is closed.
static SessionClosedEvent Create(size_t idx)
Published when a new session is created.
static SessionCreatedEvent Create(size_t idx, RomSession *sess)
Published when the active session changes.
Definition core_events.h:89
static SessionSwitchedEvent Create(size_t old_idx, size_t new_idx, RomSession *sess, bool is_transient=false)
Definition core_events.h:95
Sidebar visibility state change notification.
static SidebarStateChangedEvent Create(bool visible, bool expanded)
Activity bar or menu action request.
static UIActionRequestEvent Redo(size_t session=0)
static UIActionRequestEvent ShowCommandPalette(size_t session=0)
static UIActionRequestEvent SaveRom(size_t session=0)
static UIActionRequestEvent Create(Action act, size_t session=0)
static UIActionRequestEvent Undo(size_t session=0)
static UIActionRequestEvent ShowSettings(size_t session=0)
static UIActionRequestEvent ShowAgentProposalsSidebar(size_t session=0)
static UIActionRequestEvent ShowAgentChatSidebar(size_t session=0)
static UIActionRequestEvent OpenRom(size_t session=0)
static UIActionRequestEvent ShowEmulator(size_t session=0)
Published when zoom level changes in any canvas/editor.
static ZoomChangedEvent Create(const std::string &src, float old_z, float new_z, size_t session=0)