File tree Expand file tree Collapse file tree 3 files changed +17
-20
lines changed
examples/nswindow_example Expand file tree Collapse file tree 3 files changed +17
-20
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
3232 [self .window center ];
3333 [self .window makeKeyAndOrderFront: nil ];
3434 [self .window makeMainWindow ];
35- [NSApp activateIgnoringOtherApps: YES ];
3635
3736 // 延迟检查主窗口
3837 dispatch_async (dispatch_get_main_queue (), ^{
@@ -53,20 +52,6 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
5352 });
5453 displayManager.AddListener (&displayEventHandler);
5554
56- std::shared_ptr<BroadcastCenter> broadcastCenter = std::make_shared<BroadcastCenter>();
57-
58- BroadcastEventHandler broadcastEventHandler =
59- BroadcastEventHandler ([](const std::string& message) {
60- std::cout << " Received broadcast: " << message << std::endl;
61- });
62-
63- broadcastCenter->RegisterReceiver (" com.example.myNotification" , &broadcastEventHandler);
64-
65- // broadcastCenter.RegisterReceiver(
66- // BroadcastEventHandler ([&](const std::string& message) {
67- // std::cout << "Received broadcast: " << message << std::endl;
68- // }));
69-
7055 [[NSNotificationCenter defaultCenter ]
7156 addObserverForName: NSWindowDidBecomeMainNotification
7257 object: nil
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class Window {
3232 // Color GetBackgroundColor() const;
3333 void SetBounds (Rectangle bounds);
3434 Rectangle GetBounds () const ;
35- void SetSize (Size size);
35+ void SetSize (Size size, bool animate );
3636 Size GetSize () const ;
3737 void SetContentSize (Size size);
3838 Size GetContentSize () const ;
Original file line number Diff line number Diff line change 4040
4141void Window::Show () {
4242 [pimpl_->ns_window_ setIsVisible: YES ];
43- [pimpl_->ns_window_ makeKeyAndOrderFront: nil ];
43+ [pimpl_->ns_window_ orderFrontRegardless ];
4444}
4545
4646void Window::Hide () {
116116 return bounds;
117117}
118118
119- void Window::SetSize (Size size) {
120- [pimpl_->ns_window_ setFrame: NSMakeRect (0 , 0 , size.width, size.height) display: YES ];
119+ void Window::SetSize (Size size, bool animate) {
120+ NSRect frame = [pimpl_->ns_window_ frame ];
121+ frame.origin .y += (frame.size .height - size.height );
122+ frame.size .width = size.width ;
123+ frame.size .height = size.height ;
124+ if (animate) {
125+ [[pimpl_->ns_window_ animator ] setFrame: frame display: YES animate: YES ];
126+ } else {
127+ [pimpl_->ns_window_ setFrame: frame display: YES ];
128+ }
121129}
122130
123131Size Window::GetSize () const {
235243}
236244
237245void Window::SetPosition (Point point) {
238- [pimpl_->ns_window_ setFrameOrigin: NSMakePoint (point.x, point.y)];
246+ NSRect screenFrameRect = [[NSScreen screens ][0 ] frame ];
247+ // Convert point to bottom left origin
248+ NSPoint bottomLeft =
249+ NSMakePoint (point.x, screenFrameRect.size.height - point.y - GetSize().height);
250+ [pimpl_->ns_window_ setFrameOrigin: bottomLeft];
239251}
240252
241253Point Window::GetPosition () {
You can’t perform that action at this time.
0 commit comments