From 8b21eea5d5be2a1ac267693382e77b772a10d73a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 24 Aug 2009 21:04:55 +0200 Subject: [PATCH] Implement the GfxText request. This stops using the Gtk.Color datatype, and adds a setSoureColor to wrap setSourceRGB and which can be called with our own Color datatype. --- FPPrac.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/FPPrac.hs b/FPPrac.hs index d8fd94f..fcbf33e 100644 --- a/FPPrac.hs +++ b/FPPrac.hs @@ -30,13 +30,14 @@ data Rect = Rect 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 @@ -277,9 +278,18 @@ gfxHandler IS {..} (GfxDisc col rt) = Just $ ellipse buffer rt [penColor gfxHandler IS {..} (GfxFont st sz) = Just $ buffer `set` [ fontSize := sz, fontFace := st ] gfxHandler IS {..} (GfxPicture fd pt) = Just $ bitmapCreateFromFile fd >>= \bm -> drawBitmap buffer bm pt False [] >> bitmapGetSize bm >>= dirtyRect' sPanel pt -} +gfxHandler' IS {..} (GfxText col (Point x y) st) = Just $ do + setSourceColor col + Cairo.moveTo (fromIntegral x) (fromIntegral y) + Cairo.showText st gfxHandler' IS {..} GfxClear = Just $ 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 () dirtyPts dc ps = dirtyRect' dc (pt x y) Size {..} -- 2.30.2