diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index a3cacfaf9a..40e8d2dda4 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -8,10 +8,8 @@ - fix up the min thumb size hack - scroll bar: more intuitive behavior when clicking inside the elevator - nicer scrollbars with up/down buttons -- clicking outside menu doesn't close - only redraw dirty gadgets - faster mouse tracking -- better menu positioning - off-by-one error in pick-up? - closing ui does not stop timers diff --git a/library/ui/menus.factor b/library/ui/menus.factor index 7801b293c1..b652465389 100644 --- a/library/ui/menus.factor +++ b/library/ui/menus.factor @@ -3,8 +3,20 @@ IN: gadgets USING: generic kernel lists math namespaces sequences ; +: menu-actions ( glass -- ) + [ drop hide-glass ] [ button-down 1 ] set-action ; + +: fit-bounds ( loc dim max -- loc ) + #! Adjust loc to fit inside max. + swap v- { 0 0 0 } vmax vmin ; + +: menu-loc ( menu -- loc ) + hand rect-loc swap rect-dim world get rect-dim fit-bounds ; + : show-menu ( menu -- ) - hand screen-loc over set-rect-loc show-glass ; + dup show-glass + dup menu-loc swap set-rect-loc + world get world-glass menu-actions ; : menu-items ( assoc -- pile ) #! Given an association list mapping labels to quotations. diff --git a/library/ui/world.factor b/library/ui/world.factor index 153c2f58d1..59994f971a 100644 --- a/library/ui/world.factor +++ b/library/ui/world.factor @@ -38,8 +38,7 @@ C: world ( -- world ) : show-glass ( gadget -- ) hide-glass - dup - world get 2dup add-gadget set-world-glass + dup add-layer dup world get set-world-glass dupd add-gadget prefer ; : draw-world ( world -- ) @@ -54,8 +53,7 @@ DEFER: handle-event world get dup world-invalid >r layout-world r> [ dup world-hand update-hand draw-world ] [ drop ] ifte ; -: next-event ( -- event ? ) - dup SDL_PollEvent ; +: next-event ( -- event ? ) dup SDL_PollEvent ; : run-world ( -- ) #! Keep polling for events until there are no more events in