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
55 // Mode state
57 bool* current_map_lock = nullptr;
58 bool* is_dragging_entity = nullptr;
60
61 // Graphics
62 std::array<gfx::Bitmap, zelda3::kNumOverworldMaps>* maps_bmp = nullptr;
64
65 // Widgets (read-only pointer to editor's unique_ptr)
66 std::unique_ptr<gui::TileSelectorWidget>* blockset_selector = nullptr;
67};
68
71 std::function<void()> refresh_overworld_map;
72 std::function<absl::Status()> refresh_tile16_blockset;
73 std::function<void(int)> ensure_map_texture;
74 std::function<bool()> pick_tile16_from_hovered_canvas;
76 std::function<bool()> is_entity_hovered;
77};
78
80 public:
82
84 void Initialize(const CanvasNavigationContext& context,
85 const CanvasNavigationCallbacks& callbacks);
86
87 // ===========================================================================
88 // Map Detection and Loading
89 // ===========================================================================
90
93 absl::Status CheckForCurrentMap();
94
95 // ===========================================================================
96 // Map Interaction
97 // ===========================================================================
98
102
103 // ===========================================================================
104 // Pan and Zoom
105 // ===========================================================================
106
109 void HandleOverworldPan();
110
112 void HandleOverworldZoom();
113
115 void ZoomIn();
116
118 void ZoomOut();
119
122
124 void ResetOverworldView();
125
127 void CenterOverworldView();
128
130 void CheckForMousePan();
131
132 // ===========================================================================
133 // Blockset Selector Synchronization
134 // ===========================================================================
135
139
142
143 // ===========================================================================
144 // Background Pre-loading
145 // ===========================================================================
146
148 void QueueAdjacentMapsForPreload(int center_map);
149
151 void ProcessPreloadQueue();
152
153 private:
156
157 // Hover debounce state
159 float hover_time_ = 0.0f;
160 static constexpr float kHoverBuildDelay = 0.15f;
161
162 // Background pre-loading state
163 std::vector<int> preload_queue_;
164 static constexpr float kPreloadStartDelay = 0.3f;
165};
166
167} // namespace yaze::editor
168
169#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:150
Represents the full Overworld data, light and dark world.
Definition overworld.h:261
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< 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