Show
Ignore:
Timestamp:
10/27/07 12:41:40 (1 year ago)
Author:
morris
Message:

Fix scaling in slideshow mode

Files:

Legend:

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

    r4906 r5019  
    4949        _backgroundColor = [[NSColor whiteColor] retain]; 
    5050 
    51     _labelAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 
    52         [NSFont boldSystemFont],        NSFontAttributeName, 
    53         [NSColor blackColor],           NSForegroundColorAttributeName, 
    54         NULL]; 
    55  
    5651        [[NSNotificationCenter defaultCenter] addObserver:self 
    5752                                                                                         selector:@selector(_FH_viewFrameDidChange:) 
     
    134129 
    135130- (void)_adjustFrameSize { 
     131        NSRect          frame; 
    136132        NSSize          visibleSize, imageSize, frameSize; 
    137133        CGFloat         diff, scrollerWidth, widthAdjustment, heightAdjustment; 
     
    143139        _adjustingFrameSize = YES; 
    144140         
    145         [_scrollView setHasHorizontalScroller:NO]; 
    146         [_scrollView setHasVerticalScroller:NO]; 
    147          
    148         visibleSize = [_scrollView documentVisibleRect].size; 
    149          
    150         _adjustedImageScaling = _imageScaling; 
    151          
    152         if(_imageScaling == FHScaleNone || 
    153            _imageScaling == FHScaleWidthProportionally || 
    154            _imageScaling == FHScaleHeightProportionally) { 
    155                 scrollerWidth = [NSScroller scrollerWidth]; 
    156                 widthAdjustment = heightAdjustment = 0.0; 
    157                 horizontalScroller = verticalScroller = NO; 
    158                  
    159                 imageSize = [self _scaledSizeForSize:_rotatedImageSize usingScaling:_imageScaling bounds:visibleSize]; 
    160  
    161                 if(_imageScaling == FHScaleNone) { 
    162                         if(imageSize.height > visibleSize.height && imageSize.width > visibleSize.width) 
    163                                 horizontalScroller = verticalScroller = YES; 
    164                         else if(imageSize.height > visibleSize.height) 
    165                                 verticalScroller = YES; 
    166                         else if(imageSize.width > visibleSize.width) 
    167                                 horizontalScroller = YES; 
     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]; 
    168206                } 
    169                 else if(_imageScaling == FHScaleWidthProportionally) { 
    170                         if(imageSize.height - visibleSize.height > scrollerWidth) { 
    171                                 diff = scrollerWidth - (visibleSize.width - imageSize.width); 
    172  
    173                                 if(diff > 0.0) 
    174                                         heightAdjustment = ceil((imageSize.height / imageSize.width) * diff); 
    175                                  
    176                                 verticalScroller = YES; 
    177                         } else { 
    178                                 _adjustedImageScaling = FHScaleProportionally; 
    179                         } 
    180                 } 
    181                 else if(_imageScaling == FHScaleHeightProportionally) { 
    182                         if(imageSize.width - visibleSize.width > scrollerWidth) { 
    183                                 diff = scrollerWidth - (visibleSize.height - imageSize.height); 
    184                                  
    185                                 if(diff > 0.0) 
    186                                         widthAdjustment = ceil((imageSize.width / imageSize.height) * diff); 
    187  
    188                                 horizontalScroller = YES; 
    189                         } else { 
    190                                 _adjustedImageScaling = FHScaleProportionally; 
    191                         } 
    192                 } 
    193                  
    194                 if(_imageScaling != _adjustedImageScaling) 
    195                         imageSize = [self _scaledSizeForSize:_rotatedImageSize usingScaling:_adjustedImageScaling bounds:visibleSize]; 
    196                  
    197                 frameSize = NSMakeSize(MAX(visibleSize.width, imageSize.width), MAX(visibleSize.height, imageSize.height)); 
    198                 frameSize.width -= widthAdjustment; 
    199                 frameSize.height -= heightAdjustment; 
    200                  
    201                 [self setFrameSize:frameSize]; 
    202                  
    203                 [_scrollView setHasHorizontalScroller:horizontalScroller]; 
    204                 [_scrollView setHasVerticalScroller:verticalScroller]; 
    205  
    206                 [self scrollPoint:NSMakePoint(0.0, frameSize.height)]; 
    207207        } else { 
    208                 [self setFrameSize:visibleSize]; 
     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; 
    209216        } 
    210217 
     
    283290        [_backgroundColor release]; 
    284291         
    285         [_label release]; 
    286         [_labelAttributes release]; 
    287  
    288292        [super dealloc]; 
    289293} 
     
    411415- (void)setImageScaling:(FHImageScaling)imageScaling { 
    412416        _imageScaling = imageScaling; 
    413  
     417         
    414418        [self _adjustFrameSize]; 
    415419         
     
    443447 
    444448- (void)setBackgroundColor:(NSColor *)color { 
    445         NSColor         *textColor; 
    446          
    447449        [color retain]; 
    448450        [_backgroundColor release]; 
     
    450452        _backgroundColor = color; 
    451453         
    452         if([_backgroundColor whiteComponent] < 0.5) 
    453                 textColor = [NSColor whiteColor]; 
    454         else 
    455                 textColor = [NSColor blackColor]; 
    456          
    457         [_labelAttributes setObject:textColor forKey:NSForegroundColorAttributeName]; 
    458  
    459454        [self setNeedsDisplay:YES]; 
    460455} 
     
    464459- (NSColor *)backgroundColor { 
    465460        return _backgroundColor; 
    466 } 
    467  
    468  
    469  
    470 - (void)setLabel:(NSString *)label { 
    471         [label retain]; 
    472         [_label release]; 
    473          
    474         _label = label; 
    475  
    476         [self setNeedsDisplay:YES]; 
    477 } 
    478  
    479  
    480  
    481 - (NSString *)label { 
    482         return _label; 
    483461} 
    484462 
     
    762740                                CGContextRestoreGState(context); 
    763741                } 
    764                          
    765                 if(_label && [_label length] > 0) 
    766                         [_label drawAtPoint:NSMakePoint(10.0, 10.0) withAttributes:_labelAttributes]; 
    767742        } 
    768743}