1
8
9 import com.sekati.geom.Point;
10
11
14 class com.sekati.draw.RoundRectangle {
15
16
32 public static function draw(mc:MovieClip, topLeft:Point, bottomRight:Point, cornerRadius:Number, fillColor:Number, fillAlpha:Number, strokeWeight:Number, strokeColor:Number, strokeAlpha:Number):Void {
33 var sw:Number = (!strokeWeight) ? undefined : strokeWeight;
34 var sc:Number = (isNaN( strokeColor )) ? 0x000000 : strokeColor;
35 var sa:Number = (isNaN( strokeAlpha )) ? 100 : strokeAlpha;
36 var fa:Number = (isNaN( fillAlpha )) ? 100 : fillAlpha;
37
38 var x:Number = topLeft.x;
39 var y:Number = topLeft.y;
40 var w:Number = bottomRight.x - topLeft.x;
41 var h:Number = bottomRight.y - topLeft.y;
42
43 var theta:Number = Math.PI / 4;
44
45 var angle:Number = -Math.PI / 2;
46
47
48
49 cornerRadius = (cornerRadius > Math.min( w, h ) / 2) ? cornerRadius = Math.min( w, h ) / 2 : cornerRadius;
50
51 mc.clear( );
52 mc.lineStyle( sw, sc, sa, true, "none", "round", "round", 8 );
53 if (!isNaN( fillColor )) {
54 mc.beginFill( fillColor, fa );
55 }
56
57
58 mc.moveTo( x + cornerRadius, y );
59 mc.lineTo( x + w - cornerRadius, y );
60
61 for(var i:Number = 0; i < 8 ; i++) {
62 var calcul:Number, cx:Number, cy:Number, px:Number, py:Number;
63
64 calcul = Math.cos( angle + (theta / 2) ) * cornerRadius / Math.cos( theta / 2 );
65 cx = (i == 0 || i == 1 || i == 2 || i == 3) ? x + w - cornerRadius + calcul : x + cornerRadius + calcul;
66
67 calcul = Math.sin( angle + (theta / 2) ) * cornerRadius / Math.cos( theta / 2 );
68 cy = (i == 0 || i == 1 || i == 6 || i == 7) ? y + cornerRadius + calcul : y + h - cornerRadius + calcul;
69
70 calcul = Math.cos( angle + theta ) * cornerRadius;
71 px = (i == 0 || i == 1 || i == 2 || i == 3) ? x + w - cornerRadius + calcul : x + cornerRadius + calcul;
72
73 calcul = Math.sin( angle + theta ) * cornerRadius;
74 py = (i == 0 || i == 1 || i == 6 || i == 7) ? y + cornerRadius + calcul : y + h - cornerRadius + calcul;
75
76 mc.curveTo( cx, cy, px, py );
77
78
79 if(i == 1) mc.lineTo( x + w, y + h - cornerRadius );
80 if(i == 3) mc.lineTo( x + cornerRadius, y + h );
81 if(i == 5) mc.lineTo( x, y + cornerRadius );
82
83 angle += theta;
84 }
85 if (!isNaN( fillColor )) {
86 mc.endFill( );
87 }
88 }
89
90 private function RoundRectangle() {
91 }
92 }