-- -- | -- Module : GlobalData -- Author : Sean Seefried (http://www.cse.unsw.edu.au/~sseefried) -- Copyright : (c) 2005 -- License : BSD3 -- Created : 16 Jun 2005 -- module GlobalData where -- library imports import Data.IORef import System.Time import Foreign -- wxHaskell import Graphics.UI.WX hiding ( Size, marginWidth ) import Graphics.UI.WXCore hiding ( Size, marginWidth) import qualified Graphics.UI.WX as WX -- hs-plugins import System.Plugins as Plugins -- Pan! import Pan -- local import PanicConfAPI data TopLevelData = TopLevelData { tldPanicConf :: PanicConf , tldOpenMenuItem :: MenuItem () , tldSaveMenuItem :: MenuItem () , tldTopLevelFrame :: Frame () , tldCurrentDirectory :: FilePath , tldCurrentFile :: Maybe FilePath } data ViewerData = ViewerData -- ^ Viewer data { vwdPixels :: Ptr Int8 -- ^ pixel data -- , vwdPoints :: Ptr Frac -- ^ points for current XY pan and zoom , vwdInitTime :: ClockTime -- ^ time effect was started , vwdLastSampleTime :: ClockTime -- ^ time since last sample started , vwdVTrans :: VTrans -- ^ XY pan and zoom , vwdVSize :: VSize -- ^ size of the window , vwdSaveSize :: VSize -- ^ the size a saved image should be , vwdAspectFlag :: Bool -- ^ whether the aspect ratio should be kept -- when entering a size for the saved image , vwdTimeSamples :: [Float] -- ^ list of time samples -- ^ will always have length of -- ^ samplesToStabilise , vwdFrames :: Int -- ^ total frames displayed , vwdFramesSinceChange :: Int -- ^ frames since a perspective change. , vwdMouseClickPoint :: WX.Point -- ^ where the mouse was clicked last , vwdMouseClicked :: Bool -- ^ whether mouse is clicked or not , vwdEffectFrame :: Frame () -- ^ the effect frame , vwdGLCanvas :: GLCanvas () -- ^ OpenGL canvas on which things are -- displayed. , vwdFrameStaticText :: StaticText () -- frame rate static text box , vwdSizeStaticText :: StaticText () -- size static text box , vwdModules :: [Plugins.Module] , vwdChanged :: Bool -- has the effect changed in any way , vwdDisplayFun :: UI DisplayFun -- the display function , vwdUIRefs :: [UIRef] -- The UI references } mkVwd :: PanicConf -> Frame () -> GLCanvas () -> StaticText () -- frame static text -> StaticText () -- size static text -> [Plugins.Module] -> UI DisplayFun -> IO (IORef ViewerData) mkVwd pc f glCanvas frameStaticText sizeStaticText modules displayFun = do let (w, h) = (defaultWidth pc, defaultHeight pc) pixels <- mallocBytes (w*h*bytesPerColour) t <- getClockTime newIORef ( ViewerData { vwdPixels = pixels , vwdInitTime = t , vwdLastSampleTime = t , vwdVTrans = (0,0,1) , vwdVSize = (w,h) , vwdSaveSize = (w,h) , vwdAspectFlag = True , vwdTimeSamples = take (samplesToStabilise pc) (repeat 0) , vwdFrames = 0 , vwdFramesSinceChange = 0 , vwdMouseClickPoint = WX.Point 0 0 , vwdMouseClicked = False , vwdEffectFrame = f , vwdGLCanvas = glCanvas , vwdFrameStaticText = frameStaticText , vwdSizeStaticText = sizeStaticText , vwdModules = modules , vwdChanged = False , vwdDisplayFun = displayFun , vwdUIRefs = error "UIRefs not set yet" }) -- -- | shows a certain number of decimal places of a float. Pads with -- zeroes. showPlaces :: Int -> Float -> String showPlaces n f = showPlaces' n (show f) where showPlaces' _ "" = "" showPlaces' n ('.':cs) = '.':take n (cs ++ repeat '0') showPlaces' n (c :cs) = c:showPlaces' n cs