factor/library/ui/shapes.factor

62 lines
1.4 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 namespaces sdl sequences
vectors ;
2005-01-31 14:02:09 -05:00
2005-02-01 19:00:16 -05:00
! Shape protocol. Shapes are immutable; moving or resizing a
! shape makes a new shape.
2005-01-31 14:02:09 -05:00
! These dynamically-bound variables affect the generic word
2005-02-27 03:48:27 -05:00
! inside? and others.
2005-02-01 19:00:16 -05:00
SYMBOL: x
SYMBOL: y
GENERIC: inside? ( point shape -- ? )
2005-01-31 14:02:09 -05:00
! A shape is an object with a defined bounding
! box, and a notion of interior.
GENERIC: shape-x
GENERIC: shape-y
GENERIC: shape-w
GENERIC: shape-h
GENERIC: move-shape ( x y shape -- )
: set-shape-loc ( loc shape -- )
>r 3unseq drop r> move-shape ;
GENERIC: resize-shape ( w h shape -- )
2005-01-31 14:02:09 -05:00
: set-shape-dim ( loc shape -- )
>r 3unseq drop r> resize-shape ;
2005-03-07 22:11:36 -05:00
! The painting protocol. Painting is controlled by various
2005-06-27 03:47:22 -04:00
! dynamically-scoped variables. See library/styles.factor.
2005-03-07 22:11:36 -05:00
GENERIC: draw-shape ( obj -- )
! Utility words
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-size ( shape -- w h )
dup shape-w swap shape-h ;
: shape-dim ( shape -- dim )
dup shape-w swap shape-h 0 3vector ;
: shape-loc ( shape -- loc )
dup shape-x swap shape-y 0 3vector ;