2005-01-31 22:32:06 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
2005-02-01 20:14:03 -05:00
|
|
|
USING: alien generic kernel lists math namespaces sdl sdl-event
|
|
|
|
sdl-video ;
|
2005-02-01 19:00:16 -05:00
|
|
|
|
2005-01-31 22:32:06 -05:00
|
|
|
! The world gadget is the top level gadget that all (visible)
|
|
|
|
! gadgets are contained in. The current world is stored in the
|
|
|
|
! world variable.
|
2005-02-02 19:50:13 -05:00
|
|
|
TUPLE: world running? hand delegate ;
|
2005-02-01 19:00:16 -05:00
|
|
|
|
2005-01-31 22:32:06 -05:00
|
|
|
: <world-box> ( -- box )
|
2005-02-02 22:00:46 -05:00
|
|
|
0 0 0 0 <plain-rect> <everywhere> <gadget>
|
2005-02-03 18:18:47 -05:00
|
|
|
dup [ 216 216 216 ] color set-paint-property ;
|
2005-01-31 22:32:06 -05:00
|
|
|
|
|
|
|
C: world ( -- world )
|
|
|
|
<world-box> over set-world-delegate
|
|
|
|
t over set-world-running?
|
2005-02-01 21:47:10 -05:00
|
|
|
dup <hand> over set-world-hand ;
|
2005-01-31 22:32:06 -05:00
|
|
|
|
|
|
|
: my-hand ( -- hand ) world get world-hand ;
|
|
|
|
|
2005-02-01 19:00:16 -05:00
|
|
|
: draw-world ( -- )
|
2005-02-02 19:50:13 -05:00
|
|
|
world get dup gadget-redraw? [
|
2005-02-01 19:00:16 -05:00
|
|
|
[
|
2005-02-02 19:50:13 -05:00
|
|
|
f over set-gadget-redraw?
|
2005-02-02 22:00:46 -05:00
|
|
|
dup draw-gadget
|
|
|
|
world-hand draw-gadget
|
2005-02-01 19:00:16 -05:00
|
|
|
] with-surface
|
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|
|
|
|
|
2005-02-01 21:47:10 -05:00
|
|
|
DEFER: handle-event
|
|
|
|
|
2005-02-02 19:50:13 -05:00
|
|
|
: layout-world world get layout ;
|
|
|
|
|
2005-01-31 22:32:06 -05:00
|
|
|
: run-world ( -- )
|
|
|
|
world get world-running? [
|
|
|
|
<event> dup SDL_WaitEvent 1 = [
|
2005-02-02 22:00:46 -05:00
|
|
|
handle-event layout-world draw-world run-world
|
2005-01-31 22:32:06 -05:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte
|
|
|
|
] when ;
|
|
|
|
|
2005-02-01 20:14:03 -05:00
|
|
|
: init-world ( w h -- )
|
|
|
|
t world get set-world-running?
|
|
|
|
world get resize-gadget ;
|
|
|
|
|
|
|
|
: world-flags SDL_HWSURFACE SDL_RESIZABLE bitor ;
|
|
|
|
|
|
|
|
: start-world ( w h -- )
|
|
|
|
#! Start the Factor graphics subsystem with the given screen
|
|
|
|
#! dimensions.
|
|
|
|
2dup init-world 0 world-flags
|
|
|
|
default-paint [ [ run-world ] with-screen ] bind ;
|
|
|
|
|
2005-01-31 22:32:06 -05:00
|
|
|
global [ <world> world set ] bind
|