data Point = Point !Int !Int deriving (Show, Eq)
-type Color = Gtk.Color
+-- A color, with RGB values from 0 to 1
+data Color = Color Double Double Double deriving (Show, Eq)
-- Create a Color from Red, Green and Blue values. The inputs should be
-- between 0 and 255 (inclusive).
rgb :: Int -> Int -> Int -> Color
-rgb r g b = Gtk.Color (conv r) (conv g) (conv b)
- where conv = fromInteger . toInteger . (*256)
+rgb r g b = Color (conv r) (conv g) (conv b)
+ where conv = (/256) . fromIntegral
-- | Some predefined colours
red = rgb 0xff 0 0
-- Repack state
let state = IS { .. }
-
+
+ -- Process any initial requests
+ processPostponed state
+
-- Show the window and start the Gtk mainloop.
Gtk.widgetShowAll window
Gtk.mainGUI
+
-- | Copy the given surface to the exposed window on an expose event.
onExpose :: IORef Cairo.Surface -> EventM.EventM EventM.EExpose Bool
-}
winHandler _ _ = Nothing
+gfxHandler s req = case gfxHandler' req of
+ Nothing -> Nothing
+ Just render -> Just $ do
+ buf <- readIORef (buffer s)
+ Cairo.renderWith buf render
+ Gtk.widgetQueueDraw (window s)
+
{-
gfxHandler IS {..} (GfxLines col ps) = Just $ polyline buffer ps [penColor := col] >> dirtyPts sPanel ps
gfxHandler IS {..} (GfxPolygon col ps) = Just $ polygon buffer ps [penColor := col, brushColor := col] >> dirtyPts sPanel ps
gfxHandler IS {..} (GfxEllipse col rt) = Just $ ellipse buffer rt [penColor := col, brushKind := BrushTransparent] >> dirtyRect sPanel rt
gfxHandler IS {..} (GfxDisc col rt) = Just $ ellipse buffer rt [penColor := col, brushColor := col] >> dirtyRect sPanel rt
gfxHandler IS {..} (GfxFont st sz) = Just $ buffer `set` [ fontSize := sz, fontFace := st ]
-gfxHandler IS {..} GfxClear = Just $ dcClear buffer >> windowRefresh sPanel False
gfxHandler IS {..} (GfxPicture fd pt) = Just $ bitmapCreateFromFile fd >>= \bm -> drawBitmap buffer bm pt False [] >> bitmapGetSize bm >>= dirtyRect' sPanel pt
-}
-gfxHandler _ _ = Nothing
+gfxHandler' (GfxText col (Point x y) st) = Just $ do
+ setSourceColor col
+ Cairo.moveTo (fromIntegral x) (fromIntegral y)
+ Cairo.showText st
+gfxHandler' GfxClear = Just $ do
+ Cairo.setSourceRGB 1 1 1
+ Cairo.paint
+gfxHandler' _ = Nothing
+
+-- | Sets the source to a pattern fill of the given color
+setSourceColor :: Color -> Cairo.Render ()
+setSourceColor (Color r g b) =
+ Cairo.setSourceRGB r g b
{-
dirtyPts :: Window a -> [Point] -> IO ()