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 CheckBox. 22 */ 23public class CheckBoxIcon 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 // CheckBox-specific 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 CheckBoxIcon() 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 checkColor:uint = 0x2B333C;// added style prop 139 140 // Derived styles 141 var derStyles:Object = calcDerivedStyles(themeColor, borderColor, 142 fillColors[0], fillColors[1]); 143 144 var bDrawCheck:Boolean = false; 145 146 var g:Graphics = graphics; 147 148 g.clear(); 149 150 switch (name) 151 { 152 //-------------------------- 153 // checkbox false 154 //-------------------------- 155 156 case "upIcon": 157 { 158 // border 159 drawRoundRect( 160 0, 0, w, h, 0, 161 borderColor, 1); 162 163 if (bevel) 164 { 165 // bottom right bevel edge 166 drawRoundRect( 167 1, 1, w - 1, h - 1, 0, 168 derStyles.borderColorDrk1, 1); 169 170 // bevel highlight 171 drawRoundRect( 172 1, 1, w - 2, 1, 0, 173 derStyles.bevelHighlight1, 1); 174 175 // box fill 176 drawRoundRect( 177 1, 2, w - 2, h - 3, 0, 178 [ fillColors[0], fillColors[1] ], 1, 179 verticalGradientMatrix(0, 0, w - 4, h - 4)); 180 } 181 else 182 { 183 // box fill 184 drawRoundRect( 185 1, 1, w - 2, h - 2, 0, 186 [ fillColors[0], fillColors[1] ], 1, 187 verticalGradientMatrix(0, 0, w - 4, h - 4)); 188 } 189 break; 190 } 191 192 case "overIcon": 193 { 194 // border 195 drawRoundRect( 196 0, 0, w, h, 0, 197 derStyles.themeColDrk2, 1); 198 199 if (bevel) 200 { 201 // bottom right bevel edge 202 drawRoundRect( 203 1, 1, w - 1, h - 1, 0, 204 derStyles.themeColDrk1, 1); 205 206 // bevel highlight 207 drawRoundRect( 208 1, 1, w - 2, 1, 0, 209 derStyles.themeColLgt, 1); 210 211 // box fill 212 drawRoundRect( 213 1, 2, w - 2, h - 3, 0, 214 [ derStyles.fillColorBright1, 215 derStyles.fillColorBright2 ], 1, 216 verticalGradientMatrix(0, 0, w - 4, h -4)); 217 } 218 else 219 { 220 // box fill 221 drawRoundRect( 222 1, 1, w - 2, h - 2, 0, 223 [ derStyles.fillColorBright1, 224 derStyles.fillColorBright2 ], 1, 225 verticalGradientMatrix(0, 0, w - 4, h - 4)); 226 } 227 break; 228 } 229 230 case "downIcon": 231 { 232 // border 233 drawRoundRect( 234 0, 0, w, h, 0, 235 derStyles.themeColDrk2, 1); 236 237 if (bevel) 238 { 239 // bottom right bevel edge 240 drawRoundRect( 241 1, 1, w - 1, h - 1, 0, 242 derStyles.themeColDrk1, 1); 243 } 244 245 // box fill 246 drawRoundRect( 247 1, 1, w - 2, h - 2, 0, 248 [ derStyles.fillColorPress2, 249 derStyles.fillColorPress1 ], 1, 250 verticalGradientMatrix(0, 0, w - 4, h - 4)); 251 252 break; 253 } 254 255 case "disabledIcon": 256 { 257 drawRoundRect( 258 0, 0, w, h, 0, 259 0x999999, 0.50); 260 261 drawRoundRect( 262 1, 1, w - 2, h - 2, 0, 263 0xFFFFFF, 0.50); 264 265 break; 266 } 267 268 //-------------------------- 269 // checkbox true 270 //-------------------------- 271 272 case "selectedUpIcon": 273 { 274 bDrawCheck = true; 275 276 // border 277 drawRoundRect( 278 0, 0, w, h, 0, 279 borderColor, 1); 280 281 if (bevel) 282 { 283 // bottom right bevel edge 284 drawRoundRect( 285 1, 1, w - 1, h - 1, 0, 286 derStyles.borderColorDrk1, 1); 287 288 // bevel highlight 289 drawRoundRect( 290 1, 1, w - 2, 1, 0, 291 derStyles.bevelHighlight1, 1); 292 293 // box fill 294 drawRoundRect( 295 1, 2, w - 2, h - 3, 0, 296 [ fillColors[0], fillColors[1]], 1, 297 verticalGradientMatrix(0, 0, w - 4, h - 4)); 298 } 299 else 300 { 301 // box fill 302 drawRoundRect( 303 1, 1, w - 2, h - 2, 0, 304 [ fillColors[0], fillColors[1] ], 1, 305 verticalGradientMatrix(0, 0, w - 4, h - 4)); 306 } 307 break; 308 } 309 310 case "selectedOverIcon": 311 { 312 bDrawCheck = true; 313 314 // border 315 drawRoundRect( 316 0, 0, w, h, 0, 317 derStyles.themeColDrk2, 1); 318 319 if (bevel) 320 { 321 // bottom bevel right edge 322 drawRoundRect( 323 1, 1, w - 1, h - 1, 0, 324 derStyles.themeColDrk1, 1); 325 326 // bevel highlight 327 drawRoundRect( 328 1, 1, w - 2, 1, 0, 329 derStyles.themeColLgt, 1); 330 331 // box fill 332 drawRoundRect( 333 1, 2, w - 2, h - 3, 0, 334 [ derStyles.fillColorBright1, 335 derStyles.fillColorBright2 ], 1, 336 verticalGradientMatrix(0, 0, w - 4, h - 4)); 337 } 338 else 339 { 340 // box fill 341 drawRoundRect( 342 1, 1, w - 2, h - 2, 0, 343 [ derStyles.fillColorBright1, 344 derStyles.fillColorBright2 ], 1, 345 verticalGradientMatrix(0, 0, w - 4, h - 4)); 346 } 347 break; 348 } 349 350 case "selectedDownIcon": 351 { 352 bDrawCheck = true; 353 354 // border 355 drawRoundRect( 356 0, 0, w, h, 0, 357 derStyles.themeColDrk2, 1); 358 359 if (bevel) 360 { 361 // bottom right bevel edge 362 drawRoundRect( 363 1, 1, w - 1, h - 1, 0, 364 derStyles.themeColDrk1, 1); 365 } 366 367 // box fill 368 drawRoundRect( 369 1, 1, w - 2, h - 2, 0, 370 [ derStyles.fillColorPress2, 371 derStyles.fillColorPress1 ], 1, 372 verticalGradientMatrix(0, 0, w - 4, h - 4)); 373 374 break; 375 } 376 377 case "selectedDisabledIcon": 378 { 379 bDrawCheck = true; 380 checkColor = 0x999999; 381 382 drawRoundRect( 383 0, 0, w, h, 0, 384 0x999999, 0.50); 385 386 drawRoundRect( 387 1, 1, w - 2, h - 2, 0, 388 0xFFFFFF, 0.50); 389 390 break; 391 } 392 } 393 394 // Draw checkmark symbol 395 if (bDrawCheck) 396 { 397 g.beginFill(checkColor); 398 g.moveTo(3, 4); 399 g.lineTo(5, 9); 400 g.lineTo(7, 9); 401 g.lineTo(12, 1); 402 g.lineTo(12, 0); 403 g.lineTo(10, 0); 404 g.lineTo(6, 7); 405 g.lineTo(5, 4); 406 g.lineTo(3, 4); 407 g.endFill(); 408 } 409 } 410} 411 412} 413