Re: Drawing charts with gtk



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?

To select your directories, a very powerful method is:

1) Use a double-buffer;

2) When a press_event is received (meaning that
the user wants to see the contents of a given 
directory):

i) read the x,y position where the user clicked;
ii) draw each directory with a different color,
in the background buffer; these colors have absolutely
nothing to do with the colors that the user see on
the foreground color. However, you must guarantee
that the method used to draw the directories is
exactly the same as in the normal drawing routines.
iii) read the color of the x,y position in the
background buffer;
iv) the directory which has the color of the x,y position
is the directory the user selected;

Assuming that the user is using 8,8,8 bits for the r,g,b 
channels, this method allow you to select among 65,535 
directories in a single scan. If you need more ;-) you
need to scan the background buffer again (so in practise
there is really no limit for the number of objects to select).

I don't know whether this is the best method in your case,
it might be an overkill. You might also consider OpenGL (Mesa) to
draw those fancy directories, though again it might be an overkill.
This method to select objects is typically used in complex OpenGL 
applications, where you have different classes of 3D objects, 
3D projections, lights, etc., so there is really no deterministic
way to select objects.

You should also consider GnomeCanvas, I believe is much better
for these things than just a drawing_area.

A raw drawing_area, without nothing on top (as GtkGLArea) is 
intended only for very simple drawings. With OpenGL you could
even use different textures to draw the background of each 
directory... again this might an overkill (bloatware)...

Carlos




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