Re: Circles and DrawingAreas

On Sun, 22 Jul 2001, Fannin, David P. wrote:

Has anyone out there successfully created a circle and placed it inside a
DrawingArea?  I'm almost finished with a project, and what I thought was
going to be a trivial final detail is turning out to be quite complicated.
None of the documentation I've seen covers the DrawingArea widget or its use
in much detail.  I've gathered that I have to create a pixmap onto which to
render the circle (using Gtk::Curve I suppose), but thus far I've not been
able to get the Gtk::Gdk::Pixmap::new procedure to work.  I've read through
the Gtk-Perl Tutorial and as much of the documentation at as I
could.  Are there other sources of documentation that I may have overlooked?

Unfortunately, the tutorial doesn't cover Gdk graphics and probably never
will.  Its already too large to be considered a tutorial.  I don't have an
example handy, but what you want to look into are the Gdk drawing
privitives.  Specifically, to draw an arc you would use:

    Gtk::Gdk::draw_arc( $drawable, $gc, $filled,
                        $x, $y, $width, $height,
                        $angle1, $angle2 );

For a circle, obviously the width and height would be the same, and angle1
would be 0 and angle2 would be 360*64 (angle is measured, oddly enough, in
64th of a degree).  The $filled variable is a true or false value.

Getting the drawable value is as simple as creating a drawing area widget

    $area = new Gtk::DrawingArea();

And then getting its GdkWindow:

    $drawable = $area->window;

The tricky part is getting the graphics context.  I don't want to get too
much into this, so for a test just use something like:

    $gc = $area->style->black_gc;

Sorry I couldn't be more helpful, but I'm too lazy to put together a
sample program.  What I did give, though, should be enough to get you
started in the right direction.

One last thing you need to be aware of are the events used by the drawing
area.  The important ones are 'configure_event' and 'expose_event'.  A
'configure_event' occurs when the drawing area is created or resized.  An
'expose_event' is usually (but not always) sent when the drawing_area
needs to be repainted because another window is moved off it.

Stephen Wilhelm
    See my Gtk-Perl Tutorial:

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]