00001
00002
00003
00004
00005
00006
00007
00008
00009 class amg.GalleryRectangle extends MovieClip {
00010
00011 private var mcRectangle:MovieClip;
00012 private var _iLineWeight:Number;
00013 private var _iLineColor:Number;
00014 private var _iLineAlpha:Number;
00015 private var _iBgColor:Number;
00016 private var _iBgAlpha:Number;
00017
00018
00019
00020
00021 public function GalleryRectangle() {
00022 this.mcRectangle = createEmptyMovieClip("rectangle", this.getNextHighestDepth());
00023 this._iLineWeight = 0;
00024 this._iLineColor = 0x000000;
00025 this._iLineAlpha = 100;
00026 this._iBgColor = 0x7F7F7F;
00027 this._iBgAlpha = 100;
00028 }
00029
00030 public function setColors(lineWeight:Number,lineColor:Number,lineAlpha:Number,bgColor:Number,bgAlpha:Number){
00031 this._iLineWeight = lineWeight;
00032 this._iLineColor = lineColor;
00033 this._iLineAlpha = lineAlpha;
00034 this._iBgColor = bgColor;
00035 this._iBgAlpha = bgAlpha;
00036 }
00037
00038 public function drawRectangle(w,h,cornerRadius){
00039 var x:Number = 0;
00040 var y:Number = 0;
00041
00042 this.mcRectangle.clear();
00043
00044 this.mcRectangle.lineStyle(this._iLineWeight, this._iLineColor, this._iLineAlpha, true, "none", "round", "miter",1);
00045 this.mcRectangle.beginFill(this._iBgColor,this._iBgAlpha);
00046
00047 if (cornerRadius>0) {
00048
00049 var theta, angle, cx, cy, px, py;
00050
00051 if (cornerRadius>Math.min(w, h)/2) {
00052 cornerRadius = Math.min(w, h)/2;
00053 }
00054
00055 theta = Math.PI/4;
00056
00057 this.mcRectangle.moveTo(x+cornerRadius, y);
00058 this.mcRectangle.lineTo(x+w-cornerRadius, y);
00059
00060 angle = -Math.PI/2;
00061
00062 cx = x+w-cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00063 cy = y+cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00064 px = x+w-cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00065 py = y+cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00066 this.mcRectangle.curveTo(cx, cy, px, py);
00067 angle += theta;
00068 cx = x+w-cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00069 cy = y+cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00070 px = x+w-cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00071 py = y+cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00072 this.mcRectangle.curveTo(cx, cy, px, py);
00073
00074 this.mcRectangle.lineTo(x+w, y+h-cornerRadius);
00075
00076 angle += theta;
00077 cx = x+w-cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00078 cy = y+h-cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00079 px = x+w-cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00080 py = y+h-cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00081 this.mcRectangle.curveTo(cx, cy, px, py);
00082 angle += theta;
00083 cx = x+w-cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00084 cy = y+h-cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00085 px = x+w-cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00086 py = y+h-cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00087 this.mcRectangle.curveTo(cx, cy, px, py);
00088
00089 this.mcRectangle.lineTo(x+cornerRadius, y+h);
00090
00091 angle += theta;
00092 cx = x+cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00093 cy = y+h-cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00094 px = x+cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00095 py = y+h-cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00096 this.mcRectangle.curveTo(cx, cy, px, py);
00097 angle += theta;
00098 cx = x+cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00099 cy = y+h-cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00100 px = x+cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00101 py = y+h-cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00102 this.mcRectangle.curveTo(cx, cy, px, py);
00103
00104 this.mcRectangle.lineTo(x, y+cornerRadius);
00105
00106 angle += theta;
00107 cx = x+cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00108 cy = y+cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00109 px = x+cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00110 py = y+cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00111 this.mcRectangle.curveTo(cx, cy, px, py);
00112 angle += theta;
00113 cx = x+cornerRadius+(Math.cos(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00114 cy = y+cornerRadius+(Math.sin(angle+(theta/2))*cornerRadius/Math.cos(theta/2));
00115 px = x+cornerRadius+(Math.cos(angle+theta)*cornerRadius);
00116 py = y+cornerRadius+(Math.sin(angle+theta)*cornerRadius);
00117 this.mcRectangle.curveTo(cx, cy, px, py);
00118 } else {
00119
00120 this.mcRectangle.moveTo(x, y);
00121 this.mcRectangle.lineTo(x+w, y);
00122 this.mcRectangle.lineTo(x+w, y+h);
00123 this.mcRectangle.lineTo(x, y+h);
00124 this.mcRectangle.lineTo(x, y);
00125 }
00126
00127 this.mcRectangle.endFill();
00128
00129 }
00130 }