From ec98a6c83db990301c44cfc902a35c494e7a69e7 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 9 Dec 2008 09:22:23 -0800 Subject: [PATCH] offscreen-world widgets and offscreen pixel format fixes --- basis/cocoa/views/views.factor | 5 ++-- basis/ui/cocoa/cocoa.factor | 7 +++--- basis/ui/gadgets/worlds/worlds.factor | 11 +++++++-- basis/ui/ui.factor | 33 ++++++++++++++++++--------- extra/graphics/bitmap/bitmap.factor | 8 +++++++ 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/basis/cocoa/views/views.factor b/basis/cocoa/views/views.factor index dded68df4d..03cafd0a0a 100644 --- a/basis/cocoa/views/views.factor +++ b/basis/cocoa/views/views.factor @@ -58,8 +58,6 @@ PRIVATE> : ( attributes -- pixelfmt ) NSOpenGLPixelFormat -> alloc swap [ % - NSOpenGLPFAWindow , - NSOpenGLPFADoubleBuffer , NSOpenGLPFADepthSize , 16 , +software-renderer+ get [ NSOpenGLPFARendererID , kCGLRendererGenericFloatID , @@ -75,7 +73,8 @@ PRIVATE> -> autorelease ; : ( class dim -- view ) - [ -> alloc 0 0 ] dip first2 { } + [ -> alloc 0 0 ] dip first2 + NSOpenGLPFAWindow NSOpenGLPFADoubleBuffer 2array -> initWithFrame:pixelFormat: dup 1 -> setPostsBoundsChangedNotifications: dup 1 -> setPostsFrameChangedNotifications: ; diff --git a/basis/ui/cocoa/cocoa.factor b/basis/ui/cocoa/cocoa.factor index e4fa95d08d..cafe928b3c 100644 --- a/basis/ui/cocoa/cocoa.factor +++ b/basis/ui/cocoa/cocoa.factor @@ -16,6 +16,7 @@ TUPLE: offscreen-handle < handle context buffer ; C: window-handle C: offscreen-handle +! XXX gross! M: offscreen-handle window>> drop f ; M: offscreen-handle view>> drop f ; @@ -104,9 +105,9 @@ M: cocoa-ui-backend raise-window* ( world -- ) { [ * * malloc ] [ 2drop ] [ drop nip ] [ nip * ] } 3cleave ; : gadget-offscreen-context ( world -- context buffer ) - { NSOpenGLPFAOffScreen } - [ NSOpenGLContext -> alloc swap f -> initWithFormat:shareContext: dup ] - [ offscreen-buffer ] bi + NSOpenGLPFAOffScreen 1array + [ nip NSOpenGLContext -> alloc swap f -> initWithFormat:shareContext: dup ] + [ offscreen-buffer ] 2bi 4 npick [ -> setOffScreen:width:height:rowbytes: ] dip ; M: cocoa-ui-backend (open-offscreen-buffer) ( world -- ) diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 68a2a18210..d442e16ac4 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -13,6 +13,8 @@ title status fonts handle window-loc ; +TUPLE: offscreen-world < world ; + : find-world ( gadget -- world/f ) [ world? ] find-parent ; : show-status ( string/f gadget -- ) @@ -38,8 +40,8 @@ M: world request-focus-on ( child gadget -- ) 2dup eq? [ 2drop ] [ dup focused?>> (request-focus) ] if ; -: ( gadget title status -- world ) - { 0 1 } world new-track +: new-world ( gadget title status class -- world ) + { 0 1 } swap new-track t >>root? t >>active? H{ } clone >>fonts @@ -49,6 +51,11 @@ M: world request-focus-on ( child gadget -- ) swap 1 track-add dup request-focus ; +: ( gadget title status -- world ) + world new-world ; +: ( gadget title status -- world ) + offscreen-world new-world ; + M: world layout* dup call-next-method dup glass>> [ diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index de2eb71307..3674f48efe 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -60,23 +60,34 @@ SYMBOL: stop-after-last-window? focus-path f swap focus-gestures ; M: world graft* - dup (open-window) - dup title>> over set-title - request-focus ; + [ (open-window) ] + [ [ title>> ] keep set-title ] + [ request-focus ] tri ; : reset-world ( world -- ) #! This is used when a window is being closed, but also #! when restoring saved worlds on image startup. - dup fonts>> clear-assoc - dup unfocus-world - f >>handle drop ; + [ fonts>> clear-assoc ] + [ unfocus-world ] + [ f >>handle drop ] tri ; + +: (ungraft-world) ( world -- ) + [ free-fonts ] + [ hand-clicked close-global ] + [ hand-gadget close-global ] tri ; M: world ungraft* - dup free-fonts - dup hand-clicked close-global - dup hand-gadget close-global - dup handle>> (close-window) - reset-world ; + [ (ungraft-world) ] + [ handle>> (close-window) ] + [ reset-world ] tri ; + +M: offscreen-world graft* + (open-offscreen-buffer) ; + +M: offscreen-world ungraft* + [ (ungraft-world) ] + [ handle>> (close-offscreen-buffer) ] + [ reset-world ] tri ; : find-window ( quot -- world ) windows get values diff --git a/extra/graphics/bitmap/bitmap.factor b/extra/graphics/bitmap/bitmap.factor index 4c35e3d7d0..e3191b3866 100755 --- a/extra/graphics/bitmap/bitmap.factor +++ b/extra/graphics/bitmap/bitmap.factor @@ -23,6 +23,14 @@ TUPLE: bitmap magic size reserved offset header-length width swap [ >>array ] [ >>color-index ] bi 24 >>bit-count ; +: bgra>bitmap ( array height width -- bitmap ) + bitmap new + 2over * 4 * >>size-image + swap >>height + swap >>width + swap [ >>array ] [ >>color-index ] bi + 32 >>bit-count ; + : 8bit>array ( bitmap -- array ) [ rgb-quads>> 4 [ 3 head-slice ] map ] [ color-index>> >array ] bi [ swap nth ] with map concat ;