1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2004-2006 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package haloclassic 13{ 14 15import flash.display.Graphics; 16import mx.skins.Border; 17import mx.styles.StyleManager; 18import mx.utils.ColorUtil; 19 20/** 21 * The skin for all the states of the icon in a RadioButton. 22 */ 23public class RadioButtonIcon extends Border 24{ 25 include "../mx/core/Version.as"; 26 27 //-------------------------------------------------------------------------- 28 // 29 // Class variables 30 // 31 //-------------------------------------------------------------------------- 32 33 /** 34 * @private 35 */ 36 private static var cache:Object = {}; 37 38 //-------------------------------------------------------------------------- 39 // 40 // Class methods 41 // 42 //-------------------------------------------------------------------------- 43 44 /** 45 * @private 46 * Several colors used for drawing are calculated from the base colors 47 * of the component (themeColor, borderColor and fillColors). 48 * Since these calculations can be a bit expensive, 49 * we calculate once per color set and cache the results. 50 */ 51 private static function calcDerivedStyles(themeColor:uint, 52 borderColor:uint, 53 fillColor0:uint, 54 fillColor1:uint):Object 55 { 56 var key:String = HaloColors.getCacheKey(themeColor, borderColor, 57 fillColor0, fillColor1); 58 59 if (!cache[key]) 60 { 61 var o:Object = cache[key] = {}; 62 63 // Cross-component styles 64 HaloColors.addHaloColors(o, themeColor, fillColor0, fillColor1); 65 66 // RadioButton-unique styles 67 o.borderColorDrk1 = ColorUtil.adjustBrightness2(borderColor, -60); 68 } 69 70 return cache[key]; 71 } 72 73 //-------------------------------------------------------------------------- 74 // 75 // Constructor 76 // 77 //-------------------------------------------------------------------------- 78 79 /** 80 * Constructor. 81 */ 82 public function RadioButtonIcon() 83 { 84 super(); 85 } 86 87 //-------------------------------------------------------------------------- 88 // 89 // Overridden properties 90 // 91 //-------------------------------------------------------------------------- 92 93 //---------------------------------- 94 // measuredWidth 95 //---------------------------------- 96 97 /** 98 * @private 99 */ 100 override public function get measuredWidth():Number 101 { 102 return 12; 103 } 104 105 //---------------------------------- 106 // measuredHeight 107 //---------------------------------- 108 109 /** 110 * @private 111 */ 112 override public function get measuredHeight():Number 113 { 114 return 12; 115 } 116 117 //-------------------------------------------------------------------------- 118 // 119 // Overridden methods 120 // 121 //-------------------------------------------------------------------------- 122 123 /** 124 * @private 125 */ 126 override protected function updateDisplayList(w:Number, h:Number):void 127 { 128 super.updateDisplayList(w, h); 129 130 // User-defined styles. 131 var bevel:Boolean = getStyle("bevel"); 132 var borderColor:uint = getStyle("borderColor"); 133 var fillColors:Array = getStyle("fillColors"); 134 StyleManager.getColorNames(fillColors); 135 var themeColor:uint = getStyle("themeColor"); 136 137 // Placeholder styles stub 138 var radioColor:uint = 0x2B333C; // added style prop 139 140 // Derived styles. 141 var derStyles:Object = calcDerivedStyles(themeColor, borderColor, 142 fillColors[0], fillColors[1]); 143 144 var g:Graphics = graphics; 145 146 g.clear(); 147 148 switch (name) 149 { 150 case "upIcon": 151 { 152 if (bevel) 153 { 154 // border 155 drawRoundRect( 156 0, 0, w, h, w / 2, 157 [ borderColor, derStyles.borderColorDrk1 ], 1, 158 verticalGradientMatrix(0, 0, w, h)); 159 160 // bevel highlight 161 drawRoundRect( 162 1, 1, w - 2, h - 2, w / 2 - 1, 163 derStyles.bevelHighlight1, 1); 164 165 // radio fill 166 drawRoundRect( 167 1, 2, w - 2, h - 3, w / 2 - 1, 168 [ fillColors[0], fillColors[1] ], 1, 169 verticalGradientMatrix(0, 0, w - 2, h - 2)); 170 } 171 else 172 { 173 // border 174 drawRoundRect( 175 0, 0, w, h, w / 2, 176 borderColor,1); 177 178 // radio fill 179 drawRoundRect( 180 1, 1, w - 2, h - 2, w / 2, 181 [ fillColors[0], fillColors[1] ], 1, 182 verticalGradientMatrix(0, 0, w - 2, h - 2)); 183 } 184 break; 185 } 186 187 case "overIcon": 188 { 189 if (bevel) 190 { 191 // border 192 drawRoundRect( 193 0, 0, w, h, w / 2, 194 [ derStyles.themeColDrk2, derStyles.themeColDrk1 ], 1, 195 verticalGradientMatrix(0, 0, w, h / 2)); 196 197 // bevel highlight 198 drawRoundRect( 199 1, 1, w - 2, h - 2, w / 2 - 1, 200 derStyles.bevelHighlight1, 1); 201 202 // radio fill 203 drawRoundRect( 204 1, 2, w - 2, h - 3, w / 2 - 1, 205 [ derStyles.fillColorBright1, 206 derStyles.fillColorBright2 ], 1, 207 verticalGradientMatrix(0, 0, w - 2, h - 2)); 208 } 209 else 210 { 211 // border 212 drawRoundRect( 213 0, 0, w, h, w / 2, 214 derStyles.themeColDrk2, 1); 215 216 // radio fill 217 drawRoundRect( 218 1, 1, w - 2, h - 2, w / 2, 219 [ derStyles.fillColorBright1, 220 derStyles.fillColorBright2 ], 1, 221 verticalGradientMatrix(0, 0, w - 2, h - 2)); 222 } 223 break; 224 } 225 226 case "downIcon": 227 { 228 if (bevel) 229 { 230 // border 231 drawRoundRect( 232 0, 0, w, h, w / 2, 233 [ derStyles.themeColDrk2, 234 derStyles.themeColDrk1], 1, 235 verticalGradientMatrix(0, 0, w, h / 2)); 236 237 // bevel highlight 238 drawRoundRect( 239 1, 1, w - 2, h - 2, w / 2 - 1, 240 derStyles.bevelHighlight1, 1); 241 242 // radio fill 243 drawRoundRect( 244 1, 2, w - 2, h - 3, w / 2 - 1, 245 [ derStyles.fillColorPress2, 246 derStyles.fillColorPress1 ], 1, 247 verticalGradientMatrix(0, 0, w - 2, h - 2)); 248 } 249 else 250 { 251 // border 252 drawRoundRect( 253 0, 0, w, h, w / 2, 254 derStyles.themeColDrk2, 1); 255 256 // radio fill 257 drawRoundRect( 258 1, 1, w - 2, h - 2, w / 2, 259 [ derStyles.fillColorPress1, 260 derStyles.fillColorPress2 ], 1, 261 verticalGradientMatrix(0, 0, w - 2, h - 2)); 262 } 263 break; 264 } 265 266 case "disabledIcon": 267 { 268 drawRoundRect( 269 0, 0, w, h, w / 2, 270 0x999999, 0.50); 271 272 drawRoundRect( 273 1, 1, w - 2, h - 2, w / 2 - 1, 274 0xFFFFFF, 0.50); 275 276 break; 277 } 278 279 case "selectedUpIcon": 280 case "selectedOverIcon": 281 case "selectedDownIcon": 282 { 283 if (bevel) 284 { 285 // border 286 drawRoundRect( 287 0, 0, w, h, w / 2, 288 [ borderColor, 289 derStyles.borderColorDrk1 ], 1, 290 verticalGradientMatrix(0, 0, w, h)); 291 292 // bevel highlight 293 drawRoundRect( 294 1, 1, w - 2, h - 2, w / 2 - 1, 295 derStyles.bevelHighlight1, 1); 296 297 // radio fill 298 drawRoundRect( 299 1, 2, w - 2, h - 3, w / 2 - 1, 300 [ fillColors[0], fillColors[1] ], 1, 301 verticalGradientMatrix(0, 0, w - 2, h - 2)); 302 } 303 else 304 { 305 // border 306 drawRoundRect( 307 0, 0, w, h, w / 2, 308 borderColor, 1); 309 310 // radio fill 311 drawRoundRect( 312 1, 1, w - 2, h - 2, w / 2, 313 [ fillColors[0], fillColors[1] ], 1); 314 } 315 316 // radio symbol 317 drawRoundRect( 318 3, 3, w - 6, h - 6, 3, 319 0xFFFFFF, 0.25); 320 drawRoundRect( 321 4, 4, w - 8, h - 8, 2, 322 radioColor, 1); 323 324 break; 325 } 326 327 case "selectedDisabledIcon": 328 { 329 drawRoundRect( 330 0, 0, w, h, w/2, 331 0x999999, 0.50); 332 333 drawRoundRect( 334 1, 1, w - 2, h - 2, w / 2 - 1, 335 0xFFFFFF, 0.50); 336 337 drawRoundRect( 338 4, 4, w - 8, h - 8, 2, 339 0x999999, 1); 340 341 break; 342 } 343 } 344 } 345 346} 347 348} 349