/* Copyright © 2008 Author: Valerio Messina I-EFAA http://users.iol.it/efa */
/* A minimal GTK+ v2.8+ and Cairo v1.4+ demo. Compile with:
gcc -Wall -lm cairo.c -o cairo `pkg-config --cflags --libs gtk+-2.0` */
/* cairo.c is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cairo.c is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see . */
#include
#include
void exposeCanvas (GtkWidget* canvasPtr, GdkEventExpose* eventPtr) {
cairo_t* drawPtr;
gint x, y, width, height;
double radius;
drawPtr = gdk_cairo_create (eventPtr->window);
x = canvasPtr->allocation.x;
y = canvasPtr->allocation.y;
width = canvasPtr->allocation.width;
height = canvasPtr->allocation.height;
radius = MIN (width / 2.0, height / 2.0) - 5.0; // raggio del cerchio
printf ("x:%d y:%d width:%d height:%d radius:%f\n", x, y, width, height, radius);
// 1.0 x 1.0 workspace to be 100 x 100 pixels
// in the middle of a 120 x 120 pixel surface
//cairo_translate (drawPtr, 10, 10);
//cairo_scale (drawPtr, 100, 100);
// linee:
//cairo_move_to (drawPtr, 1, 1);
//cairo_line_to (drawPtr, 10, 10);
cairo_rectangle (drawPtr, width*.05, height*.05, width*.9, height*.9);
cairo_clip (drawPtr);
cairo_arc (drawPtr, width*.5, height*.5, radius, 0.0, 2*M_PI); // disegna un cerchio: arco 0-2PI, centrato e raggio radius
cairo_set_source_rgb (drawPtr, 1.0, 1.0, 1.0); // bianco
cairo_fill_preserve (drawPtr);
cairo_set_source_rgb (drawPtr, 0.0, 0.0, 0.0); // nero
cairo_set_line_width (drawPtr, 2.0); // 1 pixel
cairo_stroke (drawPtr);
cairo_destroy (drawPtr);
}
int main (int argc, char** argv) {
GtkWidget* windowPtr;
GtkWidget* canvasPtr;
gtk_init (&argc, &argv);
windowPtr = gtk_window_new (GTK_WINDOW_TOPLEVEL);
canvasPtr = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (windowPtr), canvasPtr);
g_signal_connect (windowPtr, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (G_OBJECT (canvasPtr), "expose-event", G_CALLBACK (exposeCanvas), NULL);
gtk_widget_show_all (windowPtr);
gtk_main ();
return (0);
}