All pastes #23563 Raw Edit

MacSlow

public c v1 · immutable
#23563 ·published 2005-09-21 23:16 UTC
rendered paste body
/*** cairo_test.c written against gtk+-2.8.3 and cairo-1.1.1 (CVS)**** compile with:**    gcc -Wall `pkg-config gtk+-2.0 --cflags --libs` cairo_test.c -o cairo_test***/#include <gtk/gtk.h>gboolean expose_event (GtkWidget* widget,					   GdkEventExpose* event,					   gpointer data){	int x = widget->allocation.x;	int y = widget->allocation.y;	int w = widget->allocation.width;	int h = widget->allocation.height;	cairo_t* cr = NULL;	printf ("expose_event() called\n");	cr = gdk_cairo_create (widget->window);	if (cr)	{		/* just draw a filled yellow rectangle */		cairo_set_source_rgb (cr, 1.0f, 1.0f, 0.0f);		cairo_rectangle (cr, x + w/4, y + h/4, w/2, h/2);		cairo_fill (cr);		cairo_destroy (cr);		gdk_window_invalidate_rect (widget->window, NULL, FALSE);		return FALSE;	}	else		return TRUE;}int main (int argc, char** argv){	GtkWidget *window = NULL;	GtkWidget* drawingArea = NULL;	GtkWidget* vBox = NULL;	gtk_init (&argc, &argv);	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);	gtk_window_set_title (GTK_WINDOW (window), "Cairo Test");	g_signal_connect (G_OBJECT (window),					  "destroy",					  G_CALLBACK (gtk_main_quit),					  NULL);	vBox = gtk_vbox_new (FALSE, 0);	gtk_container_add (GTK_CONTAINER (window), vBox);	drawingArea = gtk_drawing_area_new ();	gtk_widget_set_size_request (drawingArea, 320, 240);	g_signal_connect (G_OBJECT (drawingArea),					  "expose-event",					  G_CALLBACK (expose_event),					  NULL);	gtk_box_pack_start (GTK_BOX (vBox), drawingArea, TRUE, TRUE, 0);    gtk_widget_show_all (window);    gtk_main ();    return 0;}