seed r400 - trunk/modules/canvas
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r400 - trunk/modules/canvas
- Date: Sat, 6 Dec 2008 03:27:01 +0000 (UTC)
Author: racarr
Date: Sat Dec 6 03:27:01 2008
New Revision: 400
URL: http://svn.gnome.org/viewvc/seed?rev=400&view=rev
Log:
Seed-canvas module. Add lineWidth and a test. refactor some code out in to seed_canvas_stroke_setup.
Added:
trunk/modules/canvas/test13.js (contents, props changed)
Modified:
trunk/modules/canvas/Makefile.am
trunk/modules/canvas/seed-canvas.c
Modified: trunk/modules/canvas/Makefile.am
==============================================================================
--- trunk/modules/canvas/Makefile.am (original)
+++ trunk/modules/canvas/Makefile.am Sat Dec 6 03:27:01 2008
@@ -4,10 +4,10 @@
libcanvas_la_SOURCES = \
seed-canvas.c
-libsqlite_la_LDFLAGS = \
+libcanvas_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 test10.js test11.js test12.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 test12.js test13.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:27:01 2008
@@ -38,6 +38,84 @@
return obj;
}
+void seed_canvas_parse_color(cairo_t * cr, gchar * spec, gdouble global_alpha)
+{
+ if (*spec == '#')
+ {
+ guint r=0,g=0,b=0,a=0, found;
+ // Might be libc dependent (the alpha behaviour);
+ 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;
+ }
+ else if (*spec == 'r')
+ {
+ switch(*(spec+3))
+ {
+ case 'a':
+ {
+ gint r, g, b;
+ gfloat a;
+
+ sscanf(spec, "rgba(%d,%d,%d,%f)", &r, &g, &b, &a);
+ cairo_set_source_rgba(cr, r/255.0, g/255.0, b/255.0, a);
+ return;
+ }
+ case '(':
+ {
+ gint r, g, b;
+
+ sscanf(spec, "rgb(%d,%d,%d)", &r, &g, &b);
+ 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);
+ }
+}
+
+
+
+void seed_canvas_stroke_setup(SeedContext ctx,
+ SeedObject this_object,
+ cairo_t * cr,
+ SeedException * exception)
+{
+ gchar * stroke_color =
+ seed_value_to_string(ctx,
+ 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);
+ gdouble line_width =
+ seed_value_to_double(ctx,
+ seed_object_get_property(ctx, this_object,
+ "lineWidth"),
+ exception);
+
+ seed_canvas_parse_color(cr, stroke_color, global_alpha);
+ cairo_set_line_width(cr, line_width);
+ g_free(stroke_color);
+}
+
+
+
SeedValue seed_canvas_save (SeedContext ctx,
SeedObject function,
SeedObject this_object,
@@ -189,54 +267,6 @@
return seed_make_null(ctx);
}
-void seed_canvas_parse_color(cairo_t * cr, gchar * spec, gdouble global_alpha)
-{
- if (*spec == '#')
- {
- guint r=0,g=0,b=0,a=0, found;
- // Might be libc dependent (the alpha behaviour);
- 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;
- }
- else if (*spec == 'r')
- {
- switch(*(spec+3))
- {
- case 'a':
- {
- gint r, g, b;
- gfloat a;
-
- sscanf(spec, "rgba(%d,%d,%d,%f)", &r, &g, &b, &a);
- cairo_set_source_rgba(cr, r/255.0, g/255.0, b/255.0, a);
- return;
- }
- case '(':
- {
- gint r, g, b;
-
- sscanf(spec, "rgb(%d,%d,%d)", &r, &g, &b);
- 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,
SeedObject function,
SeedObject this_object,
@@ -246,20 +276,8 @@
{
GET_CR;
gdouble x, y, width, height;
- gchar * stroke_color =
- seed_value_to_string(ctx,
- 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, global_alpha);
- g_free(stroke_color);
+
+ seed_canvas_stroke_setup(ctx, this_object, cr, exception);
x = seed_value_to_double(ctx, arguments[0], exception);
y = seed_value_to_double(ctx, arguments[1], exception);
@@ -378,22 +396,9 @@
SeedException * exception)
{
GET_CR;
- gchar * stroke_color =
- seed_value_to_string(ctx,
- 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, global_alpha);
- g_free(stroke_color);
+ seed_canvas_stroke_setup(ctx, this_object, cr, exception);
-
cairo_stroke(cr);
return seed_make_null(ctx);
Added: trunk/modules/canvas/test13.js
==============================================================================
--- (empty file)
+++ trunk/modules/canvas/test13.js Sat Dec 6 03:27:01 2008
@@ -0,0 +1,35 @@
+#!/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);
+
+ for (i = 0; i < 10; i++){
+ ctx.lineWidth = 1+i;
+ ctx.beginPath();
+ ctx.moveTo(5+i*14,5);
+ ctx.lineTo(5+i*14,140);
+ ctx.stroke();
+ }
+
+ return true;
+ });
+Gtk.main();
+
+
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]