root/Footagehead/trunk/FHImageView.m

Revision 5019, 19.6 kB (checked in by morris, 10 months ago)

Fix scaling in slideshow mode

  • Property svn:keywords set to author date id revision
Line 
1 /* $Id$ */
2
3 /*
4  *  Copyright (c) 2003-2007 Axel Andersson
5  *  All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *  1. Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *  2. Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #import "FHImage.h"
30 #import "FHImageView.h"
31 #import "FHWindowController.h"
32
33 @interface FHImageView(Private)
34
35 - (void)_initImageView;
36
37 - (void)_adjustImageSize;
38 - (void)_adjustFrameSize;
39 - (CGFloat)_scaleFactorUsingScaling:(FHImageScaling)imageScaling bounds:(NSSize)bounds;
40 - (NSSize)_scaledSizeForSize:(NSSize)size usingScaling:(FHImageScaling)imageScaling bounds:(NSSize)bounds;
41
42 @end
43
44
45 @implementation FHImageView(Private)
46
47 - (void)_initImageView {
48         _imageScaling = FHScaleProportionally;
49         _backgroundColor = [[NSColor whiteColor] retain];
50
51         [[NSNotificationCenter defaultCenter] addObserver:self
52                                                                                          selector:@selector(_FH_viewFrameDidChange:)
53                                                                                                  name:NSViewFrameDidChangeNotification
54                                                                                            object:self];
55 }
56
57
58
59 #pragma mark -
60
61 - (void)_FH_viewFrameDidChange:(NSNotification *)notification {
62         [self _adjustFrameSize];
63                
64         if([_scrollView hasHorizontalScroller] || [_scrollView hasVerticalScroller])
65                 [_scrollView setDocumentCursor:[NSCursor openHandCursor]];
66         else
67                 [_scrollView setDocumentCursor:[NSCursor arrowCursor]];
68 }
69
70
71
72 #pragma mark -
73
74 - (void)_adjustImageSize {
75         NSSize          orientedLeftSize, orientedRightSize;
76        
77         if(_image) {
78                 _imageAngle = _imageRotation + _imageOrientation;
79                
80                 if(_imageAngle >= 360.0)
81                         _imageAngle -= 360.0;
82                
83                 if(_imageAngle == 0.0 || _imageAngle == 180.0)
84                         _rotatedImageSize = _imageSize;
85                 else
86                         _rotatedImageSize = WISwapSize(_imageSize);
87         } else {
88                 _leftImageAngle = _imageRotation + _leftImageOrientation;
89                
90                 if(_leftImageAngle >= 360.0)
91                         _leftImageAngle -= 360.0;
92                
93                 if(_leftImageAngle == 0.0 || _leftImageAngle == 180.0)
94                         _rotatedLeftImageSize = _leftImageSize;
95                 else
96                         _rotatedLeftImageSize = WISwapSize(_leftImageSize);
97
98                 if(_leftImageOrientation == 0.0 || _leftImageOrientation == 180.0)
99                         orientedLeftSize = _leftImageSize;
100                 else
101                         orientedLeftSize = WISwapSize(_leftImageSize);
102                
103                 _rightImageAngle = _imageRotation + _rightImageOrientation;
104                
105                 if(_rightImageAngle >= 360.0)
106                         _rightImageAngle -= 360.0;
107                
108                 if(_rightImageAngle == 0.0 || _rightImageAngle == 180.0)
109                         _rotatedRightImageSize = _rightImageSize;
110                 else
111                         _rotatedRightImageSize = WISwapSize(_rightImageSize);
112                
113                 if(_rightImageOrientation == 0.0 || _rightImageOrientation == 180.0)
114                         orientedRightSize = _rightImageSize;
115                 else
116                         orientedRightSize = WISwapSize(_rightImageSize);
117
118                 _imageSize.width = orientedLeftSize.width + orientedRightSize.width;
119                 _imageSize.height = MAX(orientedLeftSize.height, orientedRightSize.height);
120                
121                 if(_imageRotation == 0.0 || _imageRotation == 180.0)
122                         _rotatedImageSize = _imageSize;
123                 else
124                         _rotatedImageSize = WISwapSize(_imageSize);
125         }
126 }
127
128
129
130 - (void)_adjustFrameSize {
131         NSRect          frame;
132         NSSize          visibleSize, imageSize, frameSize;
133         CGFloat         diff, scrollerWidth, widthAdjustment, heightAdjustment;
134         BOOL            horizontalScroller, verticalScroller;
135        
136         if(_adjustingFrameSize)
137                 return;
138        
139         _adjustingFrameSize = YES;
140        
141         if(_scrollView) {
142                 [_scrollView setHasHorizontalScroller:NO];
143                 [_scrollView setHasVerticalScroller:NO];
144                
145                 visibleSize = [_scrollView documentVisibleRect].size;
146                
147                 _adjustedImageScaling = _imageScaling;
148                
149                 if(_imageScaling == FHScaleNone ||
150                    _imageScaling == FHScaleWidthProportionally ||
151                    _imageScaling == FHScaleHeightProportionally) {
152                         scrollerWidth = [NSScroller scrollerWidth];
153                         widthAdjustment = heightAdjustment = 0.0;
154                         horizontalScroller = verticalScroller = NO;
155                        
156                         imageSize = [self _scaledSizeForSize:_rotatedImageSize usingScaling:_imageScaling bounds:visibleSize];
157
158                         if(_imageScaling == FHScaleNone) {
159                                 if(imageSize.height > visibleSize.height && imageSize.width > visibleSize.width)
160                                         horizontalScroller = verticalScroller = YES;
161                                 else if(imageSize.height > visibleSize.height)
162                                         verticalScroller = YES;
163                                 else if(imageSize.width > visibleSize.width)
164                                         horizontalScroller = YES;
165                         }
166                         else if(_imageScaling == FHScaleWidthProportionally) {
167                                 if(imageSize.height - visibleSize.height > scrollerWidth) {
168                                         diff = scrollerWidth - (visibleSize.width - imageSize.width);
169
170                                         if(diff > 0.0)
171                                                 heightAdjustment = ceil((imageSize.height / imageSize.width) * diff);
172                                        
173                                         verticalScroller = YES;
174                                 } else {
175                                         _adjustedImageScaling = FHScaleProportionally;
176                                 }
177                         }
178                         else if(_imageScaling == FHScaleHeightProportionally) {
179                                 if(imageSize.width - visibleSize.width > scrollerWidth) {
180                                         diff = scrollerWidth - (visibleSize.height - imageSize.height);
181                                        
182                                         if(diff > 0.0)
183                                                 widthAdjustment = ceil((imageSize.width / imageSize.height) * diff);
184
185                                         horizontalScroller = YES;
186                                 } else {
187                                         _adjustedImageScaling = FHScaleProportionally;
188                                 }
189                         }
190                        
191                         if(_imageScaling != _adjustedImageScaling)
192                                 imageSize = [self _scaledSizeForSize:_rotatedImageSize usingScaling:_adjustedImageScaling bounds:visibleSize];
193                        
194                         frameSize = NSMakeSize(MAX(visibleSize.width, imageSize.width), MAX(visibleSize.height, imageSize.height));
195                         frameSize.width -= widthAdjustment;
196                         frameSize.height -= heightAdjustment;
197                        
198                         [self setFrameSize:frameSize];
199                        
200                         [_scrollView setHasHorizontalScroller:horizontalScroller];
201                         [_scrollView setHasVerticalScroller:verticalScroller];
202
203                         [self scrollPoint:NSMakePoint(0.0, frameSize.height)];
204                 } else {
205                         [self setFrameSize:visibleSize];
206                 }
207         } else {
208                 visibleSize = [[self window] frame].size;
209                 frameSize = [self _scaledSizeForSize:_rotatedImageSize usingScaling:_imageScaling bounds:visibleSize];
210                 frame.size = frameSize;
211                 frame.origin.x = floor((visibleSize.width  - frameSize.width)  / 2.0);
212                 frame.origin.y = floor((visibleSize.height - frameSize.height) / 2.0);
213                 WILogSize(frameSize);
214                 [self setFrame:frame];
215                 _adjustedImageScaling = _imageScaling;
216         }
217
218         _adjustingFrameSize = NO;
219 }
220
221
222
223 - (CGFloat)_scaleFactorUsingScaling:(FHImageScaling)imageScaling bounds:(NSSize)bounds {
224         CGFloat         dx, dy;
225        
226         dx = bounds.width  / _rotatedImageSize.width;
227         dy = bounds.height / _rotatedImageSize.height;
228        
229         if(imageScaling == FHScaleProportionally || imageScaling == FHScaleStretchedProportionally)
230                 return dx < dy ? dx : dy;
231         else if(imageScaling == FHScaleWidthProportionally)
232                 return dx;
233         else if(imageScaling == FHScaleHeightProportionally)
234                 return dy;
235        
236         return 1.0;
237 }
238
239
240
241 - (NSSize)_scaledSizeForSize:(NSSize)size usingScaling:(FHImageScaling)imageScaling bounds:(NSSize)bounds {
242         CGFloat         factor;
243        
244         if(imageScaling == FHScaleNone)
245                 return size;
246        
247         if(imageScaling == FHScaleStretched)
248                 return bounds;
249        
250         factor = [self _scaleFactorUsingScaling:imageScaling bounds:bounds];
251        
252         if(factor < 1.0 || imageScaling == FHScaleStretchedProportionally) {
253                 size.width              = floorf(size.width  * factor);
254                 size.height             = floorf(size.height * factor);
255         }
256        
257         return size;
258 }
259
260 @end
261
262
263 @implementation FHImageView
264
265 - (id)initWithFrame:(NSRect)frame {
266         self = [super initWithFrame:frame];
267
268         [self _initImageView];
269
270         return self;
271 }
272
273
274
275 - (id)initWithCoder:(NSCoder *)coder {
276         self = [super initWithCoder:coder];
277
278         [self _initImageView];
279
280         return self;
281 }
282
283
284
285 - (void)dealloc {
286         [_image release];
287         [_rightImage release];
288         [_leftImage release];
289
290         [_backgroundColor release];
291        
292         [super dealloc];
293 }
294
295
296
297 #pragma mark -
298
299 - (void)setImage:(FHImage *)image {
300         BOOL    display;
301
302         display = (image != NULL || _image != NULL || _leftImage != NULL || _rightImage != NULL);
303        
304         [_leftImage release];
305         _leftImage = NULL;
306        
307         [_rightImage release];
308         _rightImage = NULL;
309        
310         [image retain];
311         [_image release];
312        
313         _image = image;
314        
315         if(_image) {
316                 _imageSize                      = [_image size];
317                 _imageOrientation       = [_image orientation];
318         } else {
319                 _imageSize.width        = 0.0;
320                 _imageSize.height       = 0.0;
321                 _imageOrientation       = 0.0;
322         }
323        
324         [self _adjustImageSize];
325         [self _adjustFrameSize];
326        
327         if(display)
328                 [self setNeedsDisplay:YES];
329 }
330
331
332
333 - (FHImage *)image {
334         return _image;
335 }
336
337
338
339 - (void)setLeftImage:(FHImage *)leftImage rightImage:(FHImage *)rightImage {
340         BOOL    display;
341
342         display = (_image != NULL || leftImage != NULL || _leftImage != NULL || rightImage != NULL || _rightImage != NULL);
343        
344         [_image release];
345         _image = NULL;
346        
347         [leftImage retain];
348         [_leftImage release];
349        
350         _leftImage = leftImage;
351        
352         if(_leftImage) {
353                 _leftImageSize                  = [_leftImage size];
354                 _leftImageOrientation   = [_leftImage orientation];
355         } else {
356                 _leftImageSize.width    = 0.0;
357                 _leftImageSize.height   = 0.0;
358                 _leftImageOrientation   = 0.0;
359         }
360        
361         [rightImage retain];
362         [_rightImage release];
363        
364         _rightImage = rightImage;
365        
366         if(_rightImage) {
367                 _rightImageSize                 = [_rightImage size];
368                 _rightImageOrientation  = [_rightImage orientation];
369         } else {
370                 _rightImageSize.width   = 0.0;
371                 _rightImageSize.height  = 0.0;
372                 _rightImageOrientation  = 0.0;
373         }
374        
375         [self _adjustImageSize];
376         [self _adjustFrameSize];
377        
378         if(display)
379                 [self setNeedsDisplay:YES];
380 }
381
382
383
384 - (FHImage *)leftImage {
385         return _leftImage;
386 }
387
388
389
390 - (FHImage *)rightImage {
391         return _rightImage;
392 }
393
394
395
396 - (NSSize)imageSize {
397         return _imageSize;
398 }
399
400
401
402 - (CGFloat)zoom {
403         CGFloat         zoom;
404        
405         zoom = 100.0 * [self _scaleFactorUsingScaling:_adjustedImageScaling bounds:[self bounds].size];
406        
407         if(zoom > 100.0 && _adjustedImageScaling != FHScaleStretched && _adjustedImageScaling != FHScaleStretchedProportionally)
408                 zoom = 100.0;
409        
410         return zoom;
411 }
412
413
414
415 - (void)setImageScaling:(FHImageScaling)imageScaling {
416         _imageScaling = imageScaling;
417        
418         [self _adjustFrameSize];
419        
420         [self setNeedsDisplay:YES];
421 }
422
423
424
425 - (FHImageScaling)imageScaling {
426         return _imageScaling;
427 }
428
429
430
431 - (void)setImageRotation:(CGFloat)imageRotation {
432         _imageRotation = imageRotation;
433
434         [self _adjustImageSize];
435         [self _adjustFrameSize];
436        
437         [self setNeedsDisplay:YES];
438 }
439
440
441
442 - (CGFloat)imageRotation {
443         return _imageRotation;
444 }
445
446
447
448 - (void)setBackgroundColor:(NSColor *)color {
449         [color retain];
450         [_backgroundColor release];
451        
452         _backgroundColor = color;
453        
454         [self setNeedsDisplay:YES];
455 }
456
457
458
459 - (NSColor *)backgroundColor {
460         return _backgroundColor;
461 }
462
463
464
465 #pragma mark -
466
467 - (void)mouseDown:(NSEvent *)event {
468         _dragging = NO;
469 }
470
471
472
473 - (void)mouseDragged:(NSEvent *)event {
474         NSPoint         point, originalPoint;
475         NSRect          originalRect;
476         float           x, y;
477        
478         _dragging = YES;
479
480         if([_scrollView hasHorizontalScroller] || [_scrollView hasVerticalScroller]) {
481                 originalPoint   = [event locationInWindow];
482                 originalRect    = [self visibleRect];
483                
484                 [[NSCursor closedHandCursor] push];
485                
486                 do {
487                         event = [[self window] nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask];
488                        
489                         if([event type] == NSLeftMouseDragged) {
490                                 point   = [event locationInWindow];
491                                 x               = originalPoint.x - point.x;
492                                 y               = originalPoint.y - point.y;
493                                
494                                 [self scrollRectToVisible:NSOffsetRect(originalRect, x, y)];
495                         }
496                 } while([event type] != NSLeftMouseUp);
497                
498                 [NSCursor pop];
499         }
500 }
501
502
503
504 - (void)scrollWheel:(NSEvent *)event {
505         NSScroller              *scroller;
506         BOOL                    up, handled = NO;
507        
508         scroller = [_scrollView verticalScroller];
509         up = ([event deltaY] > 0.0f);
510        
511         if(![_scrollView hasVerticalScroller] || (up && [scroller floatValue] == 0.0f) || (!up && [scroller floatValue] == 1.0f)) {
512                 if(!up)
513                         [_delegate nextImage:self];
514                 else
515                         [_delegate previousImage:self];
516                
517                 handled = YES;
518         }
519        
520         if(!handled)
521                 [_scrollView scrollWheel:event];
522 }
523
524
525
526 #pragma mark -
527
528 - (BOOL)isOpaque {
529         return YES;
530 }
531
532
533
534 - (void)drawRect:(NSRect)frame {
535         FHImage                 *image;
536         CGContextRef    context;
537         NSRect                  bounds, rect, leftRect, rightRect;
538         NSSize                  size, rotatedLeftSize, rotatedRightSize;
539        
540         bounds = [self bounds];
541        
542         [_backgroundColor set];
543         NSRectFill(bounds);
544        
545         if(_image || _leftImage || _rightImage) {
546                 context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
547
548                 if(_leftImage && _rightImage) {
549                         size                            = [self _scaledSizeForSize:_imageSize usingScaling:_adjustedImageScaling bounds:bounds.size];
550                         leftRect.size           = [self _scaledSizeForSize:_leftImageSize usingScaling:_adjustedImageScaling bounds:bounds.size];
551                         rightRect.size          = [self _scaledSizeForSize:_rightImageSize usingScaling:_adjustedImageScaling bounds:bounds.size];
552                         rotatedLeftSize         = [self _scaledSizeForSize:_rotatedLeftImageSize usingScaling:_adjustedImageScaling bounds:bounds.size];
553                         rotatedRightSize        = [self _scaledSizeForSize:_rotatedRightImageSize usingScaling:_adjustedImageScaling bounds:bounds.size];
554                        
555                         if(_imageRotation == 0.0 || _imageRotation == 180.0) {
556                                 leftRect.origin.x = rightRect.origin.x = floorf((bounds.size.width  - size.width)  / 2.0);
557                                 leftRect.origin.y = rightRect.origin.y = floorf((bounds.size.height - size.height) / 2.0);
558                         } else {
559                                 leftRect.origin.x = rightRect.origin.x = floorf((bounds.size.width  - size.height) / 2.0);
560                                 leftRect.origin.y = rightRect.origin.y = floorf((bounds.size.height - size.width)  / 2.0);
561                         }
562                        
563                         if(_imageRotation == 0.0) {
564                                 if(_leftImageOrientation == 90.0) {
565                                         leftRect.origin.y += rotatedLeftSize.height;
566                                 }
567                                 else if(_leftImageOrientation == 180.0) {
568                                         leftRect.origin.x += rotatedLeftSize.width;
569                                         leftRect.origin.y += rotatedLeftSize.height;
570                                 }
571                                 else if(_leftImageOrientation == 270.0) {
572                                         leftRect.origin.x += rotatedLeftSize.width;
573                                 }
574                         }
575                         else if(_imageRotation == 90.0) {
576                                 if(_leftImageOrientation == 0.0) {
577                                         leftRect.origin.y += rotatedRightSize.height + rotatedLeftSize.height;
578                                 }
579                                 else if(_leftImageOrientation == 90.0) {
580                                         leftRect.origin.x += rotatedLeftSize.width;
581                                         leftRect.origin.y += rotatedRightSize.height + rotatedLeftSize.height;
582                                 }
583                                 else if(_leftImageOrientation == 180.0) {
584                                         leftRect.origin.x += rotatedLeftSize.width;
585                                         leftRect.origin.y += rotatedRightSize.height;
586                                 }
587                                 else if(_leftImageOrientation == 270.0) {
588                                         leftRect.origin.y += rotatedRightSize.height;
589                                 }
590                         }
591                         else if(_imageRotation == 180.0) {
592                                 if(_leftImageOrientation == 0.0) {
593                                         leftRect.origin.x += rotatedRightSize.width + rotatedLeftSize.width;
594                                         leftRect.origin.y += rotatedLeftSize.height;
595                                 }
596                                 else if(_leftImageOrientation == 90.0) {
597                                         leftRect.origin.x += rotatedRightSize.width + rotatedLeftSize.width;
598                                 }
599                                 else if(_leftImageOrientation == 180.0) {
600                                         leftRect.origin.x += rotatedRightSize.width;
601                                 }
602                                 else if(_leftImageOrientation == 270.0) {
603                                         leftRect.origin.x += rotatedRightSize.width;
604                                         leftRect.origin.y += rotatedLeftSize.height;
605                                 }
606                         }
607                         else if(_imageRotation == 270.0) {
608                                 if(_leftImageOrientation == 0.0) {
609                                         leftRect.origin.x += rotatedLeftSize.width;
610                                 }
611                                 else if(_leftImageOrientation == 180.0) {
612                                         leftRect.origin.y += rotatedLeftSize.height;
613                                 }
614                                 else if(_leftImageOrientation == 270.0) {
615                                         leftRect.origin.x += rotatedLeftSize.width;
616                                         leftRect.origin.y += rotatedLeftSize.height;
617                                 }
618                         }
619                        
620                         if(_leftImageAngle != 0.0) {
621                                 CGContextSaveGState(context);
622                                 CGContextTranslateCTM(context, leftRect.origin.x, leftRect.origin.y);
623                                 CGContextRotateCTM(context, -_leftImageAngle * M_PI / 180.0);
624                                 CGContextTranslateCTM(context, -leftRect.origin.x, -leftRect.origin.y);
625                         }
626                        
627                         [_leftImage drawInRect:leftRect];
628
629                         if(_leftImageAngle != 0.0)
630                                 CGContextRestoreGState(context);
631                        
632                         if(_imageRotation == 0.0) {
633                                 if(_rightImageOrientation == 0.0) {
634                                         rightRect.origin.x += rotatedLeftSize.width;
635                                 }
636                                 else if(_rightImageOrientation == 90.0) {
637                                         rightRect.origin.x += rotatedLeftSize.width;
638                                         rightRect.origin.y += rotatedRightSize.height;
639                                 }
640                                 else if(_rightImageOrientation == 180.0) {
641                                         rightRect.origin.x += rotatedLeftSize.width + rotatedRightSize.width;
642                                         rightRect.origin.y += rotatedRightSize.height;
643                                 }
644                                 else if(_rightImageOrientation == 270.0) {
645                                         rightRect.origin.x += rotatedLeftSize.width + rotatedRightSize.width;
646                                 }
647                         }
648                         else if(_imageRotation == 90.0) {
649                                 if(_rightImageOrientation == 0.0) {
650                                         rightRect.origin.y += rotatedRightSize.height;
651                                 }
652                                 else if(_rightImageOrientation == 90.0) {
653                                         rightRect.origin.x += rotatedRightSize.width;
654                                         rightRect.origin.y += rotatedRightSize.height;
655                                 }
656                                 else if(_rightImageOrientation == 180.0) {
657                                         rightRect.origin.x += rotatedRightSize.width;
658                                 }
659                         }
660                         else if(_imageRotation == 180.0) {
661                                 if(_rightImageOrientation == 0.0) {
662                                         rightRect.origin.x += rotatedRightSize.width;
663                                         rightRect.origin.y += rotatedRightSize.height;
664                                 }
665                                 else if(_rightImageOrientation == 90.0) {
666                                         rightRect.origin.x += rotatedRightSize.width;
667                                 }
668                                 else if(_rightImageOrientation == 270.0) {
669                                         rightRect.origin.y += rotatedRightSize.height;
670                                 }
671                         }
672                         else if(_imageRotation == 270.0) {
673                                 if(_rightImageOrientation == 0.0) {
674                                         rightRect.origin.x += rotatedRightSize.width;
675                                         rightRect.origin.y += rotatedLeftSize.height;
676                                 }
677                                 else if(_rightImageOrientation == 90.0) {
678                                         rightRect.origin.y += rotatedLeftSize.height;
679                                 }
680                                 else if(_rightImageOrientation == 180.0) {
681                                         rightRect.origin.y += rotatedLeftSize.height + rotatedRightSize.height;
682                                 }
683                                 else if(_rightImageOrientation == 270.0) {
684                                         rightRect.origin.x += rotatedRightSize.width;
685                                         rightRect.origin.y += rotatedLeftSize.height + rotatedRightSize.height;
686                                 }
687                         }
688
689                         if(_rightImageAngle != 0.0) {
690                                 CGContextSaveGState(context);
691                                 CGContextTranslateCTM(context, rightRect.origin.x, rightRect.origin.y);
692                                 CGContextRotateCTM(context, -_rightImageAngle * M_PI / 180.0);
693                                 CGContextTranslateCTM(context, -rightRect.origin.x, -rightRect.origin.y);
694                         }
695                        
696                         [_rightImage drawInRect:rightRect];
697                        
698                         if(_rightImageAngle != 0.0)
699                                 CGContextRestoreGState(context);
700                 } else {
701                         if(_image) {
702                                 image = _image;
703                                 size = _imageSize;
704                         } else {
705                                 image = _leftImage ? _leftImage : _rightImage;
706                                 size = _leftImage ? _leftImageSize : _rightImageSize;
707                         }
708                        
709                         rect.size = size = [self _scaledSizeForSize:size usingScaling:_adjustedImageScaling bounds:bounds.size];
710                        
711                         if(_imageAngle == 0.0 || _imageAngle == 180.0) {
712                                 rect.origin.x = floorf((bounds.size.width  - size.width)  / 2.0);
713                                 rect.origin.y = floorf((bounds.size.height - size.height) / 2.0);
714                         } else {
715                                 rect.origin.x = floorf((bounds.size.width  - size.height) / 2.0);
716                                 rect.origin.y = floorf((bounds.size.height - size.width)  / 2.0);
717                         }
718                        
719                         if(_imageAngle == 90.0) {
720                                 rect.origin.y += rect.size.width;
721                         }
722                         else if(_imageAngle == 180.0) {
723                                 rect.origin.x += rect.size.width;
724                                 rect.origin.y += rect.size.height;
725                         }
726                         else if(_imageAngle == 270.0) {
727                                 rect.origin.x += rect.size.height;
728                         }
729                        
730                         if(_imageAngle != 0.0) {
731                                 CGContextSaveGState(context);
732                                 CGContextTranslateCTM(context, rect.origin.x, rect.origin.y);
733                                 CGContextRotateCTM(context, -_imageAngle * M_PI / 180.0);
734                                 CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y);
735                         }
736                        
737                         [image drawInRect:rect];
738                        
739                         if(_imageAngle != 0.0)
740                                 CGContextRestoreGState(context);
741                 }
742         }
743 }
744
745 @end
Note: See TracBrowser for help on using the browser.