yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_navigation.cc
Go to the documentation of this file.
2
4#include "imgui/imgui.h"
5
6namespace yaze::editor {
7
9 // Determine if panning should occur:
10 // 1. Middle-click drag always pans (all modes)
11 // 2. Left-click drag pans in mouse mode when not hovering over an entity
12 bool should_pan = false;
13
14 if (ImGui::IsMouseDragging(ImGuiMouseButton_Middle)) {
15 should_pan = true;
16 } else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) &&
18 // In mouse mode, left-click pans unless hovering over an entity
19 bool over_entity = entity_renderer_ &&
20 entity_renderer_->hovered_entity() != nullptr;
21 // Also don't pan if we're currently dragging an entity
22 if (!over_entity && !is_dragging_entity_) {
23 should_pan = true;
24 }
25 }
26
27 if (!should_pan) {
28 return;
29 }
30
31 // Pan by adjusting ImGui's scroll position (scrollbars handle actual scroll)
32 ImVec2 delta = ImGui::GetIO().MouseDelta;
33 float new_scroll_x = ImGui::GetScrollX() - delta.x;
34 float new_scroll_y = ImGui::GetScrollY() - delta.y;
35
36 // Get scroll limits from ImGui
37 float max_scroll_x = ImGui::GetScrollMaxX();
38 float max_scroll_y = ImGui::GetScrollMaxY();
39
40 // Clamp to valid scroll range
41 new_scroll_x = std::clamp(new_scroll_x, 0.0f, max_scroll_x);
42 new_scroll_y = std::clamp(new_scroll_y, 0.0f, max_scroll_y);
43
44 ImGui::SetScrollX(new_scroll_x);
45 ImGui::SetScrollY(new_scroll_y);
46}
47
49 // Scroll wheel is reserved for canvas navigation/panning
50 // Use toolbar buttons or context menu for zoom control
51}
52
54 float new_scale = std::min(kOverworldMaxZoom,
57 // Scroll will be clamped automatically by ImGui on next frame
58}
59
61 float new_scale = std::max(kOverworldMinZoom,
64 // Scroll will be clamped automatically by ImGui on next frame
65}
66
68 // ImGui handles scroll clamping automatically via GetScrollMaxX/Y
69 // This function is now a no-op but kept for API compatibility
70}
71
73 // Reset ImGui scroll to top-left
74 ImGui::SetScrollX(0);
75 ImGui::SetScrollY(0);
77}
78
80 // Center the view on the current map
81 float scale = ow_map_canvas_.global_scale();
82 if (scale <= 0.0f) scale = 1.0f;
83
84 // Calculate map position within the world
85 int map_in_world = current_map_ % 0x40;
86 int map_x = (map_in_world % 8) * kOverworldMapSize;
87 int map_y = (map_in_world / 8) * kOverworldMapSize;
88
89 // Get viewport size
90 ImVec2 viewport_px = ImGui::GetContentRegionAvail();
91
92 // Calculate scroll to center the current map (in ImGui's positive scroll space)
93 float center_x = (map_x + kOverworldMapSize / 2.0f) * scale;
94 float center_y = (map_y + kOverworldMapSize / 2.0f) * scale;
95
96 float scroll_x = center_x - viewport_px.x / 2.0f;
97 float scroll_y = center_y - viewport_px.y / 2.0f;
98
99 // Clamp to valid scroll range
100 scroll_x = std::clamp(scroll_x, 0.0f, ImGui::GetScrollMaxX());
101 scroll_y = std::clamp(scroll_y, 0.0f, ImGui::GetScrollMaxY());
102
103 ImGui::SetScrollX(scroll_x);
104 ImGui::SetScrollY(scroll_y);
105}
106
107} // namespace yaze::editor
std::unique_ptr< OverworldEntityRenderer > entity_renderer_
auto global_scale() const
Definition canvas.h:494
void set_global_scale(float scale)
Definition canvas.h:453
Editors are the view controllers for the application.
Definition agent_chat.cc:23
constexpr unsigned int kOverworldMapSize
constexpr float kOverworldMaxZoom
constexpr float kOverworldMinZoom
constexpr float kOverworldZoomStep