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, size_t session) {
34 e.rom = r;
35 e.filename = file;
36 e.session_id = session;
37 return e;
38 }
39};
40
46struct RomUnloadedEvent : public Event {
47 size_t session_id = 0;
48
49 static RomUnloadedEvent Create(size_t session) {
51 e.session_id = session;
52 return e;
53 }
54};
55
62struct RomModifiedEvent : public Event {
63 Rom* rom = nullptr;
64 uint32_t address = 0;
65 size_t byte_count = 0;
66 size_t session_id = 0;
67
68 static RomModifiedEvent Create(Rom* r, size_t session, uint32_t addr = 0,
69 size_t bytes = 0) {
71 e.rom = r;
72 e.session_id = session;
73 e.address = addr;
74 e.byte_count = bytes;
75 return e;
76 }
77};
78
79// =============================================================================
80// Session Lifecycle Events
81// =============================================================================
82
88struct SessionSwitchedEvent : public Event {
89 size_t old_index = 0;
90 size_t new_index = 0;
91 RomSession* session = nullptr;
92
93 static SessionSwitchedEvent Create(size_t old_idx, size_t new_idx,
94 RomSession* sess) {
96 e.old_index = old_idx;
97 e.new_index = new_idx;
98 e.session = sess;
99 return e;
100 }
101};
102
106struct SessionCreatedEvent : public Event {
107 size_t index = 0;
108 RomSession* session = nullptr;
109
110 static SessionCreatedEvent Create(size_t idx, RomSession* sess) {
112 e.index = idx;
113 e.session = sess;
114 return e;
115 }
116};
117
121struct SessionClosedEvent : public Event {
122 size_t index = 0;
123
124 static SessionClosedEvent Create(size_t idx) {
126 e.index = idx;
127 return e;
128 }
129};
130
131// =============================================================================
132// Editor State Events
133// =============================================================================
134
138struct EditorSwitchedEvent : public Event {
139 int editor_type = 0; // EditorType enum value
140 void* editor = nullptr;
141
142 static EditorSwitchedEvent Create(int type, void* ed) {
144 e.editor_type = type;
145 e.editor = ed;
146 return e;
147 }
148};
149
150// =============================================================================
151// UI State Events
152// =============================================================================
153
161 std::string source; // Source editor: "overworld", "dungeon", "graphics", etc.
162 std::vector<int> selected_ids; // IDs of selected items (tiles, rooms, sprites, etc.)
163 int primary_id = -1; // Primary selection (first or focused item)
164 size_t session_id = 0;
165
166 static SelectionChangedEvent Create(const std::string& src,
167 const std::vector<int>& ids,
168 size_t session = 0) {
170 e.source = src;
171 e.selected_ids = ids;
172 e.primary_id = ids.empty() ? -1 : ids.front();
173 e.session_id = session;
174 return e;
175 }
176
177 static SelectionChangedEvent CreateSingle(const std::string& src, int id,
178 size_t session = 0) {
180 e.source = src;
181 e.selected_ids = {id};
182 e.primary_id = id;
183 e.session_id = session;
184 return e;
185 }
186
187 static SelectionChangedEvent CreateEmpty(const std::string& src,
188 size_t session = 0) {
190 e.source = src;
191 e.selected_ids = {};
192 e.primary_id = -1;
193 e.session_id = session;
194 return e;
195 }
196
197 bool IsEmpty() const { return selected_ids.empty(); }
198 size_t Count() const { return selected_ids.size(); }
199};
200
208 std::string panel_id; // Panel identifier (may be session-prefixed)
209 std::string base_panel_id; // Base panel ID without session prefix
210 std::string category; // Panel category ("Dungeon", "Overworld", etc.)
211 bool visible = false; // New visibility state
212 size_t session_id = 0;
213
214 static PanelVisibilityChangedEvent Create(const std::string& id,
215 const std::string& base_id,
216 const std::string& cat,
217 bool vis, size_t session = 0) {
219 e.panel_id = id;
220 e.base_panel_id = base_id;
221 e.category = cat;
222 e.visible = vis;
223 e.session_id = session;
224 return e;
225 }
226};
227
233struct ZoomChangedEvent : public Event {
234 std::string source; // Source canvas: "overworld_canvas", "dungeon_canvas", etc.
235 float old_zoom = 1.0f; // Previous zoom level
236 float new_zoom = 1.0f; // New zoom level
237 size_t session_id = 0;
238
239 static ZoomChangedEvent Create(const std::string& src, float old_z,
240 float new_z, size_t session = 0) {
242 e.source = src;
243 e.old_zoom = old_z;
244 e.new_zoom = new_z;
245 e.session_id = session;
246 return e;
247 }
248
249 float GetZoomDelta() const { return new_zoom - old_zoom; }
250 float GetZoomRatio() const {
251 return old_zoom > 0.0f ? new_zoom / old_zoom : 1.0f;
252 }
253 bool IsZoomIn() const { return new_zoom > old_zoom; }
254 bool IsZoomOut() const { return new_zoom < old_zoom; }
255};
256
257// =============================================================================
258// Navigation Request Events (cross-editor navigation)
259// =============================================================================
260
268 int room_id = -1;
269 size_t session_id = 0;
270
271 static JumpToRoomRequestEvent Create(int room, size_t session = 0) {
273 e.room_id = room;
274 e.session_id = session;
275 return e;
276 }
277};
278
286 int map_id = -1;
287 size_t session_id = 0;
288
289 static JumpToMapRequestEvent Create(int map, size_t session = 0) {
291 e.map_id = map;
292 e.session_id = session;
293 return e;
294 }
295};
296
304 int message_id = -1;
305 size_t session_id = 0;
306
307 static JumpToMessageRequestEvent Create(int message, size_t session = 0) {
309 e.message_id = message;
310 e.session_id = session;
311 return e;
312 }
313};
314
324 std::string symbol;
325 size_t session_id = 0;
326
328 size_t session = 0) {
330 e.symbol = std::move(sym);
331 e.session_id = session;
332 return e;
333 }
334};
335
336// =============================================================================
337// UI Action Request Events (activity bar, menus, shortcuts)
338// =============================================================================
339
364
366 size_t session_id = 0;
367
368 static UIActionRequestEvent Create(Action act, size_t session = 0) {
370 e.action = act;
371 e.session_id = session;
372 return e;
373 }
374
375 // Convenience factory methods
376 static UIActionRequestEvent ShowEmulator(size_t session = 0) {
377 return Create(Action::kShowEmulator, session);
378 }
379 static UIActionRequestEvent ShowSettings(size_t session = 0) {
380 return Create(Action::kShowSettings, session);
381 }
382 static UIActionRequestEvent ShowCommandPalette(size_t session = 0) {
383 return Create(Action::kShowCommandPalette, session);
384 }
385 static UIActionRequestEvent ShowAgentChatSidebar(size_t session = 0) {
386 return Create(Action::kShowAgentChatSidebar, session);
387 }
390 }
391 static UIActionRequestEvent OpenRom(size_t session = 0) {
392 return Create(Action::kOpenRom, session);
393 }
394 static UIActionRequestEvent SaveRom(size_t session = 0) {
395 return Create(Action::kSaveRom, session);
396 }
397 static UIActionRequestEvent Undo(size_t session = 0) {
398 return Create(Action::kUndo, session);
399 }
400 static UIActionRequestEvent Redo(size_t session = 0) {
401 return Create(Action::kRedo, session);
402 }
403};
404
411 bool sidebar_visible = false;
412 bool panel_expanded = false;
413
414 static SidebarStateChangedEvent Create(bool visible, bool expanded) {
416 e.sidebar_visible = visible;
417 e.panel_expanded = expanded;
418 return e;
419 }
420};
421
422// =============================================================================
423// Frame Lifecycle Events (for deferred action consolidation)
424// =============================================================================
425
431struct FrameBeginEvent : public Event {
432 float delta_time = 0.0f;
433
434 static FrameBeginEvent Create(float dt) {
436 e.delta_time = dt;
437 return e;
438 }
439};
440
446struct FrameGuiBeginEvent : public Event {
447 float delta_time = 0.0f;
448
449 static FrameGuiBeginEvent Create(float dt) {
451 e.delta_time = dt;
452 return e;
453 }
454};
455
461struct FrameEndEvent : public Event {
462 float delta_time = 0.0f;
463
464 static FrameEndEvent Create(float dt) {
466 e.delta_time = dt;
467 return e;
468 }
469};
470
471} // namespace editor
472} // namespace yaze
473
474#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:62
static RomModifiedEvent Create(Rom *r, size_t session, uint32_t addr=0, size_t bytes=0)
Definition core_events.h:68
Represents a single session, containing a ROM and its associated editors.
Published when a ROM is unloaded from a session.
Definition core_events.h:46
static RomUnloadedEvent Create(size_t session)
Definition core_events.h:49
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:88
static SessionSwitchedEvent Create(size_t old_idx, size_t new_idx, RomSession *sess)
Definition core_events.h:93
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)