Code
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:
darcs get http://haskell.galois.com/~paolo/darcs/cairobindingscd cairobindings && makethis in fact does translate the .chs files to .hs modules.ghci -fffi -lcairo -i$(pwd) demo/StarAndRing.hsand 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!
August 17th, 2005 at 4:56 pm
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!
August 18th, 2005 at 6:06 am
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 $ makemake -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:
/home/gour/repos/cairobindings
.
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 6.4.1.20050801
- c2hs-0.13.4 (maybe this is is wrong?)
- x11-libs/cairo-0.9.2 (or this one breaks api?)
Any hint?
Edit:
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:
Graphics/Rendering/Cairo/Internal.hi
Graphics/Rendering/Cairo/Internal.hi-boot
/home/gour/repos/cairobindings/Graphics/Rendering/Cairo/Internal.hi
/home/gour/repos/cairobindings/Graphics/Rendering/Cairo/Internal.hi-boot
Sincerely,
Gour
August 18th, 2005 at 9:51 am
Ok, take a look at this:
The original GDK version
![[img]](http://projects.haskell.org/gtk2hs/albums/cairo/Screenshot_drawing_gdk.thumb.png)
And now the version using cairo!
![[img]](http://projects.haskell.org/gtk2hs/albums/cairo/Screenshot_drawing_cairo.thumb.png)
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.
August 18th, 2005 at 11:12 am
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
August 18th, 2005 at 11:38 am
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.
Sincerely,
Gour
August 22nd, 2005 at 8:19 pm
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
August 22nd, 2005 at 8:34 pm
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!