Re: Drawing charts with gtk

On Sun, Apr 01, 2001 at 04:55:51PM -0500 Ronald Roth wrote:


Hi, I have written a very similar program. Check out the cvs section at There is also a first release at this site,
but the CVS version is more useful and quite stable.

The directories are not shown as
pies but they are shown as rectangles (tree map). WHat i do is the
following: First i scan the the directory structure and store it in an
internal tree. If a directory (or any subdirectory) is drawn, some
information is saved in the internal tree (in my case the upper left and
lower right corner of the rectangle, i your case this might be the center of
the arc, width, height, start and end angle).

If you move the mouse, then the move event callback is called where i search for (x,y)
in the internal tree (as i saved the geometric info). If the subfolder is
found i highlight it (i my case i do a XOR rectangle draw)

Some notes: 
* If you do a gdk_draw_* the information is not drawn permanently.
On receiving an expose event all this information will be gone. YOu have to catch
the expose event and call a expose callback. In this function you call the
real drawing method:

  gtk_signal_connect (GTK_OBJECT (drawingarea1), "expose_event",
                      GTK_SIGNAL_FUNC (on_drawingarea1_expose_event),

  on_drawingarea1_expose_event           (GtkWidget       *widget,
                                          GdkEventExpose  *event,
                                          gpointer         user_data)
    if (global.expose_timer >= 0) {
    global.expose_timer = 
      gtk_timeout_add(200, expose_timeout_cb, NULL);
    return FALSE;

  int expose_timeout_cb(gpointer data) {
    if (global.expose_timer >= 0) {
      global.expose_timer = -1;

    return 0;
The reason why i added a timeout in the expose_event callback instead of
just calling the drawing function is: the program waits 200ms before
redrawing the directories. If there occures a new expose event within this
time, the old timeout is removed a new is set. Thats useful for "merging"
several expose events into one.

* I dont think GTK supports something like event areas, as i said: i solved
this by doing a internal tree search (this is pretty fast):
  gtk_signal_connect (GTK_OBJECT (drawingarea1), "motion_notify_event",
                      GTK_SIGNAL_FUNC (on_drawingarea1_motion_notify_event),

  on_drawingarea1_motion_notify_event    (GtkWidget       *widget,
                                          GdkEventMotion  *event,
                                          gpointer         user_data)
    dir_tree_t* sub_tree;
    if (!global.current_tree) return FALSE;

    sub_tree = dir_tree_search_file(global.current_tree, 
                                    (int)(event->x), (int)(event->y));
    if (sub_tree) dir_tree_mark(sub_tree);
    return FALSE;

      I am trying to write a program for linux which performs the same task
as the "scanner" program for windows(dowload url below). This
program scans the hard disk and displays a very handy chart of all the
directories on your HD. The levels of the directories are arranged
concentrically. This makes it very easy to see what is taking up a lot of
space on the HD.

Anyway, my question is how can I draw arcs in Gtk? I've tried to wade
through the documentation on gtk's website, but it is horribly lacking. Right
now I'm just popping up a main window, placing a drawing area inside of
creating a graphics context, and calling gdk_draw_arc. I don't see
anything drawn in the main window, at all.

    Also, this program needs to be able to tell when the mouse is over
different parts of the chart, since clicking on any of the directories will
zoom in on that dir to show more detail. How can I set up widgets or event
areas which are shaped like an arc, so that I can detect those events?

Thanks for any help you can give!
-Ron Roth

dowload the scanner program from my website:

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