Re: How to draw a primitive with one color and fill it with, another? (Sergey Parhomenko)
- From: Thomas Stover <thomas wsinnovations com>
- To: gtk-app-devel-list gnome org
- Subject: Re: How to draw a primitive with one color and fill it with, another? (Sergey Parhomenko)
- Date: Tue, 15 Apr 2008 10:10:43 -0500
I would suggest you look at doing your drawing with cairo if possible.
Once I discovered that, I gave up on calling all those gdk functions.
Read the documents on their site at, http://www.cairographics.org . It
looks like most gtk drawing is going this way. I'm also fuzzy on what
the role of the pixmap is in your example. Are you trying to draw to a
widget, or to a pixmap?
Here is an untested example off of the top of my head to do what you
want to a widget (drawing area widget that is)...
void draw(GtkWidget* widget)
{
int width = widget->allocation.width;
int height = widget->allocation.height;
cairo_t *cr gdk_cairo_create(widget->window);
int x = width / 2;
int y = height / 2;
int r = 30;
/* clearing to white: (rgb values in cairo are floating points instead of bytes) */
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_rectangle(, 0, 0, width, height);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
cairo_arc(cr, x, y, r, 0.0, 0.0);
cairo_fill(cr);
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_stroke(cr);
cairo_destroy(cr);
}
Date: Mon, 14 Apr 2008 07:05:20 -0700 (PDT)
From: Sergey Parhomenko <sparhomenko yahoo com>
Subject: How to draw a primitive with one color and fill it with
another?
To: gtk-app-devel-list gnome org
Message-ID: <756250 13261 qm web46416 mail sp1 yahoo com>
Content-Type: text/plain; charset=iso-8859-1
Hello everyone.
I want to draw a red circle filled within with a green
color on my pixmap. I've set foreground and background
colors and passed TRUE as the "filled" parameter to
gdk_draw_arc(). But the circle is filled with the same
color as it is drawn, that is with the foreground
color - red.
How can I draw a red circle filled with green? The
relevant part of my code is below.
/* ... */
static GdkPixmap *pixmap = NULL;
void draw(GtkWidget* widget)
{
int width = widget->allocation.width;
int height = widget->allocation.height;
GdkGC *gc;
GdkColor colors[2];
int x = width / 2;
int y = height / 2;
int r = 30;
if (pixmap)
g_object_unref (pixmap);
pixmap = gdk_pixmap_new (widget->window,
width,
height,
-1);
gc = gdk_gc_new((GdkDrawable *)pixmap);
/* clearing to white: */
gdk_draw_rectangle (pixmap,
widget->style->white_gc,
TRUE,
0, 0,
width,
height);
gdk_color_parse("#ff0000", &colors[0]);
gdk_color_parse("#00ff00", &colors[1]);
/* By the way, can I get red and green GdkColor
faster, without these gdk_color_parse()? Are some
constants for this available? */
gdk_gc_set_rgb_fg_color(gc, &colors[0]);
gdk_gc_set_rgb_bg_color(gc, &colors[1]);
gdk_draw_arc(pixmap, gc, TRUE, x - r / 2, y - r / 2,
r, r, 0, 64 * 360);
}
/* ... */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]