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.
|
2005-02-03 22:21:51 -05:00
|
|
|
|
|
|
|
! Colors are lists of three integers, 0..255.
|
|
|
|
SYMBOL: foreground ! Used for text and outline shapes.
|
|
|
|
SYMBOL: background ! Used for filled shapes.
|
|
|
|
SYMBOL: bevel-1
|
|
|
|
SYMBOL: bevel-2
|
|
|
|
SYMBOL: bevel-up?
|
|
|
|
|
2005-02-02 22:00:46 -05:00
|
|
|
SYMBOL: font ! a list of two elements, a font name and size.
|
2005-01-31 14:02:09 -05:00
|
|
|
|
|
|
|
: 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 + ;
|
|
|
|
|
2005-02-02 22:00:46 -05:00
|
|
|
GENERIC: draw-shape ( obj -- )
|
2005-01-31 14:02:09 -05:00
|
|
|
|
2005-02-02 22:00:46 -05:00
|
|
|
M: rectangle draw-shape drop ;
|
2005-02-01 20:14:03 -05:00
|
|
|
|
2005-02-02 22:00:46 -05:00
|
|
|
M: point draw-shape ( point -- )
|
|
|
|
>r surface get r> dup point-x swap point-y
|
2005-02-03 22:21:51 -05:00
|
|
|
foreground get rgb pixelColor ;
|
2005-02-02 22:00:46 -05:00
|
|
|
|
|
|
|
TUPLE: hollow-rect delegate ;
|
|
|
|
|
|
|
|
C: hollow-rect ( x y w h -- rect )
|
|
|
|
[ >r <rectangle> r> set-hollow-rect-delegate ] keep ;
|
|
|
|
|
|
|
|
M: hollow-rect draw-shape ( rect -- )
|
2005-02-03 22:21:51 -05:00
|
|
|
>r surface get r> shape>screen foreground get rgb
|
|
|
|
rectangleColor ;
|
2005-02-02 22:00:46 -05:00
|
|
|
|
|
|
|
TUPLE: plain-rect delegate ;
|
|
|
|
|
|
|
|
C: plain-rect ( x y w h -- rect )
|
|
|
|
[ >r <rectangle> r> set-plain-rect-delegate ] keep ;
|
|
|
|
|
|
|
|
M: plain-rect draw-shape ( rect -- )
|
2005-02-03 22:21:51 -05:00
|
|
|
>r surface get r> shape>screen background get rgb
|
|
|
|
boxColor ;
|
2005-02-02 22:00:46 -05:00
|
|
|
|
|
|
|
: x1/x2/y1 ( #{ x1 y1 }# #{ x2 y2 }# -- x1 x2 y1 )
|
|
|
|
>r >rect r> real swap ;
|
|
|
|
|
|
|
|
: x1/x2/y2 ( #{ x1 y1 }# #{ x2 y2 }# -- x1 x2 y2 )
|
|
|
|
>r real r> >rect ;
|
|
|
|
|
|
|
|
: x1/y1/y2 ( #{ x1 y1 }# #{ x2 y2 }# -- x1 y1 y2 )
|
|
|
|
>r >rect r> imaginary ;
|
|
|
|
|
|
|
|
: x2/y1/y2 ( #{ x1 y1 }# #{ x2 y2 }# -- x2 y1 y2 )
|
|
|
|
>r imaginary r> >rect >r swap r> ;
|
|
|
|
|
2005-02-03 22:21:51 -05:00
|
|
|
: bevel-up ( -- rgb )
|
|
|
|
bevel-up? get [ bevel-1 get ] [ bevel-2 get ] ifte rgb ;
|
|
|
|
|
|
|
|
: bevel-down ( -- rgb )
|
|
|
|
bevel-up? get [ bevel-2 get ] [ bevel-1 get ] ifte rgb ;
|
|
|
|
|
2005-02-02 22:00:46 -05:00
|
|
|
: (draw-bevel) ( #{ x1 y1 }# #{ x2 y2 }# -- )
|
2005-02-03 22:21:51 -05:00
|
|
|
surface get pick pick x1/x2/y1 bevel-up hlineColor
|
|
|
|
surface get pick pick x1/x2/y2 bevel-down hlineColor
|
|
|
|
surface get pick pick x1/y1/y2 bevel-up vlineColor
|
|
|
|
surface get pick pick x2/y1/y2 bevel-down vlineColor
|
2005-02-02 22:00:46 -05:00
|
|
|
2drop ;
|
|
|
|
|
|
|
|
TUPLE: bevel-rect delegate bevel ;
|
|
|
|
|
|
|
|
C: bevel-rect ( bevel x y w h -- rect )
|
|
|
|
[ >r <rectangle> r> set-bevel-rect-delegate ] keep
|
|
|
|
[ set-bevel-rect-bevel ] keep ;
|
|
|
|
|
|
|
|
: draw-bevel ( #{ x1 y1 }# #{ x2 y2 }# n -- )
|
|
|
|
[
|
|
|
|
pick over #{ 1 1 }# * +
|
|
|
|
pick pick #{ 1 1 }# * -
|
|
|
|
(draw-bevel)
|
|
|
|
] repeat 2drop ;
|
|
|
|
|
|
|
|
M: bevel-rect draw-shape ( rect -- )
|
|
|
|
shape>screen >r >r rect> r> r> rect> 3 draw-bevel ;
|
2005-01-31 14:02:09 -05:00
|
|
|
|
2005-02-03 18:18:47 -05:00
|
|
|
: draw-gadget ( gadget -- )
|
|
|
|
#! All drawing done inside draw-shape is done with the
|
|
|
|
#! gadget's paint. If the gadget does not have any custom
|
|
|
|
#! paint, just call the quotation.
|
|
|
|
dup gadget-paint [
|
|
|
|
dup draw-shape
|
|
|
|
dup [
|
|
|
|
gadget-children [ draw-gadget ] each
|
|
|
|
] with-translation
|
|
|
|
] bind ;
|