Re: Interface with 64 toggleable elements: what's the best way?



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?

-- 
Sean McAfee
etzwane schwag org



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