I’m finally happy with the code and it’s really time to share it, I expect feedback, don’t be too cruel! :-)

You’ll need GHC, c2hs (I used the latest 0.14.3, but it prolly works with previous versions), and cairo (>= 0.6.0), to try compiling the code. Some instructions:

  1. darcs get
  2. cd cairobindings && make this in fact does translate the .chs files to .hs modules.
  3. ghci -fffi -lcairo -i$(pwd) demo/StarAndRing.hs and then try “main” at the prompt, it will create the starAndRing.png in the current directory

Some notes: the Makefiles are mainly thought for developing purposes locally. The base hierarchy of the modules is Graphics.Rendering.Cairo: Cairo.{chs,hs} will be the higher-level monadic interface inspired by Abraham Egnor’s one. I’m not fond on revision control systems, I’ll do my best to keep the public repository up-to-date and avoid to mess up everything (I’m a bit afraid of that :-)) - but in fact darcs is pretty nice and easy to use.

Have fun!

7 Responses to “Code”

  1. Duncan Says:

    Well done Paolo!
    I’ve got it building and it produces the png image with the circle and star.

    I’m really looking forward to the animated version with a Gtk+ GUI! :-)

  2. Gour Says:

    Hi Paolo!

    Your project is a wonderful way to promote Haskell & gtk2hs bindings and I’m looking forward to catch it with my Haskell skills ;)

    Although I do not have lot of free time at the moment, I am tempted to try out your bindings :-)

    Pulled code from the repo, emerged cairo and after running make I get:

    gour@gaura-nitai ~/repos/cairobindings $ make
    make -C Graphics/Rendering/Cairo all
    make[1]: Entering directory `/home/gour/repos/cairobindings/Graphics/Rendering/Cairo’
    c2hs -C-I/usr/include/cairo -i/home/gour/repos/cairobindings -o Types.hs Types.chs
    c2hs -C-I/usr/include/cairo -i/home/gour/repos/cairobindings -o Internal.hs Internal.chs
    c2hs: Graphics.chi not found in:

    make[1]: *** [Internal.hs] Error 1
    make[1]: Leaving directory `/home/gour/repos/cairobindings/Graphics/Rendering/Cairo’
    make: *** [all] Error 2

    It looks like my dev-environment is a little bit strange, i.e.:
    - The Glorious Glasgow Haskell Compilation System, version
    - c2hs-0.13.4 (maybe this is is wrong?)
    - x11-libs/cairo-0.9.2 (or this one breaks api?)

    Any hint?


    After upgrading to c2hs-0.14.3 it compiles nicely :)
    but building of demo fails: :-(

    ghc -v -fffi -lcairo -i$(pwd) demo/StarAndRing.hs
    Failed to load interface for `Graphics.Rendering.Cairo.Internal’:
    Could not find module `Graphics.Rendering.Cairo.Internal’:
    locations searched:


  3. Duncan Says:

    Ok, take a look at this:

    The original GDK version

    And now the version using cairo!

    So yes, we do have it working with Gtk+. Like the original version, it animates as the window is resized.

    Look closely at the full size versions of both screenshots, you’ll notice that the cairo version has nice smooth lines rather than rough pixelated edges like in the GDK version.

  4. Paolo Martini Says:

    Gour, I fixed the current buildsystem (hopefully). Could you try darcs pull and check? Thank you.
    0.9.2 should not break anything IMO - I followed the latest documentation while writing the bindings, tough I had to comment out some functions because there weren’t in 0.6.0, but not the opposite.
    Anyway, I’m working on the fonts function and I’ll go for 0.9.2 :-)

  5. Gour Says:

    Hi Paolo!

    Still - the same problem :-(

    Note that I’m on am64 and “foreign import is not implemented for GHCi on this platform”, so I have to run ghc.


  6. Silas Says:

    Congrats on finishing! I’m planning on using this, hopefully sooner rather than later. Now all that’s left is to rewrite Hudak’s School of Expression to use this instead of HGL ;-)

  7. Paolo Martini Says:

    Will do!
    There is some experimental Font support now, and the new repository is changed, I’m thinking of blog-posting about this, I’ll do soon!