factor/library/sdl/sdl-utils.factor

72 lines
1.5 KiB
Factor
Raw Normal View History

2004-10-17 19:10:46 -04:00
IN: sdl
USE: alien
USE: math
USE: namespaces
USE: stack
USE: compiler
USE: words
USE: parser
USE: kernel
USE: errors
USE: combinators
USE: lists
USE: logic
2004-10-20 21:49:10 -04:00
USE: prettyprint
2004-10-17 19:10:46 -04:00
SYMBOL: surface
SYMBOL: width
SYMBOL: height
2004-11-08 22:36:51 -05:00
SYMBOL: bpp
SYMBOL: surface
: with-screen ( width height bpp flags quot -- )
#! Set up SDL graphics and call the quotation.
[
>r
>r 3dup bpp set height set width set r>
SDL_SetVideoMode surface set
r> call SDL_Quit
] with-scope ;
2004-10-17 19:10:46 -04:00
: rgba ( r g b a -- n )
swap 8 shift bitor
swap 16 shift bitor
swap 24 shift bitor ;
2004-11-08 22:36:51 -05:00
: black 0 0 0 255 rgba ;
: white 255 255 255 255 rgba ;
: red 255 0 0 255 rgba ;
: green 0 255 0 255 rgba ;
: blue 0 0 255 255 rgba ;
: clear-surface ( color -- )
>r surface get 0 0 width get height get r> boxColor ;
2004-10-17 19:10:46 -04:00
: pixel-step ( quot #{ x y } -- )
tuck >r call >r surface get r> r> >rect rot pixelColor ;
: with-pixels ( w h quot -- )
-rot rect> [ over >r pixel-step r> ] 2times* drop ;
: 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-10-17 19:10:46 -04:00
dup SDL_LockSurface slip dup SDL_UnlockSurface
] [
slip
2004-11-08 22:36:51 -05:00
] ifte SDL_Flip drop
2004-10-17 19:10:46 -04:00
] with-scope ;
2004-10-20 21:49:10 -04:00
: event-loop ( event -- )
dup SDL_WaitEvent 1 = [
dup event-type SDL_QUIT = [
drop
] [
event-loop
] ifte
] [
drop
] ifte ;