Re: Not understanding the principles of drawing areas and primitives etc...



On Thu, 2006-03-09 at 19:39 +0100, Leo - wrote:
> I want to be able to draw lines on a gtkDrawingArea, with a color the
> user selects (r,g,b),
> however I don't understand how I would do.
> The whole business with gdkGC's and gdcColors seems very alien. If
> somebody could
> point me to a tutorial (the scribble one isn't enough since that one
> doesn't use color).

no tutorial here, but a brief lecture.

there are many different possible parameters for many drawing
primitives. in your case of line drawing, we have things like:

	* is the line dashed?
	    * if dashed, what are the stroke & gap sizes?
        * the pen width
        * the color of the line

for other drawing primitives, there are many more.

rather than constantly pass all these parameters into every drawing
function, most drawing kits based on the X Window System instead using a
Graphics Context (or GC) which contains a set of values that can be used
by any drawing primitive. This is more efficient in other ways too, but
you probably don't need to worry about them. You generally work with a
fixed number of 

> What I simply want to do is something like line(gtkDrawingArea* da,
> int x1, int y1, int x2, int y2, r, g, b)

just grab a suitable GC, such as

       Glib::RefPtr<GC> gc = get_style()->get_fg_gc();

change its foreground color, specifically for whatever state
the drawing area is in right now (widgets in GTK can be in one of
several possible states):

       gc.set_foreground_gdk (redColor, get_state());

and draw on the window:

       get_window()->draw_line (gc, x1, y1, x2, y2);

the precise details might be slightly off, i am writing from memory.

--p





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