factor/library/ui/shapes.factor

58 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
2005-02-26 02:11:25 -05:00
USING: generic kernel lists math namespaces sdl ;
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 -- )
GENERIC: resize-shape ( w h shape -- )
2005-01-31 14:02:09 -05:00
2005-03-07 22:11:36 -05:00
! The painting protocol. Painting is controlled by various
! dynamically-scoped variables.
! Colors are lists of three integers, 0..255.
SYMBOL: foreground ! Used for text and outline shapes.
SYMBOL: background ! Used for filled shapes.
SYMBOL: reverse-video
: fg reverse-video get background foreground ? get ;
: bg reverse-video get foreground background ? get ;
SYMBOL: font ! a list of two elements, a font name and size.
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 ;