module SWDc(drawInBitmap) where import Graphics.UI.WXCore drawInBitmap :: DC a -> Rect -> (DC () -> IO ()) -> IO (IO (Bitmap ())) drawInBitmap dc view draw = do bitmap <- bitmapCreateEmpty (rectSize view) (-1) memdc <- do p <- memoryDCCreateCompatible dc; return (objectCast p) memoryDCSelectObject memdc bitmap brush <- dcGetBackground dc let restOfDraw = do drawBuffered brush memdc memoryDCSelectObject memdc nullBitmap memoryDCDelete memdc return bitmap return restOfDraw where drawBuffered brush memdc = do -- set the device origin for scrolled windows dcSetDeviceOrigin memdc (pointFromVec (vecNegate (vecFromPoint (rectTopLeft view)))) dcSetClippingRegion memdc view -- set the background to the owner brush dcSetBackground memdc brush if (wxToolkit == WxMac) then withBrushStyle brushTransparent (dcSetBrush memdc) else dcSetBrush memdc brush dcClearRect (downcastDC memdc) view -- and finally do the drawing! draw (downcastDC memdc) -- down cast dcSetBrush memdc nullBrush brushDelete brush return () -- blit the memdc into the owner dc. -- dcBlit dc view memdc (rectTopLeft view) wxCOPY False