changeset 738:4f9773574234

Merge
author wycc
date Sat, 21 Aug 2010 19:14:49 +0800
parents 99186cce8cdd (diff) d0ee92a96c47 (current diff)
children 4916c3a3fe3c
files
diffstat 3 files changed, 83 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/canvas.js	Sat Aug 21 19:14:49 2010 +0800
@@ -0,0 +1,57 @@
+var mbfly = require("mbfly");
+var sys=require("sys");
+
+
+function canvas(app,root) {
+    this.mb_rt = app.mb_rt;
+    this.root = this.mb_rt.coord_new(root);
+	this.bg_r = 0;
+	this.bg_g = 0;
+	this.bg_b = 0;
+	this.bg_a = 0;
+	this.stroke_r = 0;
+	this.stroke_g = 0;
+	this.stroke_b = 0;
+	this.stroke_a = 0;
+	this.stroke_w = 1;
+}
+
+canvas.prototype.background=function(r,g,b,a) {
+    this.bg_r = r;
+	this.bg_g = g;
+	this.bg_b = b;
+	this.bg_a = a;
+}
+
+canvas.prototype.rect=function(x,y,w,h) {
+    var rect = this.mb_rt.rect_new(x,y,w,h,0,0);
+    var paint = this.mb_rt.paint_color_new(this.bg_r,this.bg_g,this.bg_b,this.bg_a);
+	paint.fill(rect);
+	this.root.add_shape(rect);
+}
+
+canvas.prototype.stroke=function(r,g,b,a) {
+    this.stroke_r = r;
+    this.stroke_g = g;
+    this.stroke_b = b;
+    this.stroke_a = a;
+}
+
+
+canvas.prototype.line=function(x1,y1,x2,y2) {
+    var s = "M "+x1+","+y1+" L "+x2+","+y2;
+	sys.puts(s);
+
+    var p = this.mb_rt.path_new(s);
+	this.root.add_shape(p);
+	var paint = this.mb_rt.paint_color_new(this.stroke_r,this.stroke_g,this.stroke_b,this.stroke_a);
+	paint.stroke(p);
+	p.stroke_width = this.stroke_w;
+}
+
+canvas.prototype.strokeWeight=function(w) {
+    this.stroke_w = w;
+}
+
+
+exports.canvas = canvas;
--- a/nodejs/test.svg	Fri Aug 20 09:34:49 2010 +0800
+++ b/nodejs/test.svg	Sat Aug 21 19:14:49 2010 +0800
@@ -33,7 +33,7 @@
      inkscape:cx="267.0313"
      inkscape:cy="228.90269"
      inkscape:document-units="px"
-     inkscape:current-layer="layer4"
+     inkscape:current-layer="layer1"
      showgrid="false"
      inkscape:window-width="1347"
      inkscape:window-height="894"
@@ -267,7 +267,7 @@
        x="24.177626"
        style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
        xml:space="preserve"><tspan
-         mbname="item1text"
+         mbname="title"
          y="44.383541"
          x="24.177626"
          id="tspan2418"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/testcanvas.js	Sat Aug 21 19:14:49 2010 +0800
@@ -0,0 +1,24 @@
+var mbapp = require("./mbapp");
+var sys=require("sys");
+var canvas=require("./canvas");
+
+app = new mbapp.app();
+
+app.canvas = new canvas.canvas(app,app.mb_rt.root);
+
+app.canvas.background(0,0,0,1);
+app.canvas.rect(0,0,400,400);
+app.canvas.strokeWeight(8);
+width=200;
+height=200;
+for(i=0;i<width;i++) {
+    x = Math.random()*255;
+	y = Math.random()*200;
+	cr = Math.random()
+	cg = Math.random()
+	cb = Math.random()
+	app.canvas.stroke(cr,cg,cb,1);
+	app.canvas.line(i,0,x,height);
+}
+
+app.loop();