1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 /**
  9   These functions are deprecated use SC.Color instead.
 10   @deprecated
 11   @see SC.Color
 12  */
 13 SC.mixin ( /** @scope SC */ {
 14 
 15   /** Returns hex color from hsv value */
 16   convertHsvToHex: function (h, s, v) {
 17     // @if (debug)
 18     SC.Logger.warn("SC.convertHsvToHex is deprecated. Please use SC.Color.hsvToRgb instead.");
 19     // @endif
 20     var rgb = SC.Color.hsvToRgb(h, s, v);
 21     return SC.Color.create({ r: rgb[0], g: rgb[1], b: rgb[2] }).toHex();
 22   },
 23 
 24   /** Returns hsv color from hex value */
 25   convertHexToHsv: function (hex) {
 26     // @if (debug)
 27     SC.Logger.warn("SC.convertHexToHsv is deprecated. Please use SC.Color.rgbToHsv instead.");
 28     // @endif
 29     var color = SC.Color.from(hex);
 30     return color && SC.Color.rgbToHsv(color.r, color.g, color.b);
 31   },
 32 
 33   /** regular expression for parsing color: rgb, hex */
 34   PARSE_COLOR_RGBRE: /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i,
 35   PARSE_COLOR_HEXRE: /^\#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,
 36 
 37   // return an array of r,g,b colour
 38   expandColor: function(color) {
 39     // @if (debug)
 40     SC.Logger.warn("SC.expandColor is deprecated. Please use SC.Color.from instead.");
 41     // @endif
 42     var hexColor, red, green, blue;
 43     hexColor = this.parseColor(color);
 44     if (hexColor) {
 45       red = parseInt(hexColor.slice(1, 3), 16);
 46       green = parseInt(hexColor.slice(3, 5), 16);
 47       blue = parseInt(hexColor.slice(5, 7), 16);
 48       return [red,green,blue];
 49     }
 50   },
 51 
 52   // parse rgb color or 3-digit hex color to return a properly formatted 6-digit hex colour spec, or false
 53   parseColor: function(string) {
 54     // @if (debug)
 55     SC.Logger.warn("SC.expandColor is deprecated. Please use SC.Color.from instead.");
 56     // @endif
 57     var i=0, color = '#', match, part;
 58     if(match = this.PARSE_COLOR_RGBRE.exec(string)) {
 59       for (i=1; i<=3; i++) {
 60         part = Math.max(0, Math.min(255, parseInt(match[i],0)));
 61         color += this.toColorPart(part);
 62       }
 63       return color;
 64     }
 65     if (match = this.PARSE_COLOR_HEXRE.exec(string)) {
 66       if(match[1].length == 3) {
 67         for (i=0; i<3; i++) {
 68           color += match[1].charAt(i) + match[1].charAt(i);
 69         }
 70         return color;
 71       }
 72       return '#' + match[1];
 73     }
 74     return false;
 75   },
 76 
 77   // convert one r,g,b number to a 2 digit hex string
 78   toColorPart: function(number) {
 79     if (number > 255) number = 255;
 80     var digits = number.toString(16);
 81     if (number < 16) return '0' + digits;
 82     return digits;
 83   }
 84 
 85 
 86 });
 87