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 = 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 ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Not understanding the principles of drawing areas and primitives etc... Colors?
> Whether it is or not, it would be nice if somebody could give me > a (c language) source snippet on how to set up colors and > colormaps for a widget and then draw a red line on it... It's pretty simple, but I do not and will not willingly use C. Here's an example which draws lines, rectangles, circles, arcs, etc.. in various colors. use Gtk (*) use Math (rand) enum DRAWING_OPS CLR LINES POINTS ARCS RECTS;; app = application("Drawing for Qu") win = window() panel = vbox() win.add(panel) btnbox = hbutton_box() btnbox.set_layout(GTK_BUTTONBOX_SPREAD) btnbox.add([button('Clear' @draw CLR) button('Lines' @draw LINES) button('Points'@draw POINTS) button('Arc' @draw ARCS) button('Rect' @draw RECTS)]) panel.pack_end(btnbox) canvas = drawing_area() canvas.size(300,300) panel.add(canvas) win.show_all drawing_window = canvas.window context = gc(drawing_window) app.main sub draw(a:Int,b:Int)->Int (x,y) = get_size(drawing_window) fill = rand(2) context.set_fg(rand(255),rand(255),rand(255)) switch b case CLR context.set_fg(rand(255),rand(255),rand(255)) draw_rect(drawing_window,context,true,0,0,x,y) break case LINES for i in 1..rand(10) # changes drawing color randomly; context.set_fg(rand(255),rand(255),rand(255)) context.set_line_attributes(rand(10),rand(2),rand(3),rand(2)) draw_line(drawing_window,context,rand(x),rand(y),rand(x),rand(y)) ;; break case POINTS for i in 1..rand(1000) # lots o' dots context.set_fg(rand(255),rand(255),rand(255)) draw_point(drawing_window,context,rand(x),rand(y));; break case ARCS draw_arc(drawing_window,context,fill==1,rand(x/2),rand(y/2),rand(x),rand(y),0,64*rand(360)) break case RECTS draw_rect(drawing_window,context,(fill==1),rand(x/2),rand(y/2),rand(x),rand(y)) break ;; return 1 ;; ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Not understanding the principles of drawing areas and primitives etc... Colors?
you can follow this basic algorithm, (there are many ways to effect this, this is just one that works and is, hopefully, descriptive):// set up colors and some GCsGdkColor red, black;GdkGC *gc, *inverse_gc;gc = gdk_gc_new(window); // regular GC for the windowinverse_gc = gdk_gc_new(window); // inverse GC// init the various aspects/qualities of the GCsred.red = 65535; red.green = 0; red.blue = 0; // redblack.red = 0; black.green = 0; black.blue = 0; // blackgdk_gc_set_rgb_fg_color(gc, &red);gdk_gc_set_rgb_bg_color(gc, &black);gdk_gc_set_rgb_fg_color(inverse_gc, &black);gdk_gc_set_rgb_bg_color(inverse_gc, &red);// plus any other qualities of the line you would like to set, like dashes, thickness, etc.// see gdk_gc_set_function(gc, FUNCTION) in the documentation// then in your configure routine for your drawing area:// make the pixmap you will be drawing onGdkPixmap *pixmap = gdk_pixmap_new(da->window, da->allocation.width, da->allocation.height, -1);// paint the background using the background color (foreground color of our inverse GC)gdk_draw_rectangle(pixmap, inverse_gc, TRUE, 0, 0, da->allocation.width, da->allocation.height);// draw a line from corner to corner, twicegdk_draw_line(pixmap, gc, 0, 0, da->allocation.width, da->allocation.height);gdk_draw_line(pixmap, gc, 0, da->allocation.height, da->allocation.width, 0);// force the expose event for the drawing area to be calledgtk_widget_queue_draw_area(da, 0, 0, da->allocation.width, da->allocation.height);// render the pixmap to the screen in your expose routine for the drawing area:gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], pixmap, event->area.x, event->area.y event->area.x, event->area.y event->area.width, event->area.height);richardOn Mar 11, 2006, at 5:29 PM, Leo - wrote:I think I can grasp the GC idea; it's just a way to reduce the number of parameters sent to certain functions, but where do I "get" the colors from? When I check up on gdk_gc_set_foreground etc. they require a gdkColor parameter, and following that link (clicking gdkColor) gets me to a page about colormaps and, my impression is that I need to set up a "palette", link it to the widget, add my colors etc. etc., before I can actually draw on my widget. Is that really the case? Whether it is or not, it would be nice if somebody could give me a (c language) source snippet on how to set up colors and colormaps for a widget and then draw a red line on it...2006/3/9, Paul Davis <[EMAIL PROTECTED] >: 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 drawingfunction, most drawing kits based on the X Window System instead using aGraphics 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, butyou probably don't need to worry about them. You generally work with afixed 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 = 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 ofseveral 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___gtk-list mailing listgtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Re: Not understanding the principles of drawing areas and primitives etc... Colors?
I think I can grasp the GC idea; it's just a way to reduce the number of parameters sent to certain functions, but where do I "get" the colors from? When I check up on gdk_gc_set_foreground etc. they require a gdkColor parameter, and following that link (clicking gdkColor) gets me to a page about colormaps and, my impression is that I need to set up a "palette", link it to the widget, add my colors etc. etc., before I can actually draw on my widget. Is that really the case? Whether it is or not, it would be nice if somebody could give me a (c language) source snippet on how to set up colors and colormaps for a widget and then draw a red line on it...2006/3/9, Paul Davis <[EMAIL PROTECTED] >: 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 drawingfunction, most drawing kits based on the X Window System instead using aGraphics 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, butyou probably don't need to worry about them. You generally work with afixed 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 = 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 ofseveral 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 ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list