Changeset 5797


Ignore:
Timestamp:
May 10, 2008, 2:02:19 PM (14 years ago)
Author:
livings124
Message:

revert the upgrade of CTGradient

Location:
trunk/macosx/CTGradient
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/CTGradient/CTGradient.h

    r5795 r5797  
    33//
    44//  Created by Chad Weider on 2/14/07.
    5 //  Writtin by Chad Weider.
     5//  Copyright (c) 2007 Chad Weider.
     6//  Some rights reserved: <http://creativecommons.org/licenses/by/2.5/>
    67//
    7 //  Released into public domain on 4/10/08.
    8 // 
    9 //  Version: 1.8
     8//  Version: 1.6
    109
    1110#import <Cocoa/Cocoa.h>
     
    3736+ (id)gradientWithBeginningColor:(NSColor *)begin endingColor:(NSColor *)end;
    3837
     38+ (id)aquaSelectedGradient;
     39+ (id)aquaNormalGradient;
     40+ (id)aquaPressedGradient;
     41
     42+ (id)unifiedSelectedGradient;
     43+ (id)unifiedNormalGradient;
     44+ (id)unifiedPressedGradient;
     45+ (id)unifiedDarkGradient;
     46
     47+ (id)sourceListSelectedGradient;
     48+ (id)sourceListUnselectedGradient;
     49
     50+ (id)rainbowGradient;
     51+ (id)hydrogenSpectrumGradient;
     52
    3953- (CTGradient *)gradientWithAlphaComponent:(float)alpha;
     54
     55- (void)addElement:(CTGradientElement*)newElement;
    4056
    4157- (CTGradient *)addColorStop:(NSColor *)color atPosition:(float)position;       //positions given relative to [0,1]
     
    5672- (void)radialFillBezierPath:(NSBezierPath *)path;
    5773
    58 - (void)addElement:(CTGradientElement*)newElement;
    59 
    6074@end
  • trunk/macosx/CTGradient/CTGradient.m

    r5795 r5797  
    33//
    44//  Created by Chad Weider on 2/14/07.
    5 //  Writtin by Chad Weider.
     5//  Copyright (c) 2007 Chad Weider.
     6//  Some rights reserved: <http://creativecommons.org/licenses/by/2.5/>
    67//
    7 //  Released into public domain on 4/10/08.
    8 //
    9 //  Version: 1.8
     8//  Version: 1.6
    109
    1110#import "CTGradient.h"
     
    1413- (void)_commonInit;
    1514- (void)setBlendingMode:(CTGradientBlendingMode)mode;
     15- (void)addElement:(CTGradientElement*)newElement;
    1616
    1717- (CTGradientElement *)elementAtIndex:(unsigned)index;
     
    157157  }
    158158
     159+ (id)aquaSelectedGradient
     160  {
     161  id newInstance = [[[self class] alloc] init];
     162 
     163  CTGradientElement color1;
     164  color1.red   = 0.58;
     165  color1.green = 0.86;
     166  color1.blue  = 0.98;
     167  color1.alpha = 1.00;
     168  color1.position = 0;
     169 
     170  CTGradientElement color2;
     171  color2.red   = 0.42;
     172  color2.green = 0.68;
     173  color2.blue  = 0.90;
     174  color2.alpha = 1.00;
     175  color2.position = 11.5/23;
     176 
     177  CTGradientElement color3;
     178  color3.red   = 0.64;
     179  color3.green = 0.80;
     180  color3.blue  = 0.94;
     181  color3.alpha = 1.00;
     182  color3.position = 11.5/23;
     183 
     184  CTGradientElement color4;
     185  color4.red   = 0.56;
     186  color4.green = 0.70;
     187  color4.blue  = 0.90;
     188  color4.alpha = 1.00;
     189  color4.position = 1;
     190 
     191  [newInstance addElement:&color1];
     192  [newInstance addElement:&color2];
     193  [newInstance addElement:&color3];
     194  [newInstance addElement:&color4];
     195 
     196  return [newInstance autorelease];
     197  }
     198
     199+ (id)aquaNormalGradient
     200  {
     201  id newInstance = [[[self class] alloc] init];
     202 
     203  CTGradientElement color1;
     204  color1.red = color1.green = color1.blue  = 0.95;
     205  color1.alpha = 1.00;
     206  color1.position = 0;
     207 
     208  CTGradientElement color2;
     209  color2.red = color2.green = color2.blue  = 0.83;
     210  color2.alpha = 1.00;
     211  color2.position = 11.5/23;
     212 
     213  CTGradientElement color3;
     214  color3.red = color3.green = color3.blue  = 0.95;
     215  color3.alpha = 1.00;
     216  color3.position = 11.5/23;
     217 
     218  CTGradientElement color4;
     219  color4.red = color4.green = color4.blue  = 0.92;
     220  color4.alpha = 1.00;
     221  color4.position = 1;
     222 
     223  [newInstance addElement:&color1];
     224  [newInstance addElement:&color2];
     225  [newInstance addElement:&color3];
     226  [newInstance addElement:&color4];
     227 
     228  return [newInstance autorelease];
     229  }
     230
     231+ (id)aquaPressedGradient
     232  {
     233  id newInstance = [[[self class] alloc] init];
     234 
     235  CTGradientElement color1;
     236  color1.red = color1.green = color1.blue  = 0.80;
     237  color1.alpha = 1.00;
     238  color1.position = 0;
     239 
     240  CTGradientElement color2;
     241  color2.red = color2.green = color2.blue  = 0.64;
     242  color2.alpha = 1.00;
     243  color2.position = 11.5/23;
     244 
     245  CTGradientElement color3;
     246  color3.red = color3.green = color3.blue  = 0.80;
     247  color3.alpha = 1.00;
     248  color3.position = 11.5/23;
     249 
     250  CTGradientElement color4;
     251  color4.red = color4.green = color4.blue  = 0.77;
     252  color4.alpha = 1.00;
     253  color4.position = 1;
     254 
     255  [newInstance addElement:&color1];
     256  [newInstance addElement:&color2];
     257  [newInstance addElement:&color3];
     258  [newInstance addElement:&color4];
     259 
     260  return [newInstance autorelease];
     261  }
     262
     263+ (id)unifiedSelectedGradient
     264  {
     265  id newInstance = [[[self class] alloc] init];
     266 
     267  CTGradientElement color1;
     268  color1.red = color1.green = color1.blue  = 0.85;
     269  color1.alpha = 1.00;
     270  color1.position = 0;
     271 
     272  CTGradientElement color2;
     273  color2.red = color2.green = color2.blue  = 0.95;
     274  color2.alpha = 1.00;
     275  color2.position = 1;
     276 
     277  [newInstance addElement:&color1];
     278  [newInstance addElement:&color2];
     279 
     280  return [newInstance autorelease];
     281  }
     282
     283+ (id)unifiedNormalGradient
     284  {
     285  id newInstance = [[[self class] alloc] init];
     286 
     287  CTGradientElement color1;
     288  color1.red = color1.green = color1.blue  = 0.75;
     289  color1.alpha = 1.00;
     290  color1.position = 0;
     291 
     292  CTGradientElement color2;
     293  color2.red = color2.green = color2.blue  = 0.90;
     294  color2.alpha = 1.00;
     295  color2.position = 1;
     296 
     297  [newInstance addElement:&color1];
     298  [newInstance addElement:&color2];
     299 
     300  return [newInstance autorelease];
     301  }
     302
     303+ (id)unifiedPressedGradient
     304  {
     305  id newInstance = [[[self class] alloc] init];
     306 
     307  CTGradientElement color1;
     308  color1.red = color1.green = color1.blue  = 0.60;
     309  color1.alpha = 1.00;
     310  color1.position = 0;
     311 
     312  CTGradientElement color2;
     313  color2.red = color2.green = color2.blue  = 0.75;
     314  color2.alpha = 1.00;
     315  color2.position = 1;
     316 
     317  [newInstance addElement:&color1];
     318  [newInstance addElement:&color2];
     319 
     320  return [newInstance autorelease];
     321  }
     322
     323+ (id)unifiedDarkGradient
     324  {
     325  id newInstance = [[[self class] alloc] init];
     326 
     327  CTGradientElement color1;
     328  color1.red = color1.green = color1.blue  = 0.68;
     329  color1.alpha = 1.00;
     330  color1.position = 0;
     331 
     332  CTGradientElement color2;
     333  color2.red = color2.green = color2.blue  = 0.83;
     334  color2.alpha = 1.00;
     335  color2.position = 1;
     336 
     337  [newInstance addElement:&color1];
     338  [newInstance addElement:&color2];
     339 
     340  return [newInstance autorelease];
     341  }
     342
     343+ (id)sourceListSelectedGradient
     344  {
     345  id newInstance = [[[self class] alloc] init];
     346 
     347  CTGradientElement color1;
     348  color1.red   = 0.06;
     349  color1.green = 0.37;
     350  color1.blue  = 0.85;
     351  color1.alpha = 1.00;
     352  color1.position = 0;
     353 
     354  CTGradientElement color2;
     355  color2.red   = 0.30;
     356  color2.green = 0.60;
     357  color2.blue  = 0.92;
     358  color2.alpha = 1.00;
     359  color2.position = 1;
     360 
     361  [newInstance addElement:&color1];
     362  [newInstance addElement:&color2];
     363 
     364  return [newInstance autorelease];
     365  }
     366
     367+ (id)sourceListUnselectedGradient
     368  {
     369  id newInstance = [[[self class] alloc] init];
     370 
     371  CTGradientElement color1;
     372  color1.red   = 0.43;
     373  color1.green = 0.43;
     374  color1.blue  = 0.43;
     375  color1.alpha = 1.00;
     376  color1.position = 0;
     377 
     378  CTGradientElement color2;
     379  color2.red   = 0.60;
     380  color2.green = 0.60;
     381  color2.blue  = 0.60;
     382  color2.alpha = 1.00;
     383  color2.position = 1;
     384 
     385  [newInstance addElement:&color1];
     386  [newInstance addElement:&color2];
     387 
     388  return [newInstance autorelease];
     389  }
     390
     391+ (id)rainbowGradient
     392  {
     393  id newInstance = [[[self class] alloc] init];
     394 
     395  CTGradientElement color1;
     396  color1.red   = 1.00;
     397  color1.green = 0.00;
     398  color1.blue  = 0.00;
     399  color1.alpha = 1.00;
     400  color1.position = 0.0;
     401 
     402  CTGradientElement color2;
     403  color2.red   = 0.54;
     404  color2.green = 0.00;
     405  color2.blue  = 1.00;
     406  color2.alpha = 1.00;
     407  color2.position = 1.0;
     408   
     409  [newInstance addElement:&color1];
     410  [newInstance addElement:&color2];
     411 
     412  [newInstance setBlendingMode:CTChromaticBlendingMode];
     413 
     414  return [newInstance autorelease];
     415  }
     416
     417+ (id)hydrogenSpectrumGradient
     418  {
     419  id newInstance = [[[self class] alloc] init];
     420 
     421  struct {float hue; float position; float width;} colorBands[4];
     422 
     423  colorBands[0].hue = 22;
     424  colorBands[0].position = .145;
     425  colorBands[0].width = .01;
     426 
     427  colorBands[1].hue = 200;
     428  colorBands[1].position = .71;
     429  colorBands[1].width = .008;
     430 
     431  colorBands[2].hue = 253;
     432  colorBands[2].position = .885;
     433  colorBands[2].width = .005;
     434 
     435  colorBands[3].hue = 275;
     436  colorBands[3].position = .965;
     437  colorBands[3].width = .003;
     438 
     439  int i;
     440  /////////////////////////////
     441  for(i = 0; i < 4; i++)
     442        {       
     443        float color[4];
     444        color[0] = colorBands[i].hue - 180*colorBands[i].width;
     445        color[1] = 1;
     446        color[2] = 0.001;
     447        color[3] = 1;
     448        transformHSV_RGB(color);
     449        CTGradientElement fadeIn;
     450        fadeIn.red   = color[0];
     451        fadeIn.green = color[1];
     452        fadeIn.blue  = color[2];
     453        fadeIn.alpha = color[3];
     454        fadeIn.position = colorBands[i].position - colorBands[i].width;
     455       
     456       
     457        color[0] = colorBands[i].hue;
     458        color[1] = 1;
     459        color[2] = 1;
     460        color[3] = 1;
     461        transformHSV_RGB(color);
     462        CTGradientElement band;
     463        band.red   = color[0];
     464        band.green = color[1];
     465        band.blue  = color[2];
     466        band.alpha = color[3];
     467        band.position = colorBands[i].position;
     468       
     469        color[0] = colorBands[i].hue + 180*colorBands[i].width;
     470        color[1] = 1;
     471        color[2] = 0.001;
     472        color[3] = 1;
     473        transformHSV_RGB(color);
     474        CTGradientElement fadeOut;
     475        fadeOut.red   = color[0];
     476        fadeOut.green = color[1];
     477        fadeOut.blue  = color[2];
     478        fadeOut.alpha = color[3];
     479        fadeOut.position = colorBands[i].position + colorBands[i].width;
     480       
     481       
     482        [newInstance addElement:&fadeIn];
     483        [newInstance addElement:&band];
     484        [newInstance addElement:&fadeOut];
     485        }
     486 
     487  [newInstance setBlendingMode:CTChromaticBlendingMode];
     488 
     489  return [newInstance autorelease];
     490  }
     491
     492#pragma mark -
     493
     494
     495
    159496#pragma mark Modification
    160497- (CTGradient *)gradientWithAlphaComponent:(float)alpha
     
    271608 
    272609 
    273   return [NSColor colorWithCalibratedRed:components[0]/components[3]    //undo premultiplication that CG requires
    274                                                                    green:components[1]/components[3]
    275                                                                     blue:components[2]/components[3]
     610  return [NSColor colorWithCalibratedRed:components[0]
     611                                                                   green:components[1]
     612                                                                    blue:components[2]
    276613                                                                   alpha:components[3]];
    277614  }
     
    349686  CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    350687  CGContextSaveGState(currentContext);
    351           #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
     688          #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    352689                CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    353690          #else
     
    366703- (void)radialFillRect:(NSRect)rect
    367704  {
    368   CGPoint startPoint, endPoint;
     705  CGPoint startPoint , endPoint;
    369706  float startRadius, endRadius;
    370707  float scalex, scaley, transx, transy;
     
    472809
    473810- (void)addElement:(CTGradientElement *)newElement
    474   {
     811{
    475812  if(elementList == nil || newElement->position < elementList->position)        //inserting at beginning of list
    476813        {
     
    6711008        out[2] = (color2->blue  - color1->blue )*position + color1->blue;
    6721009        out[3] = (color2->alpha - color1->alpha)*position + color1->alpha;
    673         }
    674  
    675   //Premultiply the color by the alpha.
    676   out[0] *= out[3];
    677   out[1] *= out[3];
    678   out[2] *= out[3];
     1010        }
    6791011  }
    6801012
     
    7651097   
    7661098  transformHSV_RGB(out);
    767  
    768   //Premultiply the color by the alpha.
    769   out[0] *= out[3];
    770   out[1] *= out[3];
    771   out[2] *= out[3];
    7721099  }
    7731100
     
    8521179   
    8531180  transformHSV_RGB(out);
    854  
    855   //Premultiply the color by the alpha.
    856   out[0] *= out[3];
    857   out[1] *= out[3];
    858   out[2] *= out[3];
    859   }
     1181  }
     1182
    8601183
    8611184
Note: See TracChangeset for help on using the changeset viewer.