! Copyright (C) 2010, 2011 Anton Gorenko, Philipp Bruschweiler.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.accessors alien.c-types alien.data
-alien.strings arrays assocs classes.struct combinators continuations
-destructors environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi
-gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi
-io.encodings.binary io.encodings.utf8 io.files io.pathnames kernel
-libc literals locals math math.bitwise math.vectors namespaces
-sequences strings system threads ui ui.backend
+USING: accessors alien.accessors alien.c-types alien.strings arrays
+assocs classes.struct combinators continuations destructors
+environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi gobject.ffi
+gtk.ffi gtk.gl.ffi io.encodings.binary io.encodings.utf8 io.files
+io.pathnames kernel libc literals locals math math.bitwise
+math.vectors namespaces sequences strings system threads ui ui.backend
ui.backend.gtk.input-methods ui.backend.gtk.io ui.backend.x11.keys
ui.clipboards ui.event-loop ui.gadgets ui.gadgets.private
ui.gadgets.worlds ui.gestures ui.pixel-formats
M: gtk-ui-backend (free-pixel-format)
handle>> g_object_unref ;
-M: gtk-ui-backend (pixel-format-attribute)
- [ handle>> ] [ >gl-config-attribs ] bi*
- { gint } [ gdk_gl_config_get_attrib drop ]
- with-out-parameters ;
-
M: window-handle select-gl-context ( handle -- )
drawable>>
[ gtk_widget_get_gl_window ] [ gtk_widget_get_gl_context ] bi
[ handle>> hDC>> ] dip >WGL_ARB-int-array f 1 { c:int c:int }
[ wglChoosePixelFormatARB win32-error=0/f ] with-out-parameters drop ;
-: arb-pixel-format-attribute ( pixel-format attribute -- value )
- >WGL_ARB
- [ drop f ] [
- [ [ world>> handle>> hDC>> ] [ handle>> ] bi 0 1 ] dip
- first c:int <ref> { c:int }
- [ wglGetPixelFormatAttribivARB win32-error=0/f ]
- with-out-parameters
- ] if-empty ;
-
CONSTANT: pfd-flag-map H{
{ double-buffered $ PFD_DOUBLEBUFFER }
{ stereo $ PFD_STEREO }
[ handle>> hDC>> ] [ >pfd ] bi*
ChoosePixelFormat dup win32-error=0/f ;
-: get-pfd ( pixel-format -- pfd )
- [ world>> handle>> hDC>> ] [ handle>> ] bi
- PIXELFORMATDESCRIPTOR c:heap-size
- PIXELFORMATDESCRIPTOR <struct>
- [ DescribePixelFormat win32-error=0/f ] keep ;
-
-: pfd-flag? ( pfd flag -- ? )
- [ dwFlags>> ] dip bitand c:c-bool> ;
-
-: (pfd-pixel-format-attribute) ( pfd attribute -- value )
- {
- { double-buffered [ PFD_DOUBLEBUFFER pfd-flag? ] }
- { stereo [ PFD_STEREO pfd-flag? ] }
- { offscreen [ PFD_DRAW_TO_BITMAP pfd-flag? ] }
- { fullscreen [ PFD_DRAW_TO_WINDOW pfd-flag? ] }
- { windowed [ PFD_DRAW_TO_WINDOW pfd-flag? ] }
- { software-rendered [ PFD_GENERIC_FORMAT pfd-flag? ] }
- { color-bits [ cColorBits>> ] }
- { red-bits [ cRedBits>> ] }
- { green-bits [ cGreenBits>> ] }
- { blue-bits [ cBlueBits>> ] }
- { alpha-bits [ cAlphaBits>> ] }
- { accum-bits [ cAccumBits>> ] }
- { accum-red-bits [ cAccumRedBits>> ] }
- { accum-green-bits [ cAccumGreenBits>> ] }
- { accum-blue-bits [ cAccumBlueBits>> ] }
- { accum-alpha-bits [ cAccumAlphaBits>> ] }
- { depth-bits [ cDepthBits>> ] }
- { stencil-bits [ cStencilBits>> ] }
- { aux-buffers [ cAuxBuffers>> ] }
- [ 2drop f ]
- } case ;
-
-: pfd-pixel-format-attribute ( pixel-format attribute -- value )
- [ get-pfd ] dip (pfd-pixel-format-attribute) ;
-
M: windows-ui-backend (make-pixel-format)
over has-wglChoosePixelFormatARB?
[ arb-make-pixel-format ] [ pfd-make-pixel-format ] if ;
M: windows-ui-backend (free-pixel-format)
drop ;
-M: windows-ui-backend (pixel-format-attribute)
- over world>> has-wglChoosePixelFormatARB?
- [ arb-pixel-format-attribute ] [ pfd-pixel-format-attribute ] if ;
-
PRIVATE>
: GET_APPCOMMAND_LPARAM ( lParam -- appCommand )