[seed] Composite type tests was testing composite types that didn't exist



commit 0b9938eb40741a164ebdc852a027ac049573aa45
Author: Robert Carr <racarr mireia (none)>
Date:   Tue Apr 14 16:26:01 2009 -0400

    Composite type tests was testing composite types that didn't exist
---
 modules/canvas/run-tests.js  |    7 ++--
 modules/canvas/seed-canvas.c |   63 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/modules/canvas/run-tests.js b/modules/canvas/run-tests.js
index 07228ce..a36b8fb 100755
--- a/modules/canvas/run-tests.js
+++ b/modules/canvas/run-tests.js
@@ -378,15 +378,16 @@ var compositeTypes = [
   'lighter','darker','copy','xor'
 ];
 function test17(ctx){
-  for (var i=0;i<4;i++){
+  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();
diff --git a/modules/canvas/seed-canvas.c b/modules/canvas/seed-canvas.c
index 5db0beb..5f4daec 100644
--- a/modules/canvas/seed-canvas.c
+++ b/modules/canvas/seed-canvas.c
@@ -22,6 +22,7 @@ typedef struct _SeedCanvasStyle {
   SeedCanvasColor stroke;
   
   gdouble global_opacity;
+  cairo_operator_t operator;
 } SeedCanvasStyle;
 
 typedef struct _SeedCanvasPrivates {
@@ -347,6 +348,58 @@ seed_canvas_update_global_alpha (SeedContext ctx,
 }
 
 gboolean
+seed_canvas_update_global_composite (SeedContext ctx,
+				     SeedObject this_object,
+				     SeedString property_name,
+				     SeedValue value, SeedException * e)
+{
+  SeedCanvasStyle *style;
+  GET_CR;
+  gchar *composite_op = seed_value_to_string (ctx, value, e);
+
+  if (!priv->styles)
+    {
+      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)->fill.a = 1;
+    }
+
+  style = (SeedCanvasStyle *)priv->styles->data;
+  
+  if (!strcmp (composite_op, "copy"))
+    style->operator = CAIRO_OPERATOR_SOURCE;
+  else if (!strcmp (composite_op, "source-over"))
+    style->operator = CAIRO_OPERATOR_OVER;
+  else if (!strcmp (composite_op, "source-in"))
+    style->operator = CAIRO_OPERATOR_IN;
+  else if (!strcmp (composite_op, "source-out"))
+    style->operator = CAIRO_OPERATOR_OUT;
+  else if (!strcmp (composite_op, "source-atop"))
+    style->operator = CAIRO_OPERATOR_ATOP;
+  else if (!strcmp (composite_op, "destination-over"))
+    style->operator = CAIRO_OPERATOR_DEST_OVER;
+  else if (!strcmp (composite_op, "destination-in"))
+    style->operator = CAIRO_OPERATOR_DEST_IN;
+  else if (!strcmp (composite_op, "destination-out"))
+    style->operator = CAIRO_OPERATOR_DEST_OVER;
+  else if (!strcmp (composite_op, "destination-atop"))
+    style->operator = CAIRO_OPERATOR_DEST_ATOP;
+  else if (!strcmp (composite_op, "xor"))
+    style->operator = CAIRO_OPERATOR_XOR;
+  else if (!strcmp (composite_op, "darker"))
+    style->operator = CAIRO_OPERATOR_SATURATE;
+  else if (!strcmp (composite_op, "lighter"))
+    style->operator = CAIRO_OPERATOR_ADD;
+  else
+    style->operator = CAIRO_OPERATOR_OVER;
+  
+  g_free (composite_op);
+  
+  return TRUE;
+}
+
+gboolean
 seed_canvas_set_linewidth (SeedContext ctx,
 			   SeedObject this_object,
 			   SeedString property_name,
@@ -420,6 +473,10 @@ 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);
 }
 
 void
@@ -431,6 +488,11 @@ 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);
+      
 }
 
 SeedValue
@@ -960,6 +1022,7 @@ seed_static_value canvas_properties[] = {
   {"strokeStyle", 0, seed_canvas_update_stroke_style, 0},
   {"fillStyle", 0, seed_canvas_update_fill_style, 0},
   {"globalAlpha", 0, seed_canvas_update_global_alpha, 0},
+  {"globalCompositeOperation", 0, seed_canvas_update_global_composite, 0},
   {0, 0, 0, 0}
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]