seed r398 - trunk/modules/canvas
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r398 - trunk/modules/canvas
- Date: Sat, 6 Dec 2008 03:14:55 +0000 (UTC)
Author: racarr
Date: Sat Dec 6 03:14:55 2008
New Revision: 398
URL: http://svn.gnome.org/viewvc/seed?rev=398&view=rev
Log:
Some more color tests/bugfixing. Support globalAlpha.
Added:
trunk/modules/canvas/test11.js (contents, props changed)
Modified:
trunk/modules/canvas/Makefile.am
trunk/modules/canvas/seed-canvas.c
trunk/modules/canvas/test10.js
Modified: trunk/modules/canvas/Makefile.am
==============================================================================
--- trunk/modules/canvas/Makefile.am (original)
+++ trunk/modules/canvas/Makefile.am Sat Dec 6 03:14:55 2008
@@ -7,7 +7,7 @@
libsqlite_la_LDFLAGS = \
`pkg-config --libs seed cairo`
-EXTRA_DIST=test1.js test2.js test3.js test4.js test5.js test6.js test7.js test8.js test9.js
+EXTRA_DIST=test1.js test2.js test3.js test4.js test5.js test6.js test7.js test8.js test9.js test10.js test11.js
AM_CPPFLAGS = \
-I../../libseed/ \
Modified: trunk/modules/canvas/seed-canvas.c
==============================================================================
--- trunk/modules/canvas/seed-canvas.c (original)
+++ trunk/modules/canvas/seed-canvas.c Sat Dec 6 03:14:55 2008
@@ -16,6 +16,7 @@
const SeedValue arguments[],
SeedException * exception)
{
+ SeedObject obj;
cairo_t * cr;
if (argument_count != 1)
{
@@ -26,10 +27,15 @@
cr = seed_pointer_get_pointer(ctx, arguments[0]);
- cairo_set_source_rgba(cr, 0, 0, 0, 1.0);
+ cairo_set_source_rgb(cr, 0, 0, 0);
- return seed_make_object(ctx, canvas_class,
+ obj = seed_make_object(ctx, canvas_class,
cr);
+
+ seed_object_set_property(ctx, obj, "globalAlpha",
+ seed_value_from_double(ctx, 1.0, exception));
+
+ return obj;
}
SeedValue seed_canvas_save (SeedContext ctx,
@@ -183,15 +189,22 @@
return seed_make_null(ctx);
}
-void seed_canvas_parse_color(cairo_t * cr, gchar * spec)
+void seed_canvas_parse_color(cairo_t * cr, gchar * spec, gdouble global_alpha)
{
if (*spec == '#')
{
- guint r=0,g=0,b=0,a=0;
+ guint r=0,g=0,b=0,a=0, found;
// Might be libc dependent (the alpha behaviour);
- sscanf(spec, "#%2x%2x%2x%2x", &r, &g, &b, &a);
- if (strlen(spec) < 8)
- a = 255;
+ if (strlen(spec) > 4)
+ found = sscanf(spec, "#%2x%2x%2x%2x", &r, &g, &b, &a);
+ else
+ {
+ found = sscanf(spec, "#%1x%1x%1x%1x", &r, &g, &b, &a);
+ r *= 17; g *= 17; b *= 17; a *= 17;
+ }
+ if (found < 4)
+ a = global_alpha*255;
+ printf("r: %d g:%d b:%d a:%d\n",r,g,b,a);
cairo_set_source_rgba(cr, r/255.0, g/255.0, b/255.0, a/255.0);
return;
}
@@ -213,11 +226,15 @@
gint r, g, b;
sscanf(spec, "rgb(%d,%d,%d)", &r, &g, &b);
- cairo_set_source_rgb(cr, r/255.0, g/255.0, b/255.0);
+ cairo_set_source_rgba(cr, r/255.0, g/255.0, b/255.0, global_alpha);
return;
}
}
}
+ else if (*spec == '[')
+ {
+ cairo_set_source_rgb(cr, 0, 0, 0);
+ }
}
SeedValue seed_canvas_stroke_rect (SeedContext ctx,
@@ -234,8 +251,14 @@
seed_object_get_property(ctx, this_object,
"strokeStyle"),
exception);
+ gdouble global_alpha =
+ seed_value_to_double(ctx,
+ seed_object_get_property(ctx, this_object,
+ "globalAlpha"),
+ exception);
- seed_canvas_parse_color(cr, stroke_color);
+
+ seed_canvas_parse_color(cr, stroke_color, global_alpha);
g_free(stroke_color);
x = seed_value_to_double(ctx, arguments[0], exception);
@@ -262,8 +285,15 @@
seed_object_get_property(ctx, this_object,
"fillStyle"),
exception);
+ gdouble global_alpha =
+ seed_value_to_double(ctx,
+ seed_object_get_property(ctx, this_object,
+ "globalAlpha"),
+ exception);
+
+
- seed_canvas_parse_color(cr, stroke_color);
+ seed_canvas_parse_color(cr, stroke_color, global_alpha);
g_free(stroke_color);
x = seed_value_to_double(ctx, arguments[0], exception);
@@ -274,6 +304,7 @@
cairo_rectangle(cr, x, y, width, height);
cairo_fill(cr);
+
return seed_make_null(ctx);
}
@@ -352,8 +383,13 @@
seed_object_get_property(ctx, this_object,
"strokeStyle"),
exception);
-
- seed_canvas_parse_color(cr, stroke_color);
+ gdouble global_alpha =
+ seed_value_to_double(ctx,
+ seed_object_get_property(ctx, this_object,
+ "globalAlpha"),
+ exception);
+
+ seed_canvas_parse_color(cr, stroke_color, global_alpha);
g_free(stroke_color);
@@ -390,8 +426,13 @@
seed_object_get_property(ctx, this_object,
"fillStyle"),
exception);
+ gdouble global_alpha =
+ seed_value_to_double(ctx,
+ seed_object_get_property(ctx, this_object,
+ "globalAlpha"),
+ exception);
- seed_canvas_parse_color(cr, stroke_color);
+ seed_canvas_parse_color(cr, stroke_color, global_alpha);
g_free(stroke_color);
Modified: trunk/modules/canvas/test10.js
==============================================================================
--- trunk/modules/canvas/test10.js (original)
+++ trunk/modules/canvas/test10.js Sat Dec 6 03:14:55 2008
@@ -10,7 +10,7 @@
d = new Gtk.DrawingArea();
w.add(d);
-w.resize(150, 150);
+w.resize(300, 150);
w.show_all();
@@ -26,6 +26,18 @@
ctx.fillRect(j*25,i*25,25,25);
}
}
+ ctx.translate(150, 0);
+ for (i=0;i<6;i++){
+ for (j=0;j<6;j++){
+ ctx.strokeStyle = 'rgb(0,' + Math.floor(255-42.5*i) + ',' +
+ Math.floor(255-42.5*j) + ')';
+ ctx.beginPath();
+ ctx.arc(12.5+j*25,12.5+i*25,10,0,Math.PI*2,true);
+ ctx.stroke();
+ }
+ }
+
+
return true;
});
Gtk.main();
Added: trunk/modules/canvas/test11.js
==============================================================================
--- (empty file)
+++ trunk/modules/canvas/test11.js Sat Dec 6 03:14:55 2008
@@ -0,0 +1,49 @@
+#!/usr/local/bin/seed
+Seed.import_namespace("Gdk");
+Seed.import_namespace("Gtk");
+Seed.import_namespace("Canvas");
+
+
+Gtk.init(null, null);
+
+w = new Gtk.Window();
+d = new Gtk.DrawingArea();
+w.add(d);
+
+w.resize(150, 150);
+
+w.show_all();
+
+d.signal.expose_event.connect(function(){
+ var cr = Gdk.cairo_create(d.window);
+ var ctx = new Canvas.CairoCanvas(cr);
+
+
+ // draw background
+ ctx.fillStyle = '#FD0';
+ ctx.fillRect(0,0,75,75);
+ ctx.fillStyle = '#6C0';
+ ctx.fillRect(75,0,75,75);
+ ctx.fillStyle = '#09F';
+ ctx.fillRect(0,75,75,75);
+ ctx.fillStyle = '#F30';
+ ctx.fillRect(75,75,75,75);
+ ctx.fillStyle = '#FFF';
+
+ // set transparency value
+ ctx.globalAlpha = 0.2;
+
+ // Draw semi transparent circles
+ for (i=0;i<7;i++){
+ ctx.beginPath();
+ ctx.arc(75,75,10+10*i,0,Math.PI*2,true);
+ ctx.fill();
+ }
+
+ return true;
+ });
+Gtk.main();
+
+
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]