Changeset 4876

Show
Ignore:
Timestamp:
08/22/07 22:59:03 (11 months ago)
Author:
morris
Message:

Rotate spreads correctly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHImage.m

    r4872 r4876  
    266266- (void)drawInRect:(NSRect)rect atAngle:(float)angle { 
    267267        NSImageRep              *imageRep; 
    268         CGContextRef    cgContext; 
    269         CGRect                  cgRect; 
    270         CGPoint                 cgPoint; 
     268        CGContextRef    context; 
    271269        BOOL                    restore = NO; 
    272270         
    273         cgContext       = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 
    274         cgRect          = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); 
     271        context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 
    275272 
    276273        if(_flipped || angle != 0.0f) { 
    277                 CGContextSaveGState(cgContext); 
     274                CGContextSaveGState(context); 
    278275                 
    279276                if(_flipped) { 
    280                         CGContextTranslateCTM(cgContext, 0.0f, rect.origin.y + rect.origin.y + rect.size.height); 
    281                         CGContextScaleCTM(cgContext, 1.0f, -1.0f); 
     277                        CGContextTranslateCTM(context, 0.0f, rect.origin.y + rect.origin.y + rect.size.height); 
     278                        CGContextScaleCTM(context, 1.0f, -1.0f); 
    282279                } else { 
    283                         cgPoint.x = rect.origin.x + (rect.size.width / 2.0f); 
    284                         cgPoint.y = rect.origin.y + (rect.size.height / 2.0f); 
    285  
    286                         CGContextTranslateCTM(cgContext, cgPoint.x, cgPoint.y); 
    287                         CGContextRotateCTM(cgContext, -angle * M_PI / 180.0f); 
    288                         CGContextTranslateCTM(cgContext, -cgPoint.x, -cgPoint.y); 
     280                        CGContextTranslateCTM(context, rect.origin.x, rect.origin.y); 
     281                        CGContextRotateCTM(context, -angle * M_PI / 180.0f); 
     282                        CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y); 
    289283                } 
    290284                 
     
    293287 
    294288        if(_CGImage) { 
    295                 CGContextDrawImage(cgContext, cgRect, _CGImage); 
     289                CGContextDrawImage(context, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height), _CGImage); 
    296290        } else { 
    297291                imageRep = [_NSImage bestRepresentationForDevice:NULL]; 
     
    306300         
    307301        if(restore) 
    308                 CGContextRestoreGState(cgContext); 
     302                CGContextRestoreGState(context); 
    309303} 
    310304 
  • Footagehead/trunk/FHImageView.m

    r4867 r4876  
    157157                return bounds; 
    158158         
    159         if(ABS(_imageRotation) == 90.0 || ABS(_imageRotation) == 270.0) { 
     159        if(ABS(_imageRotation) == 0.0 || ABS(_imageRotation) == 180.0) { 
     160                dx = bounds.width  / _combinedImageSize.width; 
     161                dy = bounds.height / _combinedImageSize.height; 
     162        } else { 
    160163                dx = bounds.width  / _combinedImageSize.height; 
    161164                dy = bounds.height / _combinedImageSize.width; 
    162         } else { 
    163                 dx = bounds.width  / _combinedImageSize.width; 
    164                 dy = bounds.height / _combinedImageSize.height; 
    165165        } 
    166166         
     
    466466- (void)drawRect:(NSRect)frame { 
    467467        FHImage         *image; 
    468         NSRect          bounds, rect
     468        NSRect          bounds, rect, leftRect, rightRect
    469469        NSSize          size; 
    470470         
     
    475475         
    476476        if(_image || _leftImage || _rightImage) { 
    477                 if(_image) { 
    478                         rect.size = [self _scaledImageSizeForSize:_combinedImageSize bounds:bounds.size]; 
     477                if(_leftImage && _rightImage) { 
     478                        size                    = [self _scaledImageSizeForSize:_combinedImageSize bounds:bounds.size]; 
     479                        leftRect.size   = [self _scaledImageSizeForSize:_leftSize bounds:bounds.size]; 
     480                        rightRect.size  = [self _scaledImageSizeForSize:_rightSize bounds:bounds.size]; 
     481                         
     482                        if(_imageRotation == 0.0) { 
     483                                leftRect.origin.x       = floorf((bounds.size.width  - size.width)  / 2.0); 
     484                                leftRect.origin.y       = floorf((bounds.size.height - size.height) / 2.0); 
     485                                rightRect.origin.x      = leftRect.origin.x + leftRect.size.width; 
     486                                rightRect.origin.y      = leftRect.origin.y; 
     487                        } 
     488                        else if(_imageRotation == 90.0) { 
     489                                rightRect.origin.x      = floorf((bounds.size.width - size.height) / 2.0); 
     490                                rightRect.origin.y      = rightRect.size.width + floorf((bounds.size.height - size.width) / 2.0); 
     491                                leftRect.origin.x = rightRect.origin.x; 
     492                                leftRect.origin.y = rightRect.origin.y + rightRect.size.width; 
     493                        } 
     494                        else if(_imageRotation == 180.0) { 
     495                                rightRect.origin.x      = rightRect.size.width + floorf((bounds.size.width - size.width) / 2.0); 
     496                                rightRect.origin.y      = rightRect.size.height + floorf((bounds.size.height - size.height) / 2.0); 
     497                                leftRect.origin.x       = rightRect.origin.x + rightRect.size.width; 
     498                                leftRect.origin.y       = rightRect.origin.y; 
     499                        } 
     500                        else if(_imageRotation == 270.0) { 
     501                                leftRect.origin.x       = leftRect.size.height + floorf((bounds.size.width - size.height) / 2.0); 
     502                                leftRect.origin.y       = floorf((bounds.size.height - size.width) / 2.0); 
     503                                rightRect.origin.x = leftRect.origin.x; 
     504                                rightRect.origin.y = leftRect.origin.y + leftRect.size.width; 
     505                        } 
     506                         
     507                        [_leftImage drawInRect:leftRect atAngle:_imageRotation]; 
     508                        [_rightImage drawInRect:rightRect atAngle:_imageRotation]; 
     509                } else { 
     510                        if(_image) { 
     511                                image = _image; 
     512                                size = _combinedImageSize; 
     513                        } else { 
     514                                image = _leftImage ? _leftImage : _rightImage; 
     515                                size = _leftImage ? _leftSize : _rightSize; 
     516                        } 
     517                         
     518                        rect.size = [self _scaledImageSizeForSize:size bounds:bounds.size]; 
    479519                        rect.origin.x = floorf((bounds.size.width  - rect.size.width)  / 2.0); 
    480520                        rect.origin.y = floorf((bounds.size.height - rect.size.height) / 2.0); 
    481521                         
    482                         [_image drawInRect:rect atAngle:_imageRotation]; 
    483                 } else { 
    484                         if(_leftImage && _rightImage) { 
    485                                 size = [self _scaledImageSizeForSize:_combinedImageSize bounds:bounds.size]; 
    486                                  
    487                                 rect.size = [self _scaledImageSizeForSize:_leftSize bounds:bounds.size]; 
    488                                 rect.origin.x = floorf((bounds.size.width  - size.width)  / 2.0); 
    489                                 rect.origin.y = floorf((bounds.size.height - size.height) / 2.0); 
    490  
    491                                 [_leftImage drawInRect:rect atAngle:_imageRotation]; 
    492  
    493                                 rect.origin.x += rect.size.width; 
    494                                 rect.size = [self _scaledImageSizeForSize:_rightSize bounds:bounds.size]; 
    495  
    496                                 [_rightImage drawInRect:rect atAngle:_imageRotation]; 
    497                         } 
    498                         else if(_leftImage || _rightImage) { 
    499                                 image = _leftImage ? _leftImage : _rightImage; 
    500                                 size = _leftImage ? _leftSize : _rightSize; 
    501                                  
    502                                 rect.size = [self _scaledImageSizeForSize:size bounds:bounds.size]; 
    503                                 rect.origin.x = floorf((bounds.size.width  - rect.size.width)  / 2.0); 
    504                                 rect.origin.y = floorf((bounds.size.height - rect.size.height) / 2.0); 
    505                                  
    506                                 [image drawInRect:rect atAngle:_imageRotation]; 
    507                         } 
     522                        [image drawInRect:rect atAngle:_imageRotation]; 
    508523                } 
    509524