]> gitweb.factorcode.org Git - factor.git/commitdiff
Move offscreen-world widget and support words into ui.offscreen vocab
authorJoe Groff <arcata@gmail.com>
Tue, 9 Dec 2008 18:07:57 +0000 (10:07 -0800)
committerJoe Groff <arcata@gmail.com>
Tue, 9 Dec 2008 18:07:57 +0000 (10:07 -0800)
basis/ui/backend/backend.factor
basis/ui/cocoa/cocoa.factor
basis/ui/ui.factor
extra/ui/offscreen/offscreen.factor [new file with mode: 0644]

index 8d5109ac7fe2bf4d43bbd356a3d71bb50ba59cb0..7b808bb2bef9e9fe07c68388dd1fe8e195001e82 100644 (file)
@@ -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 -- )
index cafe928b3cf7a3a575d2a5ca415d0878942a588b..6e19f3ffe6ef4b6b45f8e7cb16e4645952dfd136 100644 (file)
@@ -16,10 +16,6 @@ TUPLE: offscreen-handle < handle context buffer ;
 C: <window-handle> window-handle
 C: <offscreen-handle> 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 ;
index 3674f48efe17eac47bfc13481632d579d3cff0d6..cf2a6574395b0929bd106470e5220a77bbf92af9 100644 (file)
@@ -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 (file)
index 0000000..c246453
--- /dev/null
@@ -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 ;
+
+: <offscreen-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 <offscreen-world> [ open-world-window ] keep ;
+
+: offscreen-world>bitmap ( world -- bitmap )
+    [ handle>> offscreen-pixels ] [ dim>> first2 neg ] bi
+    bgra>bitmap ;
+