factor/library/ui/text.factor

40 lines
1.0 KiB
Factor
Raw Normal View History

2005-06-27 03:47:22 -04:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2005-03-06 20:03:22 -05:00
IN: gadgets
2005-04-19 20:28:01 -04:00
USING: alien hashtables kernel lists namespaces sdl sequences
2005-06-27 03:47:22 -04:00
strings styles io ;
2005-03-06 20:03:22 -05:00
: surface-rect ( x y surface -- rect )
dup surface-w swap surface-h make-rect ;
: draw-surface ( x y surface -- )
surface get SDL_UnlockSurface
[
[ surface-rect ] keep swap surface get 0 0
] keep surface-rect swap rot SDL_UpperBlit drop
surface get dup must-lock-surface? [
SDL_LockSurface
] when drop ;
2005-03-07 00:39:57 -05:00
: filter-nulls ( str -- str )
2005-07-04 17:35:22 -04:00
[ dup 0 = [ drop CHAR: \s ] when ] map ;
2005-03-07 00:39:57 -05:00
2005-03-06 20:03:22 -05:00
: size-string ( font text -- w h )
2005-06-27 03:47:22 -04:00
filter-nulls dup empty? [
drop 0 swap TTF_FontHeight
2005-03-06 20:03:22 -05:00
] [
2005-05-05 03:12:37 -04:00
0 <int> 0 <int> [ TTF_SizeUNICODE drop ] 2keep
swap *int swap *int
2005-03-06 20:03:22 -05:00
] ifte ;
2005-06-27 03:47:22 -04:00
: draw-string ( font text -- )
filter-nulls dup empty? [
2drop
2005-03-06 20:03:22 -05:00
] [
fg 3unlist make-color
bg 3unlist make-color
TTF_RenderUNICODE_Shaded
[ >r x get y get r> draw-surface ] keep
SDL_FreeSurface
] ifte ;