Skip to content

Commit a9e75c6

Browse files
committed
Added positionCallback.
1 parent 18db2d0 commit a9e75c6

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Graphics/UI/GLUT/Callbacks/Registration.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ data CallbackType
4040
| SpaceballButtonCB | ButtonBoxCB | DialsCB
4141
| TabletMotionCB | TabletButtonCB | JoystickCB
4242
| MenuStatusCB | IdleCB
43-
| CloseCB -- freeglut only
44-
| MouseWheelCB -- freeglut only
43+
-- freeglut-only callback types
44+
| CloseCB | MouseWheelCB | PositionCB
4545
deriving ( Eq, Ord )
4646

4747
isGlobal :: CallbackType -> Bool

Graphics/UI/GLUT/Callbacks/Window.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ module Graphics.UI.GLUT.Callbacks.Window (
1717
-- * Reshape callback
1818
ReshapeCallback, reshapeCallback,
1919

20+
-- * Position callback
21+
PositionCallback, positionCallback,
22+
2023
-- * Callbacks for visibility changes
2124
Visibility(..), VisibilityCallback, visibilityCallback,
2225
WindowState(..), WindowStateCallback, windowStateCallback,
@@ -64,8 +67,7 @@ import Data.Bits hiding ( shift )
6467
import Data.Char
6568
import Data.Maybe
6669
import Foreign.C.Types
67-
import Graphics.Rendering.OpenGL ( Position(..), Size(..)
68-
, SettableStateVar, makeSettableStateVar )
70+
import Graphics.Rendering.OpenGL
6971
import Graphics.UI.GLUT.Callbacks.Registration
7072
import Graphics.UI.GLUT.Raw
7173
import Graphics.UI.GLUT.State
@@ -190,6 +192,21 @@ reshapeCallback = makeSettableStateVar $
190192

191193
--------------------------------------------------------------------------------
192194

195+
-- | A position callback
196+
197+
type PositionCallback = Position -> IO ()
198+
199+
-- | (/freeglut only/) Controls the position callback for the /current window./
200+
-- The position callback for a window is called when the position of a window
201+
-- changes.
202+
203+
positionCallback :: SettableStateVar (Maybe PositionCallback)
204+
positionCallback = makeSettableStateVar $
205+
setCallback PositionCB glutPositionFunc (makePositionFunc . unmarshal)
206+
where unmarshal cb x y = cb (Position (fromIntegral x) (fromIntegral y))
207+
208+
--------------------------------------------------------------------------------
209+
193210
-- | The visibility state of the /current window/
194211

195212
data Visibility

Graphics/UI/GLUT/Raw/Callbacks.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module Graphics.UI.GLUT.Raw.Callbacks (
3333
MouseWheelFunc, makeMouseWheelFunc,
3434
OverlayDisplayFunc, makeOverlayDisplayFunc,
3535
PassiveMotionFunc, makePassiveMotionFunc,
36+
PositionFunc, makePositionFunc,
3637
ReshapeFunc, makeReshapeFunc,
3738
SpaceballButtonFunc, makeSpaceballButtonFunc,
3839
SpaceballMotionFunc, makeSpaceballMotionFunc,
@@ -140,6 +141,11 @@ type PassiveMotionFunc = CInt -> CInt -> IO ()
140141
foreign import ccall "wrapper"
141142
makePassiveMotionFunc :: PassiveMotionFunc -> IO (FunPtr PassiveMotionFunc)
142143

144+
type PositionFunc = CInt -> CInt -> IO ()
145+
146+
foreign import ccall "wrapper"
147+
makePositionFunc :: PositionFunc -> IO (FunPtr PositionFunc)
148+
143149
type ReshapeFunc = CInt -> CInt -> IO ()
144150

145151
foreign import ccall "wrapper"

Graphics/UI/GLUT/Raw/Functions.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ module Graphics.UI.GLUT.Raw.Functions (
8787
glutOverlayDisplayFunc,
8888
glutPassiveMotionFunc,
8989
glutPopWindow,
90+
glutPositionFunc,
9091
glutPositionWindow,
9192
glutPostOverlayRedisplay,
9293
glutPostRedisplay,
@@ -248,6 +249,7 @@ API_ENTRY(glutMouseWheelFunc,FunPtr MouseWheelFunc -> IO ())
248249
API_ENTRY(glutOverlayDisplayFunc,FunPtr OverlayDisplayFunc -> IO ())
249250
API_ENTRY(glutPassiveMotionFunc,FunPtr PassiveMotionFunc -> IO ())
250251
API_ENTRY(glutPopWindow,IO ())
252+
API_ENTRY(glutPositionFunc,FunPtr PositionFunc -> IO ())
251253
API_ENTRY(glutPositionWindow,CInt -> CInt -> IO ())
252254
API_ENTRY_SAFE(glutPostOverlayRedisplay,IO ())
253255
API_ENTRY(glutPostRedisplay,IO ())

0 commit comments

Comments
 (0)