diff --git a/extra/models/models.factor b/extra/models/models.factor index a6f1f6909a..6d2b0907c5 100755 --- a/extra/models/models.factor +++ b/extra/models/models.factor @@ -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. -USING: generic kernel math sequences timers arrays assocs ; +USING: generic kernel math sequences arrays assocs alarms ; IN: models TUPLE: model value connections dependencies ref locked? ; @@ -174,7 +174,7 @@ TUPLE: history back forward ; dup history-forward delete-all dup history-back (add-history) ; -TUPLE: delay model timeout ; +TUPLE: delay model timeout alarm ; : update-delay-model ( delay -- ) dup delay-model model-value swap set-model ; @@ -185,12 +185,18 @@ TUPLE: delay model timeout ; [ set-delay-model ] 2keep [ 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 tick dup remove-timer update-delay-model ; - GENERIC: range-value ( model -- value ) GENERIC: range-page-value ( model -- value ) GENERIC: range-min-value ( model -- value ) diff --git a/extra/timers/authors.txt b/extra/timers/authors.txt deleted file mode 100644 index 1901f27a24..0000000000 --- a/extra/timers/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/extra/timers/summary.txt b/extra/timers/summary.txt deleted file mode 100644 index 2b0c0b053f..0000000000 --- a/extra/timers/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Simple low-resolution timers diff --git a/extra/timers/timers-docs.factor b/extra/timers/timers-docs.factor deleted file mode 100644 index 05a52516ff..0000000000 --- a/extra/timers/timers-docs.factor +++ /dev/null @@ -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" diff --git a/extra/timers/timers.factor b/extra/timers/timers.factor deleted file mode 100644 index e3a510287b..0000000000 --- a/extra/timers/timers.factor +++ /dev/null @@ -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 ; - -: ( 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 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 ; diff --git a/extra/ui/gadgets/gadgets.factor b/extra/ui/gadgets/gadgets.factor index 0ac43af756..37c5684cc9 100755 --- a/extra/ui/gadgets/gadgets.factor +++ b/extra/ui/gadgets/gadgets.factor @@ -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. USING: arrays hashtables kernel models math namespaces sequences -timers quotations math.vectors combinators sorting vectors -dlists models ; +quotations math.vectors combinators sorting vectors dlists +models ; IN: ui.gadgets TUPLE: rect loc dim ; diff --git a/extra/ui/gestures/gestures.factor b/extra/ui/gestures/gestures.factor index 2a3e344a9e..2d3e8f6835 100755 --- a/extra/ui/gestures/gestures.factor +++ b/extra/ui/gestures/gestures.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs kernel math models namespaces 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 : set-gestures ( class hash -- ) "gestures" set-word-prop ; @@ -107,20 +107,19 @@ SYMBOL: double-click-timeout : drag-gesture ( -- ) hand-buttons get-global first button-gesture ; -TUPLE: drag-timer ; +SYMBOL: drag-timer -M: drag-timer tick drop drag-gesture ; - -drag-timer construct-empty drag-timer set-global + drag-timer set-global : start-drag-timer ( -- ) 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 ; : stop-drag-timer ( -- ) hand-buttons get-global empty? [ - drag-timer get-global remove-timer + drag-timer get-global box> cancel-alarm ] when ; : fire-motion ( -- ) diff --git a/extra/ui/tools/listener/listener-tests.factor b/extra/ui/tools/listener/listener-tests.factor index f0516f54b9..0024fa725f 100755 --- a/extra/ui/tools/listener/listener-tests.factor +++ b/extra/ui/tools/listener/listener-tests.factor @@ -1,12 +1,10 @@ USING: continuations documents ui.tools.interactor 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 threads ; IN: temporary -timers [ init-timers ] unless - [ f ] [ "word" source-editor command-map empty? ] unit-test [ ] [ [ ] with-grafted-gadget ] unit-test diff --git a/extra/ui/tools/search/search-tests.factor b/extra/ui/tools/search/search-tests.factor index 47ae786f59..49bd1a3837 100755 --- a/extra/ui/tools/search/search-tests.factor +++ b/extra/ui/tools/search/search-tests.factor @@ -1,11 +1,9 @@ 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 vocabs.loader words tools.test.ui debugger ; IN: temporary -timers get [ init-timers ] unless - [ f ] [ "no such word with this name exists, certainly" f f @@ -16,7 +14,7 @@ timers get [ init-timers ] unless : update-live-search ( search -- seq ) dup [ - 300 sleep do-timers + 300 sleep live-search-list control-value ] with-grafted-gadget ; @@ -33,7 +31,6 @@ timers get [ init-timers ] unless dup [ { "set-word-prop" } over live-search-field set-control-value 300 sleep - do-timers search-value \ set-word-prop eq? ] with-grafted-gadget ] unit-test diff --git a/extra/ui/tools/tools-tests.factor b/extra/ui/tools/tools-tests.factor index 919d1705af..ff2444e43b 100755 --- a/extra/ui/tools/tools-tests.factor +++ b/extra/ui/tools/tools-tests.factor @@ -1,6 +1,6 @@ USING: ui.tools ui.tools.interactor ui.tools.listener 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.scrollers vocabs tools.test.ui ui ; IN: temporary @@ -12,8 +12,6 @@ IN: temporary ] unit-test ] with-scope -timers get [ init-timers ] unless - [ ] [ "w" set ] unit-test [ ] [ "w" get com-scroll-up ] unit-test [ ] [ "w" get com-scroll-down ] unit-test diff --git a/extra/ui/ui-docs.factor b/extra/ui/ui-docs.factor index 7fbd6dbac1..9b3a05e101 100755 --- a/extra/ui/ui-docs.factor +++ b/extra/ui/ui-docs.factor @@ -167,7 +167,7 @@ ARTICLE: "ui-backend-init" "UI initialization and the event loop" { $subsection start-ui } "The " { $link ui } " word must not return until the event loop has stopped and the UI has been shut down." $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" "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-control-impl" } { $subsection "clipboard-protocol" } -{ $subsection "timers" } { $see-also "ui-layout-impl" } ; ARTICLE: "ui" "UI framework" diff --git a/extra/ui/ui.factor b/extra/ui/ui.factor index d5d968c4e6..1de0dac6f0 100755 --- a/extra/ui/ui.factor +++ b/extra/ui/ui.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs io kernel math models namespaces 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 hashtables ; IN: ui @@ -131,8 +131,7 @@ SYMBOL: ui-hook graft-queue [ notify ] dlist-slurp ; : ui-step ( -- ) - [ do-timers notify-queued layout-queued redraw-worlds ] - assert-depth ; + [ notify-queued layout-queued redraw-worlds ] assert-depth ; : open-world-window ( world -- ) dup pref-dim over set-gadget-dim dup relayout graft ui-step ; @@ -156,7 +155,6 @@ M: object close-window find-world [ ungraft ] when* ; : start-ui ( -- ) - init-timers restore-windows? [ restore-windows ] [ diff --git a/extra/ui/windows/windows.factor b/extra/ui/windows/windows.factor index 3a519e49d2..80c03a3f5d 100755 --- a/extra/ui/windows/windows.factor +++ b/extra/ui/windows/windows.factor @@ -5,9 +5,8 @@ ui.backend ui.clipboards ui.gadgets.worlds ui.gestures io kernel math math.vectors namespaces prettyprint sequences strings vectors words windows.kernel32 windows.gdi32 windows.user32 windows.opengl32 windows.messages windows.types windows.nt -windows threads timers libc combinators -continuations command-line shuffle opengl ui.render unicode.case -ascii math.bitfields ; +windows threads libc combinators continuations command-line +shuffle opengl ui.render unicode.case ascii math.bitfields ; IN: ui.windows TUPLE: windows-ui-backend ;