Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_g_color_8j_source.html

Full commit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_g_color_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:42 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: AppKit/CoreGraphics/CGColor.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>AppKit/CoreGraphics/CGColor.j</h1><a href="_c_g_color_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CGColor.j</span>
<a name="l00003"></a>00003 <span class="comment"> * AppKit</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2008, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="comment">//import &quot;CGPattern.j&quot;</span>
<a name="l00024"></a>00024 @<span class="keyword">import</span> <span class="stringliteral">&quot;CGColorSpace.j&quot;</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="comment">// FIXME: Move this to Objective-J.js!!!</span>
<a name="l00028"></a><a class="code" href="_c_g_color_8j.html#af2db0ac8cf6c892a2889aa61d0f75753">00028</a> var <a class="code" href="_c_g_color_8j.html#af2db0ac8cf6c892a2889aa61d0f75753">CFTypeGlobalCount</a> = 0;
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="_c_g_color_8j.html#a71413947474ba53dba0e397a1b99d495">00030</a> function <a class="code" href="_c_g_color_8j.html#a71413947474ba53dba0e397a1b99d495">CFHashCode</a>(aCFObject)
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032     <span class="keywordflow">if</span> (!aCFObject.hash)
<a name="l00033"></a>00033         aCFObject.hash = ++<a class="code" href="_c_g_color_8j.html#af2db0ac8cf6c892a2889aa61d0f75753">CFTypeGlobalCount</a>;
<a name="l00034"></a>00034         
<a name="l00035"></a>00035     <span class="keywordflow">return</span> aCFObject;
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 
<a name="l00038"></a><a class="code" href="_c_g_color_8j.html#a001f642826bcf82291c7958917492d39">00038</a> <a class="code" href="_c_g_color_8j.html#a001f642826bcf82291c7958917492d39">kCGColorWhite</a>   = <span class="stringliteral">&quot;kCGColorWhite&quot;</span>;
<a name="l00039"></a><a class="code" href="_c_g_color_8j.html#aef014c6bf09002137feea26ee9855462">00039</a> <a class="code" href="_c_g_color_8j.html#aef014c6bf09002137feea26ee9855462">kCGColorBlack</a>   = <span class="stringliteral">&quot;kCGColorBlack&quot;</span>;
<a name="l00040"></a><a class="code" href="_c_g_color_8j.html#abad85cd72cee23fd405e1adf23712911">00040</a> <a class="code" href="_c_g_color_8j.html#abad85cd72cee23fd405e1adf23712911">kCGColorClear</a>   = <span class="stringliteral">&quot;kCGColorClear&quot;</span>;
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 var _CGColorMap = { };
<a name="l00043"></a>00043 
<a name="l00044"></a><a class="code" href="_c_g_color_8j.html#ac68b08c4398af8e3f6f930a881e07e4f">00044</a> function <a class="code" href="_c_g_color_8j.html#ac68b08c4398af8e3f6f930a881e07e4f">CGColorGetConstantColor</a>(aColorName)
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046     alert(<span class="stringliteral">&quot;FIX ME&quot;</span>);
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 
<a name="l00052"></a><a class="code" href="_c_g_color_8j.html#a2472001c3e22caf783ecada5930231d2">00052</a> function <a class="code" href="_c_g_color_8j.html#a2472001c3e22caf783ecada5930231d2">CGColorRetain</a>(aColor)
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054     <span class="keywordflow">return</span> aColor;
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 
<a name="l00060"></a><a class="code" href="_c_g_color_8j.html#a86109ca29da45a145374dd4b2060c7e2">00060</a> function <a class="code" href="_c_g_color_8j.html#a86109ca29da45a145374dd4b2060c7e2">CGColorRelease</a>()
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063 
<a name="l00071"></a><a class="code" href="_c_g_color_8j.html#af5e4c5b7c77b5b905e33ac78919055e6">00071</a> function <a class="code" href="_c_g_color_8j.html#af5e4c5b7c77b5b905e33ac78919055e6">CGColorCreate</a>(aColorSpace, components)
<a name="l00072"></a>00072 {
<a name="l00073"></a>00073     <span class="keywordflow">if</span> (!aColorSpace || !components)
<a name="l00074"></a>00074         <span class="keywordflow">return</span> NULL;
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     var components = components.slice();
<a name="l00077"></a>00077     
<a name="l00078"></a>00078     <a class="code" href="_c_g_color_space_8j.html#ab068206608a9ff34736370347cc44f34">CGColorSpaceStandardizeComponents</a>(aColorSpace, components);
<a name="l00079"></a>00079     
<a name="l00080"></a>00080     var UID = <a class="code" href="_c_g_color_8j.html#a71413947474ba53dba0e397a1b99d495">CFHashCode</a>(aColorSpace) + components.join(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00081"></a>00081     
<a name="l00082"></a>00082     <span class="keywordflow">if</span> (_CGColorMap[UID])
<a name="l00083"></a>00083         <span class="keywordflow">return</span> _CGColorMap[UID];
<a name="l00084"></a>00084     
<a name="l00085"></a>00085     <span class="keywordflow">return</span> _CGColorMap[UID] = { colorspace:aColorSpace, pattern:NULL, components:components };
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 
<a name="l00096"></a><a class="code" href="_c_g_color_8j.html#a4c8841b109648695bb7c0370287badc1">00096</a> function <a class="code" href="_c_g_color_8j.html#a4c8841b109648695bb7c0370287badc1">CGColorCreateCopy</a>(aColor)
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098     <span class="comment">// Colors should be treated as immutable, so don&apos;t mutate it!</span>
<a name="l00099"></a>00099     <span class="keywordflow">return</span> aColor;
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 
<a name="l00109"></a><a class="code" href="_c_g_color_8j.html#aa0ac3308c0d92fe178f086898faa76fe">00109</a> function <a class="code" href="_c_g_color_8j.html#aa0ac3308c0d92fe178f086898faa76fe">CGColorCreateGenericGray</a>(gray, alpha)
<a name="l00110"></a>00110 {
<a name="l00111"></a>00111     <span class="keywordflow">return</span> <a class="code" href="_c_g_color_8j.html#af5e4c5b7c77b5b905e33ac78919055e6">CGColorCreate</a>(0, [gray, alpha]);
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 
<a name="l00123"></a><a class="code" href="_c_g_color_8j.html#a2104701c6fe6b6ce377af75bd596a712">00123</a> function <a class="code" href="_c_g_color_8j.html#a2104701c6fe6b6ce377af75bd596a712">CGColorCreateGenericRGB</a>(red, green, blue, alpha)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125     <span class="keywordflow">return</span> <a class="code" href="_c_g_color_8j.html#af5e4c5b7c77b5b905e33ac78919055e6">CGColorCreate</a>(0, [red, green, blue, alpha]);
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 
<a name="l00138"></a><a class="code" href="_c_g_color_8j.html#a3fa56c7529c0408b2f3b13816b310091">00138</a> function <a class="code" href="_c_g_color_8j.html#a3fa56c7529c0408b2f3b13816b310091">CGColorCreateGenericCMYK</a>(cyan, magenta, yellow, black, alpha)
<a name="l00139"></a>00139 {
<a name="l00140"></a>00140     <span class="keywordflow">return</span> <a class="code" href="_c_g_color_8j.html#af5e4c5b7c77b5b905e33ac78919055e6">CGColorCreate</a>(0, [cyan, magenta, yellow, black, alpha]);
<a name="l00141"></a>00141 }
<a name="l00142"></a>00142 
<a name="l00150"></a><a class="code" href="_c_g_color_8j.html#abf31af54f73f9d7cb39642afd20f3b59">00150</a> function <a class="code" href="_c_g_color_8j.html#abf31af54f73f9d7cb39642afd20f3b59">CGColorCreateCopyWithAlpha</a>(aColor, anAlpha)
<a name="l00151"></a>00151 {
<a name="l00152"></a>00152     var components = aColor.components;
<a name="l00153"></a>00153     
<a name="l00154"></a>00154     <span class="keywordflow">if</span> (!aColor || anAlpha == components[components.length - 1])
<a name="l00155"></a>00155         <span class="keywordflow">return</span> aColor;
<a name="l00156"></a>00156 
<a name="l00157"></a>00157     <span class="keywordflow">if</span> (aColor.pattern)
<a name="l00158"></a>00158         var copy = <a class="code" href="_c_g_color_8j.html#a7e6b723b378dc0f1126f9df39d736c90">CGColorCreateWithPattern</a>(aColor.colorspace, aColor.pattern, components);
<a name="l00159"></a>00159     <span class="keywordflow">else</span>
<a name="l00160"></a>00160         var copy = <a class="code" href="_c_g_color_8j.html#af5e4c5b7c77b5b905e33ac78919055e6">CGColorCreate</a>(aColor.colorspace, components);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     copy.components[components.length - 1] = anAlpha;
<a name="l00163"></a>00163     
<a name="l00164"></a>00164     <span class="keywordflow">return</span> copy;
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166 
<a name="l00175"></a><a class="code" href="_c_g_color_8j.html#a7e6b723b378dc0f1126f9df39d736c90">00175</a> function <a class="code" href="_c_g_color_8j.html#a7e6b723b378dc0f1126f9df39d736c90">CGColorCreateWithPattern</a>(aColorSpace, aPattern, components)
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177     <span class="keywordflow">if</span> (!aColorSpace || !aPattern || !components)
<a name="l00178"></a>00178         <span class="keywordflow">return</span> NULL;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180     <span class="keywordflow">return</span> { colorspace:aColorSpace, pattern:aPattern, components:components.slice() };
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 
<a name="l00190"></a><a class="code" href="_c_g_color_8j.html#a9b31b966e8d63a6f397b290b2fa65312">00190</a> function <a class="code" href="_c_g_color_8j.html#a9b31b966e8d63a6f397b290b2fa65312">CGColorEqualToColor</a>(lhs, rhs)
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192     <span class="keywordflow">if</span> (lhs == rhs)
<a name="l00193"></a>00193         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00194"></a>00194         
<a name="l00195"></a>00195     <span class="keywordflow">if</span> (!lhs || !rhs)
<a name="l00196"></a>00196         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00197"></a>00197 
<a name="l00198"></a>00198     var lhsComponents = lhs.components,
<a name="l00199"></a>00199         rhsComponents = rhs.components,
<a name="l00200"></a>00200         lhsComponentCount = lhsComponents.length;
<a name="l00201"></a>00201 
<a name="l00202"></a>00202     <span class="keywordflow">if</span> (lhsComponentCount != rhsComponents.length)
<a name="l00203"></a>00203         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00204"></a>00204     
<a name="l00205"></a>00205     <span class="keywordflow">while</span> (lhsComponentCount--) 
<a name="l00206"></a>00206         <span class="keywordflow">if</span> (lhsComponents[lhsComponentCount] != rhsComponents[lhsComponentCount])
<a name="l00207"></a>00207             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00208"></a>00208             
<a name="l00209"></a>00209     <span class="keywordflow">if</span> (lhs.pattern != rhs.pattern)
<a name="l00210"></a>00210         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00211"></a>00211         
<a name="l00212"></a>00212     <span class="keywordflow">if</span> (CGColorSpaceEqualToColorSpace(lhs.colorspace, rhs.colorspace))
<a name="l00213"></a>00213         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00214"></a>00214         
<a name="l00215"></a>00215     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217 
<a name="l00224"></a><a class="code" href="_c_g_color_8j.html#af409c7cc959399d9c19b11765c4aed39">00224</a> function <a class="code" href="_c_g_color_8j.html#af409c7cc959399d9c19b11765c4aed39">CGColorGetAlpha</a>(aColor)
<a name="l00225"></a>00225 {
<a name="l00226"></a>00226     var components = aColor.components;
<a name="l00227"></a>00227     
<a name="l00228"></a>00228     <span class="keywordflow">return</span> components[components.length - 1];
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230 
<a name="l00236"></a><a class="code" href="_c_g_color_8j.html#adf09adb2e44d393e0609538370b41f15">00236</a> function <a class="code" href="_c_g_color_8j.html#adf09adb2e44d393e0609538370b41f15">CGColorGetColorSpace</a>(aColor)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238     <span class="keywordflow">return</span> aColor.colorspace;
<a name="l00239"></a>00239 }
<a name="l00240"></a>00240 
<a name="l00247"></a><a class="code" href="_c_g_color_8j.html#ad87137e7bb52dc8195632efdfbed60a3">00247</a> function <a class="code" href="_c_g_color_8j.html#ad87137e7bb52dc8195632efdfbed60a3">CGColorGetComponents</a>(aColor)
<a name="l00248"></a>00248 {
<a name="l00249"></a>00249     <span class="keywordflow">return</span> aColor.components;
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00259"></a><a class="code" href="_c_g_color_8j.html#ac24b7b4a49d6e5b2ae339de2e298c9a6">00259</a> function <a class="code" href="_c_g_color_8j.html#ac24b7b4a49d6e5b2ae339de2e298c9a6">CGColorGetNumberOfComponents</a>(aColor)
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261     <span class="keywordflow">return</span> aColor.components.length;
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263 
<a name="l00270"></a><a class="code" href="_c_g_color_8j.html#a6daaa0e6750e246551184096b1b15860">00270</a> function <a class="code" href="_c_g_color_8j.html#a6daaa0e6750e246551184096b1b15860">CGColorGetPattern</a>(aColor)
<a name="l00271"></a>00271 {
<a name="l00272"></a>00272     <span class="keywordflow">return</span> aColor.pattern;
<a name="l00273"></a>00273 }
<a name="l00274"></a>00274 
<a name="l00275"></a>00275 <span class="comment">/*    var components = aColor.components;</span>
<a name="l00276"></a>00276 <span class="comment">    </span>
<a name="l00277"></a>00277 <span class="comment">    case :  _CGCSSForColor[CFGetHash(aColor)] = &quot;rgba(&quot; + ROUND(components[0] * 255.0) + &apos;,&apos; + ROUND(components[0] * 255.0) + &apos;,&apos; ROUND(components[0] * 255.0) + &apos;,&apos; + ROUND(components[0] * 255.0);</span>
<a name="l00278"></a>00278 <span class="comment">                _cssString = (hasAlpha ? &quot;rgba(&quot; : &quot;rgb(&quot;) + </span>
<a name="l00279"></a>00279 <span class="comment">                    parseInt(_components[0] * 255.0) + &quot;, &quot; + </span>
<a name="l00280"></a>00280 <span class="comment">                    parseInt(_components[1] * 255.0) + &quot;, &quot; + </span>
<a name="l00281"></a>00281 <span class="comment">                    parseInt(_components[2] * 255.0) + </span>
<a name="l00282"></a>00282 <span class="comment">                    (hasAlpha ?  (&quot;, &quot; + _components[3]) : &quot;&quot;) + &quot;)&quot;;</span>
<a name="l00283"></a>00283 <span class="comment"></span>
<a name="l00284"></a>00284 <span class="comment">function CFStringFromColor()</span>
<a name="l00285"></a>00285 <span class="comment">{</span>
<a name="l00286"></a>00286 <span class="comment"></span>
<a name="l00287"></a>00287 <span class="comment">}</span>
<a name="l00288"></a>00288 <span class="comment">*/</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:54 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_g_color_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:42 GMT -->
</html>