diff --git a/examples/example00.hs b/examples/example00.hs index 5e0eb1f..5601cb9 100644 --- a/examples/example00.hs +++ b/examples/example00.hs @@ -32,7 +32,10 @@ main = do } withAffection conf -type UserData = M.Map String G.GeglNode +data UserData = UserData + { nodeGraph :: M.Map String G.GeglNode + , elapsedTime :: Double + } load :: SDL.Surface -> IO UserData load _ = do @@ -49,12 +52,16 @@ load _ = do , ("checkerboard", checkerboard) ] traceM "loading complete" - return myMap + return $ UserData + { nodeGraph = myMap + , elapsedTime = 0 + } draw :: AffectionState (AffectionData UserData) IO () draw = do traceM "drawing" AffectionData{..} <- get + let UserData{..} = userState liftIO $ SDL.lockSurface drawSurface pixels <- liftIO $ SDL.surfacePixels drawSurface let SDL.Surface rawSurfacePtr _ = drawSurface @@ -64,7 +71,7 @@ draw = do SDL.V2 (CInt rw) (CInt rh) <- SDL.surfaceDimensions drawSurface let (w, h) = (fromIntegral rw, fromIntegral rh) liftIO $ G.gegl_node_blit - (userState M.! "checkerboard" :: G.GeglNode) + (nodeGraph M.! "checkerboard" :: G.GeglNode) 1 (G.GeglRectangle 0 0 w h) format @@ -77,9 +84,18 @@ draw = do update :: Double -> AffectionState (AffectionData UserData) IO () update sec = do traceM "updating" - -- traceM $ show sec - liftIO $ delaySec 5 - ud@AffectionData{..} <- get - put $ ud - { quitEvent = True - } + -- liftIO $ delaySec 5 + ad@AffectionData{..} <- get + let ud@UserData{..} = userState + traceM $ show elapsedTime + if elapsedTime < 5 + then + put $ ad + { userState = ud + { elapsedTime = elapsedTime + sec + } + } + else + put $ ad + { quitEvent = True + }