factor/library/ui/shapes.factor

50 lines
1.2 KiB
Factor
Raw Normal View History

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 matrices namespaces sdl
sequences vectors ;
2005-01-31 14:02:09 -05:00
2005-02-01 19:00:16 -05:00
SYMBOL: x
SYMBOL: y
: origin ( -- loc ) x get y get 0 3vector ;
GENERIC: inside? ( loc shape -- ? )
GENERIC: shape-loc ( shape -- loc )
GENERIC: set-shape-loc ( loc shape -- )
GENERIC: shape-dim ( shape -- dim )
GENERIC: set-shape-dim ( dim shape -- )
2005-01-31 14:02:09 -05:00
: shape-x shape-loc first ;
: shape-y shape-loc second ;
: shape-w shape-dim first ;
: shape-h shape-dim second ;
GENERIC: draw-shape ( shape -- )
2005-03-07 22:11:36 -05:00
2005-02-26 02:11:25 -05:00
: with-trans ( shape quot -- )
2005-01-31 14:02:09 -05:00
#! All drawing done inside the quotation is translated
#! relative to the shape's origin.
[
>r dup
shape-x x [ + ] change
shape-y y [ + ] change
r> call
] with-scope ; inline
2005-02-05 11:52:24 -05:00
: shape-pos ( shape -- pos )
dup shape-x swap shape-y rect> ;
: shape-bounds ( shape -- loc dim )
dup shape-loc swap shape-dim ;
: shape-extent ( shape -- loc dim )
dup shape-loc dup rot shape-dim v+ ;
: translate ( shape shape -- point )
#! Translate a point relative to the shape.
swap shape-loc swap shape-loc v- ;
M: vector shape-loc ;
M: vector shape-dim drop { 0 0 0 } ;