Re: rotating background images on a gtkdrawable



On 11/1/06, Yianni <odysseus lost gmail com> wrote:
Hello and apologies for the general scope of the quetion but how can I
rotate background images on a gtkdrawable?

Try cairo (with GTK+ >= 2.8.x), see an attached sample. All used
functions are documented in GTK+/GDK and cairo references.

  Olexiy
#include <gtk/gtk.h>

int
main(int argc, char **argv)
{
	GtkWidget *window;
	GtkWidget *image;
	GtkWidget *vbox;
	GdkPixmap *pixmap_src, *pixmap_dst;
	cairo_t *cr_src, *cr_dst;

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);

	gtk_widget_show(window);

	vbox = gtk_vbox_new(TRUE, 6);

	pixmap_src = gdk_pixmap_new(
		gdk_get_default_root_window(),
		100,100,-1
	);
	pixmap_dst = gdk_pixmap_new(
		gdk_get_default_root_window(),
		100,100,-1
	);

	cr_src = gdk_cairo_create(pixmap_src);

	/* set the source pixmap grey */
	cairo_set_source_rgb(cr_src, .7,.7,.7);
	cairo_rectangle(cr_src, 0.,0.,100.,100.);
	cairo_fill(cr_src);

	/* draw red diagonal lines */
	cairo_set_source_rgb(cr_src, 1.,0.5,0.5);
	cairo_move_to(cr_src, 0.,0.);
	cairo_line_to(cr_src, 100.,100.);
	cairo_stroke(cr_src);
	cairo_move_to(cr_src, 0.,100.);
	cairo_line_to(cr_src, 100.,0.);
	cairo_stroke(cr_src);

	cr_dst = gdk_cairo_create(pixmap_dst);

	/* set the dest. pixmap white */
	cairo_rectangle(cr_dst, 0.,0.,100.,100.);
	cairo_set_source_rgb(cr_dst, 1.,1.,1.);
	cairo_fill(cr_dst);

	/* rotate the source pixmap and copy it into dest. */
	cairo_rotate(cr_dst, G_PI*23.0/180.0);
	cairo_rectangle(cr_dst, 0,0,100,100);
	cairo_set_source_surface(cr_dst, cairo_get_target(cr_src), 0,0);
	cairo_fill(cr_dst);

	cairo_destroy(cr_src);
	cairo_destroy(cr_dst);

	/* show both pixmaps */
	image = gtk_image_new_from_pixmap(pixmap_src, NULL);
	gtk_widget_show(image);
	gtk_container_add(GTK_CONTAINER(vbox), image);

	image = gtk_image_new_from_pixmap(pixmap_dst, NULL);
	gtk_container_add(GTK_CONTAINER(vbox), image);

	gtk_container_add(GTK_CONTAINER(window), vbox);
	gtk_widget_show_all(window);

	gtk_main();

	return 0;
}


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