module Graphics.UI.Gtk.Cairo (
cairoFontMapGetDefault,
cairoFontMapSetResolution,
cairoFontMapGetResolution,
cairoCreateContext,
cairoContextSetResolution,
cairoContextGetResolution,
cairoContextSetFontOptions,
cairoContextGetFontOptions,
getClipRectangle,
renderWithDrawWindow,
setSourceColor,
setSourcePixbuf,
rectangle,
updateContext,
createLayout,
updateLayout,
showGlyphString,
showLayoutLine,
showLayout,
glyphStringPath,
layoutLinePath,
layoutPath
) where
import Control.Exception (bracket)
import System.Glib.FFI
import Graphics.UI.Gtk.Types
import Graphics.Rendering.Pango.Cairo
import Graphics.Rendering.Cairo.Types as Cairo
import qualified Graphics.Rendering.Cairo.Internal as Cairo.Internal
import Graphics.Rendering.Cairo.Internal (Render(Render))
import Control.Monad.Reader
import Graphics.UI.Gtk.General.Structs (Rectangle(..))
renderWithDrawWindow :: DrawWindowClass drawWindow =>
drawWindow
-> Render a
-> IO a
renderWithDrawWindow drawWindow m =
bracket (liftM Cairo.Cairo $ (\(DrawWindow arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_cairo_create argPtr1) (toDrawWindow drawWindow))
(\context -> do status <- Cairo.Internal.status context
Cairo.Internal.destroy context
unless (status == Cairo.StatusSuccess) $
fail =<< Cairo.Internal.statusToString status)
(\context -> runReaderT (Cairo.Internal.runRender m) context)
getClipRectangle :: Render (Maybe Rectangle)
getClipRectangle = Render $ do
cr <- ask
liftIO $ alloca $ \rectPtr -> do
ok <- (\(Cairo arg1) arg2 -> gdk_cairo_get_clip_rectangle arg1 arg2)
cr
(castPtr rectPtr)
if ok /= 0
then fmap Just (peek rectPtr)
else return Nothing
setSourcePixbuf ::
Pixbuf
-> Double
-> Double
-> Render ()
setSourcePixbuf pixbuf pixbufX pixbufY = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (Pixbuf arg2) arg3 arg4 -> withForeignPtr arg2 $ \argPtr2 ->gdk_cairo_set_source_pixbuf arg1 argPtr2 arg3 arg4)
cr
pixbuf
(realToFrac pixbufX)
(realToFrac pixbufY)
rectangle :: Rectangle -> Render ()
rectangle rect = Render $ do
cr <- ask
liftIO $ with rect $ \ rectPtr ->
(\(Cairo arg1) arg2 -> gdk_cairo_rectangle arg1 arg2)
cr
(castPtr rectPtr)
foreign import ccall unsafe "gdk_cairo_create"
gdk_cairo_create :: ((Ptr DrawWindow) -> (IO (Ptr Cairo)))
foreign import ccall unsafe "gdk_cairo_get_clip_rectangle"
gdk_cairo_get_clip_rectangle :: ((Ptr Cairo) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall unsafe "gdk_cairo_set_source_pixbuf"
gdk_cairo_set_source_pixbuf :: ((Ptr Cairo) -> ((Ptr Pixbuf) -> (CDouble -> (CDouble -> (IO ())))))
foreign import ccall unsafe "gdk_cairo_rectangle"
gdk_cairo_rectangle :: ((Ptr Cairo) -> ((Ptr ()) -> (IO ())))