aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-01-26 10:55:35 +0100
committertomaka <pierre.krieger1708@gmail.com>2015-01-26 10:55:35 +0100
commit1a9cf9bc5c6e9251c8035e8412edafe4bfa8869d (patch)
tree735466f6586a7f9a686e769487b55a1991bc87dc
parent9705606a20cb68187829b6767cf880ff6b4fda0c (diff)
parent73078e0569a9cadc51d64e98f4653e66e2985b8d (diff)
downloadglutin-1a9cf9bc5c6e9251c8035e8412edafe4bfa8869d.tar.gz
glutin-1a9cf9bc5c6e9251c8035e8412edafe4bfa8869d.zip
Merge pull request #231 from bjz/osx-window
Implement some more Cocoa stuff
-rw-r--r--src/cocoa/event.rs (renamed from src/osx/event.rs)0
-rw-r--r--src/cocoa/headless.rs (renamed from src/osx/headless.rs)0
-rw-r--r--src/cocoa/mod.rs (renamed from src/osx/mod.rs)48
-rw-r--r--src/cocoa/monitor.rs (renamed from src/osx/monitor.rs)0
-rw-r--r--src/lib.rs4
5 files changed, 31 insertions, 21 deletions
diff --git a/src/osx/event.rs b/src/cocoa/event.rs
index 31bed10..31bed10 100644
--- a/src/osx/event.rs
+++ b/src/cocoa/event.rs
diff --git a/src/osx/headless.rs b/src/cocoa/headless.rs
index cc19457..cc19457 100644
--- a/src/osx/headless.rs
+++ b/src/cocoa/headless.rs
diff --git a/src/osx/mod.rs b/src/cocoa/mod.rs
index 990ceb0..94ac5b3 100644
--- a/src/osx/mod.rs
+++ b/src/cocoa/mod.rs
@@ -8,7 +8,7 @@ use libc;
use BuilderAttribs;
use cocoa::base::{Class, id, YES, NO, NSUInteger, nil, objc_allocateClassPair, class, objc_registerClassPair};
-use cocoa::base::{selector, msg_send, class_addMethod, class_addIvar};
+use cocoa::base::{selector, msg_send, msg_send_stret, class_addMethod, class_addIvar};
use cocoa::base::{object_setInstanceVariable, object_getInstanceVariable};
use cocoa::appkit;
use cocoa::appkit::*;
@@ -180,16 +180,7 @@ impl WindowProxy {
let pool = NSAutoreleasePool::new(nil);
let event =
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2(
- nil,
- NSApplicationDefined,
- NSPoint::new(0.0, 0.0),
- 0,
- 0.0,
- 0,
- ptr::null_mut(),
- 0,
- 0,
- 0);
+ nil, NSApplicationDefined, NSPoint::new(0.0, 0.0), 0, 0.0, 0, ptr::null_mut(), 0, 0, 0);
NSApp().postEvent_atStart_(event, YES);
pool.drain();
}
@@ -364,30 +355,49 @@ impl Window {
}
pub fn show(&self) {
+ unsafe { NSWindow::makeKeyAndOrderFront_(self.window, nil); }
}
pub fn hide(&self) {
+ unsafe { NSWindow::orderOut_(self.window, nil); }
}
pub fn get_position(&self) -> Option<(i32, i32)> {
- unimplemented!()
+ unsafe {
+ // let content_rect = NSWindow::contentRectForFrameRect_(self.window, NSWindow::frame(self.window));
+ let content_rect: NSRect = msg_send_stret()(self.window,
+ selector("contentRectForFrameRect:"),
+ NSWindow::frame(self.window));
+ // NOTE: coordinate system might be inconsistent with other backends
+ Some((content_rect.origin.x as i32, content_rect.origin.y as i32))
+ }
}
- pub fn set_position(&self, _x: i32, _y: i32) {
- unimplemented!()
+ pub fn set_position(&self, x: i32, y: i32) {
+ unsafe {
+ // NOTE: coordinate system might be inconsistent with other backends
+ NSWindow::setFrameOrigin_(self.window, NSPoint::new(x as f64, y as f64));
+ }
}
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
- let rect = unsafe { NSView::frame(self.view) };
- Some((rect.size.width as u32, rect.size.height as u32))
+ unsafe {
+ let view_frame = NSView::frame(self.view);
+ Some((view_frame.size.width as u32, view_frame.size.height as u32))
+ }
}
pub fn get_outer_size(&self) -> Option<(u32, u32)> {
- unimplemented!()
+ unsafe {
+ let window_frame = NSWindow::frame(self.window);
+ Some((window_frame.size.width as u32, window_frame.size.height as u32))
+ }
}
- pub fn set_inner_size(&self, _x: u32, _y: u32) {
- unimplemented!()
+ pub fn set_inner_size(&self, width: u32, height: u32) {
+ unsafe {
+ NSWindow::setContentSize_(self.window, NSSize::new(width as f64, height as f64));
+ }
}
pub fn create_window_proxy(&self) -> WindowProxy {
diff --git a/src/osx/monitor.rs b/src/cocoa/monitor.rs
index 912c02d..912c02d 100644
--- a/src/osx/monitor.rs
+++ b/src/cocoa/monitor.rs
diff --git a/src/lib.rs b/src/lib.rs
index ada4185..1cf9b48 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -60,7 +60,7 @@ mod winimpl;
#[path="x11/mod.rs"]
mod winimpl;
#[cfg(target_os = "macos")]
-#[path="osx/mod.rs"]
+#[path="cocoa/mod.rs"]
mod winimpl;
#[cfg(target_os = "android")]
#[path="android/mod.rs"]
@@ -129,7 +129,7 @@ pub enum MouseCursor {
Help,
/// Progress indicator. Shows that processing is being done. But in contrast
/// with "Wait" the user may still interact with the program. Often rendered
- /// as a spinning beach ball, or an arrow with a watch or hourglass.
+ /// as a spinning beach ball, or an arrow with a watch or hourglass.
Progress,
/// Cursor showing that something cannot be done.