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-07-12 20:30:05 -04:00
|
|
|
USING: generic hashtables io kernel lists math matrices
|
|
|
|
namespaces sdl sequences strings ;
|
2005-02-27 03:48:27 -05:00
|
|
|
|
|
|
|
SYMBOL: clip
|
|
|
|
|
2005-03-01 22:19:26 -05:00
|
|
|
: >sdl-rect ( rectangle -- sdlrect )
|
2005-07-12 20:30:05 -04:00
|
|
|
[ shape-x ] keep [ shape-y ] keep [ shape-w ] keep shape-h
|
2005-03-01 22:19:26 -05:00
|
|
|
make-rect ;
|
|
|
|
|
2005-02-27 16:51:12 -05:00
|
|
|
: set-clip ( rect -- ? )
|
|
|
|
#! The top/left corner of the clip rectangle is the location
|
|
|
|
#! of the gadget on the screen. The bottom/right is the
|
2005-07-12 20:30:05 -04:00
|
|
|
#! intersected clip rectangle. Return f if the clip region
|
2005-02-27 16:51:12 -05:00
|
|
|
#! is an empty region.
|
2005-07-12 20:30:05 -04:00
|
|
|
surface get swap >sdl-rect SDL_SetClipRect ;
|
2005-02-27 16:51:12 -05:00
|
|
|
|
2005-02-27 03:48:27 -05:00
|
|
|
: with-clip ( shape quot -- )
|
2005-02-27 16:51:12 -05:00
|
|
|
#! All drawing done inside the quotation is clipped to the
|
|
|
|
#! shape's bounds. The quotation is called with a boolean
|
2005-05-05 23:58:45 -04:00
|
|
|
#! that is set to false if the gadget is entirely clipped.
|
2005-02-27 16:51:12 -05:00
|
|
|
[
|
2005-03-06 19:46:29 -05:00
|
|
|
>r screen-bounds clip [ intersect dup ] change set-clip
|
|
|
|
r> call
|
2005-02-27 16:51:12 -05:00
|
|
|
] with-scope ; inline
|
2005-02-27 03:48:27 -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 [
|
2005-05-05 23:58:45 -04:00
|
|
|
dup [
|
2005-02-27 16:51:12 -05:00
|
|
|
[
|
2005-03-01 18:55:25 -05:00
|
|
|
dup draw-shape dup [
|
2005-02-27 16:51:12 -05:00
|
|
|
gadget-children [ draw-gadget ] each
|
|
|
|
] with-trans
|
2005-07-12 20:30:05 -04:00
|
|
|
] [ drop ] ifte
|
2005-02-27 03:48:27 -05:00
|
|
|
] with-clip
|
|
|
|
] bind ;
|