module FixedDrawing where import Graphic import MeasuredGraphics(MeasuredGraphics(..),measureImageString) import GCtx(GCtx(..)) import ResourceIds(GCId) import LayoutRequest import Geometry(Rect(..),Point(..),Size(..)) import Command(DrawCommand) import Drawcmd(move) --import EitherUtils(Cont(..)) data FixedDrawing = FixD Size [DrawCommand] deriving Show instance Graphic FixedDrawing where measureGraphicK (FixD s dcmds) (GC gc _) k = k (LeafM (plainLayout s True True) drawit) where drawit (Rect p _) = [(gc,move p dcmds)] data FixedColorDrawing = FixCD Size [(GCId,[DrawCommand])] deriving Show emptyCD = blankCD 0 blankCD sz = FixCD sz [] aboveCD (FixCD (Point w1 h1) dcmds1) (FixCD (Point w2 h2) dcmds2) = FixCD sz (dcmds1++moveDcmds d dcmds2) where d = Point 0 h1 sz = Point (max w1 w2) (h1+h2) besideCD (FixCD (Point w1 h1) dcmds1) (FixCD (Point w2 h2) dcmds2) = FixCD sz (dcmds1++moveDcmds d dcmds2) where d = Point w1 0 sz = Point (w1+w2) (max h1 h2) hboxCD cds = foldr besideCD emptyCD cds vboxCD cds = foldr aboveCD emptyCD cds instance Graphic FixedColorDrawing where measureGraphicK (FixCD s gcdcmds) _ k = k (LeafM (plainLayout s True True) drawit) where drawit (Rect p _) = moveDcmds p gcdcmds moveDcmds p gcdcmds = if p==0 then gcdcmds else [(gc,move p dcmds)|(gc,dcmds)<-gcdcmds] newtype ImageString = ImageString String instance Graphic ImageString where measureGraphicK (ImageString s) = measureImageString s