module Graphics.HGL.Window
(
Window
, Title
, RedrawMode(Unbuffered, DoubleBuffered)
, openWindowEx
, getWindowRect
, closeWindow
, setGraphic
, getGraphic
, modGraphic
, directDraw
, Event(..)
, getWindowEvent
, maybeGetWindowEvent
, getWindowTick
, getTime
) where
#ifdef __HADDOCK__
import Graphics.HGL.Key
#endif
import Graphics.HGL.Units
import Graphics.HGL.Draw( Graphic )
import Graphics.HGL.Internals.Event( Event(..) )
import Graphics.HGL.Internals.Types( Title, RedrawMode(..), getTime )
import qualified Graphics.HGL.Internals.Events as E
import Graphics.HGL.Internals.Utilities( modMVar, modMVar_ )
#if !X_DISPLAY_MISSING
import Graphics.HGL.X11.Window (Window(..))
import qualified Graphics.HGL.X11.Window as X (openWindowEx, closeWindow,
redrawWindow, directDraw, getWindowRect )
#else
import Graphics.HGL.Win32.WND
(WND, openWND, getHWND, closeWND, wndRect, redrawWND, drawWND)
import Graphics.HGL.Win32.Types
import Graphics.HGL.Win32.Draw(
drawGraphic, drawBufferedGraphic
)
import Graphics.HGL.Draw (Draw)
import qualified Graphics.Win32 as Win32
#endif
import Control.Concurrent.MVar
getWindowEvent :: Window -> IO Event
maybeGetWindowEvent :: Window -> IO (Maybe Event)
getWindowTick :: Window -> IO ()
getGraphic :: Window -> IO Graphic
setGraphic :: Window -> Graphic -> IO ()
modGraphic :: Window -> (Graphic -> Graphic) -> IO ()
openWindowEx
:: Title
-> Maybe Point
-> Size
-> RedrawMode
-> Maybe Time
-> IO Window
closeWindow :: Window -> IO ()
redrawWindow :: Window -> IO ()
directDraw :: Window -> Graphic -> IO ()
getWindowRect :: Window -> IO (Point, Size)
getWindowEvent w = E.getEvent (events w)
maybeGetWindowEvent w
= do noEvent <- E.isNoEvent (events w)
if noEvent
then return Nothing
else do ev <- getWindowEvent w
return (Just ev)
getWindowTick w = E.getTick (events w)
getGraphic w = readMVar (graphic w)
setGraphic w p = do
modMVar (graphic w) (const p)
redrawWindow w
modGraphic w = modMVar_ (graphic w)
#if !X_DISPLAY_MISSING
openWindowEx = X.openWindowEx
closeWindow = X.closeWindow
getWindowRect = X.getWindowRect
redrawWindow = X.redrawWindow
directDraw = X.directDraw
#else /* X_DISPLAY_MISSING */
data Window = MkWindow {
events :: E.Events,
graphic :: MVar (Draw ()),
wnd :: WND
}
openWindowEx name pos size redrawMode tickRate = do
graphic <- newMVar (return ())
events <- E.newEvents
let draw = \ hwnd hdc -> do
p <- readMVar graphic
repaint p hwnd hdc
wnd <- openWND name (fmap fromPoint pos) (Just $ fromPoint size)
events draw (fmap fromInteger tickRate)
mkWindow wnd events graphic
where
repaint = case redrawMode of
Unbuffered -> drawGraphic
DoubleBuffered -> drawBufferedGraphic
mkWindow :: WND -> E.Events -> MVar (Draw ()) -> IO Window
mkWindow wnd events graphic = do
return (MkWindow { wnd=wnd, events=events, graphic=graphic })
closeWindow w = closeWND (wnd w)
getWindowRect w = wndRect (wnd w)
redrawWindow w = redrawWND (wnd w)
directDraw w p = drawWND (wnd w) p
windowHWND :: Window -> IO Win32.HWND
windowHWND w = getHWND (wnd w)
#endif /* X_DISPLAY_MISSING */