drawing a simple point isn't working



hello,

I want to draw a simple point on a drawing area and can't get it done. 
I'm using a tutorial and i'm following everything it says but as soon as
I want to do my own gtk_draw_point function nothing is drawn and i get
an error at runtime saying that assertion drawable != NULL failed.

I have the following code to create a blank drawing area at startup:

int configure_event (GtkWidget *widget, GdkEventConfigure *event)
{
  if (pixmap)
    gdk_pixmap_unref(pixmap);

  pixmap = gdk_pixmap_new(widget->window,
                          widget->allocation.width,
                          widget->allocation.height,
                          -1);
  gdk_draw_rectangle (pixmap,widget->style->white_gc,TRUE,
                      0, 0,
                      widget->allocation.width,
                      widget->allocation.height);
  return TRUE;
}


Then I have this code to redraw the area if exposed:
int expose_event (GtkWidget *widget, GdkEventExpose *event)
{
  gdk_draw_pixmap(widget->window,
                  widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                  pixmap,
                  event->area.x, event->area.y,
                  event->area.x, event->area.y,
                  event->area.width, event->area.height);

  return FALSE;
}


There is code in the tutorial to implement a brush to be drawn when a
mouse click is detected but I don't want to do it that way. I want to
draw a point on a line after other parts of my code do some
calculations. 

I have the following as the rest of my code (the drawing area relevant
sections):

GdkPixmap *pixmap = NULL;
GtkWidget *drawable;

drawable = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(drawable),400,300);

and I use the following to draw a point:
gdk_draw_point(pixmap,mainwindow->style->black_gc,10,10);

If I put that draw_point function within the configure_event function I
get the point draw but of course that only happens when the window is
first created.  My question is what am i missing?  If the assertion that
drawable != NULL works within the function then why not outside the
configure_event function? Also, once I get the draw_point function
working will I need to repaint the drawing area everytime a new point is
drawn in order to see it or will it appear automatically? If not, what I
just create a timeout somehow to automatically repaint after x amount of
seconds since no other signals will be generated? (my other code just
does math functions and I will be plotting points as it does so)

thanks for any help, if i need to post more code please tell me.

brandon



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