Skip to content

Commit

Permalink
[add] layer init
Browse files Browse the repository at this point in the history
  • Loading branch information
rozaliev committed May 25, 2015
1 parent 1a7576d commit ce3ebc7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/api/ios/mod.rs
Expand Up @@ -7,12 +7,13 @@ use std::mem;
use libc;
use objc;
use objc::runtime::{Class, Object, Sel, BOOL, YES};
use objc::declare::ClassDecl;
use objc::declare::{ ClassDecl, MethodImplementation };

use native_monitor::NativeMonitorId;
use { Api, PixelFormat, CreationError, BuilderAttribs, GlContext, CursorState, MouseCursor, Event };
use CreationError::OsError;


#[link(name = "UIKit", kind = "framework")]
extern {
// int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName );
Expand Down Expand Up @@ -186,10 +187,30 @@ impl Window {
decl.register();
}

extern fn init_for_gl(this: &Object, _: Sel, frame: *const libc::c_void) -> id {
unsafe {
let bounds: *const CGRect = mem::transmute(frame);
let view: id = msg_send![this, initWithFrame:(*bounds).clone()];

let layer: id = msg_send![view, layer];
let _ : () = msg_send![layer, setOpaque:YES];

view
}
}
extern fn layer_class(this: &Class, _: Sel) -> *const Class {
unsafe { mem::transmute(Class::get("CAEAGLLayer").unwrap()) }
}


let superclass = Class::get("UIView").unwrap();
let mut decl = ClassDecl::new(superclass, "MainView").unwrap();

unsafe {
decl.add_method(sel!(initForGl:),
init_for_gl as extern fn(&Object, Sel, *const libc::c_void) -> id);
decl.add_class_method(sel!(layerClass),
layer_class as extern fn(&Class, Sel) -> *const Class);
decl.register();
}
}
Expand All @@ -210,7 +231,7 @@ impl Window {

let class = Class::get("MainView").unwrap();
let view:id = msg_send![class, alloc];
let view:id = msg_send![view, initWithFrame:bounds];
let view:id = msg_send![view, initForGl:&bounds];

let color: id = msg_send![Class::get("UIColor").unwrap(), redColor];

Expand Down

0 comments on commit ce3ebc7

Please sign in to comment.