drawing area does not refresh



 Hi,

I have a problem creating a function that will draw the contents of a buffer into a drawing area.

Here is the function I call when I want to draw the contents of "buffer" into the drawingarea designated by 
"area":

int draw_in_widget(GtkWidget *area,unsigned char* buffer,int img_height,int img_width,bool is_rgb)
{
    //conversion BGR->RGB
    if(!is_rgb)
    {
        unsigned char tmp;
        for(int i=0;i<img_width*img_height;i++)
        {
            tmp = buffer[3*i];//B->tmp
            buffer[3*i] = buffer[3*i+2];//R->B
            buffer[3*i+2] = tmp;//tmp->R   
        }    
    }
    
    gpointer destroy_fn_data;
    int area_width=area->allocation.width;
    int area_height=area->allocation.height;
    
    GdkPixbuf *pixbuf_dest=gdk_pixbuf_new(GDK_COLORSPACE_RGB,FALSE,8,
        area_width,area_height);
    GdkPixbuf *pixbuf_src=gdk_pixbuf_new_from_data(buffer,GDK_COLORSPACE_RGB,FALSE,8,
        img_width,img_height,img_width*3,NULL,destroy_fn_data);
    GdkGC *gc=area->style->fg_gc[GTK_STATE_NORMAL];
    double scale_x=(double)area_width/img_width;
    double scale_y=(double)area_height/img_height;
    
    gtk_widget_queue_draw(area);
    
    gdk_pixbuf_scale(pixbuf_src,pixbuf_dest,0,0,area_width,area_height,
        0,0,scale_x,scale_y,GDK_INTERP_TILES);

    gdk_draw_pixbuf(area->window,gc,pixbuf_dest,
        0,0,0,0,area_width,area_height,GDK_RGB_DITHER_NORMAL,0,0);
      
    gdk_pixbuf_unref(pixbuf_src);
    gdk_pixbuf_unref(pixbuf_dest);
    return(0);
}


The function adapts the size of the image contained in the buffer (of size 3*img_height*img_width) to the 
size of the drawing area.

My problem is that this function only works when placed in a "on_drawingarea1_expose_event" handler.

If I place it somewhere else in my code, the image will only be drawn immediately if there is no "pause" 
after my draw_in_widget function.

And I don't know how to call the "on_drawingarea1_expose_event" handler, since I have no idea what arguments 
to give him.
The arguments asked by the handler are:
-GtkWidget *widget,
-GdkEventExpose *event,
-gpointer user_data



                
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.


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