Removed extra/timers, superceded by alarms
parent
217ca36756
commit
b7ba2d77a2
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2006, 2007 Slava Pestov.
|
! Copyright (C) 2006, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: generic kernel math sequences timers arrays assocs ;
|
USING: generic kernel math sequences arrays assocs alarms ;
|
||||||
IN: models
|
IN: models
|
||||||
|
|
||||||
TUPLE: model value connections dependencies ref locked? ;
|
TUPLE: model value connections dependencies ref locked? ;
|
||||||
|
@ -174,7 +174,7 @@ TUPLE: history back forward ;
|
||||||
dup history-forward delete-all
|
dup history-forward delete-all
|
||||||
dup history-back (add-history) ;
|
dup history-back (add-history) ;
|
||||||
|
|
||||||
TUPLE: delay model timeout ;
|
TUPLE: delay model timeout alarm ;
|
||||||
|
|
||||||
: update-delay-model ( delay -- )
|
: update-delay-model ( delay -- )
|
||||||
dup delay-model model-value swap set-model ;
|
dup delay-model model-value swap set-model ;
|
||||||
|
@ -185,12 +185,18 @@ TUPLE: delay model timeout ;
|
||||||
[ set-delay-model ] 2keep
|
[ set-delay-model ] 2keep
|
||||||
[ add-dependency ] keep ;
|
[ add-dependency ] keep ;
|
||||||
|
|
||||||
M: delay model-changed nip 0 over delay-timeout add-timer ;
|
: cancel-delay ( delay -- )
|
||||||
|
delay-model-alarm [ cancel-alarm ] when* ;
|
||||||
|
|
||||||
|
: start-delay ( delay -- )
|
||||||
|
now over delay-model-timeout dt+ f
|
||||||
|
pick [ f over set-delay-alarm update-delay-model ] curry
|
||||||
|
add-alarm swap set-delay-model-alarm ;
|
||||||
|
|
||||||
|
M: delay model-changed nip start-delay ;
|
||||||
|
|
||||||
M: delay model-activated update-delay-model ;
|
M: delay model-activated update-delay-model ;
|
||||||
|
|
||||||
M: delay tick dup remove-timer update-delay-model ;
|
|
||||||
|
|
||||||
GENERIC: range-value ( model -- value )
|
GENERIC: range-value ( model -- value )
|
||||||
GENERIC: range-page-value ( model -- value )
|
GENERIC: range-page-value ( model -- value )
|
||||||
GENERIC: range-min-value ( model -- value )
|
GENERIC: range-min-value ( model -- value )
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Slava Pestov
|
|
|
@ -1 +0,0 @@
|
||||||
Simple low-resolution timers
|
|
|
@ -1,36 +0,0 @@
|
||||||
USING: help.syntax help.markup classes kernel ;
|
|
||||||
IN: timers
|
|
||||||
|
|
||||||
HELP: init-timers
|
|
||||||
{ $description "Initializes the timer code." }
|
|
||||||
{ $notes "This word is automatically called when the UI is initialized, and it should only be called manually if timers are being used outside of the UI." } ;
|
|
||||||
|
|
||||||
HELP: tick
|
|
||||||
{ $values { "object" object } }
|
|
||||||
{ $description "Called to notify an object registered with a timer that the timer has fired." } ;
|
|
||||||
|
|
||||||
HELP: add-timer
|
|
||||||
{ $values { "object" object } { "delay" "a positive integer" } { "initial" "a positive integer" } }
|
|
||||||
{ $description "Registers a timer. Every " { $snippet "delay" } " milliseconds, " { $link tick } " will be called on the object. The initial delay from the time " { $link add-timer } " is called to when " { $link tick } " is first called is " { $snippet "initial" } " milliseconds." } ;
|
|
||||||
|
|
||||||
HELP: remove-timer
|
|
||||||
{ $values { "object" object } }
|
|
||||||
{ $description "Unregisters a timer." } ;
|
|
||||||
|
|
||||||
HELP: do-timers
|
|
||||||
{ $description "Fires all registered timers which are due to fire." }
|
|
||||||
{ $notes "This word is automatically called from the UI event loop, and it should only be called manually if timers are being used outside of the UI." } ;
|
|
||||||
|
|
||||||
{ init-timers add-timer remove-timer tick do-timers } related-words
|
|
||||||
|
|
||||||
ARTICLE: "timers" "Timers"
|
|
||||||
"Timers can be added and removed:"
|
|
||||||
{ $subsection add-timer }
|
|
||||||
{ $subsection remove-timer }
|
|
||||||
"Classes must implement a generic word so that their instances can handle timer ticks:"
|
|
||||||
{ $subsection tick }
|
|
||||||
"Timers can be used outside of the UI, however they must be initialized with an explicit call, and fired manually:"
|
|
||||||
{ $subsection init-timers }
|
|
||||||
{ $subsection do-timers } ;
|
|
||||||
|
|
||||||
ABOUT: "timers"
|
|
|
@ -1,30 +0,0 @@
|
||||||
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
|
||||||
USING: assocs kernel math namespaces sequences system ;
|
|
||||||
IN: timers
|
|
||||||
|
|
||||||
TUPLE: timer object delay next ;
|
|
||||||
|
|
||||||
: <timer> ( object delay initial -- timer )
|
|
||||||
millis + timer construct-boa ;
|
|
||||||
|
|
||||||
GENERIC: tick ( object -- )
|
|
||||||
|
|
||||||
: timers \ timers get-global ;
|
|
||||||
|
|
||||||
: init-timers ( -- ) H{ } clone \ timers set-global ;
|
|
||||||
|
|
||||||
: add-timer ( object delay initial -- )
|
|
||||||
pick >r <timer> r> timers set-at ;
|
|
||||||
|
|
||||||
: remove-timer ( object -- ) timers delete-at ;
|
|
||||||
|
|
||||||
: advance-timer ( ms timer -- )
|
|
||||||
[ timer-delay + ] keep set-timer-next ;
|
|
||||||
|
|
||||||
: do-timer ( ms timer -- )
|
|
||||||
dup timer-next pick <=
|
|
||||||
[ [ advance-timer ] keep timer-object tick ] [ 2drop ] if ;
|
|
||||||
|
|
||||||
: do-timers ( -- )
|
|
||||||
millis timers values [ do-timer ] with each ;
|
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2005, 2007 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays hashtables kernel models math namespaces sequences
|
USING: arrays hashtables kernel models math namespaces sequences
|
||||||
timers quotations math.vectors combinators sorting vectors
|
quotations math.vectors combinators sorting vectors dlists
|
||||||
dlists models ;
|
models ;
|
||||||
IN: ui.gadgets
|
IN: ui.gadgets
|
||||||
|
|
||||||
TUPLE: rect loc dim ;
|
TUPLE: rect loc dim ;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays assocs kernel math models namespaces
|
USING: arrays assocs kernel math models namespaces
|
||||||
sequences words strings system hashtables math.parser
|
sequences words strings system hashtables math.parser
|
||||||
math.vectors tuples classes ui.gadgets timers combinators.lib ;
|
math.vectors tuples classes ui.gadgets combinators.lib ;
|
||||||
IN: ui.gestures
|
IN: ui.gestures
|
||||||
|
|
||||||
: set-gestures ( class hash -- ) "gestures" set-word-prop ;
|
: set-gestures ( class hash -- ) "gestures" set-word-prop ;
|
||||||
|
@ -107,20 +107,19 @@ SYMBOL: double-click-timeout
|
||||||
: drag-gesture ( -- )
|
: drag-gesture ( -- )
|
||||||
hand-buttons get-global first <drag> button-gesture ;
|
hand-buttons get-global first <drag> button-gesture ;
|
||||||
|
|
||||||
TUPLE: drag-timer ;
|
SYMBOL: drag-timer
|
||||||
|
|
||||||
M: drag-timer tick drop drag-gesture ;
|
<box> drag-timer set-global
|
||||||
|
|
||||||
drag-timer construct-empty drag-timer set-global
|
|
||||||
|
|
||||||
: start-drag-timer ( -- )
|
: start-drag-timer ( -- )
|
||||||
hand-buttons get-global empty? [
|
hand-buttons get-global empty? [
|
||||||
drag-timer get-global 100 300 add-timer
|
now 300 milliseconds dt+ 100 milliseconds
|
||||||
|
[ drag-gesture ] add-alarm drag-timer get-global >box
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
: stop-drag-timer ( -- )
|
: stop-drag-timer ( -- )
|
||||||
hand-buttons get-global empty? [
|
hand-buttons get-global empty? [
|
||||||
drag-timer get-global remove-timer
|
drag-timer get-global box> cancel-alarm
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
: fire-motion ( -- )
|
: fire-motion ( -- )
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
USING: continuations documents ui.tools.interactor
|
USING: continuations documents ui.tools.interactor
|
||||||
ui.tools.listener hashtables kernel namespaces parser sequences
|
ui.tools.listener hashtables kernel namespaces parser sequences
|
||||||
timers tools.test ui.commands ui.gadgets ui.gadgets.editors
|
tools.test ui.commands ui.gadgets ui.gadgets.editors
|
||||||
ui.gadgets.panes vocabs words tools.test.ui slots.private
|
ui.gadgets.panes vocabs words tools.test.ui slots.private
|
||||||
threads ;
|
threads ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
timers [ init-timers ] unless
|
|
||||||
|
|
||||||
[ f ] [ "word" source-editor command-map empty? ] unit-test
|
[ f ] [ "word" source-editor command-map empty? ] unit-test
|
||||||
|
|
||||||
[ ] [ <listener-gadget> [ ] with-grafted-gadget ] unit-test
|
[ ] [ <listener-gadget> [ ] with-grafted-gadget ] unit-test
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
USING: assocs ui.tools.search help.topics io.files io.styles
|
USING: assocs ui.tools.search help.topics io.files io.styles
|
||||||
kernel namespaces sequences source-files threads timers
|
kernel namespaces sequences source-files threads
|
||||||
tools.test ui.gadgets ui.gestures vocabs
|
tools.test ui.gadgets ui.gestures vocabs
|
||||||
vocabs.loader words tools.test.ui debugger ;
|
vocabs.loader words tools.test.ui debugger ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
timers get [ init-timers ] unless
|
|
||||||
|
|
||||||
[ f ] [
|
[ f ] [
|
||||||
"no such word with this name exists, certainly"
|
"no such word with this name exists, certainly"
|
||||||
f f <definition-search>
|
f f <definition-search>
|
||||||
|
@ -16,7 +14,7 @@ timers get [ init-timers ] unless
|
||||||
|
|
||||||
: update-live-search ( search -- seq )
|
: update-live-search ( search -- seq )
|
||||||
dup [
|
dup [
|
||||||
300 sleep do-timers
|
300 sleep
|
||||||
live-search-list control-value
|
live-search-list control-value
|
||||||
] with-grafted-gadget ;
|
] with-grafted-gadget ;
|
||||||
|
|
||||||
|
@ -33,7 +31,6 @@ timers get [ init-timers ] unless
|
||||||
dup [
|
dup [
|
||||||
{ "set-word-prop" } over live-search-field set-control-value
|
{ "set-word-prop" } over live-search-field set-control-value
|
||||||
300 sleep
|
300 sleep
|
||||||
do-timers
|
|
||||||
search-value \ set-word-prop eq?
|
search-value \ set-word-prop eq?
|
||||||
] with-grafted-gadget
|
] with-grafted-gadget
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: ui.tools ui.tools.interactor ui.tools.listener
|
USING: ui.tools ui.tools.interactor ui.tools.listener
|
||||||
ui.tools.search ui.tools.workspace kernel models namespaces
|
ui.tools.search ui.tools.workspace kernel models namespaces
|
||||||
sequences timers tools.test ui.gadgets ui.gadgets.buttons
|
sequences tools.test ui.gadgets ui.gadgets.buttons
|
||||||
ui.gadgets.labelled ui.gadgets.presentations
|
ui.gadgets.labelled ui.gadgets.presentations
|
||||||
ui.gadgets.scrollers vocabs tools.test.ui ui ;
|
ui.gadgets.scrollers vocabs tools.test.ui ui ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
@ -12,8 +12,6 @@ IN: temporary
|
||||||
] unit-test
|
] unit-test
|
||||||
] with-scope
|
] with-scope
|
||||||
|
|
||||||
timers get [ init-timers ] unless
|
|
||||||
|
|
||||||
[ ] [ <workspace> "w" set ] unit-test
|
[ ] [ <workspace> "w" set ] unit-test
|
||||||
[ ] [ "w" get com-scroll-up ] unit-test
|
[ ] [ "w" get com-scroll-up ] unit-test
|
||||||
[ ] [ "w" get com-scroll-down ] unit-test
|
[ ] [ "w" get com-scroll-down ] unit-test
|
||||||
|
|
|
@ -167,7 +167,7 @@ ARTICLE: "ui-backend-init" "UI initialization and the event loop"
|
||||||
{ $subsection start-ui }
|
{ $subsection start-ui }
|
||||||
"The " { $link ui } " word must not return until the event loop has stopped and the UI has been shut down."
|
"The " { $link ui } " word must not return until the event loop has stopped and the UI has been shut down."
|
||||||
$nl
|
$nl
|
||||||
"The event loop must not block. Instead, it should poll for pending events, then call " { $link ui-step } ", which performs pending layout, runs timers and sleeps for 10 milliseconds, or until a Factor thread wakes up." ;
|
"The event loop must not block, since otherwise other Factor threads and I/O will not run. Instead, it should poll for pending events, then call " { $link ui-step } ", which performs pending layout and sleeps for 10 milliseconds." ;
|
||||||
|
|
||||||
ARTICLE: "ui-backend-windows" "UI backend window management"
|
ARTICLE: "ui-backend-windows" "UI backend window management"
|
||||||
"The high-level " { $link open-window } " word eventually calls a low-level word which you must implement:"
|
"The high-level " { $link open-window } " word eventually calls a low-level word which you must implement:"
|
||||||
|
@ -368,7 +368,6 @@ $nl
|
||||||
{ $subsection "ui-paint" }
|
{ $subsection "ui-paint" }
|
||||||
{ $subsection "ui-control-impl" }
|
{ $subsection "ui-control-impl" }
|
||||||
{ $subsection "clipboard-protocol" }
|
{ $subsection "clipboard-protocol" }
|
||||||
{ $subsection "timers" }
|
|
||||||
{ $see-also "ui-layout-impl" } ;
|
{ $see-also "ui-layout-impl" } ;
|
||||||
|
|
||||||
ARTICLE: "ui" "UI framework"
|
ARTICLE: "ui" "UI framework"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays assocs io kernel math models namespaces
|
USING: arrays assocs io kernel math models namespaces
|
||||||
prettyprint dlists sequences threads sequences words
|
prettyprint dlists sequences threads sequences words
|
||||||
timers debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks
|
debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks
|
||||||
ui.gestures ui.backend ui.render continuations init combinators
|
ui.gestures ui.backend ui.render continuations init combinators
|
||||||
hashtables ;
|
hashtables ;
|
||||||
IN: ui
|
IN: ui
|
||||||
|
@ -131,8 +131,7 @@ SYMBOL: ui-hook
|
||||||
graft-queue [ notify ] dlist-slurp ;
|
graft-queue [ notify ] dlist-slurp ;
|
||||||
|
|
||||||
: ui-step ( -- )
|
: ui-step ( -- )
|
||||||
[ do-timers notify-queued layout-queued redraw-worlds ]
|
[ notify-queued layout-queued redraw-worlds ] assert-depth ;
|
||||||
assert-depth ;
|
|
||||||
|
|
||||||
: open-world-window ( world -- )
|
: open-world-window ( world -- )
|
||||||
dup pref-dim over set-gadget-dim dup relayout graft ui-step ;
|
dup pref-dim over set-gadget-dim dup relayout graft ui-step ;
|
||||||
|
@ -156,7 +155,6 @@ M: object close-window
|
||||||
find-world [ ungraft ] when* ;
|
find-world [ ungraft ] when* ;
|
||||||
|
|
||||||
: start-ui ( -- )
|
: start-ui ( -- )
|
||||||
init-timers
|
|
||||||
restore-windows? [
|
restore-windows? [
|
||||||
restore-windows
|
restore-windows
|
||||||
] [
|
] [
|
||||||
|
|
|
@ -5,9 +5,8 @@ ui.backend ui.clipboards ui.gadgets.worlds ui.gestures io kernel
|
||||||
math math.vectors namespaces prettyprint sequences strings
|
math math.vectors namespaces prettyprint sequences strings
|
||||||
vectors words windows.kernel32 windows.gdi32 windows.user32
|
vectors words windows.kernel32 windows.gdi32 windows.user32
|
||||||
windows.opengl32 windows.messages windows.types windows.nt
|
windows.opengl32 windows.messages windows.types windows.nt
|
||||||
windows threads timers libc combinators
|
windows threads libc combinators continuations command-line
|
||||||
continuations command-line shuffle opengl ui.render unicode.case
|
shuffle opengl ui.render unicode.case ascii math.bitfields ;
|
||||||
ascii math.bitfields ;
|
|
||||||
IN: ui.windows
|
IN: ui.windows
|
||||||
|
|
||||||
TUPLE: windows-ui-backend ;
|
TUPLE: windows-ui-backend ;
|
||||||
|
|
Loading…
Reference in New Issue