GENERIC: flush-gl-context ( handle -- )
+GENERIC: offscreen-pixels ( handle -- alien )
+
HOOK: beep ui-backend ( -- )
: with-gl-context ( handle quot -- )
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 ( -- )
[ 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 ;
[ 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
--- /dev/null
+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 ;
+