Re: [gtk-list] Re: Drawing in GtkDrawingArea




On Sun, 29 Nov 1998, Marsel Osipov wrote:
> 
> void MyClass::displayPixel(RGBColor pixel, int x, int y)
> {
>   GdkColor *color;
>   GdkGC * gc;
>   gc = gdk_gc_new(d_area->window);
> 
>   color = (GdkColor *)malloc(sizeof(GdkColor));
> 

color = g_new(GdkColor,1); 

is a nice shortcut here (I know the FAQ does it with malloc)

>   color->red = (gushort)pixel.red() * (65535/255);
>   color->green = (gushort)pixel.green() * (65535/255);
>   color->blue = (gushort)pixel.blue() * (65535/255);
>   color->pixel = (gulong)(pixel.red()*65536 + pixel.green()*256 +
> pixel.blue());
>   gdk_color_alloc(gtk_widget_get_colormap(d_area), color);
> 
>   gdk_gc_set_foreground(gc, color);
>   gdk_gc_set_background(gc, color);
> 

Looks good to me, assuming the pixel functions return the right thing

>   gdk_draw_point(pixmap,
>    gc,
>    x,
>    y);
> 

In your original mail you said you were drawing to d_area->window, but 
here you're drawing on 'pixmap.' Maybe that's it?

To debug, try using a different color, say gdk_color_black, and/or
drawing a big rectangle you know you can see and will be on screen.
Then you can narrow down the problem.

Havoc




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