| Portability | non-portable (requires concurrency) |
|---|---|
| Stability | provisional |
| Maintainer | libraries@haskell.org |
| Safe Haskell | None |
Graphics.HGL.Utils
Contents
Description
Utility functions for a simple graphics library.
- openWindow :: Title -> Size -> IO Window
- clearWindow :: Window -> IO ()
- drawInWindow :: Window -> Graphic -> IO ()
- withWindow :: Title -> Size -> (Window -> IO a) -> IO a
- withWindow_ :: Title -> Size -> (Window -> IO a) -> IO ()
- runWindow :: Title -> Size -> (Window -> IO a) -> IO ()
- getWindowSize :: Window -> IO Size
- getLBP :: Window -> IO Point
- getRBP :: Window -> IO Point
- getButton :: Window -> Bool -> Bool -> IO Point
- getKey :: Window -> IO Key
- getKeyEx :: Window -> Bool -> IO Key
- wGetChar :: Window -> IO Char
- emptyGraphic :: Graphic
- overGraphic :: Graphic -> Graphic -> Graphic
- overGraphics :: [Graphic] -> Graphic
- withFont :: Font -> Graphic -> Graphic
- withTextColor :: RGB -> Graphic -> Graphic
- withTextAlignment :: Alignment -> Graphic -> Graphic
- withBkColor :: RGB -> Graphic -> Graphic
- withBkMode :: BkMode -> Graphic -> Graphic
- withPen :: Pen -> Graphic -> Graphic
- withBrush :: Brush -> Graphic -> Graphic
- withRGB :: RGB -> Graphic -> Graphic
- data Color
- colorList :: [(Color, RGB)]
- colorTable :: Array Color RGB
- withColor :: Color -> Graphic -> Graphic
- par :: IO a -> IO b -> IO (a, b)
- par_ :: IO a -> IO b -> IO ()
- parMany :: [IO ()] -> IO ()
Windows
openWindow :: Title -> Size -> IO Window
Create a window with the given title and size.
clearWindow :: Window -> IO ()
Erase all drawing in the window.
(That is, set the Graphic held by the window to emptyGraphic.)
drawInWindow :: Window -> Graphic -> IO ()
Draw the given graphic on the window, on top of anything that is
already there.
(That is, combine the given Graphic and the one held by the window
using overGraphic, store the result in the window, and display it.)
withWindow :: Title -> Size -> (Window -> IO a) -> IO a
Run an action inside a new window, ensuring that the window is destroyed on exit.
withWindow_ :: Title -> Size -> (Window -> IO a) -> IO ()
A variant of withWindow that ignores the result of the action.
runWindow :: Title -> Size -> (Window -> IO a) -> IO ()
A combination of runGraphics and withWindow_.
getWindowSize :: Window -> IO Size
The current size of the window.
Specific events
Mouse events
Wait for a press of the left mouse button, and return the position of the mouse cursor.
Wait for a press of the right mouse button, and return the position of the mouse cursor.
Arguments
| :: Window | |
| -> Bool | if |
| -> Bool | if |
| -> IO Point |
Wait for a mouse button to be pressed or released, and return the position of the mouse cursor.
Keyboard events
getKeyEx :: Window -> Bool -> IO Key
Wait until a key is pressed (if the second argument is True)
or released (otherwise).
Wait for a translated character (from a key press).
Use in preference to getKey if the aim is to read text.
Graphics
Combining Graphics
An empty drawing.
overGraphic :: Graphic -> Graphic -> Graphic
A composite drawing made by overlaying the first argument on the second.
overGraphics :: [Graphic] -> Graphic
Overlay a list of drawings.
Graphic modifiers
withTextColor :: RGB -> Graphic -> Graphic
Set the default color for drawing text.
withTextAlignment :: Alignment -> Graphic -> Graphic
Set the default alignment of text in a drawing.
withBkColor :: RGB -> Graphic -> Graphic
Set the default background color for drawing text with background
mode Opaque. The background color is ignored when the mode is
Transparent.
withBkMode :: BkMode -> Graphic -> Graphic
Set the default background mode for drawing text.
withRGB :: RGB -> Graphic -> Graphic
A convenience function that sets the brush, pen and text colors to the same value.
Named colors
data Color
Named colors.
Concurrency
par :: IO a -> IO b -> IO (a, b)
Run two IO actions in parallel and terminate when both actions terminate.
Run two IO actions in parallel and terminate when both actions terminate,
discarding the results of the actions.