Skip to content

Commit

Permalink
Added appStatusCallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
svenpanne committed Jan 29, 2014
1 parent 63f95bc commit ebc76d8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Graphics/UI/GLUT/Callbacks/Registration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data CallbackType
-- freeglut-only callback types
| CloseCB | MouseWheelCB | PositionCB
| MultiEntryCB | MultiMotionCB | MultiButtonCB
| MultiPassiveCB | InitContextCB
| MultiPassiveCB | InitContextCB | AppStatusCB
deriving ( Eq, Ord )

isGlobal :: CallbackType -> Bool
Expand Down
32 changes: 31 additions & 1 deletion Graphics/UI/GLUT/Callbacks/Window.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module Graphics.UI.GLUT.Callbacks.Window (
-- * Window close callback
CloseCallback, closeCallback,

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

-- * Keyboard callback
KeyboardCallback, keyboardCallback, keyboardUpCallback,
Expand Down Expand Up @@ -329,6 +330,35 @@ initContextCallback = makeSettableStateVar $

--------------------------------------------------------------------------------

-- | The application status of the /current window/

data AppStatus
= AppStatusPause
| AppStatusResume
deriving ( Eq, Ord, Show )

unmarshalAppStatus :: CInt -> AppStatus
unmarshalAppStatus x
| x == glut_APPSTATUS_PAUSE = AppStatusPause
| x == glut_APPSTATUS_RESUME = AppStatusResume
| otherwise = error ("unmarshalAppStatus: illegal value " ++ show x)

--------------------------------------------------------------------------------

-- | An application status callback

type AppStatusCallback = AppStatus -> IO ()

-- | Controls the application status callback for the /current window./

appStatusCallback :: SettableStateVar (Maybe AppStatusCallback)
appStatusCallback = makeSettableStateVar $
setCallback AppStatusCB glutAppStatusFunc
(makeAppStatusFunc . unmarshal)
where unmarshal cb = cb . unmarshalAppStatus

--------------------------------------------------------------------------------

-- | A keyboard callback

type KeyboardCallback = Char -> Position -> IO ()
Expand Down
6 changes: 6 additions & 0 deletions Graphics/UI/GLUT/Raw/Callbacks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-----------------------------------------------------------------------------

module Graphics.UI.GLUT.Raw.Callbacks (
AppStatusFunc, makeAppStatusFunc,
ButtonBoxFunc, makeButtonBoxFunc,
CloseFunc, makeCloseFunc,
DialsFunc, makeDialsFunc,
Expand Down Expand Up @@ -56,6 +57,11 @@ module Graphics.UI.GLUT.Raw.Callbacks (
import Foreign.C.Types
import Foreign.Ptr

type AppStatusFunc = CInt -> IO ()

foreign import ccall "wrapper"
makeAppStatusFunc :: AppStatusFunc -> IO (FunPtr AppStatusFunc)

type ButtonBoxFunc = CInt -> CInt -> IO ()

foreign import ccall "wrapper"
Expand Down
2 changes: 2 additions & 0 deletions Graphics/UI/GLUT/Raw/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
module Graphics.UI.GLUT.Raw.Functions (
glutAddMenuEntry,
glutAddSubMenu,
glutAppStatusFunc,
glutAttachMenu,
glutBitmapCharacter,
glutBitmapHeight,
Expand Down Expand Up @@ -184,6 +185,7 @@ import Graphics.UI.GLUT.Raw.Callbacks

API_ENTRY(glutAddMenuEntry,Ptr CChar -> CInt -> IO ())
API_ENTRY(glutAddSubMenu,Ptr CChar -> CInt -> IO ())
API_ENTRY(glutAppStatusFunc,FunPtr AppStatusFunc -> IO ())
API_ENTRY(glutAttachMenu,CInt -> IO ())
API_ENTRY(glutBitmapCharacter,Ptr a -> CInt -> IO ())
API_ENTRY(glutBitmapHeight,Ptr a -> IO CInt)
Expand Down
6 changes: 6 additions & 0 deletions Graphics/UI/GLUT/Raw/Tokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ glut_ALLOW_DIRECT_CONTEXT = 1
glut_ALPHA :: CUInt
glut_ALPHA = 0x0008

glut_APPSTATUS_PAUSE :: CInt
glut_APPSTATUS_PAUSE = 0x0001

glut_APPSTATUS_RESUME :: CInt
glut_APPSTATUS_RESUME = 0x0002

glut_AUX :: GLenum
glut_AUX = 0x1000

Expand Down

0 comments on commit ebc76d8

Please sign in to comment.