Skip to content

Commit ebc76d8

Browse files
committed
Added appStatusCallback.
1 parent 63f95bc commit ebc76d8

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

Graphics/UI/GLUT/Callbacks/Registration.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ data CallbackType
4343
-- freeglut-only callback types
4444
| CloseCB | MouseWheelCB | PositionCB
4545
| MultiEntryCB | MultiMotionCB | MultiButtonCB
46-
| MultiPassiveCB | InitContextCB
46+
| MultiPassiveCB | InitContextCB | AppStatusCB
4747
deriving ( Eq, Ord )
4848

4949
isGlobal :: CallbackType -> Bool

Graphics/UI/GLUT/Callbacks/Window.hs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ module Graphics.UI.GLUT.Callbacks.Window (
2727
-- * Window close callback
2828
CloseCallback, closeCallback,
2929

30-
-- * Initialize context callback
30+
-- * Life cycle callbacks for mobile platforms
3131
InitContextCallback, initContextCallback,
32+
AppStatus(..), AppStatusCallback, appStatusCallback,
3233

3334
-- * Keyboard callback
3435
KeyboardCallback, keyboardCallback, keyboardUpCallback,
@@ -329,6 +330,35 @@ initContextCallback = makeSettableStateVar $
329330

330331
--------------------------------------------------------------------------------
331332

333+
-- | The application status of the /current window/
334+
335+
data AppStatus
336+
= AppStatusPause
337+
| AppStatusResume
338+
deriving ( Eq, Ord, Show )
339+
340+
unmarshalAppStatus :: CInt -> AppStatus
341+
unmarshalAppStatus x
342+
| x == glut_APPSTATUS_PAUSE = AppStatusPause
343+
| x == glut_APPSTATUS_RESUME = AppStatusResume
344+
| otherwise = error ("unmarshalAppStatus: illegal value " ++ show x)
345+
346+
--------------------------------------------------------------------------------
347+
348+
-- | An application status callback
349+
350+
type AppStatusCallback = AppStatus -> IO ()
351+
352+
-- | Controls the application status callback for the /current window./
353+
354+
appStatusCallback :: SettableStateVar (Maybe AppStatusCallback)
355+
appStatusCallback = makeSettableStateVar $
356+
setCallback AppStatusCB glutAppStatusFunc
357+
(makeAppStatusFunc . unmarshal)
358+
where unmarshal cb = cb . unmarshalAppStatus
359+
360+
--------------------------------------------------------------------------------
361+
332362
-- | A keyboard callback
333363

334364
type KeyboardCallback = Char -> Position -> IO ()

Graphics/UI/GLUT/Raw/Callbacks.hs

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

1717
module Graphics.UI.GLUT.Raw.Callbacks (
18+
AppStatusFunc, makeAppStatusFunc,
1819
ButtonBoxFunc, makeButtonBoxFunc,
1920
CloseFunc, makeCloseFunc,
2021
DialsFunc, makeDialsFunc,
@@ -56,6 +57,11 @@ module Graphics.UI.GLUT.Raw.Callbacks (
5657
import Foreign.C.Types
5758
import Foreign.Ptr
5859

60+
type AppStatusFunc = CInt -> IO ()
61+
62+
foreign import ccall "wrapper"
63+
makeAppStatusFunc :: AppStatusFunc -> IO (FunPtr AppStatusFunc)
64+
5965
type ButtonBoxFunc = CInt -> CInt -> IO ()
6066

6167
foreign import ccall "wrapper"

Graphics/UI/GLUT/Raw/Functions.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
module Graphics.UI.GLUT.Raw.Functions (
1818
glutAddMenuEntry,
1919
glutAddSubMenu,
20+
glutAppStatusFunc,
2021
glutAttachMenu,
2122
glutBitmapCharacter,
2223
glutBitmapHeight,
@@ -184,6 +185,7 @@ import Graphics.UI.GLUT.Raw.Callbacks
184185

185186
API_ENTRY(glutAddMenuEntry,Ptr CChar -> CInt -> IO ())
186187
API_ENTRY(glutAddSubMenu,Ptr CChar -> CInt -> IO ())
188+
API_ENTRY(glutAppStatusFunc,FunPtr AppStatusFunc -> IO ())
187189
API_ENTRY(glutAttachMenu,CInt -> IO ())
188190
API_ENTRY(glutBitmapCharacter,Ptr a -> CInt -> IO ())
189191
API_ENTRY(glutBitmapHeight,Ptr a -> IO CInt)

Graphics/UI/GLUT/Raw/Tokens.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ glut_ALLOW_DIRECT_CONTEXT = 1
4848
glut_ALPHA :: CUInt
4949
glut_ALPHA = 0x0008
5050

51+
glut_APPSTATUS_PAUSE :: CInt
52+
glut_APPSTATUS_PAUSE = 0x0001
53+
54+
glut_APPSTATUS_RESUME :: CInt
55+
glut_APPSTATUS_RESUME = 0x0002
56+
5157
glut_AUX :: GLenum
5258
glut_AUX = 0x1000
5359

0 commit comments

Comments
 (0)