[cairo-commit] cairo-demo/qcairo ChangeLog, 1.1,
1.2 qcairowidget.cpp, 1.1, 1.2 qcairowidget.h, 1.1,
1.2 qkapow.cpp, 1.1, 1.2 qkapow.h, 1.1, 1.2
Behdad Esfahbod
commit at pdx.freedesktop.org
Sat Aug 20 06:37:35 EST 2005
Committed by: behdad
Update of /cvs/cairo/cairo-demo/qcairo
In directory gabe:/tmp/cvs-serv26789
Modified Files:
ChangeLog qcairowidget.cpp qcairowidget.h qkapow.cpp qkapow.h
Log Message:
2005-08-19 Behdad Esfahbod <behdad at behdad.org>
* Updated to latest Cairo interface. Patch from Mauricio Piacentini.
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/qcairo/ChangeLog,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ChangeLog 1 Jul 2005 19:49:07 -0000 1.1
+++ ChangeLog 19 Aug 2005 20:37:33 -0000 1.2
@@ -1,3 +1,7 @@
+2005-08-19 Behdad Esfahbod <behdad at behdad.org>
+
+ * Updated to latest Cairo interface. Patch from Mauricio Piacentini.
+
2005-07-01 Carl Worth <cworth at cworth.org>
From 2005-01-25 Zack Rusin <zack at kde.org>:
Index: qcairowidget.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/qcairo/qcairowidget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qcairowidget.cpp 1 Jul 2005 19:49:07 -0000 1.1
+++ qcairowidget.cpp 19 Aug 2005 20:37:33 -0000 1.2
@@ -4,7 +4,13 @@
: QWidget( parent, name )
{
setDoubleBuffered( true );
- m_cr = cairo_create();
+
+ Display *dpy = x11AppDisplay();
+ Drawable drw = handle();
+ m_surf = cairo_xlib_surface_create (dpy, drw,
+ DefaultVisual (dpy, DefaultScreen (dpy)), width(), height() );
+ m_cr = cairo_create(m_surf);
+ cairo_surface_destroy(m_surf);
}
QCairoWidget::~QCairoWidget()
@@ -40,13 +46,13 @@
drw = m_buffer.handle();
}
- cairo_set_target_drawable( m_cr, dpy, drw );
+ m_surf = cairo_get_target (m_cr);
+ cairo_xlib_surface_set_drawable (m_surf, drw, width(), height());
cairoPaint( m_cr, e->rect() );
- if ( cairo_status( m_cr ) ) {
- qDebug("Cairo is unhappy: %s\n", cairo_status_string( m_cr ) );
- exit(0);
+ if ( cairo_status( m_cr ) != CAIRO_STATUS_SUCCESS ) {
+ qDebug("Cairo is unhappy: %s\n", cairo_status_to_string( cairo_status( m_cr ) ) );
}
if ( m_doubleBuffer )
Index: qcairowidget.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/qcairo/qcairowidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qcairowidget.h 1 Jul 2005 19:49:07 -0000 1.1
+++ qcairowidget.h 19 Aug 2005 20:37:33 -0000 1.2
@@ -25,6 +25,7 @@
private:
cairo_t *m_cr;
+ cairo_surface_t * m_surf;
QPixmap m_buffer;
bool m_doubleBuffer;
};
Index: qkapow.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/qcairo/qkapow.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qkapow.cpp 1 Jul 2005 19:49:07 -0000 1.1
+++ qkapow.cpp 19 Aug 2005 20:37:33 -0000 1.2
@@ -56,7 +56,7 @@
cairo_close_path (cr);
}
-void QKapow::bend_it (double x, double y, double *new_x, double *new_y)
+void QKapow::bend_it (double *x, double *y)
{
const double cx = width() / 2, cy = 500;
double angle, radius, t;
@@ -66,53 +66,54 @@
* On top of that, we'll scale up the letters going left to right.
*/
- angle = M_PI / 2 - (double) (x - cx) / width();
+ angle = M_PI / 2 - (double) (*x - cx) / width();
t = 3 * M_PI / 4 - angle + 0.05;
angle = 3 * M_PI / 4 - pow (t, 1.8);
- radius = cy - (height() / 2 + (y - height() / 2) * t * 2);
+ radius = cy - (height() / 2 + (*y - height() / 2) * t * 2);
- *new_x = cx + cos (angle) * radius;
- *new_y = cy - sin (angle) * radius;
+ *x = cx + cos (angle) * radius;
+ *y = cy - sin (angle) * radius;
}
-static void move_to_callback(void *data, double x, double y)
+void QKapow::make_text_path (cairo_t *cr, double x, double y, const char *text)
{
- QKapow *ctx = (QKapow*)data;
- double new_x, new_y;
-
- if (ctx->first()) {
- cairo_new_path (ctx->cr());
- ctx->setFirst( 0 );
- }
-
- ctx->bend_it(x, y, &new_x, &new_y);
- cairo_move_to (ctx->cr(), new_x, new_y);
-}
+ m_first = 1;
+
+cairo_path_t *path;
+ cairo_path_data_t *data;
+ int i;
-static void line_to_callback(void *data, double x, double y)
-{
- QKapow *ctx = (QKapow*)data;
- double new_x, new_y;
+ cairo_move_to (cr, x, y);
+ cairo_text_path (cr, text);
- ctx->bend_it (x, y, &new_x, &new_y);
- cairo_line_to (ctx->cr(), new_x, new_y);
-}
+ path = cairo_copy_path_flat (cr);
-static void close_path_callback(void *data)
-{
- QKapow *ctx = (QKapow*)data;
+ cairo_new_path (cr);
- cairo_close_path (ctx->cr());
-}
+ for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ data = &path->data[i];
+ switch (data->header.type) {
+ case CAIRO_PATH_MOVE_TO:
+ x = data[1].point.x;
+ y = data[1].point.y;
+ bend_it (&x, &y);
+ cairo_move_to (cr, x, y);
+ break;
+ case CAIRO_PATH_LINE_TO:
+ x = data[1].point.x;
+ y = data[1].point.y;
+ bend_it (&x, &y);
+ cairo_line_to (cr, x, y);
+ break;
+ case CAIRO_PATH_CLOSE_PATH:
+ cairo_close_path (cr);
+ break;
+ default:
+ qDebug("unexpected path element");
+ }
+ }
-void QKapow::make_text_path (cairo_t *cr, double x, double y, const char *text)
-{
- m_first = 1;
- m_cr = cr;
- cairo_move_to (cr, x, y);
- cairo_text_path (cr, ( const unsigned char* ) text);
- cairo_current_path_flat (cr, move_to_callback, line_to_callback,
- close_path_callback, this);
+ free (path);
}
@@ -136,31 +137,31 @@
cairo_save (cr);
cairo_translate (cr, SHADOW_OFFSET, SHADOW_OFFSET);
make_star_path (cr);
- cairo_set_alpha (cr, 0.5);
- cairo_set_rgb_color (cr, 0, 0, 0);
+ cairo_paint_with_alpha (cr, 0.5);
+ cairo_set_source_rgb (cr, 0, 0, 0);
cairo_fill (cr);
cairo_restore (cr);
make_star_path (cr);
- cairo_set_alpha (cr, 1);
+ cairo_paint_with_alpha (cr, 1);
pattern =
cairo_pattern_create_radial (width() / 2, height() / 2, 10,
width() / 2, height() / 2, 230);
- cairo_pattern_add_color_stop (pattern, 0, 1, 1, 0.2, 1);
- cairo_pattern_add_color_stop (pattern, 1, 1, 0, 0, 1);
- cairo_set_pattern (cr, pattern);
+ cairo_pattern_add_color_stop_rgba (pattern, 0, 1, 1, 0.2, 1);
+ cairo_pattern_add_color_stop_rgba (pattern, 1, 1, 0, 0, 1);
+ cairo_set_source (cr, pattern);
cairo_fill (cr);
make_star_path (cr);
- cairo_set_rgb_color (cr, 0, 0, 0);
+ cairo_set_source_rgb (cr, 0, 0, 0);
cairo_stroke (cr);
- cairo_select_font (cr, fontname,
+ cairo_select_font_face (cr, fontname,
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
- cairo_scale_font (cr, 50);
- cairo_text_extents (cr, ( const unsigned char* )text.latin1(), &extents);
+ cairo_set_font_size (cr, 50);
+ cairo_text_extents (cr, ( const char* )text.latin1(), &extents);
x = width() / 2 - (extents.width / 2 + extents.x_bearing);
y = height() / 2 - (extents.height / 2 + extents.y_bearing);
@@ -169,14 +170,14 @@
pattern =
cairo_pattern_create_linear (width() / 2 - 10, height() / 4,
width() / 2 + 10, 3 * height() / 4);
- cairo_pattern_add_color_stop (pattern, 0, 1, 1, 1, 1);
- cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0.4, 1);
- cairo_set_pattern (cr, pattern);
+ cairo_pattern_add_color_stop_rgba (pattern, 0, 1, 1, 1, 1);
+ cairo_pattern_add_color_stop_rgba (pattern, 1, 0, 0, 0.4, 1);
+ cairo_set_source (cr, pattern);
cairo_fill (cr);
make_text_path (cr, x, y, text.latin1());
- cairo_set_rgb_color (cr, 0, 0, 0);
+ cairo_set_source_rgb (cr, 0, 0, 0);
cairo_stroke (cr);
cairo_show_page (cr);
Index: qkapow.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/qcairo/qkapow.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qkapow.h 1 Jul 2005 19:49:07 -0000 1.1
+++ qkapow.h 19 Aug 2005 20:37:33 -0000 1.2
@@ -34,7 +34,7 @@
{
return m_cr;
}
- void bend_it(double x, double y, double *new_x, double *new_y);
+ void bend_it (double *x, double *y);
protected:
virtual void cairoPaint( cairo_t *cr, const QRect &rect );
More information about the cairo-commit
mailing list