drawing in a not yet shown drawingarea



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




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