yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::CanvasNavigationManager Class Reference

#include <canvas_navigation_manager.h>

Collaboration diagram for yaze::editor::CanvasNavigationManager:

Public Member Functions

 CanvasNavigationManager ()=default
 
void Initialize (const CanvasNavigationContext &context, const CanvasNavigationCallbacks &callbacks)
 Initialize with shared state and callbacks.
 
absl::Status CheckForCurrentMap ()
 Detect which map the mouse is over, trigger lazy loading, draw the selection outline, and refresh textures if modified.
 
std::optional< int > TrackMapAtCanvasPosition (ImVec2 scaled_position)
 
void HandleMapInteraction ()
 Click selection (see IsMapSelectClick) and double-click to open properties. The paint-tool right-click sample itself happens in TilePaintingManager. Middle-drag only pans.
 
bool SelectMapUnderCursor ()
 Make the map under the cursor the current map, ignoring the pin (the pin, if on, then holds this map). Large areas: any quadrant selects its parent area's properties. Returns false when no map is under it.
 
void BeginCanvasViewport ()
 
void EndCanvasViewport (bool canvas_item_hovered)
 
void ZoomIn ()
 Increase canvas zoom by one step, keeping the view center fixed.
 
void ZoomOut ()
 Decrease canvas zoom by one step, keeping the view center fixed.
 
void ZoomToFit ()
 Scale so the whole current world fits the viewport.
 
void ResetOverworldView ()
 Reset scroll to top-left and scale to 1.0.
 
void CenterOverworldView ()
 Center the viewport on the current map.
 
void CenterOnMap (int map_id)
 Center the viewport on map_id (same world grid).
 
void CenterOnWorldTile (int world_x, int world_y)
 
bool is_panning () const
 
void SuspendHoverFollowUntilMouseMoves ()
 
void ScrollBlocksetCanvasToCurrentTile ()
 Scroll the blockset (tile16 selector) to show the currently selected tile16.
 
void UpdateBlocksetSelectorState ()
 Push current tile count and selection into the blockset widget.
 
void QueueAdjacentMapsForPreload (int center_map)
 Queue the 4-connected neighbors of center_map for lazy build.
 
void ProcessPreloadQueue ()
 Process one map from the preload queue (call once per frame).
 

Private Member Functions

std::optional< int > MapUnderCursor () const
 
void ZoomBySteps (int steps, ImVec2 anchor)
 
void SetScaleAboutAnchor (float new_scale, ImVec2 anchor)
 
ImVec2 ClampScroll (ImVec2 scroll) const
 
ImVec2 ContentSize () const
 

Private Attributes

CanvasNavigationContext ctx_
 
CanvasNavigationCallbacks callbacks_
 
double left_press_time_ = -1.0
 
std::optional< int > left_press_map_
 
int last_hovered_map_ = -1
 
float hover_time_ = 0.0f
 
std::vector< int > preload_queue_
 
ImVec2 viewport_min_ {0.0f, 0.0f}
 
ImVec2 viewport_size_ {0.0f, 0.0f}
 
ImVec2 last_scroll_ {0.0f, 0.0f}
 
bool canvas_item_hovered_ = false
 
bool canvas_window_hovered_ = false
 
bool viewport_known_ = false
 
std::optional< ImVec2 > hover_follow_suspended_at_
 
std::optional< ImVec2 > pending_scroll_
 
std::optional< int > pending_center_map_
 
StickyWheelPan wheel_pan_
 
float zoom_residual_ = 0.0f
 
float zoom_idle_seconds_ = 0.0f
 
int pan_button_ = -1
 
bool pan_active_ = false
 
ImVec2 pan_anchor_mouse_ {0.0f, 0.0f}
 
ImVec2 pan_anchor_scroll_ {0.0f, 0.0f}
 

Static Private Attributes

static constexpr float kHoverBuildDelay = 0.15f
 
static constexpr float kPreloadStartDelay = 0.3f
 

Detailed Description

Definition at line 126 of file canvas_navigation_manager.h.

Constructor & Destructor Documentation

◆ CanvasNavigationManager()

yaze::editor::CanvasNavigationManager::CanvasNavigationManager ( )
default

Member Function Documentation

◆ Initialize()

void yaze::editor::CanvasNavigationManager::Initialize ( const CanvasNavigationContext & context,
const CanvasNavigationCallbacks & callbacks )

Initialize with shared state and callbacks.

Definition at line 90 of file canvas_navigation_manager.cc.

References callbacks_, and ctx_.

◆ CheckForCurrentMap()

absl::Status yaze::editor::CanvasNavigationManager::CheckForCurrentMap ( )

Detect which map the mouse is over, trigger lazy loading, draw the selection outline, and refresh textures if modified.

Definition at line 122 of file canvas_navigation_manager.cc.

References yaze::gfx::Tilemap::atlas, callbacks_, ctx_, yaze::editor::CanvasNavigationContext::current_map, yaze::editor::CanvasNavigationContext::current_map_lock, yaze::editor::CanvasNavigationContext::current_mode, yaze::editor::CanvasNavigationContext::current_parent, yaze::editor::CanvasNavigationContext::current_world, yaze::gui::Canvas::DrawOutline(), yaze::editor::CanvasNavigationCallbacks::ensure_map_texture, yaze::zelda3::Overworld::EnsureMapBuilt(), yaze::editor::FormatOverworldMapStatusSegment(), yaze::gfx::Arena::Get(), yaze::zelda3::OverworldVersionHelper::GetVersion(), yaze::gui::Canvas::hover_mouse_pos(), hover_time_, yaze::zelda3::Overworld::inspected_map_count(), yaze::gfx::Bitmap::is_active(), yaze::gui::Canvas::IsMouseHovering(), kHoverBuildDelay, yaze::editor::kOverworldMapSize, kPreloadStartDelay, last_hovered_map_, yaze::editor::CanvasNavigationContext::maps_bmp, yaze::editor::CanvasNavigationContext::overworld, yaze::zelda3::Overworld::overworld_map(), yaze::editor::CanvasNavigationContext::ow_map_canvas, preload_queue_, ProcessPreloadQueue(), QueueAdjacentMapsForPreload(), yaze::gfx::Arena::QueueTextureCommand(), yaze::editor::CanvasNavigationCallbacks::refresh_overworld_map, yaze::editor::CanvasNavigationCallbacks::refresh_tile16_blockset, RETURN_IF_ERROR, yaze::editor::CanvasNavigationContext::rom, yaze::zelda3::OverworldVersionHelper::SupportsAreaEnum(), yaze::editor::CanvasNavigationContext::tile16_blockset, TrackMapAtCanvasPosition(), and yaze::gfx::Arena::UPDATE.

◆ TrackMapAtCanvasPosition()

std::optional< int > yaze::editor::CanvasNavigationManager::TrackMapAtCanvasPosition ( ImVec2 scaled_position)

◆ HandleMapInteraction()

◆ SelectMapUnderCursor()

bool yaze::editor::CanvasNavigationManager::SelectMapUnderCursor ( )

Make the map under the cursor the current map, ignoring the pin (the pin, if on, then holds this map). Large areas: any quadrant selects its parent area's properties. Returns false when no map is under it.

Definition at line 338 of file canvas_navigation_manager.cc.

References callbacks_, ctx_, yaze::editor::CanvasNavigationContext::current_map, MapUnderCursor(), and yaze::editor::CanvasNavigationContext::ow_map_canvas.

Referenced by HandleMapInteraction().

Here is the call graph for this function:

◆ BeginCanvasViewport()

◆ EndCanvasViewport()

void yaze::editor::CanvasNavigationManager::EndCanvasViewport ( bool canvas_item_hovered)

◆ ZoomIn()

void yaze::editor::CanvasNavigationManager::ZoomIn ( )

Increase canvas zoom by one step, keeping the view center fixed.

Definition at line 625 of file canvas_navigation_manager.cc.

References viewport_size_, and ZoomBySteps().

Here is the call graph for this function:

◆ ZoomOut()

void yaze::editor::CanvasNavigationManager::ZoomOut ( )

Decrease canvas zoom by one step, keeping the view center fixed.

Definition at line 629 of file canvas_navigation_manager.cc.

References viewport_size_, and ZoomBySteps().

Here is the call graph for this function:

◆ ZoomToFit()

◆ ResetOverworldView()

void yaze::editor::CanvasNavigationManager::ResetOverworldView ( )

Reset scroll to top-left and scale to 1.0.

Definition at line 650 of file canvas_navigation_manager.cc.

References ctx_, yaze::editor::CanvasNavigationContext::ow_map_canvas, pending_center_map_, pending_scroll_, and yaze::gui::Canvas::set_global_scale().

Here is the call graph for this function:

◆ CenterOverworldView()

void yaze::editor::CanvasNavigationManager::CenterOverworldView ( )

Center the viewport on the current map.

Definition at line 658 of file canvas_navigation_manager.cc.

References CenterOnMap(), ctx_, and yaze::editor::CanvasNavigationContext::current_map.

Here is the call graph for this function:

◆ CenterOnMap()

◆ CenterOnWorldTile()

void yaze::editor::CanvasNavigationManager::CenterOnWorldTile ( int world_x,
int world_y )

◆ is_panning()

bool yaze::editor::CanvasNavigationManager::is_panning ( ) const
inline

Definition at line 195 of file canvas_navigation_manager.h.

References pan_active_.

◆ SuspendHoverFollowUntilMouseMoves()

void yaze::editor::CanvasNavigationManager::SuspendHoverFollowUntilMouseMoves ( )

After keyboard map navigation: do not let the (unpinned) hover follow replace the keyboard choice until the mouse actually moves.

Definition at line 620 of file canvas_navigation_manager.cc.

References hover_follow_suspended_at_.

◆ ScrollBlocksetCanvasToCurrentTile()

void yaze::editor::CanvasNavigationManager::ScrollBlocksetCanvasToCurrentTile ( )

Scroll the blockset (tile16 selector) to show the currently selected tile16.

Definition at line 704 of file canvas_navigation_manager.cc.

References yaze::editor::CanvasNavigationContext::blockset_selector, ctx_, and yaze::editor::CanvasNavigationContext::current_tile16.

◆ UpdateBlocksetSelectorState()

void yaze::editor::CanvasNavigationManager::UpdateBlocksetSelectorState ( )

◆ QueueAdjacentMapsForPreload()

void yaze::editor::CanvasNavigationManager::QueueAdjacentMapsForPreload ( int center_map)

◆ ProcessPreloadQueue()

void yaze::editor::CanvasNavigationManager::ProcessPreloadQueue ( )

Process one map from the preload queue (call once per frame).

Definition at line 779 of file canvas_navigation_manager.cc.

References ctx_, yaze::zelda3::Overworld::EnsureMapBuilt(), LOG_DEBUG, yaze::editor::CanvasNavigationContext::overworld, and preload_queue_.

Referenced by CheckForCurrentMap().

Here is the call graph for this function:

◆ MapUnderCursor()

std::optional< int > yaze::editor::CanvasNavigationManager::MapUnderCursor ( ) const
private

◆ ZoomBySteps()

void yaze::editor::CanvasNavigationManager::ZoomBySteps ( int steps,
ImVec2 anchor )
private

◆ SetScaleAboutAnchor()

void yaze::editor::CanvasNavigationManager::SetScaleAboutAnchor ( float new_scale,
ImVec2 anchor )
private

◆ ClampScroll()

ImVec2 yaze::editor::CanvasNavigationManager::ClampScroll ( ImVec2 scroll) const
private

Definition at line 461 of file canvas_navigation_manager.cc.

References ContentSize(), and viewport_size_.

Referenced by BeginCanvasViewport().

Here is the call graph for this function:

◆ ContentSize()

ImVec2 yaze::editor::CanvasNavigationManager::ContentSize ( ) const
private

Member Data Documentation

◆ ctx_

◆ callbacks_

CanvasNavigationCallbacks yaze::editor::CanvasNavigationManager::callbacks_
private

◆ left_press_time_

double yaze::editor::CanvasNavigationManager::left_press_time_ = -1.0
private

Definition at line 231 of file canvas_navigation_manager.h.

Referenced by HandleMapInteraction().

◆ left_press_map_

std::optional<int> yaze::editor::CanvasNavigationManager::left_press_map_
private

Definition at line 232 of file canvas_navigation_manager.h.

Referenced by HandleMapInteraction().

◆ last_hovered_map_

int yaze::editor::CanvasNavigationManager::last_hovered_map_ = -1
private

Definition at line 235 of file canvas_navigation_manager.h.

Referenced by CheckForCurrentMap().

◆ hover_time_

float yaze::editor::CanvasNavigationManager::hover_time_ = 0.0f
private

Definition at line 236 of file canvas_navigation_manager.h.

Referenced by CheckForCurrentMap().

◆ kHoverBuildDelay

constexpr float yaze::editor::CanvasNavigationManager::kHoverBuildDelay = 0.15f
staticconstexprprivate

Definition at line 237 of file canvas_navigation_manager.h.

Referenced by CheckForCurrentMap().

◆ preload_queue_

std::vector<int> yaze::editor::CanvasNavigationManager::preload_queue_
private

◆ kPreloadStartDelay

constexpr float yaze::editor::CanvasNavigationManager::kPreloadStartDelay = 0.3f
staticconstexprprivate

Definition at line 241 of file canvas_navigation_manager.h.

Referenced by CheckForCurrentMap().

◆ viewport_min_

ImVec2 yaze::editor::CanvasNavigationManager::viewport_min_ {0.0f, 0.0f}
private

Definition at line 250 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport(), and EndCanvasViewport().

◆ viewport_size_

ImVec2 yaze::editor::CanvasNavigationManager::viewport_size_ {0.0f, 0.0f}
private

◆ last_scroll_

ImVec2 yaze::editor::CanvasNavigationManager::last_scroll_ {0.0f, 0.0f}
private

◆ canvas_item_hovered_

bool yaze::editor::CanvasNavigationManager::canvas_item_hovered_ = false
private

Definition at line 253 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport(), and EndCanvasViewport().

◆ canvas_window_hovered_

bool yaze::editor::CanvasNavigationManager::canvas_window_hovered_ = false
private

Definition at line 254 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport(), and EndCanvasViewport().

◆ viewport_known_

bool yaze::editor::CanvasNavigationManager::viewport_known_ = false
private

◆ hover_follow_suspended_at_

std::optional<ImVec2> yaze::editor::CanvasNavigationManager::hover_follow_suspended_at_
private

◆ pending_scroll_

std::optional<ImVec2> yaze::editor::CanvasNavigationManager::pending_scroll_
private

◆ pending_center_map_

std::optional<int> yaze::editor::CanvasNavigationManager::pending_center_map_
private

Definition at line 261 of file canvas_navigation_manager.h.

Referenced by CenterOnMap(), EndCanvasViewport(), and ResetOverworldView().

◆ wheel_pan_

StickyWheelPan yaze::editor::CanvasNavigationManager::wheel_pan_
private

Definition at line 264 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport().

◆ zoom_residual_

float yaze::editor::CanvasNavigationManager::zoom_residual_ = 0.0f
private

Definition at line 265 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport().

◆ zoom_idle_seconds_

float yaze::editor::CanvasNavigationManager::zoom_idle_seconds_ = 0.0f
private

Definition at line 266 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport().

◆ pan_button_

int yaze::editor::CanvasNavigationManager::pan_button_ = -1
private

Definition at line 269 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport().

◆ pan_active_

bool yaze::editor::CanvasNavigationManager::pan_active_ = false
private

Definition at line 270 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport(), and is_panning().

◆ pan_anchor_mouse_

ImVec2 yaze::editor::CanvasNavigationManager::pan_anchor_mouse_ {0.0f, 0.0f}
private

Definition at line 271 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport().

◆ pan_anchor_scroll_

ImVec2 yaze::editor::CanvasNavigationManager::pan_anchor_scroll_ {0.0f, 0.0f}
private

Definition at line 272 of file canvas_navigation_manager.h.

Referenced by BeginCanvasViewport().


The documentation for this class was generated from the following files: