[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Interface with 64 toggleable elements: what's the best way?
- From: Russell Shaw <rjshaw iprimus com au>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Interface with 64 toggleable elements: what's the best way?
- Date: Mon, 10 Nov 2003 03:45:13 +1100
Sean McAfee wrote:
> Russell Shaw <rjshaw@iprimus.com.au> wrote:
>
>>Sean McAfee wrote:
>>
>>>My next idea was to represent the bits as pixmaps: an empty circle for
>>>a clear bit, and a filled circle for a set bit. I want my program to
>>>be completely standalone, so now I'm trying to create a pair of
>>>textual xpm's that look like decent circles, which isn't completely
>>>trivial.
>
>>It's much easier to create an outline and solid circle using
>>gdk_draw_arc() onto GdkPixmap at the start of your program.
>
> D'oh! That did sound much easier.
>
> When I tried this approach, however, I ran into some difficulties. In
> order to craete a GtkPixmap from a GdkPixmap, one needs a second GdkPixmap,
> the bit mask. I searched high and low, but couldn't find any information on
> how one would go about creating a bit mask. I finally had to jump into the
> source of the gdk_pixmap_create_from_xpm_d() function, the only standard
> function that returns a bit mask. After some cutting and pasting, I came up
> with the following routine:
>
> void
> circular_pixmap(GdkWindow *window, int size,
> GdkPixmap **image, GdkPixmap **mask)
> {
> GdkColor mask_pattern;
> GdkGC *image_gc, *mask_gc;
>
> *image = gdk_pixmap_new(window, size, size, -1);
> *mask = gdk_pixmap_new(window, size, size, 1);
>
> image_gc = gdk_gc_new(*image);
> mask_gc = gdk_gc_new(*mask);
>
> mask_pattern.pixel = 0;
> gdk_gc_set_foreground(mask_gc, &mask_pattern);
> gdk_draw_rectangle(*mask, mask_gc, TRUE, 0, 0, -1, -1);
> mask_pattern.pixel = 1;
> gdk_gc_set_foreground(mask_gc, &mask_pattern);
>
> gdk_draw_arc(*image, image_gc, TRUE, 0, 0, size, size, 0, 64*360);
> gdk_draw_arc(*mask, mask_gc, TRUE, 0, 0, size, size, 0, 64*360);
>
> gdk_gc_destroy(image_gc);
> gdk_gc_destroy(mask_gc);
>
> }
>
> This works, but damn if it doesn't seem awfully clunky. Is there a better
> way to create a pixmap-plus-mask from scratch?
>
GdkPixmap*
circular_pixmap(GtkWidget *widget, int size, GdkColor *color)
{
GdkPixmap *dot=gdk_pixmap_new(widget,size,size,-1);
GtkStyle *style=gtk_widget_get_style(widget);
gdk_draw_rectangle(dot,style->bg_gc[NORMAL],TRUE,0,0,size,size); // background
GdkGC *gc=gdk_gc_new();
gdk_gc_copy(gc,&(style->fg_gc[NORMAL]));
gdk_colormap_alloc_color(gtk_widget_get_colormap(widget),color,TRUE,TRUE);
gdk_gc_set_foreground(gc,color);
gdk_draw_arc(dot,gc,TRUE,0,0,size,size,0,23040); // foreground
g_object_unref(gc);
return dot;
}
Draw a pixmap instead of a bitmap. I thought there was
a way to extract a "plane" from a pixmap to use as a
bitmap, but can't recall. Ideally, there should be a
way to get a clear background like with a circular clip
region or something.
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]