From 60945fa05ef306ea35fc1ec61d75c4a4a2e91803 Mon Sep 17 00:00:00 2001 From: slava Date: Mon, 13 Mar 2006 05:41:59 +0000 Subject: [PATCH] Cocoa fixes --- README.txt | 6 +----- library/cocoa/application-utils.factor | 6 ++++++ library/cocoa/subclassing.factor | 7 ++++--- library/cocoa/ui.factor | 25 +++++++++++++++---------- library/ui/world.factor | 2 +- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.txt b/README.txt index c6fc2ba3ef..c6c9a4cf2d 100644 --- a/README.txt +++ b/README.txt @@ -39,13 +39,9 @@ parameters to build the Factor runtime: linux linux-ppc macosx - macosx-sdl solaris windows -Note: If you wish to use the Factor UI on Mac OS X, you must build with -the macosx-sdl target. - The following options can be given to make: SITE_CFLAGS="..." @@ -127,6 +123,7 @@ as, and issue a command similar to the following to bootstrap Factor: library/ - sources for the library, written in Factor alien/ - C library interface bootstrap/ - code for generating boot images + cocoa/ - Mac OS X Cocoa API and Objective-C runtime binding collections/ - data types including but not limited to lists, vectors, hashtables, and operations on them compiler/ - optimizing native compiler @@ -138,7 +135,6 @@ as, and issue a command similar to the following to bootstrap Factor: io/ - input and output streams math/ - integers, ratios, floats, complex numbers, vectors, matrices opengl/ - OpenGL graphics library binding - sdl/ - SDL binding syntax/ - parser and object prettyprinter test/ - unit test framework and test suite tools/ - interactive development tools diff --git a/library/cocoa/application-utils.factor b/library/cocoa/application-utils.factor index 54cc218b48..00c363de40 100644 --- a/library/cocoa/application-utils.factor +++ b/library/cocoa/application-utils.factor @@ -8,6 +8,12 @@ objc-NSObject objc-NSView threads ; : with-autorelease-pool ( quot -- ) NSAutoreleasePool [new] slip [release] ; inline +: with-cocoa ( quot -- ) + [ + NSApplication [sharedApplication] drop + call + ] with-autorelease-pool ; inline + : [autorelease] ; : CFRunLoopDefaultMode "kCFRunLoopDefaultMode" ; diff --git a/library/cocoa/subclassing.factor b/library/cocoa/subclassing.factor index 98061c5719..9c69dacc61 100644 --- a/library/cocoa/subclassing.factor +++ b/library/cocoa/subclassing.factor @@ -69,6 +69,7 @@ libc math namespaces sequences strings ; objc_addClass ; : define-objc-class ( superclass name imeth cmeth -- ) - 2swap dup class-exists? - [ [ 2drop 2drop ] [ (define-objc-class) ] if ] keep - import-objc-class ; + 2swap [ + dup class-exists? + [ 2drop 2drop ] [ (define-objc-class) ] if + ] keep import-objc-class ; diff --git a/library/cocoa/ui.factor b/library/cocoa/ui.factor index 6df43bdb8f..7163b619d3 100644 --- a/library/cocoa/ui.factor +++ b/library/cocoa/ui.factor @@ -3,7 +3,7 @@ USING: alien arrays cocoa freetype gadgets gadgets-layouts gadgets-listener kernel namespaces objc objc-NSApplication objc-NSObject objc-NSOpenGLContext objc-NSOpenGLView objc-NSView -objc-NSWindow opengl threads ; +objc-NSWindow opengl sequences threads walker ; IN: gadgets-cocoa ! Cocoa backend for Factor UI @@ -56,15 +56,20 @@ USE: objc-FactorView FactorView [alloc] 0 0 100 100 NSOpenGLView [defaultPixelFormat] [initWithFrame:pixelFormat:] - over set-world-handle ; + [ swap set-world-handle ] keep ; + +: ( gadget title -- window ) + over rect-dim first2 0 0 2swap + [ swap [setContentView:] ] keep + dup f [makeKeyAndOrderFront:] ; [ - init-world - listener-application - - ui-title 10 10 600 600 - dup [setContentView:] - f [makeKeyAndOrderFront:] - - event-loop + [ + init-world + listener-application + + world get ui-title drop + + event-loop + ] with-cocoa ] with-freetype diff --git a/library/ui/world.factor b/library/ui/world.factor index 8815f44bb5..71503af07c 100644 --- a/library/ui/world.factor +++ b/library/ui/world.factor @@ -90,7 +90,7 @@ M: f set-message 2drop ; : world-step ( -- ) do-timers world get world-invalid >r layout-world r> - [ update-hand redraw-world ] when ; + [ update-hand world get redraw-world ] when ; SYMBOL: first-time