/* GradientAndSafePallette v2 © 2002 - 2004, Ivan Dembicki, dembicki@narod.ru class have only 3 properties: _safe, _gradient - inverse properties; Boolean; indicates type of palette. _color - read-only property; returns Number value color using mouse position. If MousePosis */ class com.sharedfonts.GradientAndSafePallette extends MovieClip { private var highlighter_mc:MovieClip; private var line_colors:Array = [0, 0x333333, 0x666666, 0x999999, 0xCCCCCC, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF]; private var rgb_colors:Array = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0xFF0000]; private var rgb_alphas:Array = [100, 100, 100, 100, 100, 100, 100]; private var rgb_ratios:Array = [255/6*0, 255/6*1, 255/6*2, 255/6*3, 255/6*4, 255/6*5, 255/6*6]; private var wb_colors:Array = [0xFFFFFF, 0xFFFFFF, 0, 0]; private var wb_alphas:Array = [100, 0, 0, 100]; private var wb_ratios:Array = [0, 255/2, 255/2, 255]; // GradientAndSafePallette function GradientAndSafePallette() { this._safe = Boolean(this._safe); } // PROPERTIES // _safe function get _safe():Boolean { return Boolean(this.highlighter_mc); } function set _safe(val:Boolean) { var w = this._width || 210, h = this._height || 120; Boolean(val) ? this.buildSafePalette() : this.buildGradientPalette(); this._width=w, this._height=h; } // _gradient function get _gradient():Boolean { return !this._safe; } function set _gradient(val:Boolean) { if (this._safe == Boolean(val)) { this._safe = !val; } } // _color function get _color():Number { var xm = this._xmouse*this._xscale/100, ym = this._ymouse*this._yscale/100; if (xm<0 || xm>this._width || ym<0 || ym>this._height) { return null; } if (this._safe) { var x = Math.round((this._xmouse-5)/10), y = Math.round((this._ymouse-5)/10); if (x == 0) { return line_colors[y]; } else if (x == 20 || x == 1) { return 0; } else { y<6 ? x -= 2 : (x += 16, y -= 6); return (Math.floor(x/6)*51) << 16 | (x%6*51) << 8 | y*51; } } else { var r, g, b, x = this._xmouse*(6/255), x_up = x-Math.floor(x); x<1 ? (r=255, g=255*x_up, b=0) : x<2 ? (r=255*(1-x_up), g=255, b=0) : x<3 ? (r=0, g=255, b=255*x_up) : x<4 ? (r=0, g=255*(1-x_up), b=255) : x<5 ? (r=255*x_up, g=0, b=255) : x<6 ? (r=255, g=0, b=255*(1-x_up)) : ""; var y = (-this._ymouse+255/2)/255*2; y>0 ? (r += (255-r)*y, g += (255-g)*y, b += (255-b)*y) : y<0 ? (r += r*y, g += g*y, b += b*y) : ""; return (r << 16 | g << 8 | b); } } // BUILD METHODS // safe palette private function buildSafePalette() { var mc = this.createEmptyMovieClip("highlighter_mc", 0); mc.lineStyle(0, 0xFFFFFF, 100), mc.lineTo(10, 0), mc.lineTo(10, 10), mc.lineTo(0, 10), mc.lineTo(0, 0), this.lineStyle(0, 0, 100); var pp = this; mc.onMouseMove = function() { this._x=0, this._y=0; var xm = pp._xmouse, ym = pp._ymouse; if (xm<0 || xm>209.9 || ym<0 || ym>119.9) { return this._visible=false; } this._visible=true, this._x=Math.round((pp._xmouse-5)/10)*10, this._y=Math.round((pp._ymouse-5)/10)*10, updateAfterEvent(); }; this.clear(), this.lineStyle(0, 0, 100); var x = 0, y = 0, i, j, d = 20; for (i=0; i<12; i++) { y = i*10; this.beginFill(line_colors[i]), this.moveTo(0, y), this.lineTo(10, y), this.lineTo(10, y+10), this.lineTo(0, y+10), this.lineTo(x, y), this.endFill(); } this.beginFill(0), this.moveTo(10, 0), this.lineTo(20, 0), this.lineTo(20, 120), this.lineTo(10, 120), this.lineTo(10, 0), this.endFill(); for (i=0; i<12; i++) { for (var j = 0; j<18; j++) { i>5 ? (x=j+18, y=i-6) : (x=j, y=i); this.beginFill((Math.floor(x/6)*51) << 16 | (x%6*51) << 8 | y*51); x=j*10, y=i*10; this.moveTo(x+d, y), this.lineTo(x+d+10, y), this.lineTo(x+d+10, y+10), this.lineTo(x+d, y+10), this.lineTo(x+d, y), this.endFill(); } } this.beginFill(0), this.moveTo(200, 0), this.lineTo(210, 0), this.lineTo(210, 120), this.lineTo(200, 120), this.lineTo(200, 0), this.endFill(); } // gradient palette private function buildGradientPalette() { this.clear(), this.highlighter_mc.removeMovieClip(); this.beginGradientFill("linear", rgb_colors, rgb_alphas, rgb_ratios, {matrixType:"box", x:0, y:0, w:255, h:255/2, r:0}); this.moveTo(0, 0), this.lineTo(0, 255), this.lineTo(255, 255), this.lineTo(255, 0), this.lineTo(0, 0), this.endFill(); this.beginGradientFill("linear", wb_colors, wb_alphas, wb_ratios, {matrixType:"box", x:0, y:0, w:255, h:255, r:90*Math.PI/180}); this.moveTo(0, 0), this.lineTo(0, 255), this.lineTo(255, 255), this.lineTo(255, 0), this.lineTo(0, 0), this.endFill(); } }