Language-Haskell

 view release on metacpan or  search on metacpan

hugs98-Nov2003/fptools/libraries/GLUT/Graphics/UI/GLUT/Window.hs  view on Meta::CPAN

-- system as the window\'s name. The intent is that the window system will label
-- the window with the name.Implicitly, the /current window/ is set to the newly
-- created window.
--
-- /X Implementation Notes:/ The proper X Inter-Client Communication Conventions
-- Manual (ICCCM) top-level properties are established. The @WM_COMMAND@
-- property that lists the command line used to invoke the GLUT program is only
-- established for the first window created.

createWindow
   :: String    -- ^ The window name
   -> IO Window -- ^ The identifier for the newly created window
createWindow name = withCString name glutCreateWindow

foreign import CALLCONV unsafe "glutCreateWindow" glutCreateWindow ::
      CString -> IO Window

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

-- | Create a subwindow of the identified window with the given relative
-- position and size. Implicitly, the /current window/ is set to the
-- newly created subwindow. Subwindows can be nested arbitrarily deep.

createSubWindow
   :: Window    -- ^ Identifier of the subwindow\'s parent window.
   -> Position  -- ^ Window position in pixels relative to parent window\'s
                --   origin.
   -> Size      -- ^ Window size in pixels
   -> IO Window -- ^ The identifier for the newly created subwindow
createSubWindow win (Position x y) (Size w h) =
   glutCreateSubWindow win
                       (fromIntegral x) (fromIntegral y)
                       (fromIntegral w) (fromIntegral h)

foreign import CALLCONV unsafe "glutCreateSubWindow" glutCreateSubWindow ::
      Window -> CInt -> CInt -> CInt -> CInt -> IO Window

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

-- | Contains the /current window\'s/ parent. If the /current window/ is a
-- top-level window, a pseudo window is returned, see 'isRealWindow'.

parentWindow :: GettableStateVar Window
parentWindow =
   makeGettableStateVar $
      simpleGet makeWindow glut_WINDOW_PARENT

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

-- | Contains the number of subwindows the /current window/ has, not counting
-- children of children.

numSubWindows :: GettableStateVar Int
numSubWindows =
   makeGettableStateVar $
      simpleGet fromIntegral glut_WINDOW_NUM_CHILDREN

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

-- | Destroy the specified window and the window\'s associated OpenGL context,
-- logical colormap (if the window is color index), and overlay and related
-- state (if an overlay has been established). Any subwindows of the destroyed
-- window are also destroyed by 'destroyWindow'. If the specified window was the
-- /current window/, the /current window/ becomes invalid ('getWindow' will
-- return 'Nothing').

foreign import CALLCONV unsafe "glutDestroyWindow" destroyWindow ::
   Window -> IO ()

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

-- | Controls the /current window/. It does /not/ affect the /layer in use/ for
-- the window; this is done using 'Graphics.UI.GLUT.Overlay.layerInUse'. If no
-- windows exist or the previously /current window/ was destroyed, a pseudo
-- window is returned, see 'isRealWindow'.

currentWindow :: StateVar Window
currentWindow = makeStateVar glutGetWindow glutSetWindow

foreign import CALLCONV unsafe "glutSetWindow" glutSetWindow :: Window -> IO ()

foreign import CALLCONV unsafe "glutGetWindow" glutGetWindow :: IO Window

-- | Returns 'True' if the given window identifier refers to a real window, not
-- a pseudo one.

isRealWindow :: Window -> Bool
isRealWindow = (/= makeWindow 0)

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

-- | Mark the normal plane of given window (or the /current window/, if none
-- is supplied) as needing to be redisplayed. The next iteration through
-- 'Graphics.UI.GLUT.Begin.mainLoop', the window\'s display callback will be
-- called to redisplay the window\'s normal plane. Multiple calls to
-- 'postRedisplay' before the next display callback opportunity generates only a
-- single redisplay callback. 'postRedisplay' may be called within a window\'s
-- display or overlay display callback to re-mark that window for redisplay.
--
-- Logically, normal plane damage notification for a window is treated as a
-- 'postRedisplay' on the damaged window. Unlike damage reported by the window
-- system, 'postRedisplay' will /not/ set to true the normal plane\'s damaged
-- status (see 'Graphics.UI.GLUT.State.damaged').
--
-- Also, see 'Graphics.UI.GLUT.Overlay.postOverlayRedisplay'.

postRedisplay :: Maybe Window -> IO ()
postRedisplay = maybe glutPostRedisplay glutPostWindowRedisplay

foreign import CALLCONV unsafe "glutPostRedisplay" glutPostRedisplay :: IO ()

-- | Mark the normal plane of the given window as needing to be redisplayed,
-- otherwise the same as 'postRedisplay'.
--
-- The advantage of this routine is that it saves the cost of a 'setWindow' call
-- (entailing an expensive OpenGL context switch), which is particularly useful
-- when multiple windows need redisplays posted at the same time. 

foreign import CALLCONV unsafe "glutPostWindowRedisplay"
   glutPostWindowRedisplay :: Window -> IO ()

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

-- | Perform a buffer swap on the /layer in use/ for the /current window/.
-- Specifically, 'swapBuffers' promotes the contents of the back buffer of the
-- /layer in use/ of the /current window/ to become the contents of the front
-- buffer. The contents of the back buffer then become undefined. The update
-- typically takes place during the vertical retrace of the monitor, rather than
-- immediately after 'swapBuffers' is called.
--
-- An implicit 'Graphics.Rendering.OpenGL.GL.FlushFinish.flush' is done by
-- 'swapBuffers' before it returns. Subsequent OpenGL commands can be issued
-- immediately after calling 'swapBuffers', but are not executed until the
-- buffer exchange is completed.
--
-- If the /layer in use/ is not double buffered, 'swapBuffers' has no effect.

foreign import CALLCONV unsafe "glutSwapBuffers" swapBuffers :: IO ()

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

-- $ChangingTheWindowGeometry
-- Note that the requests by 'windowPosition', 'windowSize', and 'fullScreen'
-- are not processed immediately. A request is executed after returning to the
-- main event loop. This allows multiple requests to the same window to be
-- coalesced.
--
-- 'windowPosition' and 'windowSize' requests on a window will disable the full
-- screen status of the window.

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

-- | Controls the position of the /current window/. For top-level windows,
-- parameters of 'Position' are pixel offsets from the screen origin. For
-- subwindows, the parameters are pixel offsets from the window\'s parent window
-- origin.
--
-- In the case of top-level windows, setting 'windowPosition' is considered only



( run in 0.650 second using v1.01-cache-2.11-cpan-39bf76dae61 )