Wang Wei Gang, April 2005
The colorime and color components I did actually consist of two components. The most basic is a palette component that includes an HSB color ring, and then packages a color button component outside.
The color palette component corresponds to the ColorPicker class. The following is the code:
Import mx.core.uicomponent; import mx.controls.textinput; import mx.controls.label; import Wix. *;
[Iconfile ("ColorPicker.png")] [INSPECTABLIST ("Color", "Visible", "Enabled")] [Event ("Change")] Class Wix.ColorPicker Extends UIComponent {static var version: string = "1.0. 0 "; static var symbolName: String =" ColorPicker "; static var symbolOwner: Object = Object (wix.ColorPicker); var className: String =" ColorPicker "; private static var LABEL_COLOR =" 0x000000 "; private static var TEXTINPUT_COLOR =" 0x000000 "; private static var LABEL_LEFT = 260; private static var TEXTINPUT_LEFT = 280; private static var TEXTINPUT_WIDTH = 40; private static var TEXTINPUT_HEIGHT = 22; private static var LINE_HEIGHT = 28; private static var LINE_TOP = 8; private static var LINE_MARGIN = 8; private var h: Number = 0; private var s: Number = 0; private var b: Number = 0; private var r: Number = 0; private var g: Number = 0; private var B: Number = 0;
Private Var Tray: Movieclip; Private Var: ColorWheel; Private Var Tube: ColorTube; Private Var Wheelmask: MovieClip; Private Var WheelStick: MovieClip; Private Var Tubestick: moviClip;
private var ringPointer: MovieClip; private var trianglePointer: MovieClip; private var labelColorValue: Label; private var txtHue: TextInput; private var txtSaturation: TextInput; private var txtBrightness: TextInput; private var txtRed: TextInput; private var txtGreen: TextInput; private var txtBlue: TextInput; private var listener1: Object; private var listener2: Object; private var _color: Number = 0x000000; [Inspectable (defaultValue = 0x000000, type = "Color")] public function get color (): Number {return _color; } public function set color (newColor: Number) {if (enabled) {_color = ColorMan.toInteger (newColor, 0, 0xFFFFFF); setRGBValue (_color);}} public function enable (b: Boolean) {this.enabled = b Wheel.enabled = B; tXTHUE.Enabled = B; txtSaturation.enabled = B; txtBrightness.enabled = B; txtred.enabled = B; txtgreen.enabled = B; txtblue.enabled = B;} Function init (void): void {super.init ();} function size (void): void {super.size ();} Function DRAW Void): void {super.draw (); public function createmovieClip (LinkageName: String, ID: String, x: Number, y: number): void {var o = createObject (linkagename, id, curdepth ); O._X = X; O._Y = Y; : Void {var o = creteObject (linkagename, id, curdepth ); O._X = x; o_y = y; if (width! = Null && height! = Null) o.setsize (width, height); IF Thetext! = null) o.Text = THETEXT; if (TheColor! =
null) o.setStyle ( "color", theColor); if (theTabIndex = null) o.tabIndex = theTabIndex;} public function createChildren (Void):! Void {super.createChildren (); createMovieClip ( "Tray", "tray ", 0, 0); CreatemovieClip (" ColorWheelmask "," Wheelmask ", 8, line_top; CreateMovieClip (" ColorWheel "," Wheel ", 8, line_top); CreateMovieClip (" Stick "," Wheelstick ", 8 Wheel ._width / 2, 8 wheel._height / 2); CreateMovieClip ("RingPointer", "RingPointer", 0, 0); CreateMovieClip ("ColorTube", "Tube", 220, line_top); CreateMovieClip ("stick", "Tubestick", 221, 0); Tubestick._Width = 20; CreatemovieClip ("Trianglepointer", "Trianglepointer", 241, 0); Wheel.init (RingPointer, Wheelmask); Tube.init (TrianglePointer); CreateComponent ("Label "," labelcolorvalue ", label_left, line_top 2, null, null," hex: #ffffff ", label_color, null;
createComponent ( "Label", "labelHue", LABEL_LEFT, LINE_TOP LINE_HEIGHT 2, null, null, "H:", LABEL_COLOR, null); createComponent ( "Label", "labelSaturation", LABEL_LEFT, LINE_TOP LINE_HEIGHT * 2 2, NULL, NULL, "S:", label_color, null; CreateComponent ("Label", "Labelbrightness", Label_left, line_top line_height * 3 2, NULL, NULL, "B:", Label_Color, NULL; createComponent ( "TextInput", "txtHue", TEXTINPUT_LEFT, LINE_TOP LINE_HEIGHT, TEXTINPUT_WIDTH, TEXTINPUT_HEIGHT, null, TEXTINPUT_COLOR, 1); createComponent ( "TextInput", "txtSaturation", TEXTINPUT_LEFT, LINE_TOP LINE_HEIGHT * 2, TEXTINPUT_WIDTH, TEXTINPUT_HEIGHT, null , TEXTINPUT_COLOR, 2); createComponent ( "TextInput", "txtBrightness", TEXTINPUT_LEFT, LINE_TOP LINE_HEIGHT * 3, TEXTINPUT_WIDTH, TEXTINPUT_HEIGHT, null, TEXTINPUT_COLOR, 3); createComponent ( "Label", "labelRed", LABEL_LEFT, LINE_TOP LINE_HEIGHT * 4 Line_margin 2, null, null, "r:", label_color, null; CreateComponent ("label", "labelgreen", label_left, line_top line_height * 5 line_margin 2, NULL, NULL, "G:", LABEL_COLOR, null); createComponent ( "Label", "labelBlue", LABEL_LEFT, LINE_TOP LINE_HEIGHT * 6 LINE_MARGIN 2, null, null, "B:", LABEL_COLOR, null); createComponent ( "TextInput", "txtRed" , TextInput_left, line_top line_height * 4
LINE_MARGIN, TEXTINPUT_WIDTH, TEXTINPUT_HEIGHT, null, TEXTINPUT_COLOR, 4); createComponent ( "TextInput", "txtGreen", TEXTINPUT_LEFT, LINE_TOP LINE_HEIGHT * 5 LINE_MARGIN, TEXTINPUT_WIDTH, TEXTINPUT_HEIGHT, null, TEXTINPUT_COLOR, 5); createComponent ( "TextInput", "txtBlue", TEXTINPUT_LEFT, LINE_TOP LINE_HEIGHT * 6 LINE_MARGIN, TEXTINPUT_WIDTH, TEXTINPUT_HEIGHT, null, TEXTINPUT_COLOR, 6); listener1 = new Object (); listener1.change = onChangeHSB; txtHue.addEventListener ( "change", listener1); txtSaturation .addEventListener ( "change", listener1); txtBrightness.addEventListener ( "change", listener1); listener2 = new Object (); listener2.change = onChangeRGB; txtRed.addEventListener ( "change", listener2); txtGreen.addEventListener ( " ", listener2); txtBlue.addeventListener (" change ", listener2); Update (true);} public function onchangergb (var p = EventObject.target._parent; if (p.enabled) {var red = PARSEINT (P.TXTRED.TEXT); IF (ISNAN (Red)) Red = 0; var green = parseint (p.txtgreen.text); if (isnan) Green = 0; var blue = parseint (p. TXTBLUE.TEXT); IF (ISNAN (Blue) Blue = 0; P.seRGB (Red, Green, Blue);}} PUBLIC FUNCTION SETRGBVALUE (RGB: Number) {IF (enabled) {var red = RGB >> 16 Var green = (RGB - (Red << 16)) >> 8; var blue = RGB - (Red << 16) - (Green << 8); setRGB (Red, Green, Blue);}} public function SETRGB (Red: Number, Green: Number, Blue: Number): Void {if (enabled) {r = colorman.tointeger (red, 0, 255);
g = colorman.tointeger (Green, 0, 255); B = Colorman.Tointeger (Blue, 0, 255); var HSB = ColorMan.RGB2HSB (R, G, B); h = HSB [0]; s = HSB [1]; b = HSB [2]; UPDATE (TRUE);}} public function onchangehsb (eventObject): void {var p = EventObject.target._parent; if (p.enabled) {var h = parseint (p. TXTHUE.TEXT); IF (ISNAN (H)) h = 0; var s = parseint (p.txtsaturation.text); if (ISNAN (s)) s = 0; var b = parseint (p.txtbrightness.text) ; IF (ISNAN (B)) B = 0; P.SethSB (h, s, b);}} public function setsb (hue: number, sature: Number, Brightness: Number): void {if (enabled) {i (hue! = null) h = colorman.tointeger (hue, 0, 360); if (Saturation! = null) s = colorman.tointeger (Saturation, 0, 100); if (Brightness! = null) B = ColorMan. TOINTEGER (Brightness, 0, 100); var RGB = colorMan.hsb2RGB (h, s, b); r = rgb [0]; g = RGB [1]; b = RGB [2]; Update (TRUE);} } Public function updateHSB (Void): void {if (enabled) {var x0 = Wheel._x wheel._ Width / 2; var y0 = wheit._y whehl._height / 2; h = colorman.getthetabyxy (RingPointer._x - x0, ingpointer._y - y0); if (ringpointer._x == x0) s = math.abs (RingPointer._Y - Y0); ELSE S = (RingPointer._x - x0) / Math.cos (H * Math.pi / 180.0); b = 100 - (TrianglePointer._y - Tube._y - 2) / 2; H = colorman.tointeger (h, 0, 360); s = colorman.tointeger (s - 1, 0, 100); b = colorman.tointeger (b, 0, 100); var rgb = colorman.hsb2RGB (h, S, b); R = RGB [0]; g = RGB [1]; b = RGB [2]; Update (false);
}}} Public function update (NeedMovePointer: Boolean): void {if (enabled) {if (NeedMovePointer) {TrianglePointer._y = Tube._y 2 (100 - b) * 2; var x0 = Wheel._x Wheel. _width / 2; var y0 = wheit._y wheel._x = x0 s * math.cos (h * math.pi / 180); RingPointer._y = Y0 S * Math.sin H * math.pi / 180);} wheelstentick._ropation = h; tubestick._y = trianglepointer._y; wheel.setbrightness (b); tube.paint (h, s); txthue.text = H.toString (); TXTSATURATION.TEXT = S.toString (); txtBrightness.Text = B.TOString (); txtred.text = r.toString (); txtgreen.text = g.toString (); txtblue.text = b.toString (); _COLOR = (r << 16) (g << 8) b; var s = _Color.Tostring (16) .touppercase (); var i, j = 6 - s.LENGTH; for (i = 0; i