module FixedDrawing where
import Graphic
import MeasuredGraphics(MeasuredGraphics(..),measureImageString)
import GCtx(GCtx(..))
import ResourceIds(GCId)
import LayoutRequest
import Geometry(Rect(..),Size(..))
import Command(DrawCommand)
import Drawcmd(move)
--import EitherUtils(Cont(..))

data FixedDrawing = FixD Size [DrawCommand] deriving Int -> FixedDrawing -> ShowS
[FixedDrawing] -> ShowS
FixedDrawing -> String
(Int -> FixedDrawing -> ShowS)
-> (FixedDrawing -> String)
-> ([FixedDrawing] -> ShowS)
-> Show FixedDrawing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FixedDrawing] -> ShowS
$cshowList :: [FixedDrawing] -> ShowS
show :: FixedDrawing -> String
$cshow :: FixedDrawing -> String
showsPrec :: Int -> FixedDrawing -> ShowS
$cshowsPrec :: Int -> FixedDrawing -> ShowS
Show

instance Graphic FixedDrawing where
  measureGraphicK :: FixedDrawing -> GCtx -> Cont (k i o) MeasuredGraphics
measureGraphicK (FixD Size
s [DrawCommand]
dcmds) (GC GCId
gc FontData
_) MeasuredGraphics -> k i o
k =
      MeasuredGraphics -> k i o
k (LayoutRequest
-> (Rect -> [(GCId, [DrawCommand])]) -> MeasuredGraphics
LeafM (Size -> Bool -> Bool -> LayoutRequest
plainLayout Size
s Bool
True Bool
True) Rect -> [(GCId, [DrawCommand])]
drawit)
    where
      drawit :: Rect -> [(GCId, [DrawCommand])]
drawit (Rect Size
p Size
_) = [(GCId
gc,Size -> [DrawCommand] -> [DrawCommand]
forall a. Move a => Size -> a -> a
move Size
p [DrawCommand]
dcmds)]

data FixedColorDrawing = FixCD Size [(GCId,[DrawCommand])] deriving Int -> FixedColorDrawing -> ShowS
[FixedColorDrawing] -> ShowS
FixedColorDrawing -> String
(Int -> FixedColorDrawing -> ShowS)
-> (FixedColorDrawing -> String)
-> ([FixedColorDrawing] -> ShowS)
-> Show FixedColorDrawing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FixedColorDrawing] -> ShowS
$cshowList :: [FixedColorDrawing] -> ShowS
show :: FixedColorDrawing -> String
$cshow :: FixedColorDrawing -> String
showsPrec :: Int -> FixedColorDrawing -> ShowS
$cshowsPrec :: Int -> FixedColorDrawing -> ShowS
Show

instance Graphic FixedColorDrawing where
  measureGraphicK :: FixedColorDrawing -> GCtx -> Cont (k i o) MeasuredGraphics
measureGraphicK (FixCD Size
s [(GCId, [DrawCommand])]
gcdcmds) GCtx
_ MeasuredGraphics -> k i o
k =
      MeasuredGraphics -> k i o
k (LayoutRequest
-> (Rect -> [(GCId, [DrawCommand])]) -> MeasuredGraphics
LeafM (Size -> Bool -> Bool -> LayoutRequest
plainLayout Size
s Bool
True Bool
True) Rect -> [(GCId, [DrawCommand])]
drawit)
    where
      drawit :: Rect -> [(GCId, [DrawCommand])]
drawit (Rect Size
p Size
_) =
        if Size
pSize -> Size -> Bool
forall a. Eq a => a -> a -> Bool
==Size
0
	then [(GCId, [DrawCommand])]
gcdcmds
	else [(GCId
gc,Size -> [DrawCommand] -> [DrawCommand]
forall a. Move a => Size -> a -> a
move Size
p [DrawCommand]
dcmds)|(GCId
gc,[DrawCommand]
dcmds)<-[(GCId, [DrawCommand])]
gcdcmds]


newtype ImageString = ImageString String

instance Graphic ImageString where
  measureGraphicK :: ImageString -> GCtx -> Cont (k i o) MeasuredGraphics
measureGraphicK (ImageString String
s) = String -> GCtx -> Cont (k i o) MeasuredGraphics
forall (f :: * -> * -> *) b ho.
FudgetIO f =>
String -> GCtx -> (MeasuredGraphics -> f b ho) -> f b ho
measureImageString String
s