Re: drawing area does not refresh



Yes, but the problem is that I can't wait until the
the handler is called.
I want to be able to refresh it even if there is a
pause just after my call to function.

I am making a program treating images from a webcam.
For reasons that would be long to explain, I need to
be able to refresh the drawinarea directly even if
there is a pause (with getchar() for example) just
after my call to the function.

--- David Neèas (Yeti) <yeti physics muni cz> wrote:

On Wed, May 10, 2006 at 09:29:31AM -0700, temp temp
wrote:
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);

You should not call gtk_widget_queue_draw() on a
widget in
its expose handler.  I wonder how the redrawing ever
stops
when each redraw attempts to invoke another
redraw...

   

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.

To invoke redraw of a widget call

    gtk_widget_queue_draw(widget);

As a result, the expose handler will be called
(somewhat
later when the main loop comes to that).

Yeti


--
Anonyms eat their boogers.



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



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