ui.pixel-formats: apply @jonenst's patch for #1859.

factor-shell
John Benediktsson 2017-10-09 10:01:41 -07:00
parent 9cdb209d01
commit dc001f9a34
2 changed files with 27 additions and 6 deletions

View File

@ -1,14 +1,24 @@
USING: specialized-arrays.instances.alien.c-types.int tools.test USING: alien.c-types literals specialized-arrays tools.test
ui.pixel-formats ; ui.pixel-formats ;
SPECIALIZED-ARRAY: int
IN: ui.pixel-formats.tests IN: ui.pixel-formats.tests
CONSTANT: attrib-table { CONSTANT: attrib-table {
{ windowed { 99 } } { windowed { 99 } }
{ double-buffered { 7 } } { double-buffered { 7 } }
{ samples { 100001 } }
} }
SYMBOL: garbageword
CONSTANT: garbageint 234
! pixel-format-attributes>int-array ! pixel-format-attributes>int-array
{ int-array{ 9 2 99 7 0 } } [ ! it should ignore garbage, even the color-bits because it's not
{ windowed double-buffered } { 9 2 } attrib-table ! in the table
{ int-array{ 9 2 99 7 100001 2 0 } } [
{
windowed "garbage" $ garbageint double-buffered
garbageword T{ samples f 2 } T{ color-bits f 24 }
} { 9 2 } attrib-table
pixel-format-attributes>int-array pixel-format-attributes>int-array
] unit-test ] unit-test

View File

@ -1,5 +1,6 @@
USING: accessors alien.c-types alien.data assocs destructors fry USING: accessors alien.c-types alien.data assocs classes
kernel math sequences specialized-arrays ui.backend ; combinators destructors fry kernel math sequences
specialized-arrays ui.backend words ;
SPECIALIZED-ARRAY: int SPECIALIZED-ARRAY: int
IN: ui.pixel-formats IN: ui.pixel-formats
@ -57,8 +58,18 @@ TUPLE: pixel-format < disposable world handle ;
M: pixel-format dispose* M: pixel-format dispose*
[ (free-pixel-format) ] [ f >>handle drop ] bi ; [ (free-pixel-format) ] [ f >>handle drop ] bi ;
: (pixel-format-attribute) ( attribute table -- arr/f )
[ dup class-of ] dip at [ swap value>> suffix ] [ drop f ] if* ;
: pixel-format-attribute>array ( obj table -- arr/f )
{
{ [ over pixel-format-attribute? ] [ (pixel-format-attribute) ] }
{ [ over word? ] [ at ] }
[ 2drop f ]
} cond ;
: pixel-format-attributes>int-array ( attrs perm table -- arr ) : pixel-format-attributes>int-array ( attrs perm table -- arr )
swapd '[ _ at ] map sift concat append swapd '[ _ pixel-format-attribute>array ] map sift concat append
! 0 happens to work as a sentinel value for all ui backends. ! 0 happens to work as a sentinel value for all ui backends.
0 suffix int >c-array ; 0 suffix int >c-array ;