2004-11-09 21:51:43 -05:00
|
|
|
! :folding=indent:collapseFolds=1:
|
|
|
|
|
|
|
|
! $Id$
|
|
|
|
!
|
|
|
|
! Copyright (C) 2004 Slava Pestov.
|
|
|
|
!
|
|
|
|
! Redistribution and use in source and binary forms, with or without
|
|
|
|
! modification, are permitted provided that the following conditions are met:
|
|
|
|
!
|
|
|
|
! 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer.
|
|
|
|
!
|
|
|
|
! 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer in the documentation
|
|
|
|
! and/or other materials provided with the distribution.
|
|
|
|
!
|
|
|
|
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2004-10-17 19:10:46 -04:00
|
|
|
IN: sdl
|
|
|
|
USE: alien
|
|
|
|
USE: math
|
|
|
|
USE: namespaces
|
|
|
|
USE: compiler
|
|
|
|
USE: words
|
|
|
|
USE: parser
|
|
|
|
USE: kernel
|
|
|
|
USE: errors
|
|
|
|
USE: lists
|
2004-10-20 21:49:10 -04:00
|
|
|
USE: prettyprint
|
2004-11-09 21:51:43 -05:00
|
|
|
USE: sdl-event
|
|
|
|
USE: sdl-gfx
|
|
|
|
USE: sdl-video
|
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
|
|
|
|
|
2004-12-26 18:52:58 -05:00
|
|
|
: init-screen ( width height bpp flags -- )
|
|
|
|
>r 3dup bpp set height set width set r>
|
|
|
|
SDL_SetVideoMode surface set ;
|
|
|
|
|
2004-11-08 22:36:51 -05:00
|
|
|
: with-screen ( width height bpp flags quot -- )
|
|
|
|
#! Set up SDL graphics and call the quotation.
|
2004-12-26 18:52:58 -05:00
|
|
|
[ >r init-screen r> call SDL_Quit ] with-scope ; inline
|
2004-10-17 19:10:46 -04:00
|
|
|
|
2005-01-23 16:47:28 -05:00
|
|
|
: rgb ( r g b a -- n )
|
|
|
|
255
|
2004-10-17 19:10:46 -04:00
|
|
|
swap 8 shift bitor
|
|
|
|
swap 16 shift bitor
|
|
|
|
swap 24 shift bitor ;
|
|
|
|
|
2005-01-23 16:47:28 -05:00
|
|
|
: black 0 0 0 ;
|
|
|
|
: white 255 255 255 ;
|
|
|
|
: red 255 0 0 ;
|
|
|
|
: green 0 255 0 ;
|
|
|
|
: blue 0 0 255 ;
|
2004-11-08 22:36:51 -05:00
|
|
|
|
|
|
|
: clear-surface ( color -- )
|
|
|
|
>r surface get 0 0 width get height get r> boxColor ;
|
|
|
|
|
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
|
2004-10-17 19:10:46 -04:00
|
|
|
|
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 ;
|