2005-01-23 21:00:52 -05:00
|
|
|
! 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-07-27 20:13:11 -04:00
|
|
|
USING: kernel lists math namespaces sequences ;
|
2004-10-17 19:10:46 -04:00
|
|
|
|
2005-03-07 00:39:57 -05:00
|
|
|
SYMBOL: surface
|
|
|
|
SYMBOL: width
|
|
|
|
SYMBOL: height
|
|
|
|
SYMBOL: bpp
|
|
|
|
|
|
|
|
: 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
|
|
|
|
|
2005-02-03 22:21:51 -05:00
|
|
|
: rgb ( [ r g b ] -- n )
|
2005-07-27 20:13:11 -04:00
|
|
|
3unseq
|
2005-01-23 16:47:28 -05:00
|
|
|
255
|
2005-07-17 03:47:14 -04:00
|
|
|
swap >fixnum 8 shift bitor
|
|
|
|
swap >fixnum 16 shift bitor
|
|
|
|
swap >fixnum 24 shift bitor ;
|
2004-10-17 19:10:46 -04:00
|
|
|
|
2005-01-23 21:00:52 -05:00
|
|
|
: 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 )
|
2005-08-24 00:30:07 -04:00
|
|
|
<sdl-rect>
|
|
|
|
[ set-sdl-rect-h ] keep
|
|
|
|
[ set-sdl-rect-w ] keep
|
|
|
|
[ set-sdl-rect-y ] keep
|
|
|
|
[ set-sdl-rect-x ] keep ;
|
2005-03-07 00:39:57 -05:00
|
|
|
|
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
|
|
|
|
2005-08-24 01:09:36 -04:00
|
|
|
: must-lock-surface? ( surface -- ? )
|
|
|
|
#! This is a macro in SDL_video.h.
|
|
|
|
dup sdl-surface-offset 0 = [
|
|
|
|
sdl-surface-flags
|
|
|
|
SDL_HWSURFACE SDL_ASYNCBLIT bitor SDL_RLEACCEL bitor
|
|
|
|
bitand 0 = not
|
|
|
|
] [
|
|
|
|
drop t
|
|
|
|
] ifte ;
|
|
|
|
|
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
|
2005-08-24 00:30:07 -04:00
|
|
|
|
|
|
|
: sdl-surface-rect ( x y surface -- rect )
|
|
|
|
dup sdl-surface-w swap sdl-surface-h make-rect ;
|