Go to the first, previous, next, last section, table of contents.

Glyph examples

A new opaque Glyph instance is created via the function glyph, so to display a red filled circle, See section Window abstraction for inexampleion of how to put up a window on your screen:


main =
 let
  filledCircle :: Picture
  filledCircle =
   fillSolid      $
   circle 20

  redCircle =
   withColour red filledCircle
 in
 mkDC []              >>= \ dc ->
   glyph redCircle dc >>= \ (gl, dh) ->
 realiseDH dc dh      >>
 return ()

Red Circle

The glyph takes a Picture value and a context to display itself in (@xref {DisplayContext}), and creates a component with a rendered representation of the Picture value. In common with all other user interface components in Haggis, glyph returns a DisplayHandle for the user interface part of the component, the other value is of type Glyph, a handle that can be used to dynamically change the Picture. For instance, to change the colour of the circle to blue


setPicture :: Glyph -> Picture -> IO ()

main =
 mkDC []              >>= \ dc ->
   glyph redCircle dc >>= \ (gl, dh) ->
 realiseDH dc dh      >>
 setPicture gl (withColour blue filledCircle) >>
 return ()

Blue circle

setPicture replaces the glyph's current picture with a new one, scaling it to fit into the current bounding box allocated to the Glyph. If you want to replace the picture and set the glyph's size equal to the size of the new picture, newPicture provides that functionality.


newPicture :: Glyph -> Picture -> IO ()

main =
 mkDC []              >>= \ dc ->
   glyph redCircle dc >>= \ (gl, dh) ->
 realiseDH dc dh      >>
 newPicture gl (withColour blue filledCircle) >>
 return ()


Go to the first, previous, next, last section, table of contents.