Re: drawing in a not yet shown drawingarea



G'Day !

Study the scribble code included with the tutorial,  it does exactly what you
are trying to do ....

Basically it creates a backing pixmap, draws on the pixmap then uses double
buffering to "draw" to the window.  You can do anything you want to your backing
pixmap before it is visible on the screen.

cheers,
Jim Parker

Sailboat racing is not a matter of life and death ....  It is far more important
than that !!!


                                                                                                              
                    
                    Victor STANESCU                                                                           
                    
                    <vstanescu logicnet ro>         To:     gtk-app-devel-list gnome org                      
                    
                    Sent by:                        cc:                                                       
                    
                    gtk-app-devel-list-admin        Subject:     drawing in a not yet shown drawingarea       
                    
                    @gnome.org                                                                                
                    
                                                                                                              
                    
                                                                                                              
                    
                    11/16/00 03:34 AM                                                                         
                    
                                                                                                              
                    
                                                                                                              
                    



Being given the following structure:

window(
           vbox(
                     scrolledwindow
                     (
                               eventbox
                               (
                                          drawingarea
                               )
                     )
                     hbox
                     (
                               progressbar
                               statusbar
                     )
           )
)

i need to draw in the drawing area. I am drawing like: (where _widget is
the drawing area)

        GdkGC *gc=gdk_gc_new(_widget->window);
        GdkColor *color = (GdkColor *)malloc(sizeof(GdkColor));
        color->red=red*(65535/255);
        color->green=green*(65535/255);
        color->blue=blue*(65535/255);
        color->pixel=(gulong)(red*65536 + green*256 + blue);
        if(gdk_colormap_alloc_color(gtk_widget_get_colormap(_widget),
color, false, true))
        {}
        else
        {
                cout<<"Color allocation failed"<<endl;
        }
        gdk_gc_set_foreground(gc , color);
        gdk_gc_set_line_attributes(gc, width, GDK_LINE_SOLID,
GDK_CAP_ROUND, GDK_JOIN_ROUND);
        gdk_draw_line(_pixmap,
                      gc,
                      x1,y1,x2,y2);
        gdk_colormap_free_colors(gtk_widget_get_colormap(_widget),
color, 1);
        gdk_gc_destroy(gc);
        free(color);

the problem is that i need to draw before i show() the window. If i
show(), then hide(), it works - it continues to draw the graphics, which
is good. But before the first show() is called, it is not drawing and it
yells that gc and window are NULL.
if i realize() the drawingarea, it is not shown any more in the window,
but it sometimes gets a separate window, other times it is just not
drawn anywhere (at least not on my desktop ;-) ).

There are also calls for the configure_event and expose event, like
this:
        gint configure_event(GtkWidget *wid, GdkEventConfigure *event,
DrawingArea *dw)
        {
                if(dw->getPixmap())
                {
                        //avem pixmap
                }
                else
                {

dw->setPixmap(gdk_pixmap_new(wid->window,wid->allocation.width,wid->allocation.height,

1));

gdk_draw_rectangle(dw->getPixmap(),wid->style->white_gc,
TRUE,0,0,wid->allocation.width,wid->allocation.height);
                }

                return TRUE;
        }


        gint expose_event(GtkWidget *wid, GdkEventExpose *event,
DrawingArea *dw)
        {
                gdk_draw_pixmap(wid->window,

wid->style->fg_gc[GTK_WIDGET_STATE(wid)],
                                dw->getPixmap(),
                                event->area.x,event->area.y,
                                event->area.x,event->area.y,
                                event->area.width,event->area.height);
                return FALSE;
        }

Could someone help me with an advice on how to draw before showing the
window on the screen for the first time?

Btw, all i need is a surface on which i can set a background pixmap, and
then, draw lines, circles, rectangles and so on, with different collors,
and intercept mouse clicks on it. If you consider that the solution i
choosed (which is very poor documented, i must say) is not the best for
my needs, i would be very glad to receive some advices. I don't require
speed (as it is not graphic intensive).

--
Victor STANESCU - network administrator
LOGIC Telecom - Bucharest, ROMANIA

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list








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