yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
canvas_navigation_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_OVERWORLD_CANVAS_NAVIGATION_MANAGER_H
2#define YAZE_APP_EDITOR_OVERWORLD_CANVAS_NAVIGATION_MANAGER_H
3
4#include <array>
5#include <functional>
6#include <memory>
7#include <vector>
8
9#include "absl/status/status.h"
11#include "app/gfx/core/bitmap.h"
15#include "rom/rom.h"
16#include "zelda3/common.h"
18
19namespace yaze::editor {
20
21// Forward declarations
22class OverworldEntityRenderer;
23
24// =============================================================================
25// CanvasNavigationManager
26// =============================================================================
27//
28// Extracted from OverworldEditor to encapsulate all canvas navigation logic:
29// - Map hover detection and lazy loading (CheckForCurrentMap)
30// - Pan and zoom controls
31// - Map interaction (context menus, lock toggle)
32// - Background preloading of adjacent maps
33// - Blockset selector synchronization
34//
35// The manager holds pointers to shared editor state (via NavigationContext)
36// and uses callbacks for operations that remain in the editor (e.g. map
37// refresh, texture creation).
38// =============================================================================
39
42 // Canvas references
44
45 // Data model
47 Rom* rom = nullptr;
48
49 // Selection state (mutable pointers into editor fields)
50 int* current_map = nullptr;
51 int* current_world = nullptr;
52 int* current_parent = nullptr;
53 int* current_tile16 = nullptr;
54 int* hovered_map = nullptr;
55
56 // Mode state
58 bool* current_map_lock = nullptr;
59 bool* is_dragging_entity = nullptr;
61
62 // Graphics
63 std::array<gfx::Bitmap, zelda3::kNumOverworldMaps>* maps_bmp = nullptr;
65
66 // Widgets (read-only pointer to editor's unique_ptr)
67 std::unique_ptr<gui::TileSelectorWidget>* blockset_selector = nullptr;
68};
69
72 std::function<void()> refresh_overworld_map;
73 std::function<absl::Status()> refresh_tile16_blockset;
74 std::function<void(int)> ensure_map_texture;
75 std::function<void(int, bool)> select_map_for_editing;
76 std::function<bool()> pick_tile16_from_hovered_canvas;
78 std::function<bool()> is_entity_hovered;
79};
80
82 public:
84
86 void Initialize(const CanvasNavigationContext& context,
87 const CanvasNavigationCallbacks& callbacks);
88
89 // ===========================================================================
90 // Map Detection and Loading
91 // ===========================================================================
92
95 absl::Status CheckForCurrentMap();
96
97 // ===========================================================================
98 // Map Interaction
99 // ===========================================================================
100
104
105 // ===========================================================================
106 // Pan and Zoom
107 // ===========================================================================
108
111 void HandleOverworldPan();
112
114 void HandleOverworldZoom();
115
117 void ZoomIn();
118
120 void ZoomOut();
121
124
126 void ResetOverworldView();
127
129 void CenterOverworldView();
130
132 void CheckForMousePan();
133
134 // ===========================================================================
135 // Blockset Selector Synchronization
136 // ===========================================================================
137
141
144
145 // ===========================================================================
146 // Background Pre-loading
147 // ===========================================================================
148
150 void QueueAdjacentMapsForPreload(int center_map);
151
153 void ProcessPreloadQueue();
154
155 private:
158
159 // Hover debounce state
161 float hover_time_ = 0.0f;
162 static constexpr float kHoverBuildDelay = 0.15f;
163
164 // Background pre-loading state
165 std::vector<int> preload_queue_;
166 static constexpr float kPreloadStartDelay = 0.3f;
167};
168
169} // namespace yaze::editor
170
171#endif // YAZE_APP_EDITOR_OVERWORLD_CANVAS_NAVIGATION_MANAGER_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
void ScrollBlocksetCanvasToCurrentTile()
Scroll the blockset (tile16 selector) to show the currently selected tile16.
absl::Status CheckForCurrentMap()
Detect which map the mouse is over, trigger lazy loading, draw the selection outline,...
void UpdateBlocksetSelectorState()
Push current tile count and selection into the blockset widget.
void ProcessPreloadQueue()
Process one map from the preload queue (call once per frame).
void HandleOverworldPan()
Pan the overworld canvas via middle-click or left-click drag (in MOUSE mode when not hovering an enti...
void QueueAdjacentMapsForPreload(int center_map)
Queue the 4-connected neighbors of center_map for lazy build.
void Initialize(const CanvasNavigationContext &context, const CanvasNavigationCallbacks &callbacks)
Initialize with shared state and callbacks.
void HandleMapInteraction()
Handle tile-mode right-click (eyedropper) and middle-click (lock/properties toggle),...
void ZoomOut()
Decrease canvas zoom by one step.
void CenterOverworldView()
Center the viewport on the current map.
void CheckForMousePan()
Legacy wrapper – delegates to HandleOverworldPan().
void ZoomIn()
Increase canvas zoom by one step.
void ResetOverworldView()
Reset scroll to top-left and scale to 1.0.
void HandleOverworldZoom()
No-op stub preserved for API compatibility.
void ClampOverworldScroll()
No-op stub – ImGui handles scroll clamping automatically.
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
Represents the full Overworld data, light and dark world.
Definition overworld.h:389
Editors are the view controllers for the application.
Callbacks for operations that remain in the OverworldEditor.
std::function< absl::Status()> refresh_tile16_blockset
std::function< void(int, bool)> select_map_for_editing
std::function< bool()> is_entity_hovered
Returns true if an entity is currently hovered (for pan suppression).
Shared state pointers that the navigation manager reads/writes.
std::unique_ptr< gui::TileSelectorWidget > * blockset_selector
std::array< gfx::Bitmap, zelda3::kNumOverworldMaps > * maps_bmp
Tilemap structure for SNES tile-based graphics management.
Definition tilemap.h:118