<li>Everything else:
<ul>
+<li>New <code>sleep ( ms -- )</code> word pauses current thread for a number of milliseconds.</li>
<li>New <code>make-hash ( quot -- namespace )</code> combinator executes quotation in a new namespace, which is then pushed on the stack.</li>
<li>Erlang/Termite-style concurrency library in <code>contrib/concurrency</code> (Chris Double).</li>
<li>Object slots are now clickable in the inspector</li>
- an interior paint that is only painted on rollover and mouse press;\r
use it for menu items. give menus a gradient background\r
- scroll bar: more intuitive behavior when clicking inside the elevator\r
-- timers\r
- nicer scrollbars with up/down buttons\r
- icons\r
- use incremental strategy for all pack layouts where possible\r
global [
<queue> \ run-queue set
10 <vector> \ sleep-queue set
+ <namespace> \ timers set
] bind ;
+
+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 -- )
+ [ <timer> ] keep 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
+ ] ifte ;
+
+: do-timers ( -- )
+ millis timers hash-values [ do-timer ] each-with ;
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: generic kernel math matrices namespaces sdl sequences
-strings styles vectors ;
+strings styles threads vectors ;
! A blinking caret
TUPLE: caret ;
C: caret ( -- caret )
<plain-gadget> over set-delegate
- dup red background set-paint-prop
- 500 over set-gadget-framerate ;
+ dup red background set-paint-prop ;
: toggle-visible ( gadget -- )
dup gadget-visible? not over set-gadget-visible?
M: caret tick* ( ms caret -- ) nip toggle-visible ;
-: add-caret ( caret parent -- ) dupd add-gadget add-timer ;
+: caret-block 500 ;
-: unparent-caret ( caret -- ) dup remove-timer unparent ;
+: add-caret ( caret parent -- )
+ dupd add-gadget caret-block add-timer ;
+
+: unparent-caret ( caret -- )
+ dup remove-timer unparent ;
+
+: reset-caret ( caret -- )
+ dup restart-timer t swap set-gadget-visible? ;
USE: line-editor
#! Execute a quotation in the line editor scope, then
#! update the display.
swap [ editor-line swap bind ] keep
+ dup editor-caret reset-caret
dup relayout scroll>bottom ; inline
: editor-text ( editor -- text )
! A gadget is a rectangle, a paint, a mapping of gestures to
! actions, and a reference to the gadget's parent.
TUPLE: gadget
- paint gestures framerate visible? relayout? root?
+ paint gestures visible? relayout? root?
parent children ;
: gadget-child gadget-children first ;
+++ /dev/null
-! Copyright (C) 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: hashtables kernel math namespaces sequences ;
-
-TUPLE: timer gadget last ;
-
-C: timer ( gadget -- timer )
- [ set-timer-gadget ] keep
- millis over set-timer-last ;
-
-GENERIC: tick* ( ms gadget -- )
-
-: next-time ( timer -- ms )
- dup timer-gadget gadget-framerate 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-gadget tick* ] [ 2drop ] ifte ;
-
-: timers ( -- hash ) world get world-timers ;
-
-: add-timer ( gadget -- ) [ <timer> ] keep timers set-hash ;
-
-: remove-timer ( gadget -- ) timers remove-hash ;
-
-: do-timers ( -- )
- millis timers hash-values [ do-timer ] each-with ;
-
-M: gadget tick* ( ms gadget -- ) 2drop ;
! 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? hand glass invalid timers ;
+TUPLE: world running? hand glass invalid ;
DEFER: <hand>
DEFER: update-hand
C: world ( -- world )
f <stack> over set-delegate
t over set-gadget-root?
- dup <hand> over set-world-hand
- <namespace> over set-world-timers ;
+ dup <hand> over set-world-hand ;
: add-invalid ( gadget -- )
world get [ world-invalid cons ] keep set-world-invalid ;