]> gitweb.factorcode.org Git - factor.git/commitdiff
HTTPD cleanups, working on help responder
authorSlava Pestov <slava@factorcode.org>
Fri, 20 Jan 2006 06:26:50 +0000 (06:26 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 20 Jan 2006 06:26:50 +0000 (06:26 +0000)
21 files changed:
TODO.FACTOR.txt
contrib/cont-responder/todo-example.factor
contrib/httpd/browser-responder.factor
contrib/httpd/default-responders.factor
contrib/httpd/help-responder.factor [new file with mode: 0644]
contrib/httpd/html.factor
contrib/httpd/load.factor
contrib/httpd/test/html.factor
contrib/httpd/xml.factor
library/bootstrap/boot-stage1.factor
library/bootstrap/boot-stage2.factor
library/freetype/freetype-gl.factor
library/help/markup.factor
library/help/stylesheet.factor
library/syntax/prettyprint.factor
library/threads.factor
library/ui/presentations.factor
library/ui/theme.factor
library/ui/timers.factor [new file with mode: 0644]
library/ui/ui.factor
library/ui/world.factor

index f7d1f4f08fc0face19144435d1aedb392ae6de8f..34c769db9a118740cbf9090a0624b277fe2a3ce4 100644 (file)
@@ -1,4 +1,3 @@
-- FUNCTION: not updating crossref correctly\r
 - need line and paragraph spacing\r
 - update HTML stream\r
 - help cross-referencing\r
@@ -10,12 +9,8 @@
   - alien calls\r
   - port ffi to win64\r
 - intrinsic char-slot set-char-slot for x86\r
-- closing ui does not stop timers\r
-- adding/removing timers automatically for animated gadgets\r
-- saving image with UI open\r
 - fix up the min thumb size hack\r
 - the invalid recursion form case needs to be fixed, for inlines too\r
-- what about tasks and timers between image restarts\r
 - code walker & exceptions\r
 - signal handler should not lose stack pointers\r
 - FIELD: char key_vector[32];\r
index 442249e2dac74d3a12a320cdb187e489980f9f61..4476e668c81b06c165eb96c7765841241d19c644 100644 (file)
@@ -27,6 +27,7 @@
 ! list of things to do. All data is stored in a directory in the 
 ! filesystem with the users name.
 IN: todo-example
+USING: xml ;
 USE: cont-responder
 USE: html
 USE: io
index 4d6d89a35017f1668c60b1ac0f4fed1d35382fc3..d3fc96ba5d8ec79d51a1cd58003d2615d7381399 100644 (file)
@@ -25,8 +25,8 @@
 ! cont-responder facilities.
 !
 IN: browser-responder
-USING: html cont-responder hashtables kernel io namespaces words lists prettyprint 
-       memory sequences ;
+USING: cont-responder hashtables help html io kernel lists
+memory namespaces prettyprint sequences words xml ;
 
 : option ( current text -- )
   #! Output the HTML option tag for the given text. If
@@ -56,13 +56,7 @@ USING: html cont-responder hashtables kernel io namespaces words lists prettypri
 
 : word-source ( vocab word -- )
   #! Write the source for the given word from the vocab as HTML.
-  swap lookup [
-    [ see ] with-simple-html-output
-  ] when* ;
-
-: vm-statistics ( -- )
-  #! Display statistics about the vm.
-  <pre> room. </pre> ;
+  swap lookup [ [ help ] with-html-stream ] when* ;
 
 : browser-body ( vocab word -- )
   #! Write out the HTML for the body of the main browser page.
@@ -70,15 +64,14 @@ USING: html cont-responder hashtables kernel io namespaces words lists prettypri
     <tr>  
       <td> <b> "Vocabularies" write </b> </td>
       <td> <b> "Words" write </b> </td>
-      <td> <b> "Source" write </b> </td>
+      <td> <b> "Documentation" write </b> </td>
     </tr>
     <tr>  
       <td "top" =valign "width: 200" =style td> over vocab-list </td> 
       <td "top" =valign "width: 200" =style td> 2dup word-list </td> 
       <td "top" =valign td> word-source </td> 
     </tr>
-  </table>
-  vm-statistics ;
+  </table> ;
 
 : browser-title ( vocab word -- )
   #! Output the HTML title for the browser.
index aa995af38d45b377aa09b97072f8759d411640c0..8c5a05ea6169952d0ff2957085c5ceae04349305 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: httpd
-USING: browser-responder cont-responder file-responder kernel
-namespaces prettyprint ;
+USING: browser-responder cont-responder file-responder
+help-responder kernel namespaces prettyprint ;
 
 #! Remove all existing responders, and create a blank
 #! responder table.
@@ -14,6 +14,12 @@ global [
         "404" "responder" set
         [ drop no-such-responder ] "get" set
     ] make-responder
+
+    ! Online help browsing
+    [
+        "help" "responder" set
+        [ help-responder ] "get" set
+    ] make-responder
     
     ! Servers Factor word definitions from the image.
     "browser" [ browser-responder ] install-cont-responder
diff --git a/contrib/httpd/help-responder.factor b/contrib/httpd/help-responder.factor
new file mode 100644 (file)
index 0000000..1430c30
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: help-responder
+USING: help html kernel sequences ;
+
+: help-responder ( filename -- )
+    dup empty? [ drop "handbook" ] when
+    dup article-title
+    [ [ (help) ] with-html-stream ] html-document ;
index 3a137f81a288710527bc8a1be398ebe522e9e7d2..330bcbf3c98bbccb9127e54163a6aa5bd6956054 100644 (file)
@@ -1,38 +1,25 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: html
-USING: generic hashtables http io kernel lists math namespaces
-sequences strings styles words ;
-
-: html-entities ( -- alist )
-    H{
-        { CHAR: < "&lt;"   }
-        { CHAR: > "&gt;"   }
-        { CHAR: & "&amp;"  }
-        { CHAR: ' "&apos;" }
-        { CHAR: " "&quot;" }
-    } ;
-
-: chars>entities ( str -- str )
-    #! Convert <, >, &, ' and " to HTML entities.
-    [
-        [ dup html-entities hash [ % ] [ , ] ?if ] each
-    ] "" make ;
+USING: generic hashtables help http io kernel lists math
+namespaces sequences strings styles words xml ;
 
 : hex-color, ( triplet -- )
     3 swap head [ 255 * >fixnum >hex 2 CHAR: 0 pad-left % ] each ;
 
-: fg-css, ( color -- )
-    "color: #" % hex-color, "; " % ;
+: fg-css, ( color -- ) "color: #" % hex-color, "; " % ;
+
+: bg-css, ( color -- ) "background-color: #" % hex-color, "; " % ;
 
 : style-css, ( flag -- )
-    dup [ italic bold-italic ] member?
+    dup
+    { italic bold-italic } member?
     [ "font-style: italic; " % ] when
-    [ bold bold-italic ] member?
+    { bold bold-italic } member?
     [ "font-weight: bold; " % ] when ;
 
 : size-css, ( size -- )
-    "font-size: " % # "; " % ;
+    "font-size: " % # "pt; " % ;
 
 : font-css, ( font -- )
     "font-family: " % % "; " % ;
@@ -47,10 +34,11 @@ sequences strings styles words ;
         swap rot hash dup [ call ] [ 2drop ] if
     ] hash-each-with ;
 
-: css-style ( style -- )
+: span-css-style ( style -- str )
     [
         H{
             { foreground  [ fg-css,        ] }
+            { background  [ bg-css,        ] }
             { font        [ font-css,      ] }
             { font-style  [ style-css,     ] }
             { font-size   [ size-css,      ] }
@@ -58,12 +46,30 @@ sequences strings styles words ;
     ] "" make ;
 
 : span-tag ( style quot -- )
-    over css-style dup "" = [
+    over span-css-style dup empty? [
         drop call
     ] [
         <span =style span> call </span>
     ] if ;
 
+: div-css-style ( style -- str )
+    drop "" ;
+    ! [
+    !     H{
+    !         { foreground  [ fg-css,        ] }
+    !         { font        [ font-css,      ] }
+    !         { font-style  [ style-css,     ] }
+    !         { font-size   [ size-css,      ] }
+    !     } hash-apply
+    ! ] "" make ;
+
+: div-tag ( style quot -- )
+    over div-css-style dup empty? [
+        drop call
+    ] [
+        <div =style div> call </div>
+    ] if ;
+
 : resolve-file-link ( path -- link )
     #! The file responder needs relative links not absolute
     #! links.
@@ -81,22 +87,30 @@ sequences strings styles words ;
         call
     ] if* ;
 
-: browser-link-href ( word -- href )
-    dup word-name swap word-vocabulary
-    [
+GENERIC: browser-link-href ( presented -- href )
+
+M: word browser-link-href
+    dup word-name swap word-vocabulary [
         "/responder/browser/?vocab=" %
         url-encode %
         "&word=" %
         url-encode %
     ] "" make ;
 
-: browser-link-tag ( style quot -- style )
-    over presented swap hash dup word? [
-        <a browser-link-href =href a> call </a>
+M: link browser-link-href
+    link-name [ \ f ] unless* dup word? [
+        browser-link-href
     ] [
-        drop call
+        [ "/responder/help/" % url-encode % ] "" make
     ] if ;
 
+M: object browser-link-href
+    drop f ;
+
+: browser-link-tag ( style quot -- style )
+    presented pick hash browser-link-href
+    [ <a =href a> call </a> ] [ call ] if* ;
+
 TUPLE: wrapper-stream scope ;
 
 C: wrapper-stream ( stream -- stream )
@@ -107,12 +121,19 @@ C: wrapper-stream ( stream -- stream )
 : with-wrapper ( stream quot -- )
     >r wrapper-stream-scope r> bind ; inline
 
+TUPLE: nested-stream ;
+
+C: nested-stream [ set-delegate ] keep ;
+
+M: nested-stream stream-close drop ;
+
 TUPLE: html-stream ;
 
 M: html-stream stream-write1 ( char stream -- )
-    [
-        dup html-entities hash [ write ] [ write1 ] ?if
-    ] with-wrapper ;
+    >r ch>string r> stream-write ;
+
+M: html-stream stream-write ( char stream -- )
+    [ chars>entities write ] with-wrapper ;
 
 M: html-stream stream-format ( str style stream -- )
     [
@@ -123,6 +144,23 @@ M: html-stream stream-format ( str style stream -- )
         ] browser-link-tag
     ] with-wrapper ;
 
+: pre-tag ( stream style quot -- )
+    wrap-margin rot hash [
+        call
+    ] [
+        over [ [ <pre> ] with-wrapper call ] keep
+        [ </pre> ] with-wrapper
+    ] if ;
+
+M: html-stream with-nested-stream ( quot style stream -- )
+    swap [
+        [ <nested-stream> swap with-stream ] pre-tag
+    ] div-tag ;
+
+M: html-stream stream-terpri [ <br/> ] with-wrapper ;
+
+M: html-stream stream-terpri* [ <br/> ] with-wrapper ;
+
 C: html-stream ( stream -- stream )
     #! Wraps the given stream in an HTML stream. An HTML stream
     #! converts special characters to entities when being
index e46a6dc4a64e6df0dca2bb316fc68583e471df6a..623438cea34ff2de668706f654b9207559f8c92b 100644 (file)
@@ -2,6 +2,7 @@ IN: scratchpad
 USING: words kernel parser sequences io compiler ;
 
 { 
+    "xml"
     "http-common"
     "mime"
     "html-tags"
@@ -9,6 +10,7 @@ USING: words kernel parser sequences io compiler ;
     "responder"
     "httpd"
     "file-responder"
+    "help-responder"
     "cont-responder"
     "browser-responder"
     "default-responders"
index 2fa0f3d10932ad188d962f1f47d617e5da12ec68..ea85c5ef80f40864b183e1d7df09c82723aaf12c 100644 (file)
@@ -1,5 +1,5 @@
 IN: temporary
-USING: html io kernel namespaces styles test ;
+USING: html io kernel namespaces styles test xml ;
 
 [
     "&lt;html&gt;&amp;&apos;sgml&apos;"
@@ -32,7 +32,7 @@ USING: html io kernel namespaces styles test ;
 [
     [
         "car"
-        H{ { font "Monospaced" } }
+        H{ { font "monospace" } }
         html-format
     ] string-out
 ] unit-test
index c3e528029e63ef5463d4fbbb7036fd6bf6a4d48a..0c11914b017fb61ab5d74a8d4afd23c9fcdd02db 100644 (file)
@@ -1,5 +1,6 @@
-USING: kernel math infix parser namespaces sequences strings prettyprint
-    errors lists hashtables vectors html io generic words ;
+USING: kernel math parser namespaces sequences strings
+prettyprint errors lists hashtables vectors io generic
+words ;
 IN: xml
 
 ! * Simple SAX-ish parser
@@ -124,12 +125,18 @@ M: xml-string-error error.
     ] if ;
 
 : entities
+    #! We have both directions here as a shortcut.
     H{
-        [[ "lt" CHAR: < ]]
-        [[ "gt" CHAR: > ]]
-        [[ "amp" CHAR: & ]]
-        [[ "apos" CHAR: ' ]]
-        [[ "quot" CHAR: " ]]
+        { "lt" CHAR: < }
+        { "gt" CHAR: > }
+        { "amp" CHAR: & }
+        { "apos" CHAR: ' }
+        { "quot" CHAR: " }
+        { CHAR: < "&lt;"   }
+        { CHAR: > "&gt;"   }
+        { CHAR: & "&amp;"  }
+        { CHAR: ' "&apos;" }
+        { CHAR: " "&quot;" }
     } ;
 
 : parse-entity ( -- ch )
@@ -334,21 +341,13 @@ M: closer process
 
 GENERIC: (xml>string) ( object -- )
 
-: reverse-entities ! not as many as entities needed for printing
-    H{
-        { CHAR: & "amp" }
-        { CHAR: < "lt" }
-        { CHAR: " "quot" }
-    } ;
-
-M: string (xml>string)
+: chars>entities ( str -- str )
+    #! Convert <, >, &, ' and " to HTML entities.
     [
-        dup reverse-entities hash [
-            CHAR: & , % CHAR: ; ,
-        ] [
-            ,
-        ] ?if
-    ] each ;
+        [ dup entities hash [ % ] [ , ] ?if ] each
+    ] "" make ;
+
+M: string (xml>string) chars>entities % ;
 
 : print-open/close ( tag -- )
     CHAR: > ,
index 90a0e95818e6f0bd2c2984c0c602383c14291da1..cb4331a40086cf98ea2db0fc6f7b4410c8715e8d 100644 (file)
@@ -171,6 +171,7 @@ vectors words ;
         "/library/freetype/freetype.factor"
         "/library/freetype/freetype-gl.factor"
 
+        "/library/ui/timers.factor"
         "/library/ui/gadgets.factor"
         "/library/ui/layouts.factor"
         "/library/ui/hierarchy.factor"
@@ -332,9 +333,6 @@ vocabularies get [
 
 "!syntax" vocabularies get remove-hash
 
-H{ } clone crossref set
-recrossref
-
 "Building generic words..." print flush
 
 all-words [ generic? ] subset [ make-generic ] each
index b9ff813427f67ef931add288e64c1ca495b41a08..d4bdc1a5e3b5c525836ea1a954501415481530b4 100644 (file)
@@ -43,6 +43,10 @@ sequences sequences-internals words ;
     0 exit\r
 ] set-boot\r
 \r
+"Building cross-referencing database..." print\r
+H{ } clone crossref set\r
+recrossref\r
+\r
 [ compiled? ] word-subset length\r
 number>string write " compiled words" print\r
 \r
index dc701b99c6c52e0fdffb6b45bbe7f9acbc844e55..45e3011610f5d3d06c4001c955e8fd482007c916 100644 (file)
@@ -54,18 +54,18 @@ M: font = eq? ;
 
 : ttf-name ( font style -- name )
     cons H{
-        { [[ "Monospaced" plain       ]] "VeraMono" }
-        { [[ "Monospaced" bold        ]] "VeraMoBd" }
-        { [[ "Monospaced" bold-italic ]] "VeraMoBI" }
-        { [[ "Monospaced" italic      ]] "VeraMoIt" }
-        { [[ "Sans Serif" plain       ]] "Vera"     }
-        { [[ "Sans Serif" bold        ]] "VeraBd"   }
-        { [[ "Sans Serif" bold-italic ]] "VeraBI"   }
-        { [[ "Sans Serif" italic      ]] "VeraIt"   }
-        { [[ "Serif" plain            ]] "VeraSe"   }
-        { [[ "Serif" bold             ]] "VeraSeBd" }
-        { [[ "Serif" bold-italic      ]] "VeraBI"   }
-        { [[ "Serif" italic           ]] "VeraIt"   }
+        { [[ "monospace" plain        ]] "VeraMono" }
+        { [[ "monospace" bold         ]] "VeraMoBd" }
+        { [[ "monospace" bold-italic  ]] "VeraMoBI" }
+        { [[ "monospace" italic       ]] "VeraMoIt" }
+        { [[ "sans-serif" plain       ]] "Vera"     }
+        { [[ "sans-serif" bold        ]] "VeraBd"   }
+        { [[ "sans-serif" bold-italic ]] "VeraBI"   }
+        { [[ "sans-serif" italic      ]] "VeraIt"   }
+        { [[ "serif" plain            ]] "VeraSe"   }
+        { [[ "serif" bold             ]] "VeraSeBd" }
+        { [[ "serif" bold-italic      ]] "VeraBI"   }
+        { [[ "serif" italic           ]] "VeraIt"   }
     } hash ;
 
 : ttf-path ( name -- string )
index 83f0cad2ea31cdc7c3366558e7fdb480d3cc1101..5106fbf6bdc5869ee6d9805c6eac486251fed4e8 100644 (file)
@@ -87,8 +87,7 @@ M: simple-element print-element [ print-element ] each ;
 : $synopsis ( content -- )
     first dup
     word-vocabulary [ "Vocabulary" $subheading $snippet ] when*
-    dup parsing? [ $syntax ] [ $stack-effect ] if
-    terpri* ;
+    dup parsing? [ $syntax ] [ $stack-effect ] if ;
 
 : $description ( content -- )
     "Description" $subheading print-element ;
@@ -110,9 +109,7 @@ M: simple-element print-element [ print-element ] each ;
     [ "," format* bl ] interleave ; inline
 
 : $see ( content -- )
-    terpri*
-    code-style [ [ first see ] with-nesting* ] with-style
-    terpri* ;
+    code-style [ [ first see ] with-nesting* ] with-style ;
 
 : $example ( content -- )
     first2 swap dup <input>
index e57f1d5544fb1cd9a66120e16aca2d782dde4da6..f438b61b54cfeb622e226492c62473b4a1952e63 100644 (file)
@@ -3,7 +3,7 @@ USING: styles ;
 
 : default-style
     H{
-        { font "Sans Serif" }
+        { font "sans-serif" }
         { font-size 12 }
         { wrap-margin 500 }
     } ;
@@ -14,22 +14,22 @@ USING: styles ;
 : emphasis-style
     H{ { font-style italic } } ;
 
-: heading-style H{ { font "Serif" } { font-size 16 } } ;
+: heading-style H{ { font "serif" } { font-size 16 } } ;
 
-: subheading-style H{ { font "Serif" } { font-style bold } } ;
+: subheading-style H{ { font "serif" } { font-style bold } } ;
 
 : subsection-style
-    H{ { font "Serif" } { font-size 14 } { font-style bold } } ;
+    H{ { font "serif" } { font-size 14 } { font-style bold } } ;
 
 : snippet-style
     H{
-        { font "Monospaced" }
+        { font "monospace" }
         { foreground { 0.3 0.3 0.3 1 } }
     } ;
 
 : code-style
     H{
-        { font "Monospaced" }
+        { font "monospace" }
         { page-color { 0.9 0.9 1 0.5 } }
         { border-width 5 }
         { wrap-margin f }
@@ -40,7 +40,7 @@ USING: styles ;
 
 : url-style
     H{
-        { font "Monospaced" }
+        { font "monospace" }
         { foreground { 0.0 0.0 1.0 1.0 } }
     } ;
 
index e4d3edc461e41cfaea417650d42ed1790fc00b17..93420453d1931a9261a870b79aca2a649bd0d91f 100644 (file)
@@ -54,7 +54,7 @@ C: section ( length -- section )
         last-newline set
         line-limit? [ "..." write end-printing get continue ] when
         line-count inc
-        "\n" write do-indent
+        terpri do-indent
     ] if ;
 
 TUPLE: text string style ;
index e3dd092842ff25ce5efb3aea4215121709b0610b..2bb70a83eee202f2c98a6a8d5ff6e60cb4634f5a 100644 (file)
@@ -42,48 +42,8 @@ DEFER: next-thread
         try stop
     ] callcc0 drop ;
 
-TUPLE: timer object delay last ;
-
-: timer-now millis swap set-timer-last ;
-
-C: timer ( object delay -- timer )
-    [ set-timer-delay ] keep
-    [ set-timer-object ] keep
-    dup timer-now ;
-
-GENERIC: tick ( ms object -- )
-
-: timers ( -- hash ) \ timers global hash ;
-
-: add-timer ( object delay -- )
-    over >r <timer> r> timers set-hash ;
-
-: remove-timer ( object -- ) timers remove-hash ;
-
-: restart-timer ( object -- )
-    timers hash [ timer-now ] when* ;
-
-: next-time ( timer -- ms ) dup timer-delay swap timer-last + ;
-
-: advance-timer ( ms timer -- delay )
-    #! Outputs the time since the last firing.
-    [ timer-last - 0 max ] 2keep set-timer-last ;
-
-: do-timer ( ms timer -- )
-    #! Takes current time, and a timer. If the timer is set to
-    #! fire, calls its callback.
-    dup next-time pick <= [
-        [ advance-timer ] keep timer-object tick
-    ] [
-        2drop
-    ] if ;
-
-: do-timers ( -- )
-    millis timers hash-values [ do-timer ] each-with ;
-
 : init-threads ( -- )
     global [
         <queue> \ run-queue set
         V{ } clone \ sleep-queue set
-        H{ } clone \ timers set
     ] bind ;
index 3bef8976844f046f71c146a00480e84144a7b771..d7025b371a7b832e3377cefe80ae018d5ed9d6ae 100644 (file)
@@ -29,7 +29,7 @@ M: gadget-stream stream-write1 ( char stream -- )
     background [ <solid> over set-gadget-interior ] apply-style ;
 
 : specified-font ( style -- font )
-    [ font swap hash [ "Monospaced" ] unless* ] keep
+    [ font swap hash [ "monospace" ] unless* ] keep
     [ font-style swap hash [ plain ] unless* ] keep
     font-size swap hash [ 12 ] unless* 3array ;
 
index ed44d7117e416ad19e8bf56bfaaa87fc6dd4c497..7a539f11d52177483aef59721813bf4d098d6e6b 100644 (file)
@@ -76,13 +76,13 @@ USING: arrays gadgets kernel sequences styles ;
 
 : label-theme ( label -- )
     { 0.0 0.0 0.0 1.0 } over set-label-color
-    { "Monospaced" plain 12 } swap set-label-font ;
+    { "monospace" plain 12 } swap set-label-font ;
 
 : editor-theme ( label -- )
     { 0.0 0.0 0.0 1.0 } over set-label-color
-    { "Monospaced" bold 12 } swap set-label-font ;
+    { "monospace" bold 12 } swap set-label-font ;
 
 : status-theme ( label -- )
     dup reverse-video-theme
     { 1.0 1.0 1.0 1.0 } over set-label-color
-    { "Monospaced" plain 12 } swap set-label-font ;
+    { "monospace" plain 12 } swap set-label-font ;
diff --git a/library/ui/timers.factor b/library/ui/timers.factor
new file mode 100644 (file)
index 0000000..cba33e0
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2005, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: gadgets
+USING: hashtables kernel math sequences ;
+
+TUPLE: timer object delay last ;
+
+: timer-now millis swap set-timer-last ;
+
+C: timer ( object delay -- timer )
+    [ set-timer-delay ] keep
+    [ set-timer-object ] keep
+    dup timer-now ;
+
+GENERIC: tick ( ms object -- )
+
+DEFER: timers
+
+: add-timer ( object delay -- )
+    over >r <timer> r> timers set-hash ;
+
+: remove-timer ( object -- ) timers remove-hash ;
+
+: restart-timer ( object -- )
+    timers hash [ timer-now ] when* ;
+
+: next-time ( timer -- ms ) dup timer-delay swap timer-last + ;
+
+: advance-timer ( ms timer -- delay )
+    [ timer-last - 0 max ] 2keep set-timer-last ;
+
+: do-timer ( ms timer -- )
+    dup next-time pick <= [
+        [ advance-timer ] keep timer-object tick
+    ] [
+        2drop
+    ] if ;
+
+: do-timers ( -- )
+    millis timers hash-values [ do-timer ] each-with ;
index fb80d5c90d5bfda9fb226e3f31ca3341fb88b4b0..757ddeed3acb93f22a638d2734e2fe8411e6ec84 100644 (file)
@@ -21,16 +21,10 @@ global [ first-time on ] bind
         ] when
     ] bind ;
 
-: check-running
-    world get [
-        world-running?
-        [ "The UI is already running" throw ] when
-    ] when* ;
-
 IN: shells
 
 : ui ( -- )
-    check-running [
+    [
         init-world world get rect-dim first2
         [ listener-application run-world ] with-gl-screen
     ] with-freetype ;
index e1d2a6254f99bc99b180b8417e192295a94ad4b4..2ae83eac1849e74f8748d3c6aa61bcaf990c573d 100644 (file)
@@ -9,13 +9,17 @@ sequences sequences strings styles threads ;
 ! gadgets are contained in. The current world is stored in the
 ! world variable. The invalid slot is a list of gadgets that
 ! need to be layout.
-TUPLE: world running? glass status invalid ;
+TUPLE: world running? glass status invalid timers ;
+
+: timers ( -- hash ) world get world-timers ;
 
 : add-layer ( gadget -- )
     world get add-gadget ;
 
 C: world ( -- world )
-    <stack> over set-delegate t over set-gadget-root? ;
+    <stack> over set-delegate
+    t over set-gadget-root?
+    H{ } clone over set-world-timers ;
 
 : add-invalid ( gadget -- )
     world get [ world-invalid cons ] keep set-world-invalid ;