factor/library/sdl/sdl-utils.factor

64 lines
1.6 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
2005-02-11 19:09:48 -05:00
! See http://factor.sf.net/license.txt for BSD license.
2004-10-17 19:10:46 -04:00
IN: sdl
2005-03-06 20:03:22 -05:00
USING: kernel lists math namespaces ;
2004-10-17 19:10:46 -04:00
2005-03-07 00:39:57 -05:00
SYMBOL: surface
SYMBOL: width
SYMBOL: height
SYMBOL: bpp
SYMBOL: surface
: init-screen ( width height bpp flags -- )
>r 3dup bpp set height set width set r>
SDL_SetVideoMode surface set ;
: with-screen ( width height bpp flags quot -- )
#! Set up SDL graphics and call the quotation.
2005-06-27 03:47:22 -04:00
SDL_INIT_EVERYTHING SDL_Init drop
2005-03-07 00:39:57 -05:00
1 SDL_EnableUNICODE drop
SDL_DEFAULT_REPEAT_DELAY SDL_DEFAULT_REPEAT_INTERVAL
SDL_EnableKeyRepeat drop
[ >r init-screen r> call SDL_Quit ] with-scope ; inline
: rgb ( [ r g b ] -- n )
3unlist
2005-01-23 16:47:28 -05:00
255
2004-10-17 19:10:46 -04:00
swap 8 shift bitor
swap 16 shift bitor
swap 24 shift bitor ;
: make-color ( r g b -- color )
#! Make an SDL_Color struct. This will go away soon in favor
#! of pass-by-value support in the FFI.
255 24 shift
swap 16 shift bitor
swap 8 shift bitor
swap bitor ;
2005-03-07 00:39:57 -05:00
: make-rect ( x y w h -- rect )
<rect>
[ set-rect-h ] keep
[ set-rect-w ] keep
[ set-rect-y ] keep
[ set-rect-x ] keep ;
2005-01-23 16:47:28 -05:00
: with-pixels ( quot -- )
width get [
height get [
[ rot dup slip swap surface get swap ] 2keep
[ rot pixelColor ] 2keep
] repeat
] repeat drop ; inline
2004-10-17 19:10:46 -04:00
: with-surface ( quot -- )
#! Execute a quotation, locking the current surface if it
#! is required (eg, hardware surface).
[
2004-11-08 22:36:51 -05:00
surface get dup must-lock-surface? [
2004-12-25 18:08:20 -05:00
dup SDL_LockSurface drop slip dup SDL_UnlockSurface
2004-10-17 19:10:46 -04:00
] [
slip
2004-11-08 22:36:51 -05:00
] ifte SDL_Flip drop
2004-12-25 18:08:20 -05:00
] with-scope ; inline