Paste: Label Text Shadow

Author: klazuka
Mode: factor
Date: Tue, 8 Sep 2009 13:45:53
Plain Text |
: draw-text* ( font text fg bg -- )
    [ rot ] dip
    [ font-with-background ] when* swap
    [ font-with-foreground ] when* swap
    draw-text ;

: draw-shadowed-text ( font text -- )
    [ over shadow>> background get draw-text* ] [ [
            0.0 -1.0 0.0 glTranslated
            foreground get transparent draw-text*
        ] do-matrix
    ] 2bi ;

: draw-normal-text ( font text -- )
    foreground get background get draw-text* ;

M: label draw-gadget*
    >label< over shadow>>
    [ draw-shadowed-text ] [ draw-normal-text ] if ;

Annotation: Label Text Shadow - note

Author: klazuka
Mode: text
Date: Tue, 8 Sep 2009 13:48:13
Plain Text |
I added a "shadow" slot to font. The shadow slot value should either be "f" (no shadow) or a color instance (the color of the shadow).

Any suggestions for making this code more clear?

Annotation: Label Text Shadow - improved

Author: klazuka
Mode: factor
Date: Tue, 8 Sep 2009 14:04:24
Plain Text |
: draw-text* ( font text fg bg -- )
    [ rot ] dip
    [ font-with-background ] when* swap
    [ font-with-foreground ] when* swap
    draw-text ;

: draw-shadowed-text ( font text -- )
    [
        { 0 1 } [ over shadow>> background get draw-text* ]
        with-translation
    ] [ foreground get transparent draw-text* ] 2bi ;

: draw-normal-text ( font text -- )
    foreground get background get draw-text* ;

M: label draw-gadget*
    >label< over shadow>>
    [ draw-shadowed-text ] [ draw-normal-text ] if ;

New Annotation

Summary:
Author:
Mode:
Body: