~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/editor/draw2d/Graphics.js

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This notice must be untouched at all times.
 
2
 
 
3
Open-jACOB Draw2D
 
4
The latest version is available at
 
5
http://www.openjacob.org
 
6
 
 
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
 
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
 
9
 
 
10
LICENSE: LGPL
 
11
 
 
12
This library is free software; you can redistribute it and/or
 
13
modify it under the terms of the GNU Lesser General Public
 
14
License (LGPL) as published by the Free Software Foundation; either
 
15
version 2.1 of the License, or (at your option) any later version.
 
16
 
 
17
This library is distributed in the hope that it will be useful,
 
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
Lesser General Public License for more details.
 
21
 
 
22
You should have received a copy of the GNU Lesser General Public
 
23
License along with this library; if not, write to the Free Software
 
24
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
 
25
or see http://www.gnu.org/copyleft/lesser.html
 
26
*/
 
27
 
 
28
/**
 
29
 * @class A Connection is the line between two {@link draw2d.Port}s.
 
30
 *
 
31
 * @version 0.9.14
 
32
 * @author Andreas Herz
 
33
 * @constructor
 
34
 */
 
35
draw2d.Graphics=function(/*:jsGraphics*/ jsGraphics, /*:float*/ rotation, /*:draw2d.Point*/translation)
 
36
{
 
37
   this.jsGraphics = jsGraphics;
 
38
   this.xt= translation.x;
 
39
   this.yt= translation.y;
 
40
   this.radian = rotation*Math.PI/180;
 
41
   this.sinRadian = Math.sin(this.radian);
 
42
   this.cosRadian = Math.cos(this.radian);
 
43
}
 
44
 
 
45
draw2d.Graphics.prototype.setStroke=function(/*:int*/ x)
 
46
{
 
47
   this.jsGraphics.setStroke(x);
 
48
}
 
49
 
 
50
draw2d.Graphics.prototype.drawLine=function(/*:int*/ x1, /*:int*/ y1, /*:int*/ x2, /*:int*/ y2)
 
51
{
 
52
   var _x1 = this.xt+x1*this.cosRadian-y1*this.sinRadian;
 
53
   var _y1 = this.yt+x1*this.sinRadian+y1*this.cosRadian;
 
54
   var _x2 = this.xt+x2*this.cosRadian-y2*this.sinRadian;
 
55
   var _y2 = this.yt+x2*this.sinRadian+y2*this.cosRadian;
 
56
 
 
57
   this.jsGraphics.drawLine(_x1,_y1,_x2,_y2);
 
58
}
 
59
 
 
60
draw2d.Graphics.prototype.fillRect=function(/*:int*/ x, /*:int*/ y, /*:int*/ w, /*:int*/ h)
 
61
{
 
62
   /*
 
63
        x1/y1              x2/y2
 
64
             +-----------+
 
65
             |           | 
 
66
             |           | 
 
67
             +-----------+
 
68
 
 
69
        x4/y4             x3/y3
 
70
   */
 
71
   var x1 = this.xt+x*this.cosRadian-y*this.sinRadian;
 
72
   var y1 = this.yt+x*this.sinRadian+y*this.cosRadian;
 
73
   var x2 = this.xt+(x+w)*this.cosRadian-y*this.sinRadian;
 
74
   var y2 = this.yt+(x+w)*this.sinRadian+y*this.cosRadian;
 
75
   var x3 = this.xt+(x+w)*this.cosRadian-(y+h)*this.sinRadian;
 
76
   var y3 = this.yt+(x+w)*this.sinRadian+(y+h)*this.cosRadian;
 
77
   var x4 = this.xt+x*this.cosRadian-(y+h)*this.sinRadian;
 
78
   var y4 = this.yt+x*this.sinRadian+(y+h)*this.cosRadian;
 
79
 
 
80
   this.jsGraphics.fillPolygon([x1,x2,x3,x4], [y1,y2,y3,y4]);
 
81
}
 
82
 
 
83
 
 
84
draw2d.Graphics.prototype.fillPolygon=function(/*:int[]*/ xArray, /*:int[]*/ yArray)
 
85
{
 
86
  var rotX = new Array();
 
87
  var rotY = new Array();
 
88
 
 
89
  // Rotate the points and translate them to the [this.startX, this.startY] position
 
90
  //
 
91
  for(var i= 0;i<xArray.length;i++)
 
92
  {
 
93
     rotX[i] = this.xt+xArray[i]*this.cosRadian-yArray[i]*this.sinRadian;
 
94
     rotY[i] = this.yt+xArray[i]*this.sinRadian+yArray[i]*this.cosRadian;
 
95
  }
 
96
 
 
97
   this.jsGraphics.fillPolygon(rotX, rotY);
 
98
}
 
99
 
 
100
draw2d.Graphics.prototype.setColor=function(/*:draw2d.Color*/ color)
 
101
{
 
102
  this.jsGraphics.setColor(color.getHTMLStyle());
 
103
}
 
104
 
 
105
 
 
106
 
 
107
draw2d.Graphics.prototype.drawPolygon=function(/*:int[]*/ xArray, /*:int[]*/ yArray)
 
108
{
 
109
  var rotX = new Array();
 
110
  var rotY = new Array();
 
111
 
 
112
  // Rotate the points and translate them to the [this.startX, this.startY] position
 
113
  //
 
114
  for(var i= 0;i<xArray.length;i++)
 
115
  {
 
116
     rotX[i] = this.xt+xArray[i]*this.cosRadian-yArray[i]*this.sinRadian;
 
117
     rotY[i] = this.yt+xArray[i]*this.sinRadian+yArray[i]*this.cosRadian;
 
118
  }
 
119
 
 
120
   this.jsGraphics.drawPolygon(rotX, rotY);
 
121
}
 
122
 
 
123