1
/* This notice must be untouched at all times.
4
The latest version is available at
5
http://www.openjacob.org
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
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.
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.
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
29
* @class A Connection is the line between two {@link draw2d.Port}s.
32
* @author Andreas Herz
35
draw2d.Graphics=function(/*:jsGraphics*/ jsGraphics, /*:float*/ rotation, /*:draw2d.Point*/translation)
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);
45
draw2d.Graphics.prototype.setStroke=function(/*:int*/ x)
47
this.jsGraphics.setStroke(x);
50
draw2d.Graphics.prototype.drawLine=function(/*:int*/ x1, /*:int*/ y1, /*:int*/ x2, /*:int*/ y2)
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;
57
this.jsGraphics.drawLine(_x1,_y1,_x2,_y2);
60
draw2d.Graphics.prototype.fillRect=function(/*:int*/ x, /*:int*/ y, /*:int*/ w, /*:int*/ h)
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;
80
this.jsGraphics.fillPolygon([x1,x2,x3,x4], [y1,y2,y3,y4]);
84
draw2d.Graphics.prototype.fillPolygon=function(/*:int[]*/ xArray, /*:int[]*/ yArray)
86
var rotX = new Array();
87
var rotY = new Array();
89
// Rotate the points and translate them to the [this.startX, this.startY] position
91
for(var i= 0;i<xArray.length;i++)
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;
97
this.jsGraphics.fillPolygon(rotX, rotY);
100
draw2d.Graphics.prototype.setColor=function(/*:draw2d.Color*/ color)
102
this.jsGraphics.setColor(color.getHTMLStyle());
107
draw2d.Graphics.prototype.drawPolygon=function(/*:int[]*/ xArray, /*:int[]*/ yArray)
109
var rotX = new Array();
110
var rotY = new Array();
112
// Rotate the points and translate them to the [this.startX, this.startY] position
114
for(var i= 0;i<xArray.length;i++)
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;
120
this.jsGraphics.drawPolygon(rotX, rotY);