gdk_draw_polygon +stipple fill has problem



Hi,

Briefly, I'm in the process of porting an application from a Dec/Alpha
(true64 unix) to a windows platform. I'm using the latest gtk win32
distribution (2.2.1). The application renders various drawings to a pixmap
(eventually drawn into a drawing area). My problem involves a couple of
drawing objects that are used as masks. When drawing these masks, I create a
simple bitmap and set the fill mode to GDK_STIPPLE and the stipple to the
mask I created. When the object is drawn part of the polygon is not
rendered. If the fill mode and stipple are not set the polygon is drawn
correctly. I've included a simple application that demonstrates this
problem. The polygon points are derived from the application itself. Maybe
someone can see what the problem is, I sure can't. It might also be worth
noting, the application draws about 40 other masks with stipple on, with no
problem. Thanks in advance.

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

static GdkPoint polygon[] =
{
    {414,    436}, {397,    449}, {379,    460}, {360,    470}, {341,
478},
    {321,    484}, {300,    489}, {280,    491}, {263,    492}, {254,
492},
    {237,    491}, {217,    489}, {196,    484}, {176,    478}, {157,
470},
    {138,    460}, {120,    449}, {103,    436}, {88,     422}, {74,
406},
    {61,     389}, {50,     372}, {40,     353}, {32,     333}, {26,
313},
    {21,     293}, {18,     272}, {17,     251}, {18,     230}, {21,
209},
    {26,     189}, {32,     169}, {40,     149}, {50,     130}, {61,
113},
    {74,     96},  {88,     80},  {103,    66},  {120,    53},  {138,
42},
    {157,    32},  {176,    24},  {196,    18},  {217,    13},  {237,
11},
    {254,    10},  {263,    10},  {280,    11},  {300,    13},  {321,
18},
    {341,    24},  {360,    32},  {379,    42},  {397,    53},  {414,
66},
    {429,    80},  {443,    96},  {456,    113}, {467,    130}, {477,
149},
    {485,    169}, {491,    189}, {496,    209}, {499,    230}, {500,
251},
    {499,    272}, {496,    293}, {491,    313}, {485,    333}, {477,
353},
    {467,    372}, {456,    389}, {443,    406}, {429,    422}, {414,
436},
    {369,    385}, {382,    374}, {392,    363}, {401,    351}, {409,
338},
    {416,    325}, {422,    311}, {427,    296}, {430,    281}, {432,
266},
    {433,    251}, {432,    236}, {430,    221}, {427,    206}, {422,
191},
    {416,    177}, {409,    164}, {399,    153}, {377,    152}, {367,
142},
    {375,    131}, {370,    118}, {358,    108}, {346,    100}, {332,
93},
    {318,    87},  {304,    83},  {289,    79},  {274,    77},  {259,
77},
    {258,    77},  {243,    77},  {228,    79},  {213,    83},  {199,
87},
    {185,    93},  {171,    100}, {166,    103}, {189,    152}, {207,
189},
    {221,    213}, {230,    279}, {285,    297}, {305,    317}, {333,
346},
    {414,    436}
};

static gint expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer
data);
static gint draw_polygon(GtkWidget *da);

void main(int argc, char **argv)
{
    GtkWidget *window;
    GtkWidget *frame;
    GtkWidget *drawing_area;

    if (! gtk_init_check(&argc, &argv))
    {
        g_error("failed to open graphics toolkit");
        exit(1);
    }

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(GTK_WIDGET(window), 550, 550);

    frame = gtk_frame_new(NULL);
    gtk_container_add(GTK_CONTAINER(window), frame);

    gtk_container_set_border_width(GTK_CONTAINER(frame), 4);
    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);

    drawing_area = gtk_drawing_area_new();
    g_signal_connect(drawing_area, "expose_event", G_CALLBACK(expose_cb),
NULL);

    gtk_container_add(GTK_CONTAINER(frame), drawing_area);

    gtk_widget_show_all(window);

    gtk_main();
}

static gint expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer
data)
{
    draw_polygon(widget);
    return TRUE;
}

static gint draw_polygon(GtkWidget *da)
{
#define gray50_width  5
#define gray50_height 5
    char gray50_bits[] =
    {
        0x02,
        0x01
    };

    GdkBitmap *mask;
    GdkColor color = {0, 65535, 0, 0}; // red
    GdkGC *gc;
    GdkGC *new_gc;

    g_return_val_if_fail (GTK_IS_DRAWING_AREA(da), TRUE);

    gc = da->style->bg_gc[GTK_WIDGET_STATE(da)];
    new_gc = gdk_gc_new(da->window);
    gdk_gc_copy(new_gc, gc);

    /* make the gc red */
    gdk_gc_set_rgb_fg_color(new_gc, &color);

    /* draw the lines before changing the gc */
    gdk_draw_lines(da->window, new_gc, polygon,
sizeof(polygon)/sizeof(GdkPoint));

    /* create a stipple mask and set the gc */
    mask = gdk_bitmap_create_from_data(NULL, gray50_bits, gray50_width,
gray50_height);
    gdk_gc_set_stipple(new_gc, mask);
    gdk_gc_set_fill(new_gc, GDK_STIPPLED);
    gdk_gc_set_line_attributes(new_gc, 0, GDK_LINE_ON_OFF_DASH,
GDK_CAP_BUTT, GDK_JOIN_BEVEL);

    /* draw the polygon, notice the bottom section is missing */
    /* without stipple, the polygon draws normally */
    gdk_draw_polygon(da->window, new_gc, TRUE, polygon,
sizeof(polygon)/sizeof(GdkPoint));

    return TRUE;
}



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