Changeset 14851
- Timestamp:
- 01/09/2006 05:05:25 PM (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Frameworks/Adium Framework/ESFileTransfer.m
r14837 r14851 19 19 #import "ESFileTransfer.h" 20 20 21 static NSBezierPath *arrowPath = nil; 21 #import <AIUtilities/AIBezierPathAdditions.h> 22 22 23 23 #define MAGIC_ARROW_SCALE 0.85 … … 272 272 } 273 273 274 - (NSBezierPath *)arrowPathInSize:(NSSize)arrowSize pointingDown:(BOOL)pointItDown shaftLengthMultiplier:(float)shaftLengthMulti275 {276 if(!arrowPath) {277 arrowPath = [[NSBezierPath bezierPath] retain];278 279 /* 5280 * / \281 * / \ 1-7 = points282 *6-7 3-4 the point of the triangle is 100% from the bottom.283 * | the back edge of the triangle is 50% from the bottom.284 * 1-2285 */286 287 # define ONE_THIRD (1.0/3.0)288 # define TWO_THIRDS (2.0/3.0)289 # define ONE_HALF 0.5290 const float shaftLength = ONE_HALF * shaftLengthMulti;291 const float shaftEndY = -(shaftLength - ONE_HALF); //the end of the arrow shaft (points 1-2).292 293 //start with the bottom vertex.294 [arrowPath moveToPoint:NSMakePoint(ONE_THIRD, shaftEndY)]; //1295 [arrowPath lineToPoint:NSMakePoint(TWO_THIRDS, shaftEndY)]; //2296 //up to the inner right corner.297 [arrowPath relativeLineToPoint:NSMakePoint(0.0, shaftLength)]; //3298 //far right.299 [arrowPath relativeLineToPoint:NSMakePoint(ONE_THIRD, 0.0)]; //4300 //top center - the point of the arrow.301 [arrowPath lineToPoint:NSMakePoint(ONE_HALF, 1.0)]; //5302 //far left.303 [arrowPath lineToPoint:NSMakePoint(0.0, ONE_HALF)]; //6304 //inner left corner.305 [arrowPath relativeLineToPoint:NSMakePoint(ONE_THIRD, 0.0)]; //7306 //to the finish line! yay!307 [arrowPath closePath];308 }309 310 NSBezierPath *path = [arrowPath copy];311 312 NSAffineTransform *transform = [NSAffineTransform transform];313 314 if(pointItDown) {315 //http://developer.apple.com/documentation/Carbon/Conceptual/QuickDrawToQuartz2D/tq_other/chapter_3_section_2.html316 [transform translateXBy:0.0 yBy:1.0];317 [transform scaleXBy:1.0 yBy:-1.0];318 319 [path transformUsingAffineTransform:transform];320 321 transform = [NSAffineTransform transform];322 }323 324 [transform scaleXBy:arrowSize.width yBy:arrowSize.height];325 326 [path transformUsingAffineTransform:transform];327 328 return [path autorelease];329 }330 331 - (NSBezierPath *)arrowPathInSize:(NSSize)arrowSize pointingDown:(BOOL)pointItDown332 {333 return [self arrowPathInSize:arrowSize pointingDown:pointItDown shaftLengthMultiplier:1.0f];334 }335 336 274 - (NSImage *)iconImage 337 275 { … … 379 317 //and the arrow on top of it. 380 318 if(drawArrow) { 381 NSBezierPath *arrow = [self arrowPathInSize:bottomRight.size pointingDown:pointingDown shaftLengthMultiplier:5.0f]; 319 NSBezierPath *arrow = [NSBezierPath bezierPathWithArrowWithShaftLengthMultiplier:2.0f]; 320 if(pointingDown) [arrow flipVertically]; 321 [arrow scaleToSize:bottomRight.size]; 382 322 383 323 //bring it into position. trunk/Frameworks/AIUtilities Framework/Source/AIBezierPathAdditions.h
r9732 r14851 22 22 @interface NSBezierPath (AIBezierPathAdditions) 23 23 24 #pragma mark Rounded rectangles 25 24 26 + (NSBezierPath *)bezierPathWithRoundedRect:(NSRect)rect radius:(float)radius; 25 27 + (NSBezierPath *)bezierPathRoundedRectOfSize:(NSSize)backgroundSize; … … 28 30 + (NSBezierPath *)bezierPathWithRoundedBottomCorners:(NSRect)rect radius:(float)radius; 29 31 32 #pragma mark Arrows 33 34 /* default metrics of the arrow (as returned by +bezierPathWithArrow): 35 * ^ 36 * / \ 37 * / \ 38 * /_ _\ ___ 39 * | | | shaft length multiplier: 40 * | | | 1.0 41 * | | | equals shaft length: 42 * |_| _|_0.5 43 * 44 * default shaft width: 1/3 45 * the bounds of this arrow are { { 0, 0 }, { 1, 1 } }. 46 * 47 * the other three methods allow you to override either or both of these metrics. 48 */ 49 + (NSBezierPath *)bezierPathWithArrowWithShaftLengthMultiplier:(float)shaftLengthMulti shaftWidth:(float)shaftWidth; 50 + (NSBezierPath *)bezierPathWithArrowWithShaftLengthMultiplier:(float)shaftLengthMulti; 51 + (NSBezierPath *)bezierPathWithArrowWithShaftWidth:(float)shaftWidth; 52 + (NSBezierPath *)bezierPathWithArrow; 53 54 #pragma mark Nifty things 55 56 //these three are in-place. they return self, so that you can do e.g. [[NSBezierPath bezierPathWithArrow] flipVertically]. 57 - (NSBezierPath *)flipHorizontally; 58 - (NSBezierPath *)flipVertically; 59 - (NSBezierPath *)scaleToSize:(NSSize)newSize; 60 61 //these three return an autoreleased copy. 62 - (NSBezierPath *)bezierPathByFlippingHorizontally; 63 - (NSBezierPath *)bezierPathByFlippingVertically; 64 - (NSBezierPath *)bezierPathByScalingToSize:(NSSize)newSize; 65 30 66 @end trunk/Frameworks/AIUtilities Framework/Source/AIBezierPathAdditions.m
r13124 r14851 23 23 #include <c.h> 24 24 25 #define ONE_THIRD (1.0/3.0) 26 #define TWO_THIRDS (2.0/3.0) 27 #define ONE_HALF 0.5 28 29 #define DEFAULT_SHAFT_WIDTH ONE_THIRD 30 #define DEFAULT_SHAFT_LENGTH_MULTI 1.0 31 25 32 @implementation NSBezierPath (AIBezierPathAdditions) 33 34 #pragma mark Rounded rectangles 26 35 27 36 + (NSBezierPath *)bezierPathRoundedRectOfSize:(NSSize)backgroundSize … … 140 149 } 141 150 151 #pragma mark Arrows 152 153 + (NSBezierPath *)bezierPathWithArrowWithShaftLengthMultiplier:(float)shaftLengthMulti shaftWidth:(float)shaftWidth { 154 NSBezierPath *arrowPath = [NSBezierPath bezierPath]; 155 156 /* 5 157 * / \ 158 * / \ 1-7 = points 159 *6-7 3-4 the point of the triangle is 100% from the bottom. 160 * | the back edge of the triangle is 50% * shaftLengthMulti from the bottom. 161 * 1-2 162 */ 163 164 const float shaftLength = ONE_HALF * shaftLengthMulti; 165 const float shaftEndY = -(shaftLength - ONE_HALF); //the end of the arrow shaft (points 1-2). 166 //wing width = the distance between 6 and 7 and 3 and 4. 167 const float wingWidth = (1.0 - shaftWidth) * 0.5; 168 169 //start with the bottom vertex. 170 [arrowPath moveToPoint:NSMakePoint(wingWidth, shaftEndY)]; //1 171 [arrowPath relativeLineToPoint:NSMakePoint(shaftWidth, 0.0)]; //2 172 //up to the inner right corner. 173 [arrowPath relativeLineToPoint:NSMakePoint(0.0, shaftLength)]; //3 174 //far right. 175 [arrowPath relativeLineToPoint:NSMakePoint(wingWidth, 0.0)]; //4 176 //top center - the point of the arrow. 177 [arrowPath lineToPoint:NSMakePoint(ONE_HALF, 1.0)]; //5 178 //far left. 179 [arrowPath lineToPoint:NSMakePoint(0.0, ONE_HALF)]; //6 180 //inner left corner. 181 [arrowPath relativeLineToPoint:NSMakePoint(wingWidth, 0.0)]; //7 182 //to the finish line! yay! 183 [arrowPath closePath]; 184 185 return arrowPath; 186 } 187 188 + (NSBezierPath *)bezierPathWithArrowWithShaftLengthMultiplier:(float)shaftLengthMulti { 189 return [self bezierPathWithArrowWithShaftLengthMultiplier:shaftLengthMulti 190 shaftWidth:DEFAULT_SHAFT_WIDTH]; 191 } 192 + (NSBezierPath *)bezierPathWithArrowWithShaftWidth:(float)shaftWidth { 193 return [self bezierPathWithArrowWithShaftLengthMultiplier:DEFAULT_SHAFT_LENGTH_MULTI 194 shaftWidth:shaftWidth]; 195 } 196 + (NSBezierPath *)bezierPathWithArrow { 197 return [self bezierPathWithArrowWithShaftLengthMultiplier:DEFAULT_SHAFT_LENGTH_MULTI 198 shaftWidth:DEFAULT_SHAFT_WIDTH]; 199 } 200 201 #pragma mark Nifty things 202 203 //these three are in-place. 204 - (NSBezierPath *)flipHorizontally { 205 NSAffineTransform *transform = [NSAffineTransform transform]; 206 207 //adapted from http://developer.apple.com/documentation/Carbon/Conceptual/QuickDrawToQuartz2D/tq_other/chapter_3_section_2.html 208 [transform translateXBy: 1.0 yBy: 0.0]; 209 [transform scaleXBy:-1.0 yBy: 1.0]; 210 211 [self transformUsingAffineTransform:transform]; 212 return self; 213 } 214 - (NSBezierPath *)flipVertically { 215 NSAffineTransform *transform = [NSAffineTransform transform]; 216 217 //http://developer.apple.com/documentation/Carbon/Conceptual/QuickDrawToQuartz2D/tq_other/chapter_3_section_2.html 218 [transform translateXBy: 0.0 yBy: 1.0]; 219 [transform scaleXBy: 1.0 yBy:-1.0]; 220 221 [self transformUsingAffineTransform:transform]; 222 return self; 223 } 224 - (NSBezierPath *)scaleToSize:(NSSize)newSize { 225 NSAffineTransform *transform = [NSAffineTransform transform]; 226 [transform scaleXBy:newSize.width yBy:newSize.height]; 227 228 [self transformUsingAffineTransform:transform]; 229 return self; 230 } 231 232 //these three return an autoreleased copy. 233 - (NSBezierPath *)bezierPathByFlippingHorizontally { 234 return [[[self copy] autorelease] flipHorizontally]; 235 } 236 - (NSBezierPath *)bezierPathByFlippingVertically { 237 return [[[self copy] autorelease] flipVertically]; 238 } 239 - (NSBezierPath *)bezierPathByScalingToSize:(NSSize)newSize { 240 return [[[self copy] autorelease] scaleToSize:newSize]; 241 } 242 142 243 @end