2005-01-31 14:02:09 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
|
|
|
USING: generic kernel lists math namespaces sdl sdl-gfx ;
|
|
|
|
|
|
|
|
! The painting protocol. Painting is controlled by various
|
|
|
|
! dynamically-scoped variables.
|
|
|
|
|
|
|
|
! "Paint" is a namespace containing some or all of these values.
|
|
|
|
SYMBOL: color ! a list of three integers, 0..255.
|
|
|
|
SYMBOL: font ! a list of two elements, a font name and size.
|
|
|
|
SYMBOL: filled ! is the interior of the shape filled?
|
|
|
|
|
|
|
|
: shape>screen ( shape -- x1 y1 x2 y2 )
|
|
|
|
[ shape-x x get + ] keep
|
|
|
|
[ shape-y y get + ] keep
|
|
|
|
[ dup shape-x swap shape-w + x get + ] keep
|
|
|
|
dup shape-y swap shape-h + y get + ;
|
|
|
|
|
|
|
|
: rgb-color ( -- rgba ) color get 3unlist rgb ;
|
|
|
|
|
|
|
|
GENERIC: draw ( obj -- )
|
|
|
|
|
2005-02-01 20:14:03 -05:00
|
|
|
M: number draw ( point -- )
|
|
|
|
>r surface get r> >rect rgb-color pixelColor ;
|
|
|
|
|
|
|
|
M: rectangle draw ( rect -- )
|
2005-01-31 14:02:09 -05:00
|
|
|
>r surface get r> shape>screen rgb-color
|
|
|
|
filled get [ boxColor ] [ rectangleColor ] ifte ;
|
|
|
|
|
|
|
|
: default-paint ( -- paint )
|
|
|
|
{{
|
|
|
|
[[ x 0 ]]
|
|
|
|
[[ y 0 ]]
|
|
|
|
[[ color [ 0 0 0 ] ]]
|
|
|
|
[[ filled f ]]
|
2005-02-01 22:48:04 -05:00
|
|
|
[[ font [[ "Monospaced" 12 ]] ]]
|
2005-01-31 14:02:09 -05:00
|
|
|
}} ;
|