1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
-- | Display mode is for drawing a static picture.
module Graphics.Gloss.Interface.IO.Display
( module Graphics.Gloss.Data.Display
, module Graphics.Gloss.Data.Picture
, module Graphics.Gloss.Data.Color
, displayIO
, Controller (..))
where
import Graphics.Gloss.Data.Display
import Graphics.Gloss.Data.Controller
import Graphics.Gloss.Data.Picture
import Graphics.Gloss.Data.Color
import Graphics.Gloss.Internals.Interface.Display
import Graphics.Gloss.Internals.Interface.Backend
-- | Open a new window and display an infrequently updated picture.
--
-- Once the window is open you can use the same commands as with @display@.
--
-- * This wrapper is intended for mostly static pictures that do not
-- need to be updated more than once per second. For example, the picture
-- could show network activity over the last minute, a daily stock price,
-- or a weather forecast. If you want to show a real-time animation where
-- the frames are redrawn more frequently then use the `animate` wrapper
-- instead.
--
-- * The provided picture generating action will be invoked, and the
-- display redrawn in two situation:
-- 1) We receive a display event, like someone clicks on the window.
-- 2) When `controllerSetRedraw` has been set, some indeterminate time
-- between the last redraw, and one second from that.
--
-- * Note that calling `controllerSetRedraw` indicates that the picture should
-- be redrawn, but does not cause this to happen immediately, due to
-- limitations in the GLUT and GLFW window managers. The display runs on
-- a one second timer interrupt, and if there have been no display events
-- we need to wait for the next timer interrupt before redrawing.
-- Having the timer interrupt period at 1 second keeps the CPU usage
-- due to the context switches at under 1%.
--
-- * Also note that the picture generating action is called for every display
-- event, so if the user pans the display then it will be invoked at 10hz
-- or more during the pan. If you are generating the picture by reading some
-- on-disk files then you should track when the files were last updated
-- and cache the picture between updates. Caching the picture avoids
-- repeatedly reading and re-parsing your files during a pan. Consider
-- storing your current picture in an IORef, passing an action that just
-- reads this IORef, and forking a new thread that watches your files for updates.
--
displayIO
:: Display -- ^ Display mode.
-> Color -- ^ Background color.
-> IO Picture -- ^ Action to produce the current picture.
-> (Controller -> IO ()) -- ^ Callback to take the display controller.
-> IO ()
displayIO dis backColor makePicture eatController
= displayWithBackend
defaultBackendState
dis
backColor
makePicture
eatController
|