module BitmapDrawing(BitmapFile(..)) where import Graphic import MeasuredGraphics(MeasuredGraphics(..)) import GCtx(GCtx(..)) import DrawTypes import Geometry(Rect(..),origin) import Xtypes --import FudgetIO import NullF() -- instances, for hbc import LayoutRequest(refpLayout,plainLayout) import Gc import StdIoUtil(echoStderrK) import Pixmap(bitmapFromData, readBitmapFile) import Data.Maybe(maybeToList) --import ContinuationIO(stderr) data BitmapFile = BitmapFile String instance Graphic BitmapFile where measureGraphicK (BitmapFile filename) gctx@(GC gc _) k = readBitmapFile filename $ \ bmret -> case bmret of BitmapBad -> echoStderrK ("Failed to load bitmap "++filename) $ k (bitmapBad gc) BitmapReturn bm -> measureGraphicK bm gctx k instance Graphic (Bitmap PixmapId) where measureGraphicK (Bitmap size optrefp pixmap) (GC gc _) k = wCreateGC gc [GCGraphicsExposures False] $ \ gc' -> k (LeafM ll (drawit gc')) where r = Rect origin size ll = refpLayout size True True (maybeToList optrefp) drawit gc (Rect p _) = [(gc,[CopyPlane (Pixmap pixmap) r p 0])] instance Graphic BitmapData where measureGraphicK bmdata gctx k = bitmapFromData bmdata $ \ (BitmapReturn bm) -> measureGraphicK bm gctx k bitmapBad gc = LeafM ll drawit where ll = plainLayout 20 False False drawit r = [(gc,[FillRectangle r])]