From ae27f48d12587311b66dda7fa0d0f941a1dfc666 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 20 Feb 2005 03:55:45 +0000 Subject: [PATCH] minor fix for rollovers --- TODO.FACTOR.txt | 1 - library/ui/buttons.factor | 9 +++++++-- library/ui/gestures.factor | 3 +++ library/ui/world.factor | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 2f668bcd31..a41171fab5 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -26,7 +26,6 @@ - ffi unicode strings: null char security hole - utf16 string boxing - sdl console crash -- UI: don't roll over if mouse button is down - more accurate types for various words - optimize out >array, >tuple, >hashtable etc - write read: write should flush diff --git a/library/ui/buttons.factor b/library/ui/buttons.factor index 2ba8b97e29..a76773f3a9 100644 --- a/library/ui/buttons.factor +++ b/library/ui/buttons.factor @@ -11,12 +11,17 @@ USING: generic kernel lists math namespaces sdl ; : mouse-over? ( gadget -- ? ) my-hand hand-gadget child? ; +: button-rollover? ( button -- ? ) + mouse-over? 1 button-down? not and ; + : rollover-update ( button -- ) - dup mouse-over? blue black ? foreground set-paint-property ; + dup button-rollover? blue black ? foreground set-paint-property ; : button-pressed? ( button -- ? ) + #! Return true if the mouse was clicked on the button, and + #! is currently over the button. dup mouse-over? [ - my-hand hand-buttons 1 swap contains? [ + 1 button-down? [ my-hand hand-clicked child? ] [ drop f diff --git a/library/ui/gestures.factor b/library/ui/gestures.factor index a126c17a3f..0d67c536e7 100644 --- a/library/ui/gestures.factor +++ b/library/ui/gestures.factor @@ -76,3 +76,6 @@ SYMBOL: button-down [ 2dup child? [ gain-focus ] hierarchy-gesture ] each-parent 2drop ; + +: button-down? ( n -- ? ) + my-hand hand-buttons contains? ; diff --git a/library/ui/world.factor b/library/ui/world.factor index f6808947c3..946d8f8411 100644 --- a/library/ui/world.factor +++ b/library/ui/world.factor @@ -47,7 +47,7 @@ DEFER: handle-event #! Keep polling for events until there are no more events in #! the queue; then block for the next event. dup SDL_PollEvent [ - dup handle-event eat-events + [ handle-event ] in-thread eat-events ] [ world get world-step [ SDL_WaitEvent ] [ drop f ] ifte ] ifte ;