yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
window_delegate.cc
Go to the documentation of this file.
1#include "window_delegate.h"
2
3#include <filesystem>
4#include <fstream>
5#include <sstream>
6
7#include "absl/strings/str_format.h"
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace editor {
12
14 // This is a placeholder - actual implementation would need to track
15 // all registered windows and set their visibility flags
16 printf("[WindowDelegate] ShowAllWindows() - %zu windows registered\n",
17 registered_windows_.size());
18}
19
21 // This is a placeholder - actual implementation would need to track
22 // all registered windows and set their visibility flags
23 printf("[WindowDelegate] HideAllWindows() - %zu windows registered\n",
24 registered_windows_.size());
25}
26
27void WindowDelegate::ShowWindow(const std::string& window_id) {
28 if (IsWindowRegistered(window_id)) {
29 printf("[WindowDelegate] ShowWindow: %s\n", window_id.c_str());
30 // Actual implementation would set window visibility flag
31 }
32}
33
34void WindowDelegate::HideWindow(const std::string& window_id) {
35 if (IsWindowRegistered(window_id)) {
36 printf("[WindowDelegate] HideWindow: %s\n", window_id.c_str());
37 // Actual implementation would set window visibility flag
38 }
39}
40
41void WindowDelegate::ToggleWindow(const std::string& window_id) {
42 if (IsWindowRegistered(window_id)) {
43 printf("[WindowDelegate] ToggleWindow: %s\n", window_id.c_str());
44 // Actual implementation would toggle window visibility flag
45 }
46}
47
48bool WindowDelegate::IsWindowVisible(const std::string& window_id) const {
49 if (!IsWindowRegistered(window_id)) {
50 return false;
51 }
52 // Actual implementation would check window visibility flag
53 return true; // Placeholder
54}
55
56void WindowDelegate::FocusWindow(const std::string& window_id) {
57 if (IsWindowRegistered(window_id)) {
58 printf("[WindowDelegate] FocusWindow: %s\n", window_id.c_str());
59 // Actual implementation would bring window to front and focus it
60 }
61}
62
63void WindowDelegate::MaximizeWindow(const std::string& window_id) {
64 if (IsWindowRegistered(window_id)) {
65 printf("[WindowDelegate] MaximizeWindow: %s\n", window_id.c_str());
66 // Actual implementation would maximize the window
67 }
68}
69
70void WindowDelegate::RestoreWindow(const std::string& window_id) {
71 if (IsWindowRegistered(window_id)) {
72 printf("[WindowDelegate] RestoreWindow: %s\n", window_id.c_str());
73 // Actual implementation would restore the window from maximized state
74 }
75}
76
77void WindowDelegate::CenterWindow(const std::string& window_id) {
78 if (IsWindowRegistered(window_id)) {
79 printf("[WindowDelegate] CenterWindow: %s\n", window_id.c_str());
80 // Actual implementation would center the window on screen
81 }
82}
83
84void WindowDelegate::DockWindow(const std::string& window_id, ImGuiDir dock_direction) {
85 if (IsWindowRegistered(window_id)) {
86 printf("[WindowDelegate] DockWindow: %s to direction %d\n",
87 window_id.c_str(), static_cast<int>(dock_direction));
88 // Actual implementation would dock the window
89 }
90}
91
92void WindowDelegate::UndockWindow(const std::string& window_id) {
93 if (IsWindowRegistered(window_id)) {
94 printf("[WindowDelegate] UndockWindow: %s\n", window_id.c_str());
95 // Actual implementation would undock the window
96 }
97}
98
99void WindowDelegate::SetDockSpace(const std::string& dock_space_id, const ImVec2& size) {
100 printf("[WindowDelegate] SetDockSpace: %s (%.1f x %.1f)\n",
101 dock_space_id.c_str(), size.x, size.y);
102 // Actual implementation would create/configure dock space
103}
104
105absl::Status WindowDelegate::SaveLayout(const std::string& preset_name) {
106 if (preset_name.empty()) {
107 return absl::InvalidArgumentError("Layout preset name cannot be empty");
108 }
109
110 std::string file_path = GetLayoutFilePath(preset_name);
111
112 try {
113 // Create directory if it doesn't exist
114 std::filesystem::path dir = std::filesystem::path(file_path).parent_path();
115 if (!std::filesystem::exists(dir)) {
116 std::filesystem::create_directories(dir);
117 }
118
119 // Save layout data (placeholder implementation)
120 std::ofstream file(file_path);
121 if (!file.is_open()) {
122 return absl::InternalError(absl::StrFormat("Failed to open layout file: %s", file_path));
123 }
124
125 file << "# YAZE Layout Preset: " << preset_name << "\n";
126 file << "# Generated by WindowDelegate\n";
127 file << "# TODO: Implement actual layout serialization\n";
128
129 file.close();
130
131 printf("[WindowDelegate] Saved layout: %s\n", preset_name.c_str());
132 return absl::OkStatus();
133
134 } catch (const std::exception& e) {
135 return absl::InternalError(absl::StrFormat("Failed to save layout: %s", e.what()));
136 }
137}
138
139absl::Status WindowDelegate::LoadLayout(const std::string& preset_name) {
140 if (preset_name.empty()) {
141 return absl::InvalidArgumentError("Layout preset name cannot be empty");
142 }
143
144 std::string file_path = GetLayoutFilePath(preset_name);
145
146 try {
147 if (!std::filesystem::exists(file_path)) {
148 return absl::NotFoundError(absl::StrFormat("Layout file not found: %s", file_path));
149 }
150
151 std::ifstream file(file_path);
152 if (!file.is_open()) {
153 return absl::InternalError(absl::StrFormat("Failed to open layout file: %s", file_path));
154 }
155
156 // Load layout data (placeholder implementation)
157 std::string line;
158 while (std::getline(file, line)) {
159 // TODO: Parse and apply layout data
160 }
161
162 file.close();
163
164 printf("[WindowDelegate] Loaded layout: %s\n", preset_name.c_str());
165 return absl::OkStatus();
166
167 } catch (const std::exception& e) {
168 return absl::InternalError(absl::StrFormat("Failed to load layout: %s", e.what()));
169 }
170}
171
173 printf("[WindowDelegate] ResetLayout()\n");
174 // Load default ImGui layout
175 ImGui::LoadIniSettingsFromMemory(nullptr);
176 return absl::OkStatus();
177}
178
179std::vector<std::string> WindowDelegate::GetAvailableLayouts() const {
180 std::vector<std::string> layouts;
181
182 try {
183 // Look for layout files in config directory
184 std::string config_dir = "config/layouts"; // TODO: Use proper config path
185 if (std::filesystem::exists(config_dir)) {
186 for (const auto& entry : std::filesystem::directory_iterator(config_dir)) {
187 if (entry.is_regular_file() && entry.path().extension() == ".ini") {
188 layouts.push_back(entry.path().stem().string());
189 }
190 }
191 }
192 } catch (const std::exception& e) {
193 printf("[WindowDelegate] Error scanning layouts: %s\n", e.what());
194 }
195
196 return layouts;
197}
198
199std::vector<std::string> WindowDelegate::GetVisibleWindows() const {
200 std::vector<std::string> visible;
201 // TODO: Implement actual visibility checking
202 return visible;
203}
204
205std::vector<std::string> WindowDelegate::GetHiddenWindows() const {
206 std::vector<std::string> hidden;
207 // TODO: Implement actual visibility checking
208 return hidden;
209}
210
211ImVec2 WindowDelegate::GetWindowSize(const std::string& window_id) const {
212 if (!IsWindowRegistered(window_id)) {
213 return ImVec2(0, 0);
214 }
215 // TODO: Implement actual size retrieval
216 return ImVec2(400, 300); // Placeholder
217}
218
219ImVec2 WindowDelegate::GetWindowPosition(const std::string& window_id) const {
220 if (!IsWindowRegistered(window_id)) {
221 return ImVec2(0, 0);
222 }
223 // TODO: Implement actual position retrieval
224 return ImVec2(100, 100); // Placeholder
225}
226
227void WindowDelegate::ShowWindowsInCategory(const std::string& category) {
228 printf("[WindowDelegate] ShowWindowsInCategory: %s\n", category.c_str());
229 // TODO: Implement category-based window showing
230}
231
232void WindowDelegate::HideWindowsInCategory(const std::string& category) {
233 printf("[WindowDelegate] HideWindowsInCategory: %s\n", category.c_str());
234 // TODO: Implement category-based window hiding
235}
236
237void WindowDelegate::ShowOnlyWindow(const std::string& window_id) {
238 printf("[WindowDelegate] ShowOnlyWindow: %s\n", window_id.c_str());
239 // TODO: Implement show-only functionality
240}
241
242void WindowDelegate::RegisterWindow(const std::string& window_id, const std::string& category) {
243 WindowInfo info;
244 info.id = window_id;
245 info.category = category;
246 info.is_registered = true;
247
248 registered_windows_[window_id] = info;
249 printf("[WindowDelegate] Registered window: %s (category: %s)\n",
250 window_id.c_str(), category.c_str());
251}
252
253void WindowDelegate::UnregisterWindow(const std::string& window_id) {
254 auto it = registered_windows_.find(window_id);
255 if (it != registered_windows_.end()) {
256 registered_windows_.erase(it);
257 printf("[WindowDelegate] Unregistered window: %s\n", window_id.c_str());
258 }
259}
260
262 printf("[WindowDelegate] LoadDeveloperLayout()\n");
263 // TODO: Implement developer-specific layout
264}
265
267 printf("[WindowDelegate] LoadDesignerLayout()\n");
268 // TODO: Implement designer-specific layout
269}
270
272 printf("[WindowDelegate] LoadModderLayout()\n");
273 // TODO: Implement modder-specific layout
274}
275
277 printf("[WindowDelegate] LoadMinimalLayout()\n");
278 // TODO: Implement minimal layout
279}
280
281bool WindowDelegate::IsWindowRegistered(const std::string& window_id) const {
282 auto it = registered_windows_.find(window_id);
283 return it != registered_windows_.end() && it->second.is_registered;
284}
285
286std::string WindowDelegate::GetLayoutFilePath(const std::string& preset_name) const {
287 // TODO: Use proper config directory path
288 return absl::StrFormat("config/layouts/%s.ini", preset_name);
289}
290
291void WindowDelegate::ApplyLayoutToWindow(const std::string& window_id, const std::string& layout_data) {
292 if (IsWindowRegistered(window_id)) {
293 printf("[WindowDelegate] ApplyLayoutToWindow: %s\n", window_id.c_str());
294 // TODO: Implement layout application
295 }
296}
297
299 ImGui::SaveIniSettingsToDisk("yaze_workspace.ini");
300 printf("[WindowDelegate] Workspace layout saved to yaze_workspace.ini\n");
301}
302
304 ImGui::LoadIniSettingsFromDisk("yaze_workspace.ini");
305 printf("[WindowDelegate] Workspace layout loaded from yaze_workspace.ini\n");
306}
307
309 // Reset to default ImGui layout
310 ImGui::LoadIniSettingsFromMemory(nullptr);
311 printf("[WindowDelegate] Workspace layout reset to default\n");
312}
313
314} // namespace editor
315} // namespace yaze
std::vector< std::string > GetVisibleWindows() const
void SetDockSpace(const std::string &dock_space_id, const ImVec2 &size=ImVec2(0, 0))
bool IsWindowVisible(const std::string &window_id) const
void UnregisterWindow(const std::string &window_id)
void RegisterWindow(const std::string &window_id, const std::string &category="")
std::unordered_map< std::string, WindowInfo > registered_windows_
void RestoreWindow(const std::string &window_id)
void MaximizeWindow(const std::string &window_id)
std::string GetLayoutFilePath(const std::string &preset_name) const
void ShowWindow(const std::string &window_id)
void HideWindow(const std::string &window_id)
std::vector< std::string > GetAvailableLayouts() const
ImVec2 GetWindowSize(const std::string &window_id) const
void ToggleWindow(const std::string &window_id)
void UndockWindow(const std::string &window_id)
absl::Status SaveLayout(const std::string &preset_name)
void ShowOnlyWindow(const std::string &window_id)
void ShowWindowsInCategory(const std::string &category)
bool IsWindowRegistered(const std::string &window_id) const
void HideWindowsInCategory(const std::string &category)
void CenterWindow(const std::string &window_id)
ImVec2 GetWindowPosition(const std::string &window_id) const
void ApplyLayoutToWindow(const std::string &window_id, const std::string &layout_data)
absl::Status LoadLayout(const std::string &preset_name)
void DockWindow(const std::string &window_id, ImGuiDir dock_direction)
std::vector< std::string > GetHiddenWindows() const
void FocusWindow(const std::string &window_id)
Main namespace for the application.
Definition controller.cc:20