-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A simple graphics library based on X11 or Win32
--
-- A simple graphics library, designed to give the programmer access to
-- most interesting parts of the Win32 Graphics Device Interface and X11
-- library without exposing the programmer to the pain and anguish
-- usually associated with using these interfaces.
--
-- The library also includes a module Graphics.SOE providing the
-- interface used in "The Haskell School of Expression", by Paul Hudak,
-- cf http://www.haskell.org/soe/.
@package HGL
@version 3.2.2
-- | The Draw monad, with graphical objects as a special case.
module Graphics.HGL.Draw.Monad
-- | An abstract representation of an image.
type Graphic = Draw ()
-- | Monad for sequential construction of images.
data Draw a
-- | Embed an IO action in a drawing action.
ioToDraw :: IO a -> Draw a
-- | Wrap a drawing action in initialization and finalization actions.
bracket :: Draw a -> (a -> Draw b) -> (a -> Draw c) -> Draw c
-- | A variant of bracket in which the inner drawing action does not
-- use the result of the pre-operation.
bracket_ :: Draw a -> (a -> Draw b) -> Draw c -> Draw c
-- | Abstract representation of keys.
module Graphics.HGL.Key
data Key
-- | Converts a character key to a character.
keyToChar :: Key -> Char
isCharKey :: Key -> Bool
isBackSpaceKey :: Key -> Bool
isTabKey :: Key -> Bool
isClearKey :: Key -> Bool
isReturnKey :: Key -> Bool
isEscapeKey :: Key -> Bool
isDeleteKey :: Key -> Bool
isHomeKey :: Key -> Bool
isLeftKey :: Key -> Bool
isUpKey :: Key -> Bool
isRightKey :: Key -> Bool
isDownKey :: Key -> Bool
isPriorKey :: Key -> Bool
isPageUpKey :: Key -> Bool
isNextKey :: Key -> Bool
isPageDownKey :: Key -> Bool
isEndKey :: Key -> Bool
isShiftLKey :: Key -> Bool
isShiftRKey :: Key -> Bool
isControlLKey :: Key -> Bool
isControlRKey :: Key -> Bool
-- | Running graphical actions.
module Graphics.HGL.Run
-- | Initialize the system to do graphics, run an action while collecting
-- user interface events and forwarding them to the action, and then
-- clean up everything else at the end. The other functions of the
-- library may only be used inside runGraphics.
runGraphics :: IO () -> IO ()
-- | Types for units in a simple graphics library.
module Graphics.HGL.Units
-- | A position within a window, measured in pixels to the right and down
-- from the top left corner.
type Point = (Int, Int)
-- | A (width, height) pair, both measured in pixels.
type Size = (Int, Int)
-- | An angle in degrees (0 to 360).
type Angle = Double
-- | Time, measured in milliseconds.
type Time = Integer
-- | Drawing various shapes.
module Graphics.HGL.Draw.Picture
-- | A filled arc from an ellipse.
arc :: Point -> Point -> Angle -> Angle -> Graphic
-- | A filled ellipse that fits inside a rectangle defined by two
-- Points on the window.
ellipse :: Point -> Point -> Graphic
-- | A filled sheared ellipse that fits inside a parallelogram defined by
-- three Points on the window. This function is implemented using
-- polygons on both Win32 and X11.
shearEllipse :: Point -> Point -> Point -> Graphic
-- | A line between two Points.
line :: Point -> Point -> Graphic
-- | A series of lines through a list of Points.
polyline :: [Point] -> Graphic
-- | A filled polygon defined by a list of Points.
polygon :: [Point] -> Graphic
-- | A series of (unfilled) Bezier curves defined by a list of 3n+1
-- control Points. This function is not supported on X11 (it
-- yields an error message and a polyline).
polyBezier :: [Point] -> Graphic
-- | Drawing text.
module Graphics.HGL.Draw.Text
-- | Render a String positioned relative to the specified
-- Point.
text :: Point -> String -> Graphic
-- | textInfo s returns:
--
--
-- - The offset at which the string would be drawn according to the
-- current text alignment (e.g., (Center,
-- Baseline) will result in an offset of (-width/2,0))
-- - The size at which the text would be drawn using the current
-- font.
--
textInfo :: String -> Draw (Point, Size)
-- | A color, comprising red, green and blue components.
data RGB
RGB :: Word8 -> Word8 -> Word8 -> RGB
-- | Set the foreground color for drawing text, returning the previous
-- value.
setTextColor :: RGB -> Draw RGB
-- | Set the background color for drawing text, returning the previous
-- value. The background color is ignored when the mode is
-- Transparent.
setBkColor :: RGB -> Draw RGB
-- | Background mode for drawing text.
data BkMode
-- | Draw text on a bounding rectangle filled with the current background
-- color.
Opaque :: BkMode
-- | Draw text without a background rectangle.
Transparent :: BkMode
-- | Set the background mode for drawing text, returning the previous
-- value.
setBkMode :: BkMode -> Draw BkMode
-- | How strings drawn with text are positioned relative to the
-- specified reference point.
type Alignment = (HAlign, VAlign)
-- | Horizontal alignment of text. Names have a tick to distinguish them
-- from Prelude names.
data HAlign
-- | align the left edge of the text with the reference point
Left' :: HAlign
-- | center the text with the reference point
Center :: HAlign
-- | align the right edge of the text with the reference point
Right' :: HAlign
-- | Vertical alignment of text.
data VAlign
-- | align the top edge of the text with the reference point
Top :: VAlign
-- | align the baseline of the text with the reference point
Baseline :: VAlign
-- | align the bottom edge of the text with the reference point
Bottom :: VAlign
-- | Set the alignment for drawing text, returning the previous value.
setTextAlignment :: Alignment -> Draw Alignment
-- | Brushes, used for filling shapes.
module Graphics.HGL.Draw.Brush
data Brush
-- | Create a Brush.
createBrush :: RGB -> IO Brush
-- | Destroy a Brush created with createBrush.
deleteBrush :: Brush -> IO ()
-- | Set the Brush for subsequent drawing, returning the previous
-- setting.
selectBrush :: Brush -> Draw Brush
-- | Create a Brush locally to a drawing.
mkBrush :: RGB -> (Brush -> Draw a) -> Draw a
-- | Pens, used for drawing lines.
--
-- Portability notes:
--
--
-- - On Win32, the pen is also used to draw a line round all the filled
-- shapes --- so the pen color also affects how polygons, ellipses and
-- regions are drawn.
-- - On Win32, the Style is ignored (i.e. treated as
-- Solid) for pens of width greater than 1. This problem does not
-- apply to X11.
--
module Graphics.HGL.Draw.Pen
data Pen
-- | The style of line drawn by a pen.
data Style
Solid :: Style
Dash :: Style
Dot :: Style
DashDot :: Style
DashDotDot :: Style
Null :: Style
InsideFrame :: Style
-- | Create a Pen.
createPen :: Style -> Int -> RGB -> IO Pen
-- | Destroy a Pen created with createPen.
deletePen :: Pen -> IO ()
-- | Set the Pen for subsequent drawing, returning the previous
-- setting.
selectPen :: Pen -> Draw Pen
-- | Create a Pen locally to a drawing.
mkPen :: Style -> Int -> RGB -> (Pen -> Draw a) -> Draw a
-- | An efficient representation of sets of pixels.
module Graphics.HGL.Draw.Region
data Region
-- | An empty region. This is not supported on Win32. It is possible to use
-- an empty rectangle region instead.
emptyRegion :: Region
-- | A rectangular region, with the given points as opposite corners.
rectangleRegion :: Point -> Point -> Region
-- | An elliptical region that fits in the rectangle with the given points
-- as opposite corners.
ellipseRegion :: Point -> Point -> Region
-- | A polygonal region defined by a list of Points.
polygonRegion :: [Point] -> Region
-- | The intersection of two regions.
intersectRegion :: Region -> Region -> Region
-- | The union of two regions.
unionRegion :: Region -> Region -> Region
-- | The part of the first region that is not also in the second.
subtractRegion :: Region -> Region -> Region
-- | The symmetric difference of two regions.
xorRegion :: Region -> Region -> Region
-- | Fill a Region using the current Brush.
regionToGraphic :: Region -> Graphic
-- | Text fonts.
--
-- Portability notes:
--
--
-- - X11 does not directly support font rotation so createFont
-- and mkFont always ignore the rotation angle argument in the X11
-- implementation of this library.
-- - Many of the font families typically available on Win32 are not
-- available on X11 (and vice-versa). In our experience, the font
-- families courier, helvetica and times are
-- somewhat portable.
--
module Graphics.HGL.Draw.Font
data Font
-- | Create a font. The rotation angle is ignored if the font is not a
-- "TrueType" font (e.g., a System font on Win32).
createFont :: Size -> Angle -> Bool -> Bool -> String -> IO Font
-- | Delete a font created with createFont.
deleteFont :: Font -> IO ()
-- | Set the font for subsequent text, and return the previous font.
selectFont :: Font -> Draw Font
-- | Generate a font for use in a drawing, and delete it afterwards. The
-- rotation angle is ignored if the font is not a "TrueType" font (e.g.,
-- a System font on Win32).
mkFont :: Size -> Angle -> Bool -> Bool -> String -> (Font -> Draw a) -> Draw a
-- | Drawing in a simple graphics library.
module Graphics.HGL.Draw
-- | Windows in a simple graphics library.
module Graphics.HGL.Window
data Window
-- | Title of a window.
type Title = String
-- | How to draw in a window.
data RedrawMode
-- | use a double buffer to reduce flicker. You should probably use
-- this for animations.
DoubleBuffered :: RedrawMode
-- | draw directly to the window. This runs slightly faster but is more
-- prone to flicker.
Unbuffered :: RedrawMode
-- | General window creation.
openWindowEx :: Title -> Maybe Point -> Size -> RedrawMode -> Maybe Time -> IO Window
-- | The position of the top left corner of the window on the screen, and
-- the size of the window.
getWindowRect :: Window -> IO (Point, Size)
-- | Close the window.
closeWindow :: Window -> IO ()
-- | Set the current drawing in a window.
setGraphic :: Window -> Graphic -> IO ()
-- | Get the current drawing in a window.
getGraphic :: Window -> IO Graphic
-- | Update the drawing for a window. Note that this does not force a
-- redraw.
modGraphic :: Window -> (Graphic -> Graphic) -> IO ()
directDraw :: Window -> Graphic -> IO ()
-- | A user interface event.
--
-- Notes:
--
--
-- - Programmers should assume that the Event datatype will be
-- extended in the not-too-distant future and that individual events may
-- change slightly. As a minimum, you should add a "match anything"
-- alternative to any function which pattern matches against
-- Events.
-- - X11 systems typically have three button mice. Button 1 is used as
-- the left button, button 3 as the right button and button 2 (the middle
-- button) is ignored.
--
data Event
-- | a properly translated character, sent after a key press.
Char :: Char -> Event
-- | the character represented by a key combination
[char] :: Event -> Char
-- | occurs when a key was pressed or released.
Key :: Key -> Bool -> Event
-- | representation of the keyboard keys pressed
[keysym] :: Event -> Key
-- | if True, the key was pressed; otherwise it was released
[isDown] :: Event -> Bool
-- | occurs when a mouse button is pressed or released.
Button :: Point -> Bool -> Bool -> Event
-- | the position of the mouse cursor
[pt] :: Event -> Point
-- | if True, it was the left button
[isLeft] :: Event -> Bool
-- | if True, the key was pressed; otherwise it was released
[isDown] :: Event -> Bool
-- | occurs when the mouse is moved inside the window.
MouseMove :: Point -> Event
-- | the position of the mouse cursor
[pt] :: Event -> Point
-- | occurs when the window is resized.
Resize :: Event
-- | occurs when the window is closed.
Closed :: Event
-- | Wait for the next event on the given window.
getWindowEvent :: Window -> IO Event
-- | Check for a pending event on the given window.
maybeGetWindowEvent :: Window -> IO (Maybe Event)
-- | Wait for the next tick event from the timer on the given window.
getWindowTick :: Window -> IO ()
-- | Time in milliseconds since some arbitrary epoch.
getTime :: IO Integer
-- | Core functions of a simple graphics library.
module Graphics.HGL.Core
-- | Utility functions for a simple graphics library.
module Graphics.HGL.Utils
-- | Create a window with the given title and size.
openWindow :: Title -> Size -> IO Window
-- | Erase all drawing in the window. (That is, set the Graphic held
-- by the window to emptyGraphic.)
clearWindow :: Window -> 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.)
drawInWindow :: Window -> Graphic -> IO ()
-- | Run an action inside a new window, ensuring that the window is
-- destroyed on exit.
withWindow :: Title -> Size -> (Window -> IO a) -> IO a
-- | A variant of withWindow that ignores the result of the action.
withWindow_ :: Title -> Size -> (Window -> IO a) -> IO ()
-- | A combination of runGraphics and withWindow_.
runWindow :: Title -> Size -> (Window -> IO a) -> IO ()
-- | The current size of the window.
getWindowSize :: Window -> IO Size
-- | Wait for a press of the left mouse button, and return the position of
-- the mouse cursor.
getLBP :: Window -> IO Point
-- | Wait for a press of the right mouse button, and return the position of
-- the mouse cursor.
getRBP :: Window -> IO Point
-- | Wait for a mouse button to be pressed or released, and return the
-- position of the mouse cursor.
getButton :: Window -> Bool -> Bool -> IO Point
-- | Wait until a key is pressed and released.
getKey :: Window -> IO Key
-- | Wait until a key is pressed (if the second argument is True) or
-- released (otherwise).
getKeyEx :: Window -> Bool -> IO Key
-- | Wait for a translated character (from a key press). Use in preference
-- to getKey if the aim is to read text.
wGetChar :: Window -> IO Char
-- | An empty drawing.
emptyGraphic :: Graphic
-- | A composite drawing made by overlaying the first argument on the
-- second.
overGraphic :: Graphic -> Graphic -> Graphic
-- | Overlay a list of drawings.
overGraphics :: [Graphic] -> Graphic
-- | Set the default font for a drawing.
withFont :: Font -> Graphic -> Graphic
-- | Set the default color for drawing text.
withTextColor :: RGB -> Graphic -> Graphic
-- | Set the default alignment of text in a drawing.
withTextAlignment :: Alignment -> Graphic -> Graphic
-- | Set the default background color for drawing text with background mode
-- Opaque. The background color is ignored when the mode is
-- Transparent.
withBkColor :: RGB -> Graphic -> Graphic
-- | Set the default background mode for drawing text.
withBkMode :: BkMode -> Graphic -> Graphic
-- | Set the default pen for drawing lines.
withPen :: Pen -> Graphic -> Graphic
-- | Set the default brush for filling shapes.
withBrush :: Brush -> Graphic -> Graphic
-- | A convenience function that sets the brush, pen and text colors to the
-- same value.
withRGB :: RGB -> Graphic -> Graphic
-- | Named colors.
data Color
Black :: Color
Blue :: Color
Green :: Color
Cyan :: Color
Red :: Color
Magenta :: Color
Yellow :: Color
White :: Color
-- | A mapping of Color names to RGB triples.
colorList :: [(Color, RGB)]
-- | A mapping of Color names to RGB triples.
colorTable :: Array Color RGB
-- | Set the default drawing color for a Graphic.
withColor :: Color -> Graphic -> Graphic
-- | Run two IO actions in parallel and terminate when both actions
-- terminate.
par :: IO a -> IO b -> IO (a, b)
-- | Run two IO actions in parallel and terminate when both actions
-- terminate, discarding the results of the actions.
par_ :: IO a -> IO b -> IO ()
-- | Run several IO actions in parallel and terminate when all
-- actions terminate, discarding the results of the actions.
parMany :: [IO ()] -> IO ()
instance GHC.Read.Read Graphics.HGL.Utils.Color
instance GHC.Show.Show Graphics.HGL.Utils.Color
instance GHC.Arr.Ix Graphics.HGL.Utils.Color
instance GHC.Enum.Enum Graphics.HGL.Utils.Color
instance GHC.Enum.Bounded Graphics.HGL.Utils.Color
instance GHC.Classes.Ord Graphics.HGL.Utils.Color
instance GHC.Classes.Eq Graphics.HGL.Utils.Color
-- | A simple graphics library.
module Graphics.HGL
-- | The graphics library used in The Haskell School of Expression,
-- by Paul Hudak, cf http://www.haskell.org/soe/.
--
-- Notes:
--
--
-- - This module is called SOEGraphics in the book. It is a
-- cut down version of Graphics.HGL, with the interface frozen to
-- match the book.
-- - In chapters 13, 17 and 19 of the book, there are imports of
-- modules Win32Misc and Word. These should be omitted,
-- as timeGetTime and word32ToInt are provided by this
-- module.
--
module Graphics.SOE
-- | Initialize the system to do graphics, run an action while collecting
-- user interface events and forwarding them to the action, and then
-- clean up everything else at the end. The other functions of the
-- library may only be used inside runGraphics.
runGraphics :: IO () -> IO ()
-- | Title of a window.
type Title = String
-- | A (width, height) pair, both measured in pixels.
type Size = (Int, Int)
data Window
-- | Create a window with the given title and size.
openWindow :: Title -> Size -> IO Window
-- | The current size of the window.
getWindowSize :: Window -> IO Size
-- | Erase all drawing in the window. (That is, set the Graphic held
-- by the window to emptyGraphic.)
clearWindow :: Window -> 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.)
drawInWindow :: Window -> Graphic -> IO ()
-- | Another name for drawInWindow, retained for backwards
-- compatibility.
drawInWindowNow :: Window -> Graphic -> IO ()
-- | Set the current drawing in a window.
setGraphic :: Window -> Graphic -> IO ()
-- | Close the window.
closeWindow :: Window -> IO ()
-- | an extended version of openWindow.
openWindowEx :: Title -> Maybe Point -> Maybe Size -> RedrawMode -> Maybe Word32 -> IO Window
-- | How to draw in a window.
data RedrawMode
-- | Draw directly to the window (slightly faster than
-- drawBufferedGraphic, but more prone to flicker).
drawGraphic :: RedrawMode
-- | Use a double buffer to reduce flicker and thus improve the look
-- of animations.
drawBufferedGraphic :: RedrawMode
-- | An abstract representation of an image.
type Graphic = Draw ()
-- | An empty drawing.
emptyGraphic :: Graphic
-- | A composite drawing made by overlaying the first argument on the
-- second.
overGraphic :: Graphic -> Graphic -> Graphic
-- | Overlay a list of drawings.
overGraphics :: [Graphic] -> Graphic
-- | Named colors.
data Color
Black :: Color
Blue :: Color
Green :: Color
Cyan :: Color
Red :: Color
Magenta :: Color
Yellow :: Color
White :: Color
-- | Set the default drawing color for a Graphic.
withColor :: Color -> Graphic -> Graphic
-- | Render a String positioned relative to the specified
-- Point.
text :: Point -> String -> Graphic
-- | A position within a window, measured in pixels to the right and down
-- from the top left corner.
type Point = (Int, Int)
-- | A filled ellipse that fits inside a rectangle defined by two
-- Points on the window.
ellipse :: Point -> Point -> Graphic
-- | A filled sheared ellipse that fits inside a parallelogram defined by
-- three Points on the window. This function is implemented using
-- polygons on both Win32 and X11.
shearEllipse :: Point -> Point -> Point -> Graphic
-- | A line between two Points.
line :: Point -> Point -> Graphic
-- | A filled polygon defined by a list of Points.
polygon :: [Point] -> Graphic
-- | A series of lines through a list of Points.
polyline :: [Point] -> Graphic
-- | A series of (unfilled) Bezier curves defined by a list of 3n+1
-- control Points. This function is not supported on X11 (it
-- yields an error message and a polyline).
polyBezier :: [Point] -> Graphic
-- | An angle in degrees (0 to 360).
type Angle = Double
-- | A filled arc from an ellipse.
arc :: Point -> Point -> Angle -> Angle -> Graphic
data Region
-- | A rectangular region, with the given points as opposite corners.
createRectangle :: Point -> Point -> Region
-- | An elliptical region that fits in the rectangle with the given points
-- as opposite corners.
createEllipse :: Point -> Point -> Region
-- | A polygonal region defined by a list of Points.
createPolygon :: [Point] -> Region
-- | The intersection of two regions.
andRegion :: Region -> Region -> Region
-- | The union of two regions.
orRegion :: Region -> Region -> Region
-- | The symmetric difference of two regions.
xorRegion :: Region -> Region -> Region
-- | The part of the first region that is not also in the second.
diffRegion :: Region -> Region -> Region
-- | Draw a Region in the current color.
drawRegion :: Region -> Graphic
-- | Wait until a key is pressed and released, and return the corresponding
-- character.
getKey :: Window -> IO Char
-- | Wait for a press of the left mouse button, and return the position of
-- the mouse cursor.
getLBP :: Window -> IO Point
-- | Wait for a press of the right mouse button, and return the position of
-- the mouse cursor.
getRBP :: Window -> IO Point
-- | User interface events
data Event
-- | occurs when a key was pressed or released.
Key :: Char -> Bool -> Event
-- | character corresponding to the key
[char] :: Event -> Char
-- | if True, the key was pressed; otherwise it was released
[isDown] :: Event -> Bool
-- | occurs when a mouse button is pressed or released.
Button :: Point -> Bool -> Bool -> Event
-- | the position of the mouse cursor
[pt] :: Event -> Point
-- | if True, it was the left button
[isLeft] :: Event -> Bool
-- | if True, the key was pressed; otherwise it was released
[isDown] :: Event -> Bool
-- | occurs when the mouse is moved inside the window.
MouseMove :: Point -> Event
-- | the position of the mouse cursor
[pt] :: Event -> Point
-- | occurs when the window is resized. The new window size can be
-- discovered using getWindowSize.
Resize :: Event
-- | occurs when the window is closed.
Closed :: Event
-- | Return a pending eventin the window, if any.
maybeGetWindowEvent :: Window -> IO (Maybe Event)
-- | Wait for the next event in the window.
getWindowEvent :: Window -> IO Event
-- | 32-bit unsigned integer type
data Word32 :: *
-- | Wait for the next tick event from the timer on the given window.
getWindowTick :: Window -> IO ()
-- | The current time of day (in milliseconds).
timeGetTime :: IO Word32
-- | An obsolete special case of fromIntegral.
word32ToInt :: Word32 -> Int
instance GHC.Show.Show Graphics.SOE.Event