Help starting with gtk



I'm just starting programming with GTK/GDK and I'm struggling with the
lack of docs.  I have a Debian system with GTK 1.0.1.  I'm new to x
programming.

I'll include the test program I'm working with - it compiles without
warnings but gives errors when run on my setup.  The program was pulled
together from bits of the faq and tutorial - I want to be able to draw
different shapes in different colours on the window every 1/2 second, but
I cant get past the warnings eg. 

** WARNING **: file gdkgc.c: line 43 (gdk_gc_new_with_values): "window !=
NULL"

** WARNING **: file gdkgc.c: line 375 (gdk_gc_set_foreground): "gc !=
NULL"

** WARNING **: file gdkdraw.c: line 117 (gdk_draw_arc): "gc != NULL"

I'd welcome any comment - please pull the code apart

#include <gtk/gtk.h>
struct col3 {
  GtkWidget *area;
  GdkGC *gc;
  GdkColor *red, *green, *blue;};

gint delete_event(GtkWidget *widget, gpointer data){
    gtk_main_quit ();
  return 0;}

void drawit(struct col3 *data){
  gdk_gc_set_foreground(data->gc, data->red);
  gdk_draw_arc(data->area->window,data->gc,1,50,50,25,25,0,0);
  g_print("wehello");}

int main(int argc, char *argv[]){
  GtkWidget *window;
  struct col3 data;

  gtk_init (&argc, &argv);
  data.area = gtk_drawing_area_new ();
  gtk_drawing_area_size(GTK_DRAWING_AREA(data.area),100,100);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect (GTK_OBJECT (window), "delete_event",
                      GTK_SIGNAL_FUNC (delete_event), NULL);
  gtk_window_set_title (GTK_WINDOW (window), "Adding Program");
  gtk_container_add(GTK_CONTAINER(window),data.area);
  data.gc=gdk_gc_new(data.area->window);
  data.red = (GdkColor *)malloc(sizeof(GdkColor));
  data.green = (GdkColor *)malloc(sizeof(GdkColor));
  data.blue = (GdkColor *)malloc(sizeof(GdkColor));
  data.red->red = 65535;
  data.red->green = 0;
  data.red->blue = 0;
  data.green->red = 0;
  data.green->green = 65535;
  data.green->blue = 0;   
  data.blue->red = 0;
  data.blue->green = 0;
  data.blue->blue = 65535;
  data.red->pixel = (gulong)(255*65536);
  data.green->pixel = (gulong)(255*256);
  data.blue->pixel = (gulong)(255);
  gdk_color_alloc(gtk_widget_get_colormap(data.area), data.red);
  gdk_color_alloc(gtk_widget_get_colormap(data.area), data.green);
  gdk_color_alloc(gtk_widget_get_colormap(data.area), data.blue);
  gtk_widget_show(data.area);
  gtk_widget_show(window);
  gtk_timeout_add(500,(GtkFunction)drawit,&data);
  gtk_main();
  return 0;}




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