allocDemo :: (MonadIO m, Rezed s m, Fonts s m, Time s m, Resources s m)
          => m (AnimationDemo m)
allocDemo = do
  comicFont <- getFontPath "KMKDSP__.ttf"
  let cdesc = fontDescriptor comicFont 16
  title      <- allocText cdesc white "Animation Demo"
  playBtn    <- allocButton (iconButtonPainter 32) [faPlay]
  pauseBtn   <- allocButton (iconButtonPainter 32) [faPause]
  pause      <- slot False
  anime      <- allocAnime myTween
  lastRs     <- slot []
  (_,square) <- allocColorPicture $
    setGeometry $ fan $ mapVertices (,white) $ rectangle (-10) 10

  V2 tw _    <- sizeOfText title
  V2 playw _ <- sizeOfButton playBtn

  let render rs = do
        renderText title $ move 0 16 : rs
        isPaused <- unslot pause
        stillPaused <- if isPaused
          then (renderButton playBtn $ move (tw + 4) 0 : rs) >>= \case
            ButtonStateClicked -> return False
            _ -> return isPaused
          else (renderButton pauseBtn $ move (tw + 4) 0 : rs) >>= \case
            ButtonStateClicked -> return True
            _ -> return isPaused
        unless stillPaused $
          stepAnime anime >>= reslot lastRs
        rrs   <- unslot lastRs
        (_,rnd) <- unslot square
        io $ rnd $ rrs ++ rs
        pause `is` stillPaused

      free = do
        freeText title
        freeButton playBtn
        freeButton pauseBtn
  return
    AnimationDemo{ demoRenderer = (free, render)
                 , pauseDemo = pause `is` True
                 , resumeDemo = pause `is` False
                 }
allocDemo :: (MonadIO m, Rezed s m, Fonts s m, Time s m, Resources s m)
          => m (AnimationDemo m)
allocDemo = do
  comicFont <- getFontPath "KMKDSP__.ttf"
  let cdesc = fontDescriptor comicFont 16
  title      <- allocText cdesc white "Animation Demo"
  playBtn    <- allocButton (iconButtonPainter 32) [faPlay]
  pauseBtn   <- allocButton (iconButtonPainter 32) [faPause]
  pause      <- slot False
  anime      <- allocAnime myTween
  lastRs     <- slot []
  (_,square) <- allocColorPicture $
    setGeometry $ fan $ mapVertices (,white) $ rectangle (-10) 10

  V2 tw _    <- sizeOfText title
  V2 playw _ <- sizeOfButton playBtn

  let render rs = do
        renderText title $ move 0 16 : rs
        isPaused <- unslot pause
        stillPaused <- if isPaused
          then (renderButton playBtn $ move (tw + 4) 0 : rs) >>= \case
            ButtonStateClicked -> return False
            _ -> return isPaused
          else (renderButton pauseBtn $ move (tw + 4) 0 : rs) >>= \case
            ButtonStateClicked -> return True
            _ -> return isPaused
        unless stillPaused $
          stepAnime anime >>= reslot lastRs
        rrs   <- unslot lastRs
        (_,rnd) <- unslot square
        io $ rnd $ rrs ++ rs
        pause `is` stillPaused

      free = do
        freeText title
        freeButton playBtn
        freeButton pauseBtn
  return
    AnimationDemo{ demoRenderer = (free, render)
                 , pauseDemo = pause `is` True
                 , resumeDemo = pause `is` False
                 }
allocDemo = do
  comicFont <- getFontPath "KMKDSP__.ttf"
  let cdesc = fontDescriptor comicFont 16
  title      <- allocText cdesc white "Animation Demo"
  playBtn    <- allocButton (iconButtonPainter 32) [faPlay]
  pauseBtn   <- allocButton (iconButtonPainter 32) [faPause]
  pause      <- slot False
  anime      <- allocAnime myTween
  lastRs     <- slot []
  (_,square) <- allocColorPicture $
    setGeometry $ fan $ mapVertices (,white) $ rectangle (-10) 10

  V2 tw _    <- sizeOfText title
  V2 playw _ <- sizeOfButton playBtn

  let render rs = do
        renderText title $ move 0 16 : rs
        isPaused <- unslot pause
        stillPaused <- if isPaused
          then (renderButton playBtn $ move (tw + 4) 0 : rs) >>= \case
            ButtonStateClicked -> return False
            _ -> return isPaused
          else (renderButton pauseBtn $ move (tw + 4) 0 : rs) >>= \case
            ButtonStateClicked -> return True
            _ -> return isPaused
        unless stillPaused $
          stepAnime anime >>= reslot lastRs
        rrs   <- unslot lastRs
        (_,rnd) <- unslot square
        io $ rnd $ rrs ++ rs
        pause `is` stillPaused

      free = do
        freeText title
        freeButton playBtn
        freeButton pauseBtn
  return
    AnimationDemo{ demoRenderer = (free, render)
                 , pauseDemo = pause `is` True
                 , resumeDemo = pause `is` False
                 }