graphics problem

Roman Goldov <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hello, i installed CentOS 7 and gtk-devel libaries. I learn GTK+ and Cairo. I downloaded (copied) from Internet an exmple of cairo file (file9.c that is attached) where i tried to draw lines (graphics) on the window. However, the window is opened and it is empty, and also theer is warning message in the terminal:

[...@localhost ~]$ gcc -Wall -g file9.c -o file9.exe `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
[...@localhost ~]$ ./file9.exe 

(file9.exe:9678): GLib-GObject-WARNING **: gsignal.c:2462: signal 'draw' is invalid for instance '0x968440' of type 'GtkDrawingArea'

I would appreciate help in solving the problem. A detailed answer would be appreciated because i am a new user of Linux.
Thank you.
Roman Goldov

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
file9.c (text/x-c, 1.8 KB)
#include <cairo.h>
#include <gtk/gtk.h>

static void do_drawing(cairo_t *);

struct {
  int count;
  double coordx[100];
  double coordy[100];
} glob;

static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr, 
    gpointer user_data)
{
  do_drawing(cr);

  return FALSE;
}

static void do_drawing(cairo_t *cr)
{
  cairo_set_source_rgb(cr, 0, 0, 0);
  cairo_set_line_width(cr, 0.5);

  int i, j;
  for (i = 0; i <= glob.count - 1; i++ ) {
      for (j = 0; j <= glob.count - 1; j++ ) {
          cairo_move_to(cr, glob.coordx[i], glob.coordy[i]);
          cairo_line_to(cr, glob.coordx[j], glob.coordy[j]);
      }
  }

  glob.count = 0;
  cairo_stroke(cr);    
}

static gboolean clicked(GtkWidget *widget, GdkEventButton *event,
    gpointer user_data)
{
    if (event->button == 1) {
        glob.coordx[glob.count] = event->x;
        glob.coordy[glob.count++] = event->y;
    }

    if (event->button == 3) {
        gtk_widget_queue_draw(widget);
    }

    return TRUE;
}


int main(int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *darea;
  
  glob.count = 0;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  darea = gtk_drawing_area_new();
  gtk_container_add(GTK_CONTAINER(window), darea);
 
  gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);

  g_signal_connect(G_OBJECT(darea), "draw", 
      G_CALLBACK(on_draw_event), NULL); 
  g_signal_connect(window, "destroy",
      G_CALLBACK(gtk_main_quit), NULL);  
    
  g_signal_connect(window, "button-press-event", 
      G_CALLBACK(clicked), NULL);
 
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 400, 300); 
  gtk_window_set_title(GTK_WINDOW(window), "Lines");

  gtk_widget_show_all(window);

  gtk_main();

  return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.