forked from dnewcome/Donatello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrect.js
45 lines (39 loc) · 1.08 KB
/
rect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Draw a rectangular region to the scene.
*/
Donatello.prototype.rect = function( x, y, w, h, a ) {
return this.pgram( x, y, w, h, null, a );
}
Donatello.Pgram = function( parent, x, y, dx, dy, skew, a ) {
a = Donatello.attrDefaults( a );
var el = Donatello.createElement( x, y, dx, dy, 'div');
var s = a['stroke-width'];
var c = a['stroke'];
var f = a['fill'];
var style = a['stroke-style'];
this.properties = {
x: x, y: y, dx: dy, skew: skew,
'stroke-width': s,
'stroke-style': style,
'stroke': c,
'fill': f
};
parent.dom.appendChild( el );
this.dom = el;
this.attr( a );
}
Donatello.Pgram.prototype = new Donatello( null );
/**
* generalized parallelogram, used by rect.
*/
Donatello.Pgram.prototype.draw = function() {
var el = this.dom;
var skew = this.properties.skew;
el.style.borderWidth = this.properties['stroke-width'] + 'px';
if( skew != null ) {
el.style[ Donatello.getTransform() ] += 'skew(' + skew + 'deg)';
}
}
Donatello.prototype.pgram = function( x, y, dx, dy, skew, a ) {
return new Donatello.Pgram( this, x, y, dx, dy, skew, a );
}