From 03d99c5fcc9755dfae60aa04032a2aeba246c1fb Mon Sep 17 00:00:00 2001 From: tpajenka Date: Wed, 21 May 2014 14:03:28 +0200 Subject: [PATCH] bugfix mouse motion handler: handler has been invoked with wrong coordinates, motion handler is now also called while leaving while still mouse-active --- src/UI/Callbacks.hs | 6 ++++-- src/UI/UIBase.hs | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/UI/Callbacks.hs b/src/UI/Callbacks.hs index 4231b33..4008e02 100644 --- a/src/UI/Callbacks.hs +++ b/src/UI/Callbacks.hs @@ -220,7 +220,9 @@ mouseSetLeaving wid px = do modify $ ui.uiButtonState.mouseInside .~ False case target ^. eventHandlers.(at MouseMotionEvent) of --existing handler? 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' Nothing -> return () @@ -236,7 +238,7 @@ mouseMoveHandler px = do Left b -> -- no child hit if b == state ^. ui.uiButtonState.mouseInside then -- > moving inside or outside 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' Nothing -> return () else if b then -- && not mouseInside --> entering diff --git a/src/UI/UIBase.hs b/src/UI/UIBase.hs index efa3167..5424900 100644 --- a/src/UI/UIBase.hs +++ b/src/UI/UIBase.hs @@ -124,7 +124,7 @@ data EventHandler m = -- The boolean value indicates if the button press happened within the widget -- ('_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) , -- |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 -- ('_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) } | @@ -148,9 +148,9 @@ data EventHandler m = -- |The function 'onMouseMove' is invoked when the mouse is moved inside the -- widget’s extent ('isInside') while no button is pressed or when the mouse is inside the -- widget’s 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) , -- |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 -- widget’s 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) } deriving ()