shove cocoa pixel format attribute conversion into a functor so we can reuse it

db4
Joe Groff 2009-05-01 16:33:49 -05:00
parent 65b33c145c
commit 2a7c26c20a
2 changed files with 39 additions and 17 deletions

View File

@ -9,7 +9,8 @@ core-graphics.types destructors fry generalizations io.thread
kernel libc literals locals math math.rectangles memory
namespaces sequences specialized-arrays.int threads ui
ui.backend ui.backend.cocoa.views ui.clipboards ui.gadgets
ui.gadgets.worlds ui.pixel-formats ui.private words.symbol ;
ui.gadgets.worlds ui.pixel-formats ui.pixel-formats.private
ui.private words.symbol ;
IN: ui.backend.cocoa
TUPLE: handle ;
@ -23,9 +24,7 @@ SINGLETON: cocoa-ui-backend
<PRIVATE
GENERIC: >NSOpenGLPFA ( attribute -- NSOpenGLPFAs )
CONSTANT: attribute>NSOpenGLPFA-map H{
PIXEL-FORMAT-ATTRIBUTE-TABLE: NSOpenGLPFA H{
{ double-buffered { $ NSOpenGLPFADoubleBuffer } }
{ stereo { $ NSOpenGLPFAStereo } }
{ offscreen { $ NSOpenGLPFAOffScreen } }
@ -49,28 +48,20 @@ CONSTANT: attribute>NSOpenGLPFA-map H{
{ samples { $ NSOpenGLPFASamples } }
}
M: object >NSOpenGLPFA
drop { } ;
M: symbol >NSOpenGLPFA
attribute>NSOpenGLPFA-map at [ { } ] unless* ;
M: pixel-format-attribute >NSOpenGLPFA
dup class attribute>NSOpenGLPFA-map at
[ swap value>> suffix ]
[ drop { } ] if* ;
PRIVATE>
M: cocoa-ui-backend (make-pixel-format)
[ >NSOpenGLPFA ] map concat 0 suffix >int-array
>NSOpenGLPFA-int-array
NSOpenGLPixelFormat -> alloc swap -> initWithAttributes: ;
M: cocoa-ui-backend (free-pixel-format)
-> release ;
M: cocoa-ui-backend (pixel-format-attribute)
attribute>NSOpenGLPFA-map at
>NSOpenGLPFA
[ drop f ]
[ first 0 <int> [ swap 0 -> getValues:forAttribute:forVirtualScreen: ] keep *int ]
[ drop f ] if* ;
if-empty ;
TUPLE: pasteboard handle ;

View File

@ -1,4 +1,6 @@
USING: accessors destructors kernel math ui.backend ;
USING: accessors assocs classes destructors functors kernel
lexer math parser sequences specialized-arrays.int ui.backend
words.symbol ;
IN: ui.pixel-formats
SYMBOLS:
@ -59,3 +61,32 @@ M: pixel-format dispose
: pixel-format-attribute ( pixel-format attribute-name -- value )
[ handle>> ] dip (pixel-format-attribute) ;
<PRIVATE
FUNCTOR: define-pixel-format-attribute-table ( NAME TABLE -- )
>PFA DEFINES >${NAME}
>PFA-int-array DEFINES >${NAME}-int-array
WHERE
GENERIC: >PFA ( attribute -- pfas )
M: object >PFA
drop { } ;
M: symbol >PFA
TABLE at [ { } ] unless* ;
M: pixel-format-attribute >PFA
dup class TABLE at
[ swap value>> suffix ]
[ drop { } ] if* ;
: >PFA-int-array ( attribute -- int-array )
[ >PFA ] map concat 0 suffix >int-array ;
;FUNCTOR
SYNTAX: PIXEL-FORMAT-ATTRIBUTE-TABLE:
scan scan-object define-pixel-format-attribute-table ;
PRIVATE>