module BitmapDrawing where
import Graphic
import MeasuredGraphics(MeasuredGraphics(..))
import GCtx(GCtx(..))
import Event(BitmapReturn(..))
import DrawTypes
import Geometry(Rect(..),origin)
import Xtypes
import NullF()
import LayoutRequest(refpLayout,plainLayout)
import Gc
import StdIoUtil(echoStderrK)
import Pixmap(readBitmapFile)
import Data.Maybe(maybeToList)
data BitmapFile = BitmapFile String
instance Graphic BitmapFile where
measureGraphicK :: BitmapFile -> GCtx -> Cont (k i o) MeasuredGraphics
measureGraphicK (BitmapFile String
filename) (GC GCId
gc FontData
_) MeasuredGraphics -> k i o
k =
String -> (BitmapReturn -> k i o) -> k i o
forall (f :: * -> * -> *) b ho.
FudgetIO f =>
String -> (BitmapReturn -> f b ho) -> f b ho
readBitmapFile String
filename ((BitmapReturn -> k i o) -> k i o)
-> (BitmapReturn -> k i o) -> k i o
forall a b. (a -> b) -> a -> b
$ \ BitmapReturn
bmret ->
case BitmapReturn
bmret of
BitmapReturn Size
size Maybe Size
optrefp PixmapId
pixmap ->
GCId -> [GCAttributes Pixel FontId] -> (GCId -> k i o) -> k i o
forall (f :: * -> * -> *) b ho.
FudgetIO f =>
GCId -> [GCAttributes Pixel FontId] -> (GCId -> f b ho) -> f b ho
wCreateGC GCId
gc [Bool -> GCAttributes Pixel FontId
forall a b. Bool -> GCAttributes a b
GCGraphicsExposures Bool
False] ((GCId -> k i o) -> k i o) -> (GCId -> k i o) -> k i o
forall a b. (a -> b) -> a -> b
$ \ GCId
gc' ->
MeasuredGraphics -> k i o
k (LayoutRequest
-> (Rect -> [(GCId, [DrawCommand])]) -> MeasuredGraphics
LeafM LayoutRequest
ll (GCId -> Rect -> [(GCId, [DrawCommand])]
forall a. a -> Rect -> [(a, [DrawCommand])]
drawit GCId
gc'))
where r :: Rect
r = Size -> Size -> Rect
Rect Size
origin Size
size
ll :: LayoutRequest
ll = Size -> Bool -> Bool -> [Size] -> LayoutRequest
refpLayout Size
size Bool
True Bool
True (Maybe Size -> [Size]
forall a. Maybe a -> [a]
maybeToList Maybe Size
optrefp)
drawit :: a -> Rect -> [(a, [DrawCommand])]
drawit a
gc (Rect Size
p Size
_) = [(a
gc,[Drawable -> Rect -> Size -> Int -> DrawCommand
CopyPlane (PixmapId -> Drawable
Pixmap PixmapId
pixmap) Rect
r Size
p Int
0])]
BitmapReturn
_ ->
String -> k i o -> k i o
forall (f :: * -> * -> *) b ho.
FudgetIO f =>
String -> f b ho -> f b ho
echoStderrK (String
"Failed to load bitmap "String -> String -> String
forall a. [a] -> [a] -> [a]
++String
filename) (k i o -> k i o) -> k i o -> k i o
forall a b. (a -> b) -> a -> b
$
MeasuredGraphics -> k i o
k (LayoutRequest
-> (Rect -> [(GCId, [DrawCommand])]) -> MeasuredGraphics
LeafM LayoutRequest
ll Rect -> [(GCId, [DrawCommand])]
drawit)
where ll :: LayoutRequest
ll = Size -> Bool -> Bool -> LayoutRequest
plainLayout Size
20 Bool
False Bool
False
drawit :: Rect -> [(GCId, [DrawCommand])]
drawit Rect
r = [(GCId
gc,[Rect -> DrawCommand
FillRectangle Rect
r])]