PageRenderTime 62ms CodeModel.GetById 17ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/AppKit/GTMNSBezierPath+ShadingTest.m

http://macfuse.googlecode.com/
Objective C | 177 lines | 126 code | 22 blank | 29 comment | 0 complexity | 5fdccc2853e8adb2bc27b32f57c1a7ac MD5 | raw file
  1//
  2//  GTMNSBezierPath+ShadingTest.m
  3//
  4//  Copyright 2006-2008 Google Inc.
  5//
  6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7//  use this file except in compliance with the License.  You may obtain a copy
  8//  of the License at
  9// 
 10//  http://www.apache.org/licenses/LICENSE-2.0
 11// 
 12//  Unless required by applicable law or agreed to in writing, software
 13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 15//  License for the specific language governing permissions and limitations under
 16//  the License.
 17//
 18
 19#import <Cocoa/Cocoa.h>
 20
 21#import <SenTestingKit/SenTestingKit.h>
 22
 23#import "GTMLinearRGBShading.h"
 24#import "GTMAppKit+UnitTesting.h"
 25#import "GTMNSBezierPath+Shading.h"
 26
 27@interface GTMNSBezierPath_ShadingTest : GTMTestCase<GTMUnitTestViewDrawer>
 28@end
 29  
 30@implementation GTMNSBezierPath_ShadingTest
 31
 32- (void)testShadings {
 33  GTMAssertDrawingEqualToImageNamed(self,
 34                                    NSMakeSize(310, 410), 
 35                                    @"GTMNSBezierPath+ShadingTest", nil, nil);
 36}
 37
 38- (void)gtm_unitTestViewDrawRect:(NSRect)rect contextInfo:(void*)contextInfo {
 39  
 40  NSColor *theColorArray[] = { [NSColor blueColor],
 41    [NSColor redColor], [NSColor yellowColor],
 42    [NSColor blueColor], [NSColor greenColor],
 43    [NSColor redColor] };
 44  CGFloat theFloatArray[] = { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 };
 45  
 46  GTMLinearRGBShading *shading =
 47    [GTMLinearRGBShading shadingWithColors:theColorArray
 48                            fromSpaceNamed:NSCalibratedRGBColorSpace
 49                               atPositions:theFloatArray
 50                                     count:sizeof(theFloatArray)/sizeof(CGFloat)]; 
 51  NSBezierPath *shadedPath;
 52  
 53  // axial stroke rect - diagonal fill
 54  NSRect axialStrokeRect = NSMakeRect(10.0f, 10.0f, 90.0f, 90.0f);
 55  shadedPath = [NSBezierPath bezierPathWithRect:axialStrokeRect];
 56  [shadedPath setLineWidth: 10.0f];
 57  NSPoint startPoint = NSMakePoint(axialStrokeRect.origin.x + 20.0f,
 58                                   axialStrokeRect.origin.y + 20.0f);
 59  NSPoint endPoint = NSMakePoint(axialStrokeRect.origin.x + axialStrokeRect.size.width - 20.0f,
 60                                 axialStrokeRect.origin.y + axialStrokeRect.size.height - 20.0f);
 61  [shadedPath gtm_strokeAxiallyFrom:startPoint to:endPoint extendingStart:YES extendingEnd:YES shading:shading];
 62
 63  // axial stroke rect - v line fill
 64  axialStrokeRect = NSMakeRect(110.0f, 10.0f, 90.0f, 90.0f);
 65  shadedPath = [NSBezierPath bezierPathWithRect:axialStrokeRect];
 66  [shadedPath setLineWidth: 10.0f];
 67  startPoint = NSMakePoint(axialStrokeRect.origin.x + axialStrokeRect.size.width / 2.0f,
 68                           axialStrokeRect.origin.y + 20.0f);
 69  endPoint = NSMakePoint(axialStrokeRect.origin.x + axialStrokeRect.size.width / 2.0f,
 70                         axialStrokeRect.origin.y + axialStrokeRect.size.height - 20.0f);
 71  [shadedPath gtm_strokeAxiallyFrom:startPoint to:endPoint extendingStart:YES extendingEnd:YES shading:shading];
 72  
 73  // axial stroke rect - h line fill
 74  axialStrokeRect = NSMakeRect(210.0f, 10.0f, 90.0f, 90.0f);
 75  shadedPath = [NSBezierPath bezierPathWithRect:axialStrokeRect];
 76  [shadedPath setLineWidth: 10.0f];
 77  startPoint = NSMakePoint(axialStrokeRect.origin.x + 20.0f,
 78                           axialStrokeRect.origin.y + axialStrokeRect.size.height / 2.0f);
 79  endPoint = NSMakePoint(axialStrokeRect.origin.x + axialStrokeRect.size.width - 20.0f,
 80                         axialStrokeRect.origin.y + axialStrokeRect.size.height / 2.0f);
 81  [shadedPath gtm_strokeAxiallyFrom:startPoint to:endPoint extendingStart:YES extendingEnd:YES shading:shading];
 82  
 83  // axial fill rect - diagonal fill
 84  NSRect axialFillRect = NSMakeRect(10.0f, 110.0f, 90.0f, 90.0f);
 85  shadedPath = [NSBezierPath bezierPathWithRect:axialFillRect];
 86  startPoint = NSMakePoint(axialFillRect.origin.x + 20.0f,
 87                           axialFillRect.origin.y + 20.0f);
 88  endPoint = NSMakePoint(axialFillRect.origin.x + axialFillRect.size.width - 20.0f,
 89                         axialFillRect.origin.y + axialFillRect.size.height - 20.0f);
 90  [shadedPath gtm_fillAxiallyFrom:startPoint to:endPoint extendingStart:YES extendingEnd:YES shading:shading];
 91  
 92  // axial fill rect - v line fill
 93  axialFillRect = NSMakeRect(110.0f, 110.0f, 90.0f, 90.0f);
 94  shadedPath = [NSBezierPath bezierPathWithRect:axialFillRect];
 95  startPoint = NSMakePoint(axialFillRect.origin.x + axialFillRect.size.width / 2.0f,
 96                           axialFillRect.origin.y + 20.0f);
 97  endPoint = NSMakePoint(axialFillRect.origin.x + axialFillRect.size.width / 2.0f,
 98                         axialFillRect.origin.y + axialFillRect.size.height - 20.0f);
 99  [shadedPath gtm_fillAxiallyFrom:startPoint to:endPoint extendingStart:YES extendingEnd:YES shading:shading];
100  
101  // axial fill rect - h line fill
102  axialFillRect = NSMakeRect(210.0f, 110.0f, 90.0f, 90.0f);
103  shadedPath = [NSBezierPath bezierPathWithRect:axialFillRect];
104  startPoint = NSMakePoint(axialFillRect.origin.x + 20.0f,
105                           axialFillRect.origin.y + axialFillRect.size.height / 2.0f);
106  endPoint = NSMakePoint(axialFillRect.origin.x + axialFillRect.size.width - 20.0f,
107                         axialFillRect.origin.y + axialFillRect.size.height / 2.0f);
108  [shadedPath gtm_fillAxiallyFrom:startPoint to:endPoint extendingStart:YES extendingEnd:YES shading:shading];
109  
110  // radial stroke rect - diagonal fill
111  NSRect radialStrokeRect = NSMakeRect(10.0f, 210.0f, 90.0f, 90.0f);
112  shadedPath = [NSBezierPath bezierPathWithRect:radialStrokeRect];
113  startPoint = NSMakePoint(radialStrokeRect.origin.x + 20.0f,
114                           radialStrokeRect.origin.y + 20.0f);
115  endPoint = NSMakePoint(radialStrokeRect.origin.x + radialStrokeRect.size.width - 20.0f,
116                         radialStrokeRect.origin.y + radialStrokeRect.size.height - 20.0f);
117  [shadedPath gtm_strokeRadiallyFrom:startPoint fromRadius:60.0f 
118                                  to:endPoint toRadius:20.0f
119                      extendingStart:YES extendingEnd:YES shading:shading];
120  
121  // radial stroke rect - v line fill
122  radialStrokeRect = NSMakeRect(110.0f, 210.0f, 90.0f, 90.0f);
123  shadedPath = [NSBezierPath bezierPathWithRect:radialStrokeRect];
124  startPoint = NSMakePoint(radialStrokeRect.origin.x + radialStrokeRect.size.width / 2.0f,
125                           radialStrokeRect.origin.y + 20.0f);
126  endPoint = NSMakePoint(radialStrokeRect.origin.x + radialStrokeRect.size.width / 2.0f,
127                         radialStrokeRect.origin.y + radialStrokeRect.size.height - 20.0f);
128  [shadedPath gtm_strokeRadiallyFrom:startPoint fromRadius:60.0f 
129                                  to:endPoint toRadius:20.0f
130                      extendingStart:YES extendingEnd:YES shading:shading];
131  
132  // radial stroke rect - h line fill
133  radialStrokeRect = NSMakeRect(210.0f, 210.0f, 90.0f, 90.0f);
134  shadedPath = [NSBezierPath bezierPathWithRect:radialStrokeRect];
135  startPoint = NSMakePoint(radialStrokeRect.origin.x + 20.0f,
136                           radialStrokeRect.origin.y + radialStrokeRect.size.height / 2.0f);
137  endPoint = NSMakePoint(radialStrokeRect.origin.x + radialStrokeRect.size.width - 20.0f,
138                         radialStrokeRect.origin.y + radialStrokeRect.size.height / 2.0f);
139  [shadedPath gtm_strokeRadiallyFrom:startPoint fromRadius:60.0f 
140                                  to:endPoint toRadius:20.0f
141                      extendingStart:YES extendingEnd:YES shading:shading];
142  
143  // radial fill rect - diagonal fill
144  NSRect radialFillRect = NSMakeRect(10.0f, 310.0f, 90.0f, 90.0f);
145  shadedPath = [NSBezierPath bezierPathWithRect:radialFillRect];
146  startPoint = NSMakePoint(radialFillRect.origin.x + 20.0f,
147                           radialFillRect.origin.y + 20.0f);
148  endPoint = NSMakePoint(radialFillRect.origin.x + radialFillRect.size.width - 20.0f,
149                         radialFillRect.origin.y + radialFillRect.size.height - 20.0f);
150  [shadedPath gtm_fillRadiallyFrom:startPoint fromRadius:10.0f 
151                                to:endPoint toRadius:20.0f
152                    extendingStart:YES extendingEnd:YES shading:shading];
153
154  // radial fill rect - v line fill
155  radialFillRect = NSMakeRect(110.0f, 310.0f, 90.0f, 90.0f);
156  shadedPath = [NSBezierPath bezierPathWithRect:radialFillRect];
157  startPoint = NSMakePoint(radialFillRect.origin.x + radialFillRect.size.width / 2.0f,
158                           radialFillRect.origin.y + 20.0f);
159  endPoint = NSMakePoint(radialFillRect.origin.x + radialFillRect.size.width / 2.0f,
160                         radialFillRect.origin.y + radialFillRect.size.height - 20.0f);
161  [shadedPath gtm_fillRadiallyFrom:startPoint fromRadius:10.0f 
162                                to:endPoint toRadius:20.0f
163                    extendingStart:YES extendingEnd:YES shading:shading];
164  
165  // radial fill rect - h line fill
166  radialFillRect = NSMakeRect(210.0f, 310.0f, 90.0f, 90.0f);
167  shadedPath = [NSBezierPath bezierPathWithRect:radialFillRect];
168  startPoint = NSMakePoint(radialFillRect.origin.x + 20.0f,
169                           radialFillRect.origin.y + radialFillRect.size.height / 2.0f);
170  endPoint = NSMakePoint(radialFillRect.origin.x + radialFillRect.size.width - 20.0f,
171                         radialFillRect.origin.y + radialFillRect.size.height / 2.0f);
172  [shadedPath gtm_fillRadiallyFrom:startPoint fromRadius:10.0f 
173                                to:endPoint toRadius:20.0f
174                    extendingStart:YES extendingEnd:YES shading:shading];
175}
176
177@end