module Visualise where import Graphics.UI.Gtk import Graphics.UI.Gtk.Gdk.Events import Graphics.Rendering.Cairo import Graphics.UI.Gtk.Scrolling.ScrolledWindow import Graphics.UI.Gtk.Abstract.Container -- Simple ways of displaying visualisations -- Copied from one of the gtk2hs examples -- Makes a scrollable canvas and draws a static image on it inNewWindow :: Render (Double,Double) -> IO () inNewWindow act = do initGUI dia <- dialogNew dialogAddButton dia stockClose ResponseClose contain <- dialogGetUpper dia scroll <- scrolledWindowNew Nothing Nothing canvas <- drawingAreaNew canvas `onExpose` updateCanvas canvas act scrolledWindowAddWithViewport scroll canvas boxPackStartDefaults contain scroll widgetShow scroll widgetShow canvas dialogRun dia widgetDestroy dia -- Flush all commands that are waiting to be sent to the graphics server. -- This ensures that the window is actually closed before ghci displays the -- prompt again. flush where updateCanvas :: DrawingArea -> Render (Double,Double) -> Event -> IO Bool updateCanvas canvas act (Expose {}) = do win <- widgetGetDrawWindow canvas (height,width) <- renderWithDrawable win act widgetSetSizeRequest canvas (ceiling width) (ceiling height) return True updateCanvas canvas act _ = return False renderToPS fileName act = do withPSSurface fileName 2000 6000 (\ surface -> renderWith surface (act >> surfaceFlush surface))