diff --git a/basis/ui/backend/backend.factor b/basis/ui/backend/backend.factor index 8d5109ac7f..7b808bb2be 100644 --- a/basis/ui/backend/backend.factor +++ b/basis/ui/backend/backend.factor @@ -27,6 +27,8 @@ GENERIC: select-gl-context ( handle -- ) GENERIC: flush-gl-context ( handle -- ) +GENERIC: offscreen-pixels ( handle -- alien ) + HOOK: beep ui-backend ( -- ) : with-gl-context ( handle quot -- ) diff --git a/basis/ui/cocoa/cocoa.factor b/basis/ui/cocoa/cocoa.factor index cafe928b3c..6e19f3ffe6 100644 --- a/basis/ui/cocoa/cocoa.factor +++ b/basis/ui/cocoa/cocoa.factor @@ -16,10 +16,6 @@ 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 ; - SINGLETON: cocoa-ui-backend M: cocoa-ui-backend do-events ( -- ) @@ -117,15 +113,18 @@ M: cocoa-ui-backend (close-offscreen-buffer) ( handle -- ) [ context>> -> release ] [ buffer>> free ] bi ; -GENERIC: gl-context ( handle -- context ) -M: window-handle gl-context view>> -> openGLContext ; -M: offscreen-handle gl-context context>> ; +GENERIC: (gl-context) ( handle -- context ) +M: window-handle (gl-context) view>> -> openGLContext ; +M: offscreen-handle (gl-context) context>> ; M: handle select-gl-context ( handle -- ) - gl-context -> makeCurrentContext ; + (gl-context) -> makeCurrentContext ; M: handle flush-gl-context ( handle -- ) - gl-context -> flushBuffer ; + (gl-context) -> flushBuffer ; + +M: offscreen-handle offscreen-pixels ( handle -- alien ) + buffer>> ; M: cocoa-ui-backend beep ( -- ) NSBeep ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 3674f48efe..cf2a657439 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -81,14 +81,6 @@ M: world ungraft* [ 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 [ gadget-child swap call ] with find-last nip ; inline diff --git a/extra/ui/offscreen/offscreen.factor b/extra/ui/offscreen/offscreen.factor new file mode 100644 index 0000000000..c246453082 --- /dev/null +++ b/extra/ui/offscreen/offscreen.factor @@ -0,0 +1,24 @@ +USING: accessors graphics.bitmap kernel math sequences +ui.gadgets ui.gadgets.worlds ui ui.backend ; +IN: ui.offscreen + +TUPLE: offscreen-world < world ; + +: ( gadget title status -- world ) + offscreen-world new-world ; + +M: offscreen-world graft* + (open-offscreen-buffer) ; + +M: offscreen-world ungraft* + [ (ungraft-world) ] + [ handle>> (close-offscreen-buffer) ] + [ reset-world ] tri ; + +: open-offscreen ( gadget -- world ) + "" f [ open-world-window ] keep ; + +: offscreen-world>bitmap ( world -- bitmap ) + [ handle>> offscreen-pixels ] [ dim>> first2 neg ] bi + bgra>bitmap ; +