module Main where

import Graphics.Rendering.Diagrams
import Control.Arrow ((***))

main = renderOverPNG "alasdair.png" "bubble.png" dia

para sz = vcatA left . map (text sz)

underlay a b = a `withSize` b ## b
atop a b = vcatA hcenter [(a `withSize` b), b]

plainbubble strs = bubble `underlay` writing
    where writing    = para 12 strs
          bubble w h = fc white $ lc white $ roundRect (w*1.2) (h*1.2)

dia = position [((0,0),nil), ((450,280), alitalk), ((230,300),plea)]
    where alitalk = bubbletail left top `atop` plainbubble quote
          plea    = bubbletail right top `atop` plainbubble ["help!"]

quote =
    ["Come join me!"
    ,""
    ,"We shall drink mead and tell"
    ,"tales of our ancestors!"]

bubbletail ha va w h = fc white $ lc white $ curved 0 $ pathFromVertices pts
  where scaleWH = map (\(x,y) -> (x*w/3,y*h/2))
        pts = scaleWH $ map (if ha==left then id else negate ***
                             if va==top then id else negate) upleft
        upleft = [(-0.25,0),(-1,-1),(0.25,0)]

