head 1.3; access; symbols; locks; strict; comment @ * @; 1.3 date 2005.08.15.05.31.38; author behdad; state Exp; branches; next 1.2; commitid 6044430028b14567; 1.2 date 2005.08.12.07.24.27; author behdad; state Exp; branches; next 1.1; commitid 75b042fc4e5b4567; 1.1 date 2004.11.11.17.49.08; author pippin; state Exp; branches; next ; desc @@ 1.3 log @2005-08-15 Behdad Esfahbod * hello.c: fix signature of paint to match those of expose-event. @ text @/* hello world for gtk with cairo support, by Øvyind Kolås */ #include #include #define DEFAULT_WIDTH 400 #define DEFAULT_HEIGHT 200 /* forward definition of actual painting function for our drawing area widget */ static void paint (GtkWidget *widget, GdkEventExpose *eev, gpointer data); gint main (gint argc, gchar **argv) { GtkWidget *window; GtkWidget *canvas; gtk_init (&argc, &argv); /* create a new top level window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* make the gtk terminate the process the close button is pressed */ g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); /* create a new drawing area widget */ canvas = gtk_drawing_area_new (); /* set a requested (minimum size) for the canvas */ gtk_widget_set_size_request (canvas, DEFAULT_WIDTH, DEFAULT_HEIGHT); /* connect our drawing method to the "expose" signal */ g_signal_connect (G_OBJECT (canvas), "expose-event", G_CALLBACK (paint), NULL /*< here we can pass a pointer to a custom data structure */ ); /* pack canvas widget into window */ gtk_container_add (GTK_CONTAINER (window), canvas); /* show window and all it's children (just the canvas widget) */ gtk_widget_show_all (window); /* enter main loop */ gtk_main (); return 0; } /* the actual function invoked to paint the canvas * widget, this is where most cairo painting functions * will go */ static void paint (GtkWidget *widget, GdkEventExpose *eev, gpointer data) { gint width, height; gint i; cairo_t *cr; width = widget->allocation.width; height = widget->allocation.height; cr = gdk_cairo_create (widget->window); /* clear background */ cairo_set_source_rgb (cr, 1,1,1); cairo_paint (cr); cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); /* enclosing in a save/restore pair since we alter the * font size */ cairo_save (cr); cairo_set_font_size (cr, 40); cairo_move_to (cr, 40, 60); cairo_set_source_rgb (cr, 0,0,0); cairo_show_text (cr, "Hello World"); cairo_restore (cr); cairo_set_source_rgb (cr, 1,0,0); cairo_set_font_size (cr, 20); cairo_move_to (cr, 50, 100); cairo_show_text (cr, "greetings from gtk and cairo"); cairo_set_source_rgb (cr, 0,0,1); cairo_move_to (cr, 0, 150); for (i=0; i< width/10; i++) { cairo_rel_line_to (cr, 5, 10); cairo_rel_line_to (cr, 5, -10); } cairo_stroke (cr); cairo_destroy (cr); } @ 1.2 log @2005-08-12 Behdad Esfahbod * hello.c, mouse_events.c: updated to latest cairo+gtk api. * README: noted the change from gtkcairo to cairo+gtk. @ text @d12 3 a14 2 static void paint (GtkWidget *widget, gpointer data); d69 3 a71 2 paint (GtkWidget *widget, gpointer data) @ 1.1 log @added simple gtkcairo demo @ text @d1 1 a1 1 /* hello world for gtkcairo, by Øvyind Kolås d5 1 a5 1 #include d10 1 a10 1 /* forward definition of actual painting function for our gtkcairo widget a12 1 cairo_t *cr, d20 1 a20 1 GtkWidget *gtkcairo; d33 1 a33 1 /* create a new gtkcairo widget d35 1 a35 1 gtkcairo = gtk_cairo_new (); d37 1 a37 1 /* set a requested (minimum size) for the gtkcairo widget d39 1 a39 1 gtk_widget_set_size_request (gtkcairo, DEFAULT_WIDTH, DEFAULT_HEIGHT); d41 1 a41 1 /* connect our drawing method to the "paint" signal d43 1 a43 1 g_signal_connect (G_OBJECT (gtkcairo), "paint", d48 1 a48 1 /* pack gtkcairo widget into window d50 1 a50 1 gtk_container_add (GTK_CONTAINER (window), gtkcairo); d52 1 a52 1 /* show window and all it's children (just the gtkcairo widget) d63 1 a63 1 /* the actual function invoked to paint the gtkcairo a68 1 cairo_t *cr, d73 1 d78 1 a78 5 /* enclosing the painting function in a save/restore pair is a * good idea since we'll return to a sane state then */ cairo_save (cr); d81 2 a83 3 cairo_rectangle (cr, 0, 0, width, height); cairo_set_rgb_color (cr, 1,1,1); cairo_fill (cr); d85 2 a86 3 cairo_select_font (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); d92 1 a92 1 cairo_scale_font (cr, 40); d94 1 a94 1 cairo_set_rgb_color (cr, 0,0,0); d98 2 a99 2 cairo_set_rgb_color (cr, 1,0,0); cairo_scale_font (cr, 20); d103 1 a103 1 cairo_set_rgb_color (cr, 0,0,1); a110 1 d113 1 a113 1 cairo_restore (cr); @