Skip to content

Commit 7f8d4b0

Browse files
committed
Introduce an internal Point type
This reverts changes made to remove Point.
1 parent 3f3a1a9 commit 7f8d4b0

File tree

5 files changed

+46
-41
lines changed

5 files changed

+46
-41
lines changed

src/SDL/Event.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ data WindowExposedEventData =
169169
data WindowMovedEventData =
170170
WindowMovedEventData {windowMovedEventWindow :: Window
171171
-- ^ The associated 'Window'.
172-
,windowMovedEventPosition :: V2 Int32
172+
,windowMovedEventPosition :: Point V2 Int32
173173
-- ^ The new position of the 'Window'.
174174
}
175175
deriving (Eq,Ord,Generic,Show,Typeable)
@@ -289,7 +289,7 @@ data MouseMotionEventData =
289289
-- ^ The 'MouseDevice' that was moved.
290290
,mouseMotionEventState :: [MouseButton]
291291
-- ^ A collection of 'MouseButton's that are currently held down.
292-
,mouseMotionEventPos :: V2 Int32
292+
,mouseMotionEventPos :: Point V2 Int32
293293
-- ^ The new position of the mouse.
294294
,mouseMotionEventRelMotion :: V2 Int32
295295
-- ^ The relative mouse motion of the mouse.
@@ -308,7 +308,7 @@ data MouseButtonEventData =
308308
-- ^ The button that was pressed or released.
309309
,mouseButtonEventClicks :: Word8
310310
-- ^ The amount of clicks. 1 for a single-click, 2 for a double-click, etc.
311-
,mouseButtonEventPos :: V2 Int32
311+
,mouseButtonEventPos :: Point V2 Int32
312312
-- ^ The coordinates of the mouse click.
313313
}
314314
deriving (Eq,Ord,Generic,Show,Typeable)
@@ -428,7 +428,7 @@ data TouchFingerEventData =
428428
-- ^ The touch device index.
429429
,touchFingerEventFingerID :: Raw.FingerID
430430
-- ^ The finger index.
431-
,touchFingerEventPos :: V2 CFloat
431+
,touchFingerEventPos :: Point V2 CFloat
432432
-- ^ The location of the touch event, normalized between 0 and 1.
433433
,touchFingerEventRelMotion :: V2 CFloat
434434
-- ^ The distance moved, normalized between -1 and 1.
@@ -445,7 +445,7 @@ data MultiGestureEventData =
445445
-- ^ The amount that the fingers rotated during this motion.
446446
,multiGestureEventDDist :: CFloat
447447
-- ^ The amount that the fingers pinched during this motion.
448-
,multiGestureEventPos :: V2 CFloat
448+
,multiGestureEventPos :: Point V2 CFloat
449449
-- ^ The normalized center of the gesture.
450450
,multiGestureEventNumFingers :: Word16
451451
-- ^ The number of fingers used in this gesture.
@@ -462,7 +462,7 @@ data DollarGestureEventData =
462462
-- ^ The number of fingers used to draw the stroke.
463463
,dollarGestureEventError :: CFloat
464464
-- ^ The difference between the gesture template and the actual performed gesture (lower errors correspond to closer matches).
465-
,dollarGestureEventPos :: V2 CFloat
465+
,dollarGestureEventPos :: Point V2 CFloat
466466
-- ^ The normalized center of the gesture.
467467
}
468468
deriving (Eq,Ord,Generic,Show,Typeable)
@@ -513,7 +513,7 @@ convertRaw (Raw.WindowEvent t ts a b c d) =
513513
Raw.SDL_WINDOWEVENT_MOVED ->
514514
WindowMovedEvent
515515
(WindowMovedEventData w'
516-
((V2 c d)))
516+
(P (V2 c d)))
517517
Raw.SDL_WINDOWEVENT_RESIZED ->
518518
WindowResizedEvent
519519
(WindowResizedEventData w'
@@ -582,7 +582,7 @@ convertRaw (Raw.MouseMotionEvent _ ts a b c d e f g) =
582582
(MouseMotionEventData w'
583583
(fromNumber b)
584584
buttons
585-
((V2 d e))
585+
(P (V2 d e))
586586
(V2 f g))))
587587
where mask `test` x =
588588
if mask .&. x /= 0
@@ -608,7 +608,7 @@ convertRaw (Raw.MouseButtonEvent t ts a b c _ e f g) =
608608
(fromNumber b)
609609
button
610610
e
611-
((V2 f g)))))
611+
(P (V2 f g)))))
612612
convertRaw (Raw.MouseWheelEvent _ ts a b c d) =
613613
do w' <- fmap Window (Raw.getWindowFromID a)
614614
return (Event ts
@@ -648,7 +648,7 @@ convertRaw (Raw.TouchFingerEvent _ ts a b c d e f g) =
648648
(TouchFingerEvent
649649
(TouchFingerEventData a
650650
b
651-
((V2 c d))
651+
(P (V2 c d))
652652
(V2 e f)
653653
g)))
654654
convertRaw (Raw.MultiGestureEvent _ ts a b c d e f) =
@@ -657,7 +657,7 @@ convertRaw (Raw.MultiGestureEvent _ ts a b c d e f) =
657657
(MultiGestureEventData a
658658
b
659659
c
660-
((V2 d e))
660+
(P (V2 d e))
661661
f)))
662662
convertRaw (Raw.DollarGestureEvent _ ts a b c d e f) =
663663
return (Event ts
@@ -666,7 +666,7 @@ convertRaw (Raw.DollarGestureEvent _ ts a b c d e f) =
666666
b
667667
c
668668
d
669-
((V2 e f)))))
669+
(P (V2 e f)))))
670670
convertRaw (Raw.DropEvent _ ts a) =
671671
return (Event ts (DropEvent (DropEventData a)))
672672
convertRaw (Raw.ClipboardUpdateEvent _ ts) =

src/SDL/Input/Mouse.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ getMouseLocationMode = do
8484
return $ if relativeMode then RelativeLocation else AbsoluteLocation
8585

8686
-- | Return proper mouse location depending on mouse mode
87-
getModalMouseLocation :: MonadIO m => m (LocationMode, V2 CInt)
87+
getModalMouseLocation :: MonadIO m => m (LocationMode, Point V2 CInt)
8888
getModalMouseLocation = do
8989
mode <- getMouseLocationMode
9090
location <- case mode of
@@ -105,7 +105,7 @@ getRelativeMouseMode :: MonadIO m => m Bool
105105
getRelativeMouseMode = Raw.getRelativeMouseMode
106106

107107
--deprecated
108-
getMouseLocation :: MonadIO m => m (V2 CInt)
108+
getMouseLocation :: MonadIO m => m (Point V2 CInt)
109109
{-# DEPRECATED getMouseLocation "Use getAbsoluteMouseLocation instead, or getModalMouseLocation to match future behavior." #-}
110110
getMouseLocation = getAbsoluteMouseLocation
111111

@@ -138,9 +138,9 @@ data WarpMouseOrigin
138138
deriving (Data, Eq, Generic, Ord, Show, Typeable)
139139

140140
-- | Move the current location of a mouse pointer. The 'WarpMouseOrigin' specifies the origin for the given warp coordinates.
141-
warpMouse :: MonadIO m => WarpMouseOrigin -> V2 CInt -> m ()
142-
warpMouse (WarpInWindow (Window w)) ((V2 x y)) = Raw.warpMouseInWindow w x y
143-
warpMouse WarpCurrentFocus ((V2 x y)) = Raw.warpMouseInWindow nullPtr x y
141+
warpMouse :: MonadIO m => WarpMouseOrigin -> Point V2 CInt -> m ()
142+
warpMouse (WarpInWindow (Window w)) (P (V2 x y)) = Raw.warpMouseInWindow w x y
143+
warpMouse WarpCurrentFocus (P (V2 x y)) = Raw.warpMouseInWindow nullPtr x y
144144

145145
-- | Get or set whether the cursor is currently visible.
146146
--
@@ -159,20 +159,20 @@ cursorVisible = makeStateVar getCursorVisible setCursorVisible
159159
getCursorVisible = (== 1) <$> Raw.showCursor (-1)
160160

161161
-- | Retrieve the current location of the mouse, relative to the currently focused window.
162-
getAbsoluteMouseLocation :: MonadIO m => m (V2 CInt)
162+
getAbsoluteMouseLocation :: MonadIO m => m (Point V2 CInt)
163163
getAbsoluteMouseLocation = liftIO $
164164
alloca $ \x ->
165165
alloca $ \y -> do
166166
_ <- Raw.getMouseState x y -- We don't deal with button states here
167-
(V2 <$> peek x <*> peek y)
167+
P <$> (V2 <$> peek x <*> peek y)
168168

169169
-- | Retrieve mouse motion
170-
getRelativeMouseLocation :: MonadIO m => m (V2 CInt)
170+
getRelativeMouseLocation :: MonadIO m => m (Point V2 CInt)
171171
getRelativeMouseLocation = liftIO $
172172
alloca $ \x ->
173173
alloca $ \y -> do
174174
_ <- Raw.getRelativeMouseState x y
175-
(V2 <$> peek x <*> peek y)
175+
P <$> (V2 <$> peek x <*> peek y)
176176

177177

178178
-- | Retrieve a mapping of which buttons are currently held down.
@@ -216,9 +216,9 @@ createCursor :: MonadIO m
216216
=> V.Vector Bool -- ^ Whether this part of the cursor is black. Use 'False' for white and 'True' for black.
217217
-> V.Vector Bool -- ^ Whether or not pixels are visible. Use 'True' for visible and 'False' for transparent.
218218
-> V2 CInt -- ^ The width and height of the cursor.
219-
-> V2 CInt -- ^ The X- and Y-axis location of the upper left corner of the cursor relative to the actual mouse position
219+
-> Point V2 CInt -- ^ The X- and Y-axis location of the upper left corner of the cursor relative to the actual mouse position
220220
-> m Cursor
221-
createCursor dta msk (V2 w h) ((V2 hx hy)) =
221+
createCursor dta msk (V2 w h) (P (V2 hx hy)) =
222222
liftIO . fmap Cursor $
223223
throwIfNull "SDL.Input.Mouse.createCursor" "SDL_createCursor" $
224224
V.unsafeWith (V.map (bool 0 1) dta) $ \unsafeDta ->
@@ -236,9 +236,9 @@ freeCursor = Raw.freeCursor . unwrapCursor
236236
-- See @<https://wiki.libsdl.org/SDL_CreateColorCursor SDL_CreateColorCursor>@ for C documentation.
237237
createColorCursor :: MonadIO m
238238
=> Surface
239-
-> V2 CInt -- ^ The location of the cursor hot spot
239+
-> Point V2 CInt -- ^ The location of the cursor hot spot
240240
-> m Cursor
241-
createColorCursor (Surface surfPtr _) ((V2 hx hy)) =
241+
createColorCursor (Surface surfPtr _) (P (V2 hx hy)) =
242242
liftIO . fmap Cursor $
243243
throwIfNull "SDL.Input.Mouse.createColorCursor" "SDL_createColorCursor" $
244244
Raw.createColorCursor surfPtr hx hy

src/SDL/Internal/Vect.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
23
module SDL.Internal.Vect
34
( V2(..)
45
, V3(..)
56
, V4(..)
7+
, Point(..)
68
) where
79

810
-- Copied from the 'linear' package by Edward Kmett.
@@ -11,6 +13,9 @@ import Control.Applicative (liftA2)
1113
import Foreign.Storable
1214
import Foreign.Ptr (castPtr)
1315

16+
newtype Point f a = P (f a)
17+
deriving (Show, Read, Ord, Eq, Functor, Applicative, Num, Storable)
18+
1419
data V2 a = V2 !a !a
1520
deriving (Show, Read, Ord, Eq)
1621

src/SDL/Video.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ createWindow title config = liftIO $ do
113113
let create' (V2 w h) = case windowPosition config of
114114
Centered -> let u = Raw.SDL_WINDOWPOS_CENTERED in create u u w h
115115
Wherever -> let u = Raw.SDL_WINDOWPOS_UNDEFINED in create u u w h
116-
Absolute ((V2 x y)) -> create x y w h
116+
Absolute (P (V2 x y)) -> create x y w h
117117
create' (windowInitialSize config) flags >>= return . Window
118118
where
119119
flags = foldr (.|.) 0
@@ -216,7 +216,7 @@ instance FromNumber WindowMode Word32 where
216216
data WindowPosition
217217
= Centered
218218
| Wherever -- ^ Let the window mananger decide where it's best to place the window.
219-
| Absolute (V2 CInt)
219+
| Absolute (Point V2 CInt)
220220
deriving (Eq, Generic, Ord, Read, Show, Typeable)
221221

222222
-- | Destroy the given window. The 'Window' handler may not be used
@@ -276,7 +276,7 @@ setWindowPosition :: MonadIO m => Window -> WindowPosition -> m ()
276276
setWindowPosition (Window w) pos = case pos of
277277
Centered -> let u = Raw.SDL_WINDOWPOS_CENTERED in Raw.setWindowPosition w u u
278278
Wherever -> let u = Raw.SDL_WINDOWPOS_UNDEFINED in Raw.setWindowPosition w u u
279-
Absolute ((V2 x y)) -> Raw.setWindowPosition w x y
279+
Absolute (P (V2 x y)) -> Raw.setWindowPosition w x y
280280

281281
-- | Get the position of the window.
282282
getWindowAbsolutePosition :: MonadIO m => Window -> m (V2 CInt)
@@ -351,7 +351,7 @@ getWindowConfig (Window w) = do
351351
, windowMode = fromNumber wFlags
352352
-- Should we store the openGL config that was used to create the window?
353353
, windowOpenGL = Nothing
354-
, windowPosition = Absolute (wPos)
354+
, windowPosition = Absolute (P wPos)
355355
, windowResizable = wFlags .&. Raw.SDL_WINDOW_RESIZABLE > 0
356356
, windowInitialSize = wSize
357357
}
@@ -450,7 +450,7 @@ windowGammaRamp (Window w) = makeStateVar getWindowGammaRamp setWindowGammaRamp
450450

451451
data Display = Display {
452452
displayName :: String
453-
, displayBoundsPosition :: V2 CInt
453+
, displayBoundsPosition :: Point V2 CInt
454454
-- ^ Position of the desktop area represented by the display,
455455
-- with the primary display located at @(0, 0)@.
456456
, displayBoundsSize :: V2 CInt
@@ -505,7 +505,7 @@ getDisplays = liftIO $ do
505505

506506
return $ Display {
507507
displayName = name'
508-
, displayBoundsPosition = (V2 x y)
508+
, displayBoundsPosition = P (V2 x y)
509509
, displayBoundsSize = V2 w h
510510
, displayModes = modes
511511
}

src/SDL/Video/Renderer.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ surfaceBlit :: MonadIO m
152152
=> Surface -- ^ The 'Surface' to be copied from
153153
-> Maybe (Rectangle CInt) -- ^ The rectangle to be copied, or 'Nothing' to copy the entire surface
154154
-> Surface -- ^ The 'Surface' that is the blit target
155-
-> Maybe (V2 CInt) -- ^ The position to blit to
155+
-> Maybe (Point V2 CInt) -- ^ The position to blit to
156156
-> m ()
157157
surfaceBlit (Surface src _) srcRect (Surface dst _) dstLoc = liftIO $
158158
throwIfNeg_ "SDL.Video.blitSurface" "SDL_BlitSurface" $
@@ -549,7 +549,7 @@ instance ToNumber BlendMode Word32 where
549549
toNumber BlendAdditive = Raw.SDL_BLENDMODE_ADD
550550
toNumber BlendMod = Raw.SDL_BLENDMODE_MOD
551551

552-
data Rectangle a = Rectangle (V2 a) (V2 a)
552+
data Rectangle a = Rectangle (Point V2 a) (V2 a)
553553
deriving (Eq, Functor, Generic, Ord, Read, Show, Typeable)
554554

555555
instance Storable a => Storable (Rectangle a) where
@@ -721,7 +721,7 @@ copyEx :: MonadIO m
721721
-> Maybe (Rectangle CInt) -- ^ The source rectangle to copy, or 'Nothing' for the whole texture
722722
-> Maybe (Rectangle CInt) -- ^ The destination rectangle to copy to, or 'Nothing' for the whole rendering target. The texture will be stretched to fill the given rectangle.
723723
-> CDouble -- ^ An angle in degrees that indicates the point around which the destination rectangle will be rotated.
724-
-> Maybe (V2 CInt) -- ^ The point of rotation
724+
-> Maybe (Point V2 CInt) -- ^ The point of rotation
725725
-> V2 Bool -- ^ Whether to flip in the X or Y axis.
726726
-> m () -- ^ Whether to flip in the X or Y axis.
727727
copyEx (Renderer r) (Texture t) srcRect dstRect theta center flips =
@@ -740,10 +740,10 @@ copyEx (Renderer r) (Texture t) srcRect dstRect theta center flips =
740740
-- See @<https://wiki.libsdl.org/SDL_RenderDrawLine SDL_RenderDrawLine>@ for C documentation.
741741
drawLine :: (Functor m,MonadIO m)
742742
=> Renderer
743-
-> V2 CInt -- ^ The start point of the line
744-
-> V2 CInt -- ^ The end point of the line
743+
-> Point V2 CInt -- ^ The start point of the line
744+
-> Point V2 CInt -- ^ The end point of the line
745745
-> m ()
746-
drawLine (Renderer r) ((V2 x y)) ((V2 x' y')) =
746+
drawLine (Renderer r) (P (V2 x y)) (P (V2 x' y')) =
747747
throwIfNeg_ "SDL.Video.drawLine" "SDL_RenderDrawLine" $
748748
Raw.renderDrawLine r x y x' y'
749749

@@ -752,7 +752,7 @@ drawLine (Renderer r) ((V2 x y)) ((V2 x' y')) =
752752
-- See @<https://wiki.libsdl.org/SDL_RenderDrawLines SDL_RenderDrawLines>@ for C documentation.
753753
drawLines :: MonadIO m
754754
=> Renderer
755-
-> SV.Vector (V2 CInt) -- ^ A 'SV.Vector' of points along the line. SDL will draw lines between these points.
755+
-> SV.Vector (Point V2 CInt) -- ^ A 'SV.Vector' of points along the line. SDL will draw lines between these points.
756756
-> m ()
757757
drawLines (Renderer r) points =
758758
liftIO $
@@ -765,15 +765,15 @@ drawLines (Renderer r) points =
765765
-- | Draw a point on the current rendering target.
766766
--
767767
-- See @<https://wiki.libsdl.org/SDL_RenderDrawPoint SDL_RenderDrawPoint>@ for C documentation.
768-
drawPoint :: (Functor m, MonadIO m) => Renderer -> V2 CInt -> m ()
769-
drawPoint (Renderer r) (V2 x y) =
768+
drawPoint :: (Functor m, MonadIO m) => Renderer -> Point V2 CInt -> m ()
769+
drawPoint (Renderer r) (P (V2 x y)) =
770770
throwIfNeg_ "SDL.Video.drawPoint" "SDL_RenderDrawPoint" $
771771
Raw.renderDrawPoint r x y
772772

773773
-- | Draw multiple points on the current rendering target.
774774
--
775775
-- See @<https://wiki.libsdl.org/SDL_RenderDrawPoints SDL_RenderDrawPoints>@ for C documentation.
776-
drawPoints :: MonadIO m => Renderer -> SV.Vector (V2 CInt) -> m ()
776+
drawPoints :: MonadIO m => Renderer -> SV.Vector (Point V2 CInt) -> m ()
777777
drawPoints (Renderer r) points =
778778
liftIO $
779779
throwIfNeg_ "SDL.Video.drawPoints" "SDL_RenderDrawPoints" $

0 commit comments

Comments
 (0)