[cairo] graphics problem

Stefan Salewski mail at ssalewski.de
Wed Oct 14 07:28:20 PDT 2015


On Wed, 2015-10-14 at 14:47 +0300, Roman Goldov wrote:
> i would appreciate if someone could send me a few examples (of full
> working C-files) of how one could incorporate 
> cairo into gtk+-1.2. - at the moment i looked through examples at the
> web-site "http://cairographics.org/examples/",
> howevere i could not understand how one could use cairo functions to
> draw/insert lines, color rectangles and other color (or b/w) pictures
> in a window created by gtk+.

So you have no special reasons using old GTK2 only? I would really
assume that your CentOS offers GTK3 as well. Have you tried the built
instruction from zetcode.com for gtk3:

gcc example.c -o example `pkg-config --cflags --libs gtk+-3.0`

Yes, there are not many examples available for cairo and gtkdrawingarea.
I am using that for my schematics editor (
http://ssalewski.de/PetEd.html.en) but that is in Ruby, later I may
translate that to Nim.

I guees you have reasons using plain C only.

GTK3 is shipped with at least one example for cairo and drawingarea, for
GTK 3.18.1 that is

gtk+-3.18.1/examples/drawing.c

You can compile it with

gcc drawing.c -o test `pkg-config --cflags --libs gtk+-3.0`

and lauch with

./test

When you hold down left mouse button you can draw on screen, before that
you may resize the window.

I just got

(test:2726): Gtk-CRITICAL **: gtk_main_quit: assertion 'main_loops !=
NULL' failed

when closing that window. May be caused by the fact that this example is
for GTK 3.18 and my gentoo box is running still gtk 3.16.

So you may find out which gtk version is really installed on your box
and use examples/drawing.c matched for that version. You can download
full gtk sources from www.gtk.org, what I did. Or you may try from
github, https://github.com/GNOME/gtk/tree/master/examples but that may
give you only the latest example.

For your zetcode example, remember how it works. You set points by
clicking left mouse button, but they remain invisible until you click
right mouse button.

If you really need old GTK2, try downloading GTK2 source package from
gtk.org, I guess it contains an old drawing.c.

Or you may search with google for sources of the old GTK2 book from
Andrew  Krause, there was one example available, and sources where
freely available 7 years ago. I may still have them somewhere, but it is
some work to find...



More information about the cairo mailing list