]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Sat, 16 Jan 2010 20:24:47 +0000 (12:24 -0800)
committerJoe Groff <arcata@gmail.com>
Sat, 16 Jan 2010 20:24:47 +0000 (12:24 -0800)
27 files changed:
basis/ui/gadgets/tracks/tracks.factor
basis/ui/gadgets/worlds/worlds.factor
basis/ui/ui-docs.factor
basis/ui/ui.factor
extra/bunny/bunny.factor
extra/color-picker/color-picker.factor
extra/color-table/color-table.factor
extra/demos/demos.factor
extra/game/loop/loop.factor
extra/game/worlds/worlds.factor
extra/gpu/demos/bunny/bunny.factor
extra/gpu/demos/raytrace/raytrace.factor
extra/hello-ui/hello-ui.factor
extra/hello-unicode/hello-unicode.factor
extra/jamshred/jamshred.factor
extra/key-caps/key-caps.factor
extra/lcd/lcd.factor
extra/maze/maze.factor
extra/merger/merger.factor
extra/nehe/2/2.factor
extra/nehe/3/3.factor
extra/nehe/4/4.factor
extra/nehe/5/5.factor
extra/nehe/nehe.factor
extra/spheres/spheres.factor
extra/terrain/terrain.factor
extra/ui/gadgets/worlds/null/null.factor

index 387f41a6a4e461144315a25f0c5ffd82a3af53cb..89389485b24832e4c0b8e5be83fe2d2097a09651 100644 (file)
@@ -39,7 +39,8 @@ TUPLE: track < pack sizes ;
 M: track layout* ( track -- ) dup track-layout pack-layout ;
 
 : track-pref-dims-1 ( track -- dim )
-    children>> pref-dims max-dim ;
+    [ children>> pref-dims max-dim ]
+    [ pref-dim>> { 0 0 } or ] bi vmax ;
 
 : track-pref-dims-2 ( track -- dim )
     [
index 8f38cee988c308db60eb461bf28a8d6f957b3fe0..8a22107f3a0d187bad87e78b24c42238dc334dcb 100644 (file)
@@ -50,7 +50,8 @@ TUPLE: world-attributes
     status
     gadgets
     { pixel-format-attributes initial: $ default-world-pixel-format-attributes }
-    { window-controls initial: $ default-world-window-controls } ;
+    { window-controls initial: $ default-world-window-controls }
+    pref-dim ;
 
 : <world-attributes> ( -- world-attributes )
     world-attributes new ; inline
@@ -132,7 +133,8 @@ M: world request-focus-on ( child gadget -- )
         [ window-controls>> >>window-controls ]
         [ initial-background-color >>background-color ]
         [ grab-input?>> >>grab-input? ]
-        [ gadgets>> [ 1 track-add ] each ]
+        [ gadgets>> dup sequence? [ [ 1 track-add ] each ] [ 1 track-add ] if ]
+        [ pref-dim>> >>pref-dim ]
     } cleave ;
 
 : <world> ( world-attributes -- world )
index 51ff4c2609c2fe1924dad9b0970486b680267bae..b55ea44c6bc8474082096191ae3a3cd6ef3eeae1 100644 (file)
@@ -2,7 +2,7 @@ USING: help.markup help.syntax strings quotations debugger
 namespaces ui.backend ui.gadgets ui.gadgets.worlds
 ui.gadgets.tracks ui.gadgets.packs ui.gadgets.grids
 ui.gadgets.private math.rectangles colors ui.text fonts
-kernel ui.private classes sequences ;
+kernel ui.private vocabs.loader classes sequences ;
 IN: ui
 
 HELP: windows
@@ -150,7 +150,9 @@ ARTICLE: "ui-windows" "Top-level windows"
 "When the gadget is removed from a parent shown in a top-level window, or when the top-level window is closed, a corresponding generic word is called to clean up:"
 { $subsections ungraft* }
 "The root of the gadget hierarchy in a window is a special gadget which is rarely operated on directly, but it is helpful to know it exists:"
-{ $subsections world } ;
+{ $subsections world }
+"There is also syntax for defining a main window as the entry point for a vocabulary:"
+{ $subsections POSTPONE: MAIN-WINDOW: } ;
 
 ARTICLE: "ui-backend" "Developing UI backends"
 "None of the words documented in this section should be called directly by user code. They are only of interest when developing new UI backends."
@@ -325,6 +327,20 @@ HELP: normal-title-bar
 HELP: textured-background
 { $description "Asks for a window to have a background that blends seamlessly with the window frame. Factor will leave the window background transparent and pass mouse button gestures not handled directly by a gadget through to the window system so that the window can be dragged from anywhere on its background." } ;
 
+HELP: MAIN-WINDOW:
+{ $syntax "MAIN-WINDOW: window-word { attributes }
+    attribute-code ;" }
+{ $description "Defines a " { $link POSTPONE: MAIN: } " word for the current vocabulary named " { $snippet "window-word" } " that opens a UI window when the vocabulary is " { $link run } ". The " { $snippet "attributes" } " specify the key-value pairs of the window's " { $link world-attributes } ". The " { $snippet "attribute-code" } " is run with the " { $snippet "world-attributes" } " on the stack; this allows the word to construct gadget objects to place in the " { $snippet "gadget" } " slot or set other runtime-dependent world attributes." }
+{ $examples
+"From the " { $vocab-link "hello-ui" } " vocabulary. Creates a window with the title \"Hi\" containing a label reading \"Hello world\":"
+{ $code
+"""USING: accessors ui ui.gadgets.labels ;
+IN: hello-ui
+
+MAIN-WINDOW: hello { { title "Hi" } }
+    "Hello world" <label> >>gadgets ;"""
+} } ;
+
 ARTICLE: "ui.gadgets.worlds-window-controls" "Window controls"
 "The following window controls can be placed in a " { $link world } " window:"
 { $subsections
index 8260608cd4cb40ccb492cc1bd464ce5010264945..e0fa560935f35b551040fbb2c1cafe3d96a45011 100644 (file)
@@ -5,7 +5,7 @@ deques sequences threads words continuations init
 combinators combinators.short-circuit hashtables concurrency.flags
 sets accessors calendar fry destructors ui.gadgets ui.gadgets.private
 ui.gadgets.worlds ui.gadgets.tracks ui.gestures ui.backend ui.render
-strings ;
+strings classes.tuple classes.tuple.parser lexer vocabs.parser parser ;
 IN: ui
 
 <PRIVATE
@@ -242,3 +242,17 @@ M: object close-window
     ui-running? [ call( -- ) ] [ '[ init-ui @ ] (with-ui) ] if ;
 
 HOOK: beep ui-backend ( -- )
+
+: parse-main-window-attributes ( class -- attributes )
+    "{" expect dup all-slots parse-tuple-literal-slots ;
+
+: define-main-window ( word attributes quot -- )
+    [
+        '[ [ f _ clone @ open-window ] with-ui ] (( -- )) define-declared
+    ] [ 2drop current-vocab (>>main) ] 3bi ;
+
+SYNTAX: MAIN-WINDOW:
+    CREATE
+    world-attributes parse-main-window-attributes
+    parse-definition
+    define-main-window ;
index b7400c4acb53e054c7497d95dd2d451b8cc41848..bbb89f6beaabd6e15d3df20746aafc02f9034a0f 100644 (file)
@@ -44,24 +44,17 @@ M: bunny-world draw-world*
         [ geom>> ] [ get-draw ] bi draw-bunny
     ] if ;
 
-M: bunny-world pref-dim* ( gadget -- dim )
-    drop { 640 480 } ;
-    
 bunny-world H{
     { T{ key-down f f "TAB" } [ next-draw ] }
 } set-gestures
 
-: bunny-window ( -- )
-    [
-        f T{ world-attributes
-            { world-class bunny-world }
-            { title "Bunny" }
-            { pixel-format-attributes {
-                windowed
-                double-buffered
-                T{ depth-bits { value 16 } }
-            } }
-        } open-window
-    ] with-ui ;
-
-MAIN: bunny-window
+MAIN-WINDOW: bunny-window {
+        { world-class bunny-world }
+        { title "Bunny" }
+        { pixel-format-attributes {
+            windowed
+            double-buffered
+            T{ depth-bits { value 16 } }
+        } }
+        { pref-dim { 640 480 } }
+    } ;
index 56a60d6fc8b9ddd1e748ff5f3caf1c974e05757f..a76f07c0fea453d77b8de25d4545519674e51453 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.parser models
+USING: arrays kernel math math.functions math.parser models
 models.arrow models.range models.product sequences ui
 ui.gadgets ui.gadgets.tracks ui.gadgets.labels ui.gadgets.packs
 ui.gadgets.sliders ui.pens.solid ui.render math.rectangles accessors
@@ -45,7 +45,5 @@ M: color-preview model-changed
             ] bi
         ] bi* ;
 
-: color-picker-window ( -- )
-    [ <color-picker> "Color Picker" open-window ] with-ui ;
-
-MAIN: color-picker-window
+MAIN-WINDOW: color-picker-window { { title "Color Picker" } }
+    <color-picker> >>gadgets ;
index 0865dabcf7f17a69ae91fc6aa209102ef25e7654..a154ff82d0902e3392834e74f537d95f9858ca81 100644 (file)
@@ -37,7 +37,5 @@ M: color-renderer row-value
         10 >>min-rows
         10 >>max-rows ;
 
-: color-table-demo ( -- )
-    [ <color-table> <scroller> "Colors" open-window ] with-ui ;
-
-MAIN: color-table-demo
+MAIN-WINDOW: color-table-demo { { title "Colors" } }
+    <color-table> <scroller> >>gadgets ;
index dfd73f1236d84f758dd6589c03c75c1b95d1fe1e..9c60d8ad1a7eedcbd3d8e2f8520674b7ec8114e9 100644 (file)
@@ -11,6 +11,5 @@ IN: demos
 : <demo-runner> ( -- gadget )
     <pile> 1 >>fill { 2 2 } >>gap demo-vocabs [ <run-vocab-button> add-gadget ] each ;
 
-: demos ( -- ) [ <demo-runner> { 2 2 } <border> <scroller> "Demos" open-window ] with-ui ;
-
-MAIN: demos
\ No newline at end of file
+MAIN-WINDOW: demos { { title "Demos" } }
+    <demo-runner> { 2 2 } <border> <scroller> >>gadgets ;
index c0f36d0294ddef784ea9e9964144e3c7f0151759..0862a5e48c8ac6bc39c11865a11e335e757080a4 100644 (file)
@@ -4,7 +4,7 @@ sequences ;
 IN: game.loop
 
 TUPLE: game-loop
-    { tick-length integer read-only }
+    { tick-interval-micros integer read-only }
     delegate
     { last-tick integer }
     thread 
@@ -24,7 +24,7 @@ SYMBOL: game-loop
     last-tick>> system-micros swap - ;
 
 : tick-slice ( loop -- slice )
-    [ since-last-tick ] [ tick-length>> ] bi /f 1.0 min ;
+    [ since-last-tick ] [ tick-interval-micros>> ] bi /f 1.0 min ;
 
 CONSTANT: MAX-FRAMES-TO-SKIP 5
 
@@ -49,12 +49,12 @@ TUPLE: game-loop-error game-loop error ;
 
 : increment-tick ( loop -- )
     [ 1 + ] change-tick-number
-    dup tick-length>> [ + ] curry change-last-tick
+    dup tick-interval-micros>> [ + ] curry change-last-tick
     drop ;
 
 : ?tick ( loop count -- )
     [ system-micros >>last-tick drop ] [
-        over [ since-last-tick ] [ tick-length>> ] bi >=
+        over [ since-last-tick ] [ tick-interval-micros>> ] bi >=
         [ [ drop increment-tick ] [ drop tick ] [ 1 - ?tick ] 2tri ]
         [ 2drop ] if
     ] if-zero ;
@@ -97,7 +97,7 @@ PRIVATE>
     f >>thread
     drop ;
 
-: <game-loop> ( tick-length delegate -- loop )
+: <game-loop> ( tick-interval-micros delegate -- loop )
     system-micros f f 0 0 system-micros 0 0
     game-loop boa ;
 
index 308b5006cf2ed14593949737b96dbf4245c7b5fb..f614943f0408d2b1f6e4c026656ce954c9af918e 100644 (file)
@@ -1,19 +1,20 @@
-USING: accessors game.input game.loop kernel math ui.gadgets
-ui.gadgets.worlds ui.gestures threads ;
+USING: accessors combinators fry game.input game.loop generic kernel math
+parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
+words ;
 IN: game.worlds
 
 TUPLE: game-world < world
     game-loop
     { tick-slice float initial: 0.0 } ;
 
-GENERIC: tick-length ( world -- micros )
+GENERIC: tick-interval-micros ( world -- micros )
 
 M: game-world draw*
     swap >>tick-slice relayout-1 yield ;
 
 M: game-world begin-world
     open-game-input 
-    dup [ tick-length ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
+    dup [ tick-interval-micros ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
     drop ;
 
 M: game-world end-world
@@ -21,3 +22,29 @@ M: game-world end-world
     close-game-input
     drop ;
 
+TUPLE: game-attributes < world-attributes
+    { tick-interval-micros fixnum read-only } ;
+
+: verify-game-attributes ( attributes -- )
+    world-class>> { f world } member?
+    [ "GAME: must be given a custom world-class" throw ] when ;
+
+: define-game-tick-interval-micros ( attributes -- )
+    [ world-class>> \ tick-interval-micros create-method ]
+    [ tick-interval-micros>> '[ drop _ ] ] bi
+    define ;
+
+: define-game-methods ( attributes -- )
+    {
+        [ verify-game-attributes ]
+        [ define-game-tick-interval-micros ]
+    } cleave ;
+
+: define-game ( word attributes -- )
+    [ [ ] define-main-window ]
+    [ nip define-game-methods ] 2bi ;
+
+SYNTAX: GAME:
+    CREATE
+    game-attributes parse-main-window-attributes
+    define-game ;
index 57fcf4e3ea13464c1a225b23f2f4c1d49d4f265d..067e9344531b5a6365fd1bb502da3903de65c808 100644 (file)
@@ -7,7 +7,7 @@ io io.encodings.ascii io.files io.files.temp kernel locals math
 math.matrices math.vectors.simd math.parser math.vectors
 method-chains namespaces sequences splitting threads ui ui.gadgets
 ui.gadgets.worlds ui.pixel-formats specialized-arrays
-specialized-vectors ;
+specialized-vectors literals ;
 FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-VECTOR: uint
@@ -293,24 +293,19 @@ M: bunny-world draw-world*
 AFTER: bunny-world resize-world
     [ sobel>> framebuffer>> ] [ dim>> ] bi resize-framebuffer ;
 
-M: bunny-world pref-dim* drop { 1024 768 } ;
-M: bunny-world tick-length drop 1000000 60 /i ;
 M: bunny-world wasd-movement-speed drop 1/160. ;
 M: bunny-world wasd-near-plane drop 1/32. ;
 M: bunny-world wasd-far-plane drop 256.0 ;
 
-: bunny-window ( -- )
-    [
-        f T{ world-attributes
-            { world-class bunny-world }
-            { title "Bunny" }
-            { pixel-format-attributes {
-                windowed
-                double-buffered
-                T{ depth-bits { value 24 } }
-            } }
-            { grab-input? t }
-        } open-window
-    ] with-ui ;
-
-MAIN: bunny-window
+GAME: bunny-game {
+        { world-class bunny-world }
+        { title "Bunny" }
+        { pixel-format-attributes {
+            windowed
+            double-buffered
+            T{ depth-bits { value 24 } }
+        } }
+        { grab-input? t }
+        { pref-dim { 1024 768 } }
+        { tick-interval-micros $[ 1,000,000 60 /i ] }
+    }
index bac55beacd2cd717b583af8b2103629f654aea2c..8883609bce38faf5525bea2f470696a307b44e09 100644 (file)
@@ -92,21 +92,16 @@ M: raytrace-world draw-world*
         { "vertex-array"   [ vertex-array>>              ] }
     } <render-set> render ;
 
-M: raytrace-world pref-dim* drop { 1024 768 } ;
-M: raytrace-world tick-length drop 1000000 60 /i ;
 M: raytrace-world wasd-movement-speed drop 1/4. ;
 
-: raytrace-window ( -- )
-    [
-        f T{ world-attributes
-            { world-class raytrace-world }
-            { title "Raytracing" }
-            { pixel-format-attributes {
-                windowed
-                double-buffered
-            } }
-            { grab-input? t }
-        } open-window
-    ] with-ui ;
-
-MAIN: raytrace-window
+GAME: raytrace-game {
+        { world-class raytrace-world }
+        { title "Raytracing" }
+        { pixel-format-attributes {
+            windowed
+            double-buffered
+        } }
+        { grab-input? t }
+        { pref-dim { 1024 768 } }
+        { tick-interval-micros $[ 1,000,000 60 /i ] }
+    }
index 3843eec091301d8b9b49f5cb73461d7248c8bfcf..9ed9457d5ad5ed1483e0e99dea81e12875fe17b0 100644 (file)
@@ -1,7 +1,5 @@
-USING: ui ui.gadgets.labels ;
+USING: accessors ui ui.gadgets.labels ;
 IN: hello-ui
 
-: hello ( -- )
-    [ "Hello world" <label> "Hi" open-window ] with-ui ;
-
-MAIN: hello
+MAIN-WINDOW: hello { { title "Hi" } }
+    "Hello world" <label> >>gadgets ;
index 4374db20031d427d2e216163d155b1ab74d3bf5c..f088fdd53b65b5ab791e1da249b4c95428310ee1 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: ui.gadgets.panes ui.gadgets.borders ui io io.styles ;
+USING: accessors ui.gadgets.panes ui.gadgets.borders ui io io.styles ;
 IN: hello-unicode
 
 : <hello-gadget> ( -- gadget )
@@ -15,6 +15,5 @@ IN: hello-unicode
         ] with-style
     ] make-pane { 10 10 } <border> ;
 
-: hello-unicode ( -- ) [ <hello-gadget> "გამარჯობა" open-window ] with-ui ;
-
-MAIN: hello-unicode
\ No newline at end of file
+MAIN-WINDOW: hello-unicode { { title "გამარჯობა" } }
+    <hello-gadget> >>gadgets ;
index ae981ae1b3fc5a021b729a2863a4b575c037a114..96e88cb6627cab288152cdfc15dd0d0df17df7f0 100644 (file)
@@ -79,7 +79,5 @@ jamshred-gadget H{
     { mouse-scroll [ handle-mouse-scroll ] }
 } set-gestures
 
-: jamshred-window ( -- )
-    [ <jamshred> <jamshred-gadget> "Jamshred" open-window ] with-ui ;
-
-MAIN: jamshred-window
+MAIN-WINDOW: jamshred-window { { title "Jamshred" } }
+    <jamshred> <jamshred-gadget> >>gadgets ;
index da901ed61e52c50bb51d58ef13e1363e2e087c78..585ca2d16fa4b573646649f15c98bd9142128397 100644 (file)
@@ -173,9 +173,5 @@ M: key-caps-gadget ungraft*
 M: key-caps-gadget handle-gesture
     drop [ key-down? ] [ key-up? ] bi or not ;
 
-: key-caps ( -- )
-    [
-        <key-caps-gadget> { 5 5 } <border> "Key Caps" open-window
-    ] with-ui ;
-
-MAIN: key-caps
+MAIN-WINDOW: key-caps { { title "Key Caps" } }
+    <key-caps-gadget> { 5 5 } <border> >>gadgets ;
index 56aa3373e5caee610e50705199b9de8805086a34..0056df046c8e223961c95cd73d601ba1b3fb19e1 100644 (file)
@@ -24,7 +24,5 @@ IN: lcd
     "99:99:99" lcd >>string
     monospace-font >>font ;
 
-: time-window ( -- )
-    [ time get <time-display> "Time" open-window ] with-ui ;
-
-MAIN: time-window
+MAIN-WINDOW: time-window { { title "Time" } }
+    time get <time-display> >>gadgets ;
index 4238dab16888c53e09277076ea8b869ff822ee49..5d0d55b64e0957595a19af469c94f98e934bc922 100644 (file)
@@ -61,7 +61,7 @@ M: maze draw-gadget* [ n draw-maze ] draw-canvas ;
 
 M: maze pref-dim* drop { 400 400 } ;
 
-: maze-window ( -- )
-    [ <maze> "Maze" open-window ] with-ui ;
+MAIN-WINDOW: maze-window { { title "Maze" } }
+    <maze> >>gadgets ;
 
 MAIN: maze-window
index ee9207e4caff4121d83fe92e08798862116cc801..a990dd30c42765d6d7acc9d146e2232b52951e6e 100644 (file)
@@ -4,7 +4,11 @@ ui.gadgets ui.gadgets.buttons ui.gadgets.labeled
 ui.gadgets.tracks ui.gadgets.labels ui.gadgets.glass
 math.rectangles cocoa.dialogs ;
 IN: merger
-: main ( -- ) [
+
+MAIN-WINDOW: merger-window {
+        { title "Merging" }
+        { pref-dim { 300 220 } }
+    }
    vertical <track>
     { "From:" "To:" } f <model> f <model> 2array
     [
@@ -25,7 +29,5 @@ IN: merger
          ] with-directory
       ] keep hide-glass
     ] [ drop ] if ]
-    "merge" swap <border-button> 0.4 track-add { 300 220 } >>pref-dim "Merging" open-window
-] with-ui ;
-
-MAIN: main
\ No newline at end of file
+    "merge" swap <border-button> 0.4 track-add
+    >>gadgets ;
index 1a77b501f0d561d31721da7d0af6557606901ba3..d28bbdb9043ca01563ef851b2d66f50b09c6f437 100644 (file)
@@ -1,5 +1,5 @@
 USING: arrays kernel math opengl opengl.gl opengl.glu
-opengl.demo-support ui ui.gadgets ui.render ;
+opengl.demo-support ui ui.gadgets ui.render literals accessors ;
 IN: nehe.2
 
 TUPLE: nehe2-gadget < gadget ;
@@ -10,9 +10,6 @@ CONSTANT: height 256
 : <nehe2-gadget> (  -- gadget )
   nehe2-gadget new ;
 
-M: nehe2-gadget pref-dim* ( gadget -- dim )
-  drop width height 2array ;
-
 M: nehe2-gadget draw-gadget* ( gadget -- )
   drop
   GL_PROJECTION glMatrixMode
@@ -42,5 +39,5 @@ M: nehe2-gadget draw-gadget* ( gadget -- )
     -1.0 -1.0 0.0 glVertex3f
   ] do-state ;
 
-: run2 ( -- )
-  <nehe2-gadget> "NeHe Tutorial 2" open-window ;
+MAIN-WINDOW: run2 { { title "NeHe Tutorial 2" } { pref-dim { $ width $ height } } }
+  <nehe2-gadget> >>gadgets ;
index 228107618b43146b31b7b0fa37842400eb9d427a..1a3181dfbac92f461270d864beca05c5bca3adc7 100644 (file)
@@ -1,5 +1,5 @@
 USING: arrays kernel math opengl opengl.gl opengl.glu
-opengl.demo-support ui ui.gadgets ui.render ;
+opengl.demo-support ui ui.gadgets ui.render literals accessors ;
 IN: nehe.3
 
 TUPLE: nehe3-gadget < gadget ;
@@ -10,9 +10,6 @@ CONSTANT: height 256
 : <nehe3-gadget> (  -- gadget )
   nehe3-gadget new ;
 
-M: nehe3-gadget pref-dim* ( gadget -- dim )
-  drop width height 2array ;
-
 M: nehe3-gadget draw-gadget* ( gadget -- )
   drop
   GL_PROJECTION glMatrixMode
@@ -46,5 +43,5 @@ M: nehe3-gadget draw-gadget* ( gadget -- )
     -1.0 -1.0 0.0 glVertex3f
   ] do-state ;
 
-: run3 ( -- )
-  <nehe3-gadget> "NeHe Tutorial 3" open-window ;
+MAIN-WINDOW: run3 { { title "NeHe Tutorial 3" } { pref-dim { $ width $ height } } }
+  <nehe3-gadget> >>gadgets ;
index 63d334510a604459c01a680f6457a38815b54631..0cddcfcaa3ca3b62f1753d5f91283ef4a4050a39 100644 (file)
@@ -1,6 +1,6 @@
 USING: arrays kernel math opengl opengl.gl opengl.glu
 opengl.demo-support ui ui.gadgets ui.render threads accessors
-calendar ;
+calendar literals ;
 IN: nehe.4
 
 TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ;
@@ -14,9 +14,6 @@ CONSTANT: height 256
     0.0 >>rtri
     0.0 >>rquad ;
 
-M: nehe4-gadget pref-dim* ( gadget -- dim )
-  drop width height 2array ;
-
 M: nehe4-gadget draw-gadget* ( gadget -- )
   GL_PROJECTION glMatrixMode
   glLoadIdentity
@@ -71,5 +68,5 @@ M: nehe4-gadget graft* ( gadget -- )
 M: nehe4-gadget ungraft* ( gadget -- )
   t >>quit? drop ;
 
-: run4 ( -- )
-  <nehe4-gadget> "NeHe Tutorial 4" open-window ;
+MAIN-WINDOW: run4 { { title "NeHe Tutorial 4" } { pref-dim { $ width $ height } } }
+  <nehe4-gadget> >>gadgets ;
index 60662b9e0fc3b35d2147f646bdc520fb47620518..e6f5c6e6bac1beccafbb9c40df7e4b18f4aac5db 100644 (file)
@@ -1,6 +1,6 @@
 USING: arrays kernel math opengl opengl.gl opengl.glu\r
 opengl.demo-support ui ui.gadgets ui.render threads accessors\r
-calendar ;\r
+calendar literals ;\r
 IN: nehe.5\r
 \r
 TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;\r
@@ -13,9 +13,6 @@ CONSTANT: height 256
     0.0 >>rtri\r
     0.0 >>rquad ;\r
 \r
-M: nehe5-gadget pref-dim* ( gadget -- dim )\r
-  drop width height 2array ;\r
-\r
 M: nehe5-gadget draw-gadget* ( gadget -- )\r
   GL_PROJECTION glMatrixMode\r
   glLoadIdentity\r
@@ -123,6 +120,5 @@ M: nehe5-gadget graft* ( gadget -- )
 M: nehe5-gadget ungraft* ( gadget -- )\r
   t >>quit? drop ;\r
 \r
-\r
-: run5 ( -- )\r
-  <nehe5-gadget> "NeHe Tutorial 5" open-window ;\r
+MAIN-WINDOW: run5 { { title "NeHe Tutorial 5" } { pref-dim { $ width $ height } } }\r
+  <nehe5-gadget> >>gadgets ;\r
index 70ab0f0f5da66fa23a9f6839af8be4b40547b237..a4c2aedf23e41425b5448583d83e5c68f4e6cece 100644 (file)
@@ -1,15 +1,13 @@
 USING: ui.gadgets.buttons ui.gadgets.packs ui.gadgets ui
-nehe.2 nehe.3 nehe.4 nehe.5 kernel ;
+nehe.2 nehe.3 nehe.4 nehe.5 kernel accessors ;
 IN: nehe
 
-: nehe-window ( -- )
-    [
-        <filled-pile>
-            "Nehe 2" [ drop run2 ] <border-button> add-gadget
-            "Nehe 3" [ drop run3 ] <border-button> add-gadget
-            "Nehe 4" [ drop run4 ] <border-button> add-gadget
-            "Nehe 5" [ drop run5 ] <border-button> add-gadget
-        "Nehe examples" open-window
-    ] with-ui ;
+MAIN-WINDOW: nehe-window { { title "Nehe Examples" } }
+    <filled-pile>
+        "Nehe 2" [ drop run2 ] <border-button> add-gadget
+        "Nehe 3" [ drop run3 ] <border-button> add-gadget
+        "Nehe 4" [ drop run4 ] <border-button> add-gadget
+        "Nehe 5" [ drop run5 ] <border-button> add-gadget
+        >>gadgets ;
 
 MAIN: nehe-window
index b7431caef8663821743e240b9a26b07ba5931ac3..819dbe892e861613e18f3d92cf55181b3252870d 100644 (file)
@@ -196,9 +196,6 @@ M: spheres-world end-world
         [ plane-program>> [ delete-gl-program ] when* ]
     } cleave ;
 
-M: spheres-world pref-dim*
-    drop { 640 480 } ;
-
 :: (draw-sphere) ( program center radius -- )
     program "center" glGetAttribLocation center first3 glVertexAttrib3f
     program "radius" glGetAttribLocation radius glVertexAttrib1f
@@ -299,17 +296,13 @@ M: spheres-world draw-world*
         ]
     } cleave ;
 
-: spheres-window ( -- )
-    [
-        f T{ world-attributes
-            { world-class spheres-world }
-            { title "Spheres" }
-            { pixel-format-attributes {
-                windowed
-                double-buffered
-                T{ depth-bits { value 16 } }
-            } }
-        } open-window
-    ] with-ui ;
-
-MAIN: spheres-window
+MAIN-WINDOW: spheres-window {
+        { world-class spheres-world }
+        { title "Spheres" }
+        { pixel-format-attributes {
+            windowed
+            double-buffered
+            T{ depth-bits { value 16 } }
+        } }
+        { pref-dim { 640 480 } }
+    } ;
index 89c7ccb8ba68b4420af6c60da08e6663ae64823c..adbeb9c441fa2fb7f062ea2d9f390a819fd7084b 100644 (file)
@@ -55,9 +55,6 @@ TUPLE: terrain-world < game-world
         float-4{ 0.0 0.0 0.0 1.0 } >>velocity
         VELOCITY-MODIFIER-NORMAL >>velocity-modifier ;
 
-M: terrain-world tick-length
-    drop 1000000 60 /i ;
-
 : frustum ( dim -- -x x -y y near far )
     dup first2 min v/n
     NEAR-PLANE FOV / v*n first2 [ [ neg ] keep ] bi@
@@ -290,20 +287,15 @@ M: terrain-world draw-world*
         ] with-gl-program ]
     } cleave gl-error ;
 
-M: terrain-world pref-dim* drop { 1024 768 } ;
-
-: terrain-window ( -- )
-    [
-        f T{ world-attributes
-            { world-class terrain-world }
-            { title "Terrain" }
-            { pixel-format-attributes {
-                windowed
-                double-buffered
-                T{ depth-bits { value 24 } }
-            } }
-            { grab-input? t }
-        } open-window
-    ] with-ui ;
-
-MAIN: terrain-window
+GAME: terrain-game {
+        { world-class terrain-world }
+        { title "Terrain" }
+        { pixel-format-attributes {
+            windowed
+            double-buffered
+            T{ depth-bits { value 24 } }
+        } }
+        { grab-input? t }
+        { pref-dim { 1024 768 } }
+        { tick-interval-micros $[ 1,000,000 60 /i ] }
+    }
index 0f116f0d51fe6c52c9e411d38ff9923d7ee9aebf..eb0e1c1d5c5fde0f8a8b3e50a96c4c3b09e69605 100644 (file)
@@ -7,7 +7,6 @@ M: null-world begin-world drop ;
 M: null-world end-world drop ;
 M: null-world draw-world* drop ;
 M: null-world resize-world drop ;
-M: null-world pref-dim* drop { 512 512 } ;
 
 : null-window ( title -- world )
     <world-attributes>
@@ -19,6 +18,7 @@ M: null-world pref-dim* drop { 512 512 } ;
             backing-store
             T{ depth-bits f 24 }
         } >>pixel-format-attributes
+        { 512 512 } >>pref-dim
     f swap open-window* ;
 
 : into-window ( world quot -- world )