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 {
32
32
[self .window center ];
33
33
[self .window makeKeyAndOrderFront: nil ];
34
34
[self .window makeMainWindow ];
35
- [NSApp activateIgnoringOtherApps: YES ];
36
35
37
36
// 延迟检查主窗口
38
37
dispatch_async (dispatch_get_main_queue (), ^{
@@ -53,20 +52,6 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
53
52
});
54
53
displayManager.AddListener (&displayEventHandler);
55
54
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
-
70
55
[[NSNotificationCenter defaultCenter ]
71
56
addObserverForName: NSWindowDidBecomeMainNotification
72
57
object: nil
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class Window {
32
32
// Color GetBackgroundColor() const;
33
33
void SetBounds (Rectangle bounds);
34
34
Rectangle GetBounds () const ;
35
- void SetSize (Size size);
35
+ void SetSize (Size size, bool animate );
36
36
Size GetSize () const ;
37
37
void SetContentSize (Size size);
38
38
Size GetContentSize () const ;
Original file line number Diff line number Diff line change 40
40
41
41
void Window::Show () {
42
42
[pimpl_->ns_window_ setIsVisible: YES ];
43
- [pimpl_->ns_window_ makeKeyAndOrderFront: nil ];
43
+ [pimpl_->ns_window_ orderFrontRegardless ];
44
44
}
45
45
46
46
void Window::Hide () {
116
116
return bounds;
117
117
}
118
118
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
+ }
121
129
}
122
130
123
131
Size Window::GetSize () const {
235
243
}
236
244
237
245
void 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];
239
251
}
240
252
241
253
Point Window::GetPosition () {
You can’t perform that action at this time.
0 commit comments