Skip to content

Commit 8a6979b

Browse files
committed
Added multi-touch support.
1 parent a9e75c6 commit 8a6979b

File tree

4 files changed

+117
-7
lines changed

4 files changed

+117
-7
lines changed

Graphics/UI/GLUT/Callbacks/Registration.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ data CallbackType
4242
| MenuStatusCB | IdleCB
4343
-- freeglut-only callback types
4444
| CloseCB | MouseWheelCB | PositionCB
45+
| MultiEntryCB | MultiMotionCB | MultiButtonCB
46+
| MultiPassiveCB
4547
deriving ( Eq, Ord )
4648

4749
isGlobal :: CallbackType -> Bool

Graphics/UI/GLUT/Callbacks/Window.hs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ module Graphics.UI.GLUT.Callbacks.Window (
6060

6161
-- * Joystick callback
6262
JoystickButtons(..), JoystickPosition(..),
63-
JoystickCallback, joystickCallback
63+
JoystickCallback, joystickCallback,
64+
65+
-- * Multi-touch support
66+
TouchID,
67+
MultiMouseCallback, multiMouseCallback,
68+
MultiCrossingCallback, multiCrossingCallback,
69+
MultiMotionCallback, multiMotionCallback, multiPassiveMotionCallback
70+
6471
) where
6572

6673
import Data.Bits hiding ( shift )
@@ -294,15 +301,20 @@ windowStateCallback = makeSettableStateVar $
294301

295302
--------------------------------------------------------------------------------
296303

304+
-- | A window close callback
305+
297306
type CloseCallback = IO ()
298307

308+
-- | Controls the window close callback for the /current window/.
309+
299310
closeCallback :: SettableStateVar (Maybe CloseCallback)
300311
closeCallback = makeSettableStateVar $
301312
setCallback CloseCB glutCloseFunc makeCloseFunc
302313

303314
--------------------------------------------------------------------------------
304315

305316
-- | A keyboard callback
317+
306318
type KeyboardCallback = Char -> Position -> IO ()
307319

308320
setKeyboardCallback :: Maybe KeyboardCallback -> IO ()
@@ -313,6 +325,7 @@ setKeyboardCallback =
313325

314326
-- | Controls the keyboard callback for the /current window/. This is
315327
-- activated only when a key is pressed.
328+
316329
keyboardCallback :: SettableStateVar (Maybe KeyboardCallback)
317330
keyboardCallback = makeSettableStateVar setKeyboardCallback
318331

@@ -327,8 +340,10 @@ setKeyboardUpCallback =
327340

328341
-- | Controls the keyboard callback for the /current window/. This is
329342
-- activated only when a key is released.
343+
330344
keyboardUpCallback :: SettableStateVar (Maybe KeyboardCallback)
331345
keyboardUpCallback = makeSettableStateVar setKeyboardUpCallback
346+
332347
--------------------------------------------------------------------------------
333348

334349
-- | Special keys
@@ -406,6 +421,7 @@ unmarshalSpecialKey x
406421
--------------------------------------------------------------------------------
407422

408423
-- | A special key callback
424+
409425
type SpecialCallback = SpecialKey -> Position -> IO ()
410426

411427
setSpecialCallback :: Maybe SpecialCallback -> IO ()
@@ -416,8 +432,10 @@ setSpecialCallback =
416432

417433
-- | Controls the special key callback for the /current window/. This is
418434
-- activated only when a special key is pressed.
435+
419436
specialCallback :: SettableStateVar (Maybe SpecialCallback)
420437
specialCallback = makeSettableStateVar setSpecialCallback
438+
421439
--------------------------------------------------------------------------------
422440

423441
setSpecialUpCallback :: Maybe SpecialCallback -> IO ()
@@ -428,8 +446,10 @@ setSpecialUpCallback =
428446

429447
-- | Controls the special key callback for the /current window/. This is
430448
-- activated only when a special key is released.
449+
431450
specialUpCallback :: SettableStateVar (Maybe SpecialCallback)
432451
specialUpCallback = makeSettableStateVar setSpecialUpCallback
452+
433453
--------------------------------------------------------------------------------
434454

435455
-- | The current state of a key or button
@@ -448,6 +468,7 @@ unmarshalKeyState x
448468
--------------------------------------------------------------------------------
449469

450470
-- | A mouse callback
471+
451472
type MouseCallback = MouseButton -> KeyState -> Position -> IO ()
452473

453474
setMouseCallback :: Maybe MouseCallback -> IO ()
@@ -458,8 +479,10 @@ setMouseCallback =
458479
(Position (fromIntegral x) (fromIntegral y))
459480

460481
-- | Controls the mouse callback for the /current window/.
482+
461483
mouseCallback :: SettableStateVar (Maybe MouseCallback)
462484
mouseCallback = makeSettableStateVar setMouseCallback
485+
463486
--------------------------------------------------------------------------------
464487

465488
-- | The state of the keyboard modifiers
@@ -867,3 +890,56 @@ joystickCallback =
867890
(JoystickPosition (fromIntegral x)
868891
(fromIntegral y)
869892
(fromIntegral z))
893+
894+
--------------------------------------------------------------------------------
895+
896+
-- | A description where the multi-touch event is coming from, the freeglut
897+
-- specs are very vague about the actual semantics. It contains the device ID
898+
-- and\/or the cursor\/finger ID.
899+
900+
type TouchID = Int
901+
902+
-- | A multi-touch variant of 'MouseCallback'.
903+
904+
type MultiMouseCallback = TouchID -> MouseCallback
905+
906+
-- | (/freeglut only/) A multi-touch variant of 'mouseCallback'.
907+
908+
multiMouseCallback :: SettableStateVar (Maybe MultiMouseCallback)
909+
multiMouseCallback = makeSettableStateVar $
910+
setCallback MultiButtonCB glutMultiButtonFunc (makeMultiButtonFunc . unmarshal)
911+
where unmarshal cb d x y b s = cb (fromIntegral d)
912+
(unmarshalMouseButton b)
913+
(unmarshalKeyState s)
914+
(Position (fromIntegral x) (fromIntegral y))
915+
916+
-- | A multi-touch variant of 'CrossingCallback'.
917+
918+
type MultiCrossingCallback = TouchID -> CrossingCallback
919+
920+
-- | (/freeglut only/) A multi-touch variant of 'crossingCallback'.
921+
922+
multiCrossingCallback :: SettableStateVar (Maybe MultiCrossingCallback)
923+
multiCrossingCallback = makeSettableStateVar $
924+
setCallback MultiEntryCB glutMultiEntryFunc (makeMultiEntryFunc . unmarshal)
925+
where unmarshal cb d c = cb (fromIntegral d) (unmarshalCrossing c)
926+
927+
-- | A multi-touch variant of 'MotionCallback'.
928+
929+
type MultiMotionCallback = TouchID -> MotionCallback
930+
931+
-- | (/freeglut only/) A multi-touch variant of 'motionCallback'.
932+
933+
multiMotionCallback :: SettableStateVar (Maybe MultiMotionCallback)
934+
multiMotionCallback = makeSettableStateVar $
935+
setCallback MultiMotionCB glutMultiMotionFunc (makeMultiMotionFunc . unmarshal)
936+
where unmarshal cb d x y =
937+
cb (fromIntegral d) (Position (fromIntegral x) (fromIntegral y))
938+
939+
-- | (/freeglut only/) A multi-touch variant of 'passiveMotionCallback'.
940+
941+
multiPassiveMotionCallback :: SettableStateVar (Maybe MultiMotionCallback)
942+
multiPassiveMotionCallback = makeSettableStateVar $
943+
setCallback MultiPassiveCB glutMultiPassiveFunc (makeMultiPassiveFunc . unmarshal)
944+
where unmarshal cb d x y =
945+
cb (fromIntegral d) (Position (fromIntegral x) (fromIntegral y))

Graphics/UI/GLUT/Raw/Callbacks.hs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
-----------------------------------------------------------------------------
1616

1717
module Graphics.UI.GLUT.Raw.Callbacks (
18-
MenuFunc, makeMenuFunc,
1918
ButtonBoxFunc, makeButtonBoxFunc,
2019
CloseFunc, makeCloseFunc,
2120
DialsFunc, makeDialsFunc,
@@ -26,11 +25,16 @@ module Graphics.UI.GLUT.Raw.Callbacks (
2625
KeyboardFunc, makeKeyboardFunc,
2726
KeyboardUpFunc, makeKeyboardUpFunc,
2827
MenuDestroyFunc, makeMenuDestroyFunc,
28+
MenuFunc, makeMenuFunc,
2929
MenuStateFunc, makeMenuStateFunc,
3030
MenuStatusFunc, makeMenuStatusFunc,
3131
MotionFunc, makeMotionFunc,
3232
MouseFunc, makeMouseFunc,
3333
MouseWheelFunc, makeMouseWheelFunc,
34+
MultiButtonFunc, makeMultiButtonFunc,
35+
MultiEntryFunc, makeMultiEntryFunc,
36+
MultiMotionFunc, makeMultiMotionFunc,
37+
MultiPassiveFunc, makeMultiPassiveFunc,
3438
OverlayDisplayFunc, makeOverlayDisplayFunc,
3539
PassiveMotionFunc, makePassiveMotionFunc,
3640
PositionFunc, makePositionFunc,
@@ -51,11 +55,6 @@ module Graphics.UI.GLUT.Raw.Callbacks (
5155
import Foreign.C.Types
5256
import Foreign.Ptr
5357

54-
type MenuFunc = CInt -> IO ()
55-
56-
foreign import ccall "wrapper"
57-
makeMenuFunc :: MenuFunc -> IO (FunPtr MenuFunc)
58-
5958
type ButtonBoxFunc = CInt -> CInt -> IO ()
6059

6160
foreign import ccall "wrapper"
@@ -106,6 +105,11 @@ type MenuDestroyFunc = IO ()
106105
foreign import ccall "wrapper"
107106
makeMenuDestroyFunc :: MenuDestroyFunc -> IO (FunPtr MenuDestroyFunc)
108107

108+
type MenuFunc = CInt -> IO ()
109+
110+
foreign import ccall "wrapper"
111+
makeMenuFunc :: MenuFunc -> IO (FunPtr MenuFunc)
112+
109113
type MenuStateFunc = CInt -> IO ()
110114

111115
foreign import ccall "wrapper"
@@ -131,6 +135,26 @@ type MouseWheelFunc = CInt -> CInt -> CInt -> CInt -> IO ()
131135
foreign import ccall "wrapper"
132136
makeMouseWheelFunc :: MouseWheelFunc -> IO (FunPtr MouseWheelFunc)
133137

138+
type MultiButtonFunc = CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
139+
140+
foreign import ccall "wrapper"
141+
makeMultiButtonFunc :: MultiButtonFunc -> IO (FunPtr MultiButtonFunc)
142+
143+
type MultiEntryFunc = CInt -> CInt -> IO ()
144+
145+
foreign import ccall "wrapper"
146+
makeMultiEntryFunc :: MultiEntryFunc -> IO (FunPtr MultiEntryFunc)
147+
148+
type MultiMotionFunc = CInt -> CInt -> CInt -> IO ()
149+
150+
foreign import ccall "wrapper"
151+
makeMultiMotionFunc :: MultiMotionFunc -> IO (FunPtr MultiMotionFunc)
152+
153+
type MultiPassiveFunc = CInt -> CInt -> CInt -> IO ()
154+
155+
foreign import ccall "wrapper"
156+
makeMultiPassiveFunc :: MultiPassiveFunc -> IO (FunPtr MultiPassiveFunc)
157+
134158
type OverlayDisplayFunc = IO ()
135159

136160
foreign import ccall "wrapper"

Graphics/UI/GLUT/Raw/Functions.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ module Graphics.UI.GLUT.Raw.Functions (
8484
glutMotionFunc,
8585
glutMouseFunc,
8686
glutMouseWheelFunc,
87+
glutMultiButtonFunc,
88+
glutMultiEntryFunc,
89+
glutMultiMotionFunc,
90+
glutMultiPassiveFunc,
8791
glutOverlayDisplayFunc,
8892
glutPassiveMotionFunc,
8993
glutPopWindow,
@@ -246,6 +250,10 @@ API_ENTRY(glutMenuStatusFunc,FunPtr MenuStatusFunc -> IO ())
246250
API_ENTRY(glutMotionFunc,FunPtr MotionFunc -> IO ())
247251
API_ENTRY(glutMouseFunc,FunPtr MouseFunc -> IO ())
248252
API_ENTRY(glutMouseWheelFunc,FunPtr MouseWheelFunc -> IO ())
253+
API_ENTRY(glutMultiButtonFunc,FunPtr MultiButtonFunc -> IO ())
254+
API_ENTRY(glutMultiEntryFunc,FunPtr MultiEntryFunc -> IO ())
255+
API_ENTRY(glutMultiMotionFunc,FunPtr MultiMotionFunc -> IO ())
256+
API_ENTRY(glutMultiPassiveFunc,FunPtr MultiPassiveFunc -> IO ())
249257
API_ENTRY(glutOverlayDisplayFunc,FunPtr OverlayDisplayFunc -> IO ())
250258
API_ENTRY(glutPassiveMotionFunc,FunPtr PassiveMotionFunc -> IO ())
251259
API_ENTRY(glutPopWindow,IO ())

0 commit comments

Comments
 (0)