[cairo-commit] cairo-demo/gtk .cvsignore, 1.3, 1.4 ChangeLog, 1.4,
1.5 Makefile, 1.4, 1.5 README, 1.3, 1.4 hello.c, 1.1,
1.2 mouse_events.c, 1.1, 1.2
Behdad Esfahbod
commit at pdx.freedesktop.org
Fri Aug 12 00:24:29 PDT 2005
Committed by: behdad
Update of /cvs/cairo/cairo-demo/gtk
In directory gabe:/tmp/cvs-serv30128
Modified Files:
.cvsignore ChangeLog Makefile README hello.c mouse_events.c
Log Message:
2005-08-12 Behdad Esfahbod <behdad at behdad.org>
* hello.c, mouse_events.c: updated to latest cairo+gtk api.
* README: noted the change from gtkcairo to cairo+gtk.
Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtk/.cvsignore,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- .cvsignore 11 Nov 2004 19:47:51 -0000 1.3
+++ .cvsignore 12 Aug 2005 07:24:27 -0000 1.4
@@ -1 +1,2 @@
+hello
mouse_events
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtk/ChangeLog,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ChangeLog 11 Nov 2004 19:45:53 -0000 1.4
+++ ChangeLog 12 Aug 2005 07:24:27 -0000 1.5
@@ -1,3 +1,8 @@
+2005-08-12 Behdad Esfahbod <behdad at behdad.org>
+
+ * hello.c, mouse_events.c: updated to latest cairo+gtk api.
+ * README: noted the change from gtkcairo to cairo+gtk.
+
2004-11-11 Ãyvind KolÃ¥s <pippin at freedesktop.org>
* mouse_events.c: illustration handling of mouse events, by
Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtk/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile 11 Nov 2004 19:45:53 -0000 1.4
+++ Makefile 12 Aug 2005 07:24:27 -0000 1.5
@@ -4,10 +4,10 @@
CFLAGS = -g -Wall
-CFLAGS += `pkg-config gtkcairo --cflags`
-LDFLAGS += `pkg-config gtkcairo --libs`
+CFLAGS += `pkg-config gtk+-2.0 --cflags`
+LDFLAGS += `pkg-config gtk+-2.0 --libs`
all: $(APPS)
clean:
- rm -f *.o $(APPS)
+ $(RM): $(APPS)
Index: README
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtk/README,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- README 11 Nov 2004 19:52:11 -0000 1.3
+++ README 12 Aug 2005 07:24:27 -0000 1.4
@@ -1,7 +1,7 @@
-Sample usage of the gtkcairo widget.
+Sample usage of the gtk+ with cairo support.
-hello A very simple application with a gtkcairo widget in a window,
- displaying some text.
+hello A very simple application with a drawing area widget in a window,
+ displaying some text and graphics using cairo.
mouse_events Illustrating how to add handlers for mouse events
@@ -10,10 +10,5 @@
proper inheritance
==================
-See the ../gtkcairo_slide for an example on how to properly use inheritance
-to create a proper new GtkWidget based on gtkcairo, when cairo is integrated
-according to plan, minimal changes should be needed for either approach to
-work.
-
-
-
+See the ../gtk_slide for an example on how to properly use inheritance
+to create a proper new GtkWidget based using cairo.
Index: hello.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtk/hello.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hello.c 11 Nov 2004 17:49:08 -0000 1.1
+++ hello.c 12 Aug 2005 07:24:27 -0000 1.2
@@ -1,16 +1,15 @@
-/* hello world for gtkcairo, by Ãvyind KolÃ¥s
+/* hello world for gtk with cairo support, by Ãvyind KolÃ¥s
*/
#include <gtk/gtk.h>
-#include <gtkcairo.h>
+#include <cairo.h>
#define DEFAULT_WIDTH 400
#define DEFAULT_HEIGHT 200
-/* forward definition of actual painting function for our gtkcairo widget
+/* forward definition of actual painting function for our drawing area widget
*/
static void paint (GtkWidget *widget,
- cairo_t *cr,
gpointer data);
gint
@@ -18,7 +17,7 @@
gchar **argv)
{
GtkWidget *window;
- GtkWidget *gtkcairo;
+ GtkWidget *canvas;
gtk_init (&argc, &argv);
@@ -31,26 +30,26 @@
g_signal_connect (G_OBJECT (window), "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
- /* create a new gtkcairo widget
+ /* create a new drawing area widget
*/
- gtkcairo = gtk_cairo_new ();
+ canvas = gtk_drawing_area_new ();
- /* set a requested (minimum size) for the gtkcairo widget
+ /* set a requested (minimum size) for the canvas
*/
- gtk_widget_set_size_request (gtkcairo, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ gtk_widget_set_size_request (canvas, DEFAULT_WIDTH, DEFAULT_HEIGHT);
- /* connect our drawing method to the "paint" signal
+ /* connect our drawing method to the "expose" signal
*/
- g_signal_connect (G_OBJECT (gtkcairo), "paint",
+ g_signal_connect (G_OBJECT (canvas), "expose-event",
G_CALLBACK (paint),
NULL /*< here we can pass a pointer to a custom data structure */
);
- /* pack gtkcairo widget into window
+ /* pack canvas widget into window
*/
- gtk_container_add (GTK_CONTAINER (window), gtkcairo);
+ gtk_container_add (GTK_CONTAINER (window), canvas);
- /* show window and all it's children (just the gtkcairo widget)
+ /* show window and all it's children (just the canvas widget)
*/
gtk_widget_show_all (window);
@@ -61,53 +60,47 @@
}
-/* the actual function invoked to paint the gtkcairo
+/* the actual function invoked to paint the canvas
* widget, this is where most cairo painting functions
* will go
*/
static void
paint (GtkWidget *widget,
- cairo_t *cr,
gpointer data)
{
gint width, height;
gint i;
+ cairo_t *cr;
width = widget->allocation.width;
height = widget->allocation.height;
- /* enclosing the painting function in a save/restore pair is a
- * good idea since we'll return to a sane state then
- */
-
- cairo_save (cr);
+ cr = gdk_cairo_create (widget->window);
/* clear background */
-
- cairo_rectangle (cr, 0, 0, width, height);
- cairo_set_rgb_color (cr, 1,1,1);
- cairo_fill (cr);
+ cairo_set_source_rgb (cr, 1,1,1);
+ cairo_paint (cr);
- cairo_select_font (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
- CAIRO_FONT_WEIGHT_BOLD);
+ cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
+ CAIRO_FONT_WEIGHT_BOLD);
/* enclosing in a save/restore pair since we alter the
* font size
*/
cairo_save (cr);
- cairo_scale_font (cr, 40);
+ cairo_set_font_size (cr, 40);
cairo_move_to (cr, 40, 60);
- cairo_set_rgb_color (cr, 0,0,0);
+ cairo_set_source_rgb (cr, 0,0,0);
cairo_show_text (cr, "Hello World");
cairo_restore (cr);
- cairo_set_rgb_color (cr, 1,0,0);
- cairo_scale_font (cr, 20);
+ cairo_set_source_rgb (cr, 1,0,0);
+ cairo_set_font_size (cr, 20);
cairo_move_to (cr, 50, 100);
cairo_show_text (cr, "greetings from gtk and cairo");
- cairo_set_rgb_color (cr, 0,0,1);
+ cairo_set_source_rgb (cr, 0,0,1);
cairo_move_to (cr, 0, 150);
for (i=0; i< width/10; i++)
@@ -115,8 +108,7 @@
cairo_rel_line_to (cr, 5, 10);
cairo_rel_line_to (cr, 5, -10);
}
-
cairo_stroke (cr);
- cairo_restore (cr);
+ cairo_destroy (cr);
}
Index: mouse_events.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtk/mouse_events.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mouse_events.c 11 Nov 2004 19:45:53 -0000 1.1
+++ mouse_events.c 12 Aug 2005 07:24:27 -0000 1.2
@@ -1,10 +1,10 @@
-/* alpha blended rubber band using gtkcairo, demonstrating mouse intercation
+/* alpha blended rubber band using canvas, demonstrating mouse intercation
*
* only things that are new compared to hello.c are commented
*/
#include <gtk/gtk.h>
-#include <gtkcairo.h>
+#include <cairo.h>
#define DEFAULT_WIDTH 400
#define DEFAULT_HEIGHT 200
@@ -19,9 +19,9 @@
}
SelectionInfo;
-static void paint (GtkWidget *widget,
- cairo_t *cr,
- SelectionInfo *sel_info);
+static void paint (GtkWidget *widget,
+ GdkEventExpose *eev,
+ SelectionInfo *sel_info);
/* forward definitions of handler for mouse events
*/
@@ -42,7 +42,7 @@
gchar **argv)
{
GtkWidget *window;
- GtkWidget *gtkcairo;
+ GtkWidget *canvas;
SelectionInfo selection = {FALSE, 0, 0, 0, 0};
gtk_init (&argc, &argv);
@@ -51,20 +51,20 @@
g_signal_connect (G_OBJECT (window), "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
- gtkcairo = gtk_cairo_new ();
- gtk_widget_set_size_request (gtkcairo, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ canvas = gtk_drawing_area_new ();
+ gtk_widget_set_size_request (canvas, DEFAULT_WIDTH, DEFAULT_HEIGHT);
- /* connect our drawing method to the "paint" signal
+ /* connect our drawing method to the "expose" signal
* passing in a pointer to the selection structure as the user data
*/
- g_signal_connect (G_OBJECT (gtkcairo), "paint",
+ g_signal_connect (G_OBJECT (canvas), "expose-event",
G_CALLBACK (paint),
&selection
);
- /* add additional events the gtkcairo widget will listen for
+ /* add additional events the canvas widget will listen for
*/
- gtk_widget_add_events (gtkcairo,
+ gtk_widget_add_events (canvas,
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK);
@@ -73,20 +73,20 @@
/* connect our rubber banding callbacks, like the paint callback
* we pass the selection as userdata
*/
- g_signal_connect (G_OBJECT (gtkcairo), "button_press_event",
+ g_signal_connect (G_OBJECT (canvas), "button_press_event",
G_CALLBACK (event_press),
&selection
);
- g_signal_connect (G_OBJECT (gtkcairo), "button_release_event",
+ g_signal_connect (G_OBJECT (canvas), "button_release_event",
G_CALLBACK (event_release),
&selection
);
- g_signal_connect (G_OBJECT (gtkcairo), "motion_notify_event",
+ g_signal_connect (G_OBJECT (canvas), "motion_notify_event",
G_CALLBACK (event_motion),
&selection
);
- gtk_container_add (GTK_CONTAINER (window), gtkcairo);
+ gtk_container_add (GTK_CONTAINER (window), canvas);
gtk_widget_show_all (window);
gtk_main ();
@@ -102,54 +102,52 @@
{
if (!sel_info->active)
return;
+
cairo_save (cr);
cairo_rectangle (cr, sel_info->x, sel_info->y,
sel_info->w, sel_info->h);
- cairo_save (cr);
- cairo_set_rgb_color (cr, 0, 0, 1);
- cairo_set_alpha (cr, 0.2);
- cairo_fill (cr);
- cairo_restore (cr);
- cairo_set_rgb_color (cr, 0, 0, 0);
- cairo_set_alpha (cr, 0.5);
+ cairo_set_source_rgba (cr, 0, 0, 1, 0.2);
+ cairo_fill_preserve (cr);
+
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
cairo_stroke (cr);
cairo_restore (cr);
}
static void
-paint (GtkWidget *widget,
- cairo_t *cr,
- SelectionInfo *sel_info)
+paint (GtkWidget *widget,
+ GdkEventExpose *eev,
+ SelectionInfo *sel_info)
{
gint width, height;
gint i;
+ cairo_t *cr;
width = widget->allocation.width;
height = widget->allocation.height;
- cairo_save (cr);
+ cr = gdk_cairo_create (widget->window);
- cairo_rectangle (cr, 0, 0, width, height);
- cairo_set_rgb_color (cr, 1,1,1);
- cairo_fill (cr);
+ cairo_set_source_rgb (cr, 1,1,1);
+ cairo_paint (cr);
- cairo_select_font (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
+ cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_save (cr);
- cairo_scale_font (cr, 20);
+ cairo_set_font_size (cr, 20);
cairo_move_to (cr, 40, 60);
- cairo_set_rgb_color (cr, 0,0,0);
+ cairo_set_source_rgb (cr, 0,0,0);
cairo_show_text (cr, "Drag your mouse here");
cairo_restore (cr);
- cairo_set_rgb_color (cr, 1,0,0);
- cairo_scale_font (cr, 15);
+ cairo_set_source_rgb (cr, 1,0,0);
+ cairo_set_font_size (cr, 15);
cairo_move_to (cr, 50, 100);
cairo_show_text (cr, "(and see alpha blended selection)");
- cairo_set_rgb_color (cr, 0,0,1);
+ cairo_set_source_rgb (cr, 0,0,1);
cairo_move_to (cr, 0, 150);
for (i=0; i< width/10; i++)
@@ -163,7 +161,7 @@
/* paint the selection */
paint_selection (cr, sel_info);
- cairo_restore (cr);
+ cairo_destroy (cr);
}
@@ -179,7 +177,7 @@
sel_info->w = 0;
sel_info->h = 0;
- /* tell the gtkcairo widget that it needs to redraw itself */
+ /* tell the canvas widget that it needs to redraw itself */
gtk_widget_queue_draw (widget);
return TRUE;
@@ -194,7 +192,7 @@
sel_info->w = mev->x - sel_info->x;
sel_info->h = mev->y - sel_info->y;
- /* tell the gtkcairo widget that it needs to redraw itself */
+ /* tell the canvas widget that it needs to redraw itself */
gtk_widget_queue_draw (widget);
return TRUE;
}
@@ -206,7 +204,7 @@
{
sel_info->active = FALSE;
- /* tell the gtkcairo widget that it needs to redraw itself */
+ /* tell the canvas widget that it needs to redraw itself */
gtk_widget_queue_draw (widget);
return TRUE;
}
More information about the cairo-commit
mailing list