[cairo-commit] gtkcairo/tests Makefile.am,NONE,1.1 demo.c,NONE,1.1
Carl Worth
commit at pdx.freedesktop.org
Tue Nov 18 07:17:09 PST 2003
- Previous message: [cairo-commit] gtkcairo/gtkcairo Makefile.am,NONE,1.1 gtkcairo.c,NONE,1.1 gtkcairo.h,NONE,1.1
- Next message: [cairo-commit] cairo ChangeLog,1.110,1.111 cairo.pc.in,1.5,1.6 configure.in,1.30,1.31
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: cworth
Update of /cvs/cairo/gtkcairo/tests
In directory pdx:/tmp/cvs-serv6348/tests
Added Files:
Makefile.am demo.c
Log Message:
Initial import of gtkcairo (courtesy of Evan Martin <martine at danga.com>)
--- NEW FILE: Makefile.am ---
noinst_PROGRAMS = demo
demo_SOURCES = \
demo.c
AM_CFLAGS = $(GTKCAIRO_CFLAGS)
demo_LDADD = $(GTKCAIRO_LIBS) $(top_srcdir)/gtkcairo/libgtkcairo.la
--- NEW FILE: demo.c ---
/* vim: set ts=4 sw=4 noet : */
#include <gtk/gtk.h>
#include <gtkcairo/gtkcairo.h>
#define ANIMATE_ROTATE_STEP 0.05
#define ANIMATE_FRAME_DELAY 40
#define ROTATE_MAX 6.28 /* 2*pi */
#define MARGIN 20
#define BOX_SIZE 100
static void
setup_transform(cairo_t *cairo) {
cairo_default_matrix(cairo);
cairo_translate(cairo, BOX_SIZE+MARGIN, BOX_SIZE+MARGIN);
}
static void
expose(GtkCairo *gtkcairo) {
cairo_t *cairo = gtk_cairo_get_cairo(gtkcairo);
cairo_rectangle (cairo, 0, 0, BOX_SIZE, BOX_SIZE);
cairo_set_rgb_color (cairo, 1, 1, 1);
cairo_fill (cairo);
}
static void
slider_changed(GtkRange *range, GtkCairo *gtkcairo) {
cairo_t *cairo = gtk_cairo_get_cairo(gtkcairo);
setup_transform(cairo);
cairo_rotate(cairo, gtk_range_get_value(range));
gtk_widget_queue_draw(GTK_WIDGET(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() {
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);
gtkcairo = gtk_cairo_new();
setup_transform(gtk_cairo_get_cairo(GTK_CAIRO(gtkcairo)));
gtk_widget_set_usize(GTK_WIDGET(gtkcairo),
2*(BOX_SIZE+MARGIN), 2*(BOX_SIZE+MARGIN));
g_signal_connect_after(G_OBJECT(gtkcairo), "expose-event",
G_CALLBACK(expose), NULL);
gtk_container_add(GTK_CONTAINER(frame), gtkcairo);
gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
slider = gtk_hscale_new_with_range(0, ROTATE_MAX, 0.05);
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;
}
- Previous message: [cairo-commit] gtkcairo/gtkcairo Makefile.am,NONE,1.1 gtkcairo.c,NONE,1.1 gtkcairo.h,NONE,1.1
- Next message: [cairo-commit] cairo ChangeLog,1.110,1.111 cairo.pc.in,1.5,1.6 configure.in,1.30,1.31
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list