drawThumbnails :: Context -> CFloat -> CFloat -> CFloat -> CFloat -> V.Vector Image -> CFloat -> IO ()
drawThumbnails vg x y w h images t =
  do let cornerRadius = 3
         thumb = 60
         arry = 30.5
         nimages = V.length images
         stackh = (fromIntegral nimages/2)*(thumb+10)+10
         u = (1+cos (t*0.5))*0.5
         u2 = (1-cos (t*0.2))*0.5
         dv = 1/(fromIntegral nimages - 1)
     save vg

     shadowPaint <- boxGradient vg x (y+4) w h (cornerRadius*2) 20 (rgba 0 0 0 128) (rgba 0 0 0 0)
     beginPath vg
     rect vg (x-10) (y-10) (w+20) (h+30)
     roundedRect vg x y w h cornerRadius
     pathWinding vg (fromIntegral $ fromEnum Hole)
     fillPaint vg shadowPaint
     fill vg

     beginPath vg
     roundedRect vg x y w h cornerRadius
     moveTo vg (x-10) (y+arry)
     lineTo vg (x+1) (y+arry-11)
     lineTo vg (x+1) (y+arry+11)
     fillColor vg (rgba 200 200 200 255)
     fill vg

     save vg
     scissor vg x y w h
     translate vg 0 (-(stackh-h)*u)

     flip V.imapM_ images $ \i image -> do
       let tx = x + 10 + fromIntegral (i `mod` 2) * (thumb + 10)
           ty = y + 10 + fromIntegral (i `div` 2) * (thumb + 10)
           v = fromIntegral i * dv
           a = clamp ((u2-v)/dv) 0 1
           drawImage iw ih ix iy = do
             imgPaint <- imagePattern vg (tx+ix) (ty+iy) iw ih (0/180*pi) image a
             beginPath vg
             roundedRect vg tx ty thumb thumb 5
             fillPaint vg imgPaint
             fill vg
       (imgw,imgh) <- imageSize vg image

       when (a < 1) $ drawSpinner vg (tx + thumb/2) (ty+thumb/2) (thumb*0.25) t

       if imgw < imgh
       then
         let iw = thumb
             ih = iw*fromIntegral imgh/fromIntegral imgw
             ix = 0
             iy = -(ih-thumb)*0.5
         in drawImage iw ih ix iy
       else
         let ih = thumb
             iw = ih * fromIntegral imgw/ fromIntegral imgh
             ix = -(iw-thumb)*0.5
             iy = 0
         in drawImage iw ih ix iy

       shadowPaint <- boxGradient vg (tx-1) ty (thumb+2) (thumb+2) 5 3 (rgba 0 0 0 128) (rgba 0 0 0 0)
       beginPath vg
       rect vg (tx-5) (ty-5) (thumb+10) (thumb+10)
       roundedRect vg tx ty thumb thumb 6
       pathWinding vg (fromIntegral $ fromEnum Hole)
       fillPaint vg shadowPaint
       fill vg

       beginPath vg
       roundedRect vg (tx+0.5) (ty+0.5) (thumb-1) (thumb-1) (4-0.5)
       strokeWidth vg 1
       strokeColor vg (rgba 255 255 255 192)
       stroke vg


     restore vg

     restore vg
drawThumbnails :: Context -> CFloat -> CFloat -> CFloat -> CFloat -> V.Vector Image -> CFloat -> IO ()
drawThumbnails vg x y w h images t =
  do let cornerRadius = 3
         thumb = 60
         arry = 30.5
         nimages = V.length images
         stackh = (fromIntegral nimages/2)*(thumb+10)+10
         u = (1+cos (t*0.5))*0.5
         u2 = (1-cos (t*0.2))*0.5
         dv = 1/(fromIntegral nimages - 1)
     save vg

     shadowPaint <- boxGradient vg x (y+4) w h (cornerRadius*2) 20 (rgba 0 0 0 128) (rgba 0 0 0 0)
     beginPath vg
     rect vg (x-10) (y-10) (w+20) (h+30)
     roundedRect vg x y w h cornerRadius
     pathWinding vg (fromIntegral $ fromEnum Hole)
     fillPaint vg shadowPaint
     fill vg

     beginPath vg
     roundedRect vg x y w h cornerRadius
     moveTo vg (x-10) (y+arry)
     lineTo vg (x+1) (y+arry-11)
     lineTo vg (x+1) (y+arry+11)
     fillColor vg (rgba 200 200 200 255)
     fill vg

     save vg
     scissor vg x y w h
     translate vg 0 (-(stackh-h)*u)

     flip V.imapM_ images $ \i image -> do
       let tx = x + 10 + fromIntegral (i `mod` 2) * (thumb + 10)
           ty = y + 10 + fromIntegral (i `div` 2) * (thumb + 10)
           v = fromIntegral i * dv
           a = clamp ((u2-v)/dv) 0 1
           drawImage iw ih ix iy = do
             imgPaint <- imagePattern vg (tx+ix) (ty+iy) iw ih (0/180*pi) image a
             beginPath vg
             roundedRect vg tx ty thumb thumb 5
             fillPaint vg imgPaint
             fill vg
       (imgw,imgh) <- imageSize vg image

       when (a < 1) $ drawSpinner vg (tx + thumb/2) (ty+thumb/2) (thumb*0.25) t

       if imgw < imgh
       then
         let iw = thumb
             ih = iw*fromIntegral imgh/fromIntegral imgw
             ix = 0
             iy = -(ih-thumb)*0.5
         in drawImage iw ih ix iy
       else
         let ih = thumb
             iw = ih * fromIntegral imgw/ fromIntegral imgh
             ix = -(iw-thumb)*0.5
             iy = 0
         in drawImage iw ih ix iy

       shadowPaint <- boxGradient vg (tx-1) ty (thumb+2) (thumb+2) 5 3 (rgba 0 0 0 128) (rgba 0 0 0 0)
       beginPath vg
       rect vg (tx-5) (ty-5) (thumb+10) (thumb+10)
       roundedRect vg tx ty thumb thumb 6
       pathWinding vg (fromIntegral $ fromEnum Hole)
       fillPaint vg shadowPaint
       fill vg

       beginPath vg
       roundedRect vg (tx+0.5) (ty+0.5) (thumb-1) (thumb-1) (4-0.5)
       strokeWidth vg 1
       strokeColor vg (rgba 255 255 255 192)
       stroke vg


     restore vg

     restore vg
drawThumbnails vg x y w h images t =
  do let cornerRadius = 3
         thumb = 60
         arry = 30.5
         nimages = V.length images
         stackh = (fromIntegral nimages/2)*(thumb+10)+10
         u = (1+cos (t*0.5))*0.5
         u2 = (1-cos (t*0.2))*0.5
         dv = 1/(fromIntegral nimages - 1)
     save vg

     shadowPaint <- boxGradient vg x (y+4) w h (cornerRadius*2) 20 (rgba 0 0 0 128) (rgba 0 0 0 0)
     beginPath vg
     rect vg (x-10) (y-10) (w+20) (h+30)
     roundedRect vg x y w h cornerRadius
     pathWinding vg (fromIntegral $ fromEnum Hole)
     fillPaint vg shadowPaint
     fill vg

     beginPath vg
     roundedRect vg x y w h cornerRadius
     moveTo vg (x-10) (y+arry)
     lineTo vg (x+1) (y+arry-11)
     lineTo vg (x+1) (y+arry+11)
     fillColor vg (rgba 200 200 200 255)
     fill vg

     save vg
     scissor vg x y w h
     translate vg 0 (-(stackh-h)*u)

     flip V.imapM_ images $ \i image -> do
       let tx = x + 10 + fromIntegral (i `mod` 2) * (thumb + 10)
           ty = y + 10 + fromIntegral (i `div` 2) * (thumb + 10)
           v = fromIntegral i * dv
           a = clamp ((u2-v)/dv) 0 1
           drawImage iw ih ix iy = do
             imgPaint <- imagePattern vg (tx+ix) (ty+iy) iw ih (0/180*pi) image a
             beginPath vg
             roundedRect vg tx ty thumb thumb 5
             fillPaint vg imgPaint
             fill vg
       (imgw,imgh) <- imageSize vg image

       when (a < 1) $ drawSpinner vg (tx + thumb/2) (ty+thumb/2) (thumb*0.25) t

       if imgw < imgh
       then
         let iw = thumb
             ih = iw*fromIntegral imgh/fromIntegral imgw
             ix = 0
             iy = -(ih-thumb)*0.5
         in drawImage iw ih ix iy
       else
         let ih = thumb
             iw = ih * fromIntegral imgw/ fromIntegral imgh
             ix = -(iw-thumb)*0.5
             iy = 0
         in drawImage iw ih ix iy

       shadowPaint <- boxGradient vg (tx-1) ty (thumb+2) (thumb+2) 5 3 (rgba 0 0 0 128) (rgba 0 0 0 0)
       beginPath vg
       rect vg (tx-5) (ty-5) (thumb+10) (thumb+10)
       roundedRect vg tx ty thumb thumb 6
       pathWinding vg (fromIntegral $ fromEnum Hole)
       fillPaint vg shadowPaint
       fill vg

       beginPath vg
       roundedRect vg (tx+0.5) (ty+0.5) (thumb-1) (thumb-1) (4-0.5)
       strokeWidth vg 1
       strokeColor vg (rgba 255 255 255 192)
       stroke vg


     restore vg

     restore vg