diff options
author | crupest <crupest@outlook.com> | 2021-10-14 21:58:14 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-10-14 21:58:14 +0800 |
commit | d3e2a751353e6c5b0e4d7c0a2af1cdbc09d3ea95 (patch) | |
tree | f88c16c14c187db9cade505b6ed6153a0630c6e9 /src/osx/gui | |
parent | 5ba45b02e1adee6b1ba15d70c9052cbc1f3c26c5 (diff) | |
download | cru-d3e2a751353e6c5b0e4d7c0a2af1cdbc09d3ea95.tar.gz cru-d3e2a751353e6c5b0e4d7c0a2af1cdbc09d3ea95.tar.bz2 cru-d3e2a751353e6c5b0e4d7c0a2af1cdbc09d3ea95.zip |
...
Diffstat (limited to 'src/osx/gui')
-rw-r--r-- | src/osx/gui/UiApplication.mm | 26 | ||||
-rw-r--r-- | src/osx/gui/Window.mm | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/osx/gui/UiApplication.mm b/src/osx/gui/UiApplication.mm index 2491390f..d2e6fe30 100644 --- a/src/osx/gui/UiApplication.mm +++ b/src/osx/gui/UiApplication.mm @@ -1,13 +1,18 @@ #include "cru/osx/gui/UiApplication.hpp" #include "cru/osx/graphics/quartz/Factory.hpp" +#include "cru/osx/gui/Window.hpp" +#include "cru/platform/gui/UiApplication.hpp" +#include "cru/platform/gui/Window.hpp" #include <AppKit/NSApplication.h> #include <Foundation/NSRunLoop.h> #include <algorithm> +#include <iterator> #include <memory> #include <unordered_map> +#include <vector> @interface AppDelegate : NSObject <NSApplicationDelegate> - (id)init:(cru::platform::gui::osx::details::OsxUiApplicationPrivate*)p; @@ -43,6 +48,8 @@ class OsxUiApplicationPrivate { std::unordered_map<long long, std::function<void()>> next_tick_; std::unordered_map<long long, NSTimer*> timers_; + std::vector<OsxWindow*> windows_; + std::unique_ptr<platform::graphics::osx::quartz::QuartzGraphicsFactory> quartz_graphics_factory_; }; @@ -122,6 +129,25 @@ void OsxUiApplication::CancelTimer(long long id) { p_->timers_.erase(i); } } + +std::vector<INativeWindow*> OsxUiApplication::GetAllWindow() { + std::vector<INativeWindow*> result; + std::transform(p_->windows_.cbegin(), p_->windows_.cend(), std::back_inserter(result), + [](OsxWindow* w) { return static_cast<INativeWindow*>(w); }); + return result; +} + +INativeWindow* OsxUiApplication::CreateWindow(INativeWindow* parent, CreateWindowFlag flags) { + auto window = new OsxWindow(this, parent, !(flags & CreateWindowFlags::NoCaptionAndBorder)); + p_->windows_.push_back(window); + return window; +} + +void OsxUiApplication::UnregisterWindow(OsxWindow* window) { + p_->windows_.erase( + std::remove(p_->windows_.begin(), p_->windows_.end(), static_cast<INativeWindow*>(window)), + p_->windows_.cend()); +} } @implementation AppDelegate diff --git a/src/osx/gui/Window.mm b/src/osx/gui/Window.mm index ff5572f2..c2134c76 100644 --- a/src/osx/gui/Window.mm +++ b/src/osx/gui/Window.mm @@ -92,6 +92,8 @@ OsxWindow::~OsxWindow() { if (p_->window_) { [p_->window_ close]; } + + dynamic_cast<OsxUiApplication*>(GetUiApplication())->UnregisterWindow(this); } void OsxWindow::Close() { |