Finally a visible window!

This commit is contained in:
Daniel Collin 2015-12-19 11:44:36 +01:00
parent 08028c1e54
commit 026be10b8b
2 changed files with 17 additions and 4 deletions

View file

@ -10,7 +10,7 @@ fn main() {
//let mut carry;
//let mut seed = 0xbeefu32;
//let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT];
let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT];
let window = match macos::Window::new("Noise Test - Press ESC to exit",
WIDTH,
@ -25,6 +25,7 @@ fn main() {
};
loop {
window.update(&buffer);
/*
for i in buffer.iter_mut() {
noise = seed;

View file

@ -59,6 +59,8 @@ impl WindowDelegate {
let state: *mut libc::c_void = *this.get_ivar("glutinState");
let state = &mut *(state as *mut DelegateState);
println!("did_resize");
//let _: () = msg_send![*state.context, update];
if let Some(handler) = state.resize_handler {
@ -75,6 +77,7 @@ impl WindowDelegate {
// TODO: center the cursor if the window had mouse grab when it
// lost focus
println!("became key window");
let state: *mut libc::c_void = *this.get_ivar("glutinState");
let state = state as *mut DelegateState;
//(*state).pending_events.lock().unwrap().push_back(Focused(true));
@ -93,7 +96,7 @@ impl WindowDelegate {
static INIT: Once = ONCE_INIT;
INIT.call_once(|| unsafe {
// Create new NSWindowDelegate
println!("Create new NSWindowDelegate");
let superclass = Class::get("NSObject").unwrap();
let mut decl = ClassDecl::new(superclass, "GlutinWindowDelegate").unwrap();
@ -169,6 +172,7 @@ impl Window {
};
app.activateIgnoringOtherApps_(YES);
window.makeKeyAndOrderFront_(nil);
let ds = DelegateState {
view: view.clone(),
@ -202,6 +206,7 @@ impl Window {
window.non_nil().map(|window| {
let title = IdRef::new(NSString::alloc(nil).init_str(name));
window.setLevel_(NSMainMenuWindowLevel as i64 + 1);
window.setTitle_(*title);
window.center();
window
@ -216,7 +221,14 @@ impl Window {
})
}
pub fn update(_: &[u32]) {
pub fn update(&self, _: &[u32]) {
unsafe {
NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
NSAnyEventMask.bits(),
NSDate::distantPast(nil),
NSDefaultRunLoopMode,
YES);
}
}
pub fn get_keys() -> Option<Vec<Key>> {