99 lines
2.8 KiB
C++
99 lines
2.8 KiB
C++
#include "EditorWindowManager.h"
|
|
|
|
#include "EditorWindow.h"
|
|
|
|
namespace XCEngine::UI::Editor::App {
|
|
|
|
EditorWindow* EditorWindowManager::FindWindow(HWND hwnd) {
|
|
if (hwnd == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
for (const std::unique_ptr<EditorWindow>& window : m_windows) {
|
|
if (window != nullptr && window->GetHwnd() == hwnd) {
|
|
return window.get();
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
const EditorWindow* EditorWindowManager::FindWindow(HWND hwnd) const {
|
|
return const_cast<EditorWindowManager*>(this)->FindWindow(hwnd);
|
|
}
|
|
|
|
EditorWindow* EditorWindowManager::FindWindow(std::string_view windowId) {
|
|
if (windowId.empty()) {
|
|
return nullptr;
|
|
}
|
|
|
|
for (const std::unique_ptr<EditorWindow>& window : m_windows) {
|
|
if (window != nullptr && window->GetWindowId() == windowId) {
|
|
return window.get();
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
const EditorWindow* EditorWindowManager::FindWindow(std::string_view windowId) const {
|
|
return const_cast<EditorWindowManager*>(this)->FindWindow(windowId);
|
|
}
|
|
|
|
EditorWindow* EditorWindowManager::FindPrimaryWindow() {
|
|
for (const std::unique_ptr<EditorWindow>& window : m_windows) {
|
|
if (window != nullptr && window->IsPrimary()) {
|
|
return window.get();
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
const EditorWindow* EditorWindowManager::FindPrimaryWindow() const {
|
|
return const_cast<EditorWindowManager*>(this)->FindPrimaryWindow();
|
|
}
|
|
|
|
EditorWindow* EditorWindowManager::FindTopmostWindowAtScreenPoint(
|
|
const POINT& screenPoint,
|
|
std::string_view excludedWindowId) {
|
|
if (const HWND hitWindow = WindowFromPoint(screenPoint); hitWindow != nullptr) {
|
|
const HWND rootWindow = GetAncestor(hitWindow, GA_ROOT);
|
|
if (EditorWindow* window = FindWindow(rootWindow);
|
|
window != nullptr &&
|
|
window->GetWindowId() != excludedWindowId) {
|
|
return window;
|
|
}
|
|
}
|
|
|
|
for (auto it = m_windows.rbegin(); it != m_windows.rend(); ++it) {
|
|
EditorWindow* const window = it->get();
|
|
if (window == nullptr ||
|
|
window->GetHwnd() == nullptr ||
|
|
window->GetWindowId() == excludedWindowId) {
|
|
continue;
|
|
}
|
|
|
|
RECT windowRect = {};
|
|
if (GetWindowRect(window->GetHwnd(), &windowRect) &&
|
|
screenPoint.x >= windowRect.left &&
|
|
screenPoint.x < windowRect.right &&
|
|
screenPoint.y >= windowRect.top &&
|
|
screenPoint.y < windowRect.bottom) {
|
|
return window;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
const EditorWindow* EditorWindowManager::FindTopmostWindowAtScreenPoint(
|
|
const POINT& screenPoint,
|
|
std::string_view excludedWindowId) const {
|
|
return const_cast<EditorWindowManager*>(this)->FindTopmostWindowAtScreenPoint(
|
|
screenPoint,
|
|
excludedWindowId);
|
|
}
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|