2006-02-09 20:36:11 -05:00
|
|
|
! Copyright (C) 2006 Slava Pestov
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: cocoa
|
2006-03-12 23:21:01 -05:00
|
|
|
USING: alien errors gadgets io kernel namespaces
|
|
|
|
objc-NSApplication objc-NSAutoreleasePool objc-NSException
|
|
|
|
objc-NSObject objc-NSView threads ;
|
2006-02-09 20:36:11 -05:00
|
|
|
|
|
|
|
: with-autorelease-pool ( quot -- )
|
2006-02-09 22:11:22 -05:00
|
|
|
NSAutoreleasePool [new] slip [release] ; inline
|
2006-02-09 20:36:11 -05:00
|
|
|
|
|
|
|
: <NSString> <CFString> [autorelease] ;
|
|
|
|
|
2006-02-09 22:11:22 -05:00
|
|
|
: CFRunLoopDefaultMode "kCFRunLoopDefaultMode" <NSString> ;
|
|
|
|
|
|
|
|
: next-event ( app -- event )
|
|
|
|
0 f CFRunLoopDefaultMode 1
|
2006-02-09 20:36:11 -05:00
|
|
|
[nextEventMatchingMask:untilDate:inMode:dequeue:] ;
|
|
|
|
|
|
|
|
: do-events ( app -- )
|
2006-02-09 22:11:22 -05:00
|
|
|
dup next-event [ dupd [sendEvent:] do-events ] [ drop ] if* ;
|
2006-02-09 20:36:11 -05:00
|
|
|
|
2006-02-09 22:11:22 -05:00
|
|
|
: (event-loop) ( -- )
|
2006-02-09 20:36:11 -05:00
|
|
|
[
|
2006-03-12 23:21:01 -05:00
|
|
|
NSApplication [sharedApplication] do-events world-step
|
2006-02-09 22:11:22 -05:00
|
|
|
] with-autorelease-pool 10 sleep (event-loop) ;
|
|
|
|
|
|
|
|
: event-loop ( -- )
|
|
|
|
\ NSApplication get expired? [
|
|
|
|
NSApplication [sharedApplication]
|
|
|
|
\ NSApplication set-global
|
|
|
|
[ (event-loop) ] in-thread
|
|
|
|
] when ;
|
2006-02-19 22:08:08 -05:00
|
|
|
|
|
|
|
IN: errors
|
|
|
|
|
|
|
|
: objc-error. ( alien -- )
|
|
|
|
"Objective C exception:" print [reason] CF>string print ;
|
2006-03-12 23:21:01 -05:00
|
|
|
|
|
|
|
IN: gadgets
|
|
|
|
|
|
|
|
: redraw-world ( gadgets -- )
|
|
|
|
world-handle 1 [setNeedsDisplay:] ;
|