bugfix mouse motion handler: handler has been invoked with wrong coordinates, motion handler is now also called while leaving while still mouse-active

This commit is contained in:
tpajenka 2014-05-21 14:03:28 +02:00
parent 8a84e7ba95
commit 03d99c5fcc
2 changed files with 9 additions and 7 deletions

View File

@ -220,7 +220,9 @@ mouseSetLeaving wid px = do
modify $ ui.uiButtonState.mouseInside .~ False modify $ ui.uiButtonState.mouseInside .~ False
case target ^. eventHandlers.(at MouseMotionEvent) of --existing handler? case target ^. eventHandlers.(at MouseMotionEvent) of --existing handler?
Just ma -> do Just ma -> do
target' <- fromJust (ma ^? onMouseLeave) px target --TODO unsafe fromJust target_ <- fromJust (ma ^? onMouseLeave) px target --TODO unsafe fromJust
target' <- if state ^. ui.uiButtonState.mousePressed <= 0 then return target_
else fromJust (ma ^? onMouseMove) px target_ --TODO unsafe fromJust
modify $ ui.uiMap %~ Map.insert wid target' modify $ ui.uiMap %~ Map.insert wid target'
Nothing -> return () Nothing -> return ()
@ -236,7 +238,7 @@ mouseMoveHandler px = do
Left b -> -- no child hit Left b -> -- no child hit
if b == state ^. ui.uiButtonState.mouseInside then -- > moving inside or outside if b == state ^. ui.uiButtonState.mouseInside then -- > moving inside or outside
case target ^. eventHandlers.(at MouseMotionEvent) of --existing handler? case target ^. eventHandlers.(at MouseMotionEvent) of --existing handler?
Just ma -> do target' <- fromJust (ma ^? onMouseMove) px' target Just ma -> do target' <- fromJust (ma ^? onMouseMove) (px -: px') target
modify $ ui.uiMap %~ Map.insert wid target' modify $ ui.uiMap %~ Map.insert wid target'
Nothing -> return () Nothing -> return ()
else if b then -- && not mouseInside --> entering else if b then -- && not mouseInside --> entering

View File

@ -124,7 +124,7 @@ data EventHandler m =
-- The boolean value indicates if the button press happened within the widget -- The boolean value indicates if the button press happened within the widget
-- ('_isInside'). -- ('_isInside').
-- --
-- The function returns the altered widget resulting from the button press -- The function returns the altered widget resulting from the button press.
_onMousePress :: MouseButton -> Pixel -> Bool -> GUIWidget m -> m (GUIWidget m) _onMousePress :: MouseButton -> Pixel -> Bool -> GUIWidget m -> m (GUIWidget m)
, ,
-- |The function 'onMouseReleased' is called when a button is released -- |The function 'onMouseReleased' is called when a button is released
@ -136,7 +136,7 @@ data EventHandler m =
-- The boolean value indicates if the button release happened within the widget -- The boolean value indicates if the button release happened within the widget
-- ('_isInside'). -- ('_isInside').
-- --
-- The function returns the altered widget resulting from the button press -- The function returns the altered widget resulting from the button press.
_onMouseRelease :: MouseButton -> Pixel -> Bool -> GUIWidget m -> m (GUIWidget m) _onMouseRelease :: MouseButton -> Pixel -> Bool -> GUIWidget m -> m (GUIWidget m)
} }
| |
@ -148,9 +148,9 @@ data EventHandler m =
-- |The function 'onMouseMove' is invoked when the mouse is moved inside the -- |The function 'onMouseMove' is invoked when the mouse is moved inside the
-- widgets extent ('isInside') while no button is pressed or when the mouse is inside the -- widgets extent ('isInside') while no button is pressed or when the mouse is inside the
-- widgets extent while another button loses its mouse-active state. Triggered after -- widgets extent while another button loses its mouse-active state. Triggered after
-- '_onMouseEnter'. -- '_onMouseEnter' or '_onMouseLeave' (only if still mouse-active on leaving) if applicable.
-- --
-- The function returns the altered widget resulting from the button press -- The function returns the altered widget resulting from the button press.
_onMouseMove :: Pixel -> GUIWidget m -> m (GUIWidget m) _onMouseMove :: Pixel -> GUIWidget m -> m (GUIWidget m)
, ,
-- |The function 'onMouseMove' is invoked when the mouse enters the -- |The function 'onMouseMove' is invoked when the mouse enters the
@ -163,7 +163,7 @@ data EventHandler m =
-- |The function 'onMouseLeave' is invoked when the mouse leaves the -- |The function 'onMouseLeave' is invoked when the mouse leaves the
-- widgets extent ('isInside') while no other widget is mouse-active. -- widgets extent ('isInside') while no other widget is mouse-active.
-- --
-- The function returns the altered widget resulting from the button press -- The function returns the altered widget resulting from the button press.
_onMouseLeave :: Pixel -> GUIWidget m -> m (GUIWidget m) _onMouseLeave :: Pixel -> GUIWidget m -> m (GUIWidget m)
} }
deriving () deriving ()