]> gitweb.factorcode.org Git - factor.git/commitdiff
shove cocoa pixel format attribute conversion into a functor so we can reuse it
authorJoe Groff <arcata@gmail.com>
Fri, 1 May 2009 21:33:49 +0000 (16:33 -0500)
committerJoe Groff <arcata@gmail.com>
Fri, 1 May 2009 21:33:49 +0000 (16:33 -0500)
basis/ui/backend/cocoa/cocoa.factor
basis/ui/pixel-formats/pixel-formats.factor

index 8a91dfd94deadbada6274ed2bc02d165776099a3..ba0a7b9c7e28c86c0be7fefb8c0a17beb1ae3646 100755 (executable)
@@ -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 ;
 
index 3032c2551f642a7d736e6ca906539bfbace6363d..5c16407135ecb7a88929dad22b0e5a5c9bcc1a93 100644 (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>