[seed] I don't understand canvas...some more work on handling state correctly
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] I don't understand canvas...some more work on handling state correctly
- Date: Tue, 14 Apr 2009 19:18:28 -0400 (EDT)
commit 2dd8699f08cecceeecc68115797f0571a47afbd0
Author: Robert Carr <racarr mireia (none)>
Date: Tue Apr 14 19:18:22 2009 -0400
I don't understand canvas...some more work on handling state correctly
---
modules/canvas/run-tests.js | 38 ++++++++++++++++++++------------------
modules/canvas/seed-canvas.c | 17 ++++++++---------
2 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/modules/canvas/run-tests.js b/modules/canvas/run-tests.js
index a36b8fb..9a0c47a 100755
--- a/modules/canvas/run-tests.js
+++ b/modules/canvas/run-tests.js
@@ -377,25 +377,27 @@ var compositeTypes = [
'destination-over','destination-in','destination-out','destination-atop',
'lighter','darker','copy','xor'
];
-function test17(ctx){
- for (var i=0;i<3;i++){
- for (var j = 0;j<4;j++){
- // draw rectangle
- ctx.fillStyle = "#09f";
- ctx.fillRect(70*i,70*j,40,40);
-
- // set composite property
- Seed.print(compositeTypes[i*4+j])
- ctx.globalCompositeOperation = compositeTypes[i*4+j];
-
- // draw circle
- ctx.fillStyle = "#f30";
- ctx.beginPath();
- ctx.arc(35+70*i,35+70*j,17,0,Math.PI*2,true);
- ctx.fill();
- }
+ function test17(ctx){
+ for (var i=0;i<3;i++){
+ for (var j = 0;j<4;j++){
+ // draw rectangle
+ ctx.save();
+ ctx.fillStyle = "#09f";
+ ctx.fillRect(70*i,70*j,40,40);
+
+ // set composite property
+// Seed.print(compositeTypes[i*4+j])
+ ctx.globalCompositeOperation = compositeTypes[i*4+j];
+
+ // draw circle
+ ctx.fillStyle = "#f30";
+ ctx.beginPath();
+ ctx.arc(30+70*i,30+70*j,17,0,Math.PI*2,true);
+ ctx.fill();
+ ctx.restore();
+ }
+ }
}
-}
tests = [test1, test2, test3, test4,
diff --git a/modules/canvas/seed-canvas.c b/modules/canvas/seed-canvas.c
index 5f4daec..87ed220 100644
--- a/modules/canvas/seed-canvas.c
+++ b/modules/canvas/seed-canvas.c
@@ -281,6 +281,7 @@ seed_canvas_update_stroke_style (SeedContext ctx,
priv->styles = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
((SeedCanvasStyle *) priv->styles->data)->fill.a = 1;
+ ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
}
style = (SeedCanvasStyle *)priv->styles->data;
@@ -309,6 +310,7 @@ seed_canvas_update_fill_style (SeedContext ctx,
priv->styles = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
((SeedCanvasStyle *) priv->styles->data)->stroke.a = 1;
+ ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
}
style = (SeedCanvasStyle *)priv->styles->data;
@@ -338,6 +340,7 @@ seed_canvas_update_global_alpha (SeedContext ctx,
((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
((SeedCanvasStyle *) priv->styles->data)->stroke.a = 1;
((SeedCanvasStyle *) priv->styles->data)->fill.a = 1;
+ ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
}
style = (SeedCanvasStyle *)priv->styles->data;
@@ -363,6 +366,7 @@ seed_canvas_update_global_composite (SeedContext ctx,
((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
((SeedCanvasStyle *) priv->styles->data)->stroke.a = 1;
((SeedCanvasStyle *) priv->styles->data)->fill.a = 1;
+ ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
}
style = (SeedCanvasStyle *)priv->styles->data;
@@ -394,6 +398,8 @@ seed_canvas_update_global_composite (SeedContext ctx,
else
style->operator = CAIRO_OPERATOR_OVER;
+ cairo_set_operator (cr, style->operator);
+
g_free (composite_op);
return TRUE;
@@ -473,10 +479,7 @@ seed_canvas_apply_stroke_style (SeedCanvasStyle *style,
style->stroke.g,
style->stroke.b,
style->stroke.a * style->global_opacity);
- if (style->operator)
- cairo_set_operator (cr, style->operator);
- else
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_operator (cr, style->operator);
}
void
@@ -488,11 +491,7 @@ seed_canvas_apply_fill_style (SeedCanvasStyle *style,
style->fill.g,
style->fill.b,
style->fill.a * style->global_opacity);
- if (style->operator)
- cairo_set_operator (cr, style->operator);
- else
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-
+ cairo_set_operator (cr, style->operator);
}
SeedValue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]