[cairo-commit] gtkcairo/tests demo.c,1.6,1.7

OEyvind Kolaas commit at pdx.freedesktop.org
Mon Aug 9 09:32:43 PDT 2004


Committed by: pippin

Update of /cvs/cairo/gtkcairo/tests
In directory pdx:/tmp/cvs-serv2054/tests

Modified Files:
	demo.c 
Log Message:
license change to LGPL


Index: demo.c
===================================================================
RCS file: /cvs/cairo/gtkcairo/tests/demo.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** demo.c	13 Jul 2004 14:33:35 -0000	1.6
--- demo.c	9 Aug 2004 16:32:41 -0000	1.7
***************
*** 1,3 ****
! /* vim: set ts=4 sw=4 noet : */
  
  #include <gtk/gtk.h>
--- 1,3 ----
! /* vim: set ts=4 sw=4 et : */
  
  #include <gtk/gtk.h>
***************
*** 13,32 ****
  
  static void
! paint (GtkCairo *gtkcairo, cairo_t *cairo, GtkRange *range) {
! 	GtkWidget *widget = GTK_WIDGET(gtkcairo);
! 
! 	gint width = widget->allocation.width;
! 	gint height = widget->allocation.height;
! 	gint box_size = (width+height)/6, box_overlap = (width+height)/32;
  
      cairo_save (cairo);
  
! 	cairo_default_matrix (cairo);
! 	cairo_translate (cairo, width/2, height/2);
  
! 	cairo_rotate (cairo, gtk_range_get_value(range));
! 	cairo_rectangle (cairo, -box_size, -box_size, box_size, box_size);
! 	cairo_set_rgb_color (cairo, 1, 0, 0);
! 	cairo_fill (cairo);
      cairo_restore (cairo);
  }
--- 13,33 ----
  
  static void
! paint (GtkWidget *widget,
!        cairo_t   *cairo,
!        GtkRange  *range)
! {
!     gint width  = widget->allocation.width;
!     gint height = widget->allocation.height;
!     gint box_size = (width+height)/6, box_overlap = (width+height)/32;
  
      cairo_save (cairo);
  
!     cairo_default_matrix (cairo);
!     cairo_translate (cairo, width/2, height/2);
  
!     cairo_rotate (cairo, gtk_range_get_value(range));
!     cairo_rectangle (cairo, -box_size, -box_size, box_size, box_size);
!     cairo_set_rgb_color (cairo, 1, 0, 0);
!     cairo_fill (cairo);
      cairo_restore (cairo);
  }
***************
*** 34,109 ****
  static void
  slider_changed (GtkRange *range, GtkWidget *gtkcairo) {
! 	gtk_widget_queue_draw (gtkcairo);
  }
  
  static gboolean
  animate_step (GtkRange *range) {
! 	double newval = gtk_range_get_value (range) + ANIMATE_ROTATE_STEP;
! 	if (newval > ROTATE_MAX) newval -= ROTATE_MAX;
! 	gtk_range_set_value(range, newval);
! 	return TRUE;
  }
  
  static void
  animate_toggled (GtkToggleButton *tb, GtkRange *range) {
! 	static guint timerid = 0;
! 	gboolean active = gtk_toggle_button_get_active(tb);
! 	if (active && !timerid) {
! 		timerid = gtk_timeout_add (ANIMATE_FRAME_DELAY,
! 		                          (GtkFunction)animate_step, range);
! 	} else if (!active && timerid) {
! 		gtk_timeout_remove (timerid);
! 		timerid = 0;
! 	}
  }
  
  static void
  show_test (void) {
! 	GtkWidget *win, *vbox, *frame, *gtkcairo, *slider, *animate;
  
! 	win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
! 	gtk_window_set_title (GTK_WINDOW (win), "GtkCairo Demo");
! 	g_signal_connect (G_OBJECT (win), "delete-event",
! 	                  G_CALLBACK (gtk_main_quit), NULL);
  
! 	vbox = gtk_vbox_new (FALSE, 6);
! 	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
  
! 	frame = gtk_frame_new (NULL);
! 	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  
! 	slider = gtk_hscale_new_with_range (0, ROTATE_MAX, 0.05);
  
! 	gtkcairo = gtk_cairo_new ();
! 	gtk_widget_set_usize (GTK_WIDGET (gtkcairo), INITIAL_SIZE, INITIAL_SIZE);
! 	g_signal_connect (G_OBJECT (gtkcairo), "paint",
! 	                  G_CALLBACK (paint), slider);
  
! 	gtk_container_add (GTK_CONTAINER (frame), gtkcairo);
! 	gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
  
! 	gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
! 	g_signal_connect (G_OBJECT (slider), "value-changed",
! 	                  G_CALLBACK (slider_changed), gtkcairo);
! 	gtk_box_pack_start (GTK_BOX (vbox), slider, FALSE, FALSE, 0);
  
! 	animate = gtk_check_button_new_with_label ("Animate");
! 	g_signal_connect (G_OBJECT (animate), "toggled",
! 	                  G_CALLBACK(animate_toggled), slider);
! 	gtk_box_pack_start (GTK_BOX (vbox), animate, FALSE, FALSE, 0);
! 	
! 	gtk_container_add (GTK_CONTAINER (win), vbox);
! 	gtk_widget_show_all (vbox);
  
! 	gtk_widget_show (win);
  }
  
  int
  main (int argc, char *argv[]) {
! 	gtk_init (&argc, &argv);
! 	show_test ();
! 	gtk_main ();
  
! 	return 0;
  }
  
--- 35,110 ----
  static void
  slider_changed (GtkRange *range, GtkWidget *gtkcairo) {
!     gtk_widget_queue_draw (gtkcairo);
  }
  
  static gboolean
  animate_step (GtkRange *range) {
!     double newval = gtk_range_get_value (range) + ANIMATE_ROTATE_STEP;
!     if (newval > ROTATE_MAX) newval -= ROTATE_MAX;
!     gtk_range_set_value(range, newval);
!     return TRUE;
  }
  
  static void
  animate_toggled (GtkToggleButton *tb, GtkRange *range) {
!     static guint timerid = 0;
!     gboolean active = gtk_toggle_button_get_active(tb);
!     if (active && !timerid) {
!         timerid = gtk_timeout_add (ANIMATE_FRAME_DELAY,
!                                   (GtkFunction)animate_step, range);
!     } else if (!active && timerid) {
!         gtk_timeout_remove (timerid);
!         timerid = 0;
!     }
  }
  
  static void
  show_test (void) {
!     GtkWidget *win, *vbox, *frame, *gtkcairo, *slider, *animate;
  
!     win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
!     gtk_window_set_title (GTK_WINDOW (win), "GtkCairo Demo");
!     g_signal_connect (G_OBJECT (win), "delete-event",
!                       G_CALLBACK (gtk_main_quit), NULL);
  
!     vbox = gtk_vbox_new (FALSE, 6);
!     gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
  
!     frame = gtk_frame_new (NULL);
!     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  
!     slider = gtk_hscale_new_with_range (0, ROTATE_MAX, 0.05);
  
!     gtkcairo = gtk_cairo_new ();
!     gtk_widget_set_usize (GTK_WIDGET (gtkcairo), INITIAL_SIZE, INITIAL_SIZE);
!     g_signal_connect (G_OBJECT (gtkcairo), "paint",
!                       G_CALLBACK (paint), slider);
  
!     gtk_container_add (GTK_CONTAINER (frame), gtkcairo);
!     gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
  
!     gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
!     g_signal_connect (G_OBJECT (slider), "value-changed",
!                       G_CALLBACK (slider_changed), gtkcairo);
!     gtk_box_pack_start (GTK_BOX (vbox), slider, FALSE, FALSE, 0);
  
!     animate = gtk_check_button_new_with_label ("Animate");
!     g_signal_connect (G_OBJECT (animate), "toggled",
!                       G_CALLBACK(animate_toggled), slider);
!     gtk_box_pack_start (GTK_BOX (vbox), animate, FALSE, FALSE, 0);
  
!     gtk_container_add (GTK_CONTAINER (win), vbox);
!     gtk_widget_show_all (vbox);
! 
!     gtk_widget_show (win);
  }
  
  int
  main (int argc, char *argv[]) {
!     gtk_init (&argc, &argv);
!     show_test ();
!     gtk_main ();
  
!     return 0;
  }
  




More information about the cairo-commit mailing list