aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cocoa/mod.rs51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/cocoa/mod.rs b/src/cocoa/mod.rs
index f4b2726..62eedc6 100644
--- a/src/cocoa/mod.rs
+++ b/src/cocoa/mod.rs
@@ -456,10 +456,7 @@ impl Window {
NSBackingStoreBuffered,
NO,
));
-
- if *window == nil {
- None
- } else {
+ window.non_nil().map(|window| {
let title = IdRef::new(NSString::alloc(nil).init_str(title));
window.setTitle_(*title);
window.setAcceptsMouseMovedEvents_(YES);
@@ -469,21 +466,19 @@ impl Window {
else {
window.center();
}
- Some(window)
- }
+ window
+ })
}
}
fn create_view(window: id) -> Option<IdRef> {
unsafe {
let view = IdRef::new(NSView::alloc(nil).init());
- if *view == nil {
- None
- } else {
+ view.non_nil().map(|view| {
view.setWantsBestResolutionOpenGLSurface_(YES);
window.setContentView_(*view);
- Some(view)
- }
+ view
+ })
}
}
@@ -513,21 +508,17 @@ impl Window {
];
let pixelformat = IdRef::new(NSOpenGLPixelFormat::alloc(nil).initWithAttributes_(&attributes));
- if *pixelformat == nil {
- return None;
- }
-
- let context = IdRef::new(NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(*pixelformat, nil));
- if *context == nil {
- None
- } else {
- context.setView_(view);
- if vsync {
- let value = 1;
- context.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
- }
- Some(context)
- }
+ pixelformat.non_nil().map(|pixelformat| {
+ let context = IdRef::new(NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(*pixelformat, nil));
+ context.non_nil().map(|context| {
+ context.setView_(view);
+ if vsync {
+ let value = 1;
+ context.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
+ }
+ context
+ })
+ }).unwrap_or(None)
}
}
@@ -715,9 +706,15 @@ impl IdRef {
}
fn retain(i: id) -> IdRef {
- unsafe { msg_send::<()>()(i, selector("retain")) };
+ if i != nil {
+ unsafe { msg_send::<()>()(i, selector("retain")) };
+ }
IdRef(i)
}
+
+ fn non_nil(self) -> Option<IdRef> {
+ if self.0 == nil { None } else { Some(self) }
+ }
}
impl Drop for IdRef {