mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 07:40:47 +00:00
* Headers/AppKit/NSImageCell.h:
* Headers/AppKit/NSCell.h: Move NSImageScaling constants to NSCell * Source/NSImageCell.m: * Source/NSCell.m: Refactor the image scaling logic to a private method in NSCell, -_scaleImageWithSize:toFitInSize:scalingType: which can be share by NSImageCell, NSButtonCell, and any other cell classes that need it. * Source/NSButtonCell.m: * Headers/AppKit/NSButtonCell.h: Implement -imageScaling and -setImageScaling methods. * Source/GSThemeDrawing.m: * Headers/Additions/GNUstepGUI/GSTheme.h: Remove the -drawImage:inButtonCell:withFrame:position: API intended to let themes substitute images right before drawing, as IMHO it's the wrong place to hook in new images (by the time this method was caleld, sizing/positionging was already done). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34160 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0f9c9bd394
commit
5eae61ca3e
9 changed files with 202 additions and 119 deletions
|
@ -36,6 +36,12 @@
|
|||
#import "GNUstepGUI/GSTheme.h"
|
||||
#import "GSGuiPrivate.h"
|
||||
|
||||
@interface NSCell (Private)
|
||||
- (NSSize) _scaleImageWithSize: (NSSize)imageSize
|
||||
toFitInSize: (NSSize)canvasSize
|
||||
scalingType: (NSImageScaling)scalingType;
|
||||
@end
|
||||
|
||||
@implementation NSImageCell
|
||||
|
||||
//
|
||||
|
@ -171,25 +177,6 @@ yBottomInRect(NSSize innerSize, NSRect outerRect, BOOL flipped)
|
|||
return NSMinY(outerRect);
|
||||
}
|
||||
|
||||
static inline NSSize
|
||||
scaleProportionally(NSSize imageSize, NSRect canvasRect, BOOL scaleUpOrDown)
|
||||
{
|
||||
float ratio;
|
||||
|
||||
/* Get the smaller ratio and scale the image size by it. */
|
||||
ratio = MIN(NSWidth(canvasRect) / imageSize.width,
|
||||
NSHeight(canvasRect) / imageSize.height);
|
||||
|
||||
/* Only scale down, unless scaleUpOrDown is YES */
|
||||
if (ratio < 1.0 || scaleUpOrDown)
|
||||
{
|
||||
imageSize.width *= ratio;
|
||||
imageSize.height *= ratio;
|
||||
}
|
||||
|
||||
return imageSize;
|
||||
}
|
||||
|
||||
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
|
||||
{
|
||||
NSPoint position;
|
||||
|
@ -205,35 +192,9 @@ scaleProportionally(NSSize imageSize, NSRect canvasRect, BOOL scaleUpOrDown)
|
|||
cellFrame = [self drawingRectForBounds: cellFrame];
|
||||
|
||||
realImageSize = [_cell_image size];
|
||||
|
||||
switch (_imageScaling)
|
||||
{
|
||||
case NSScaleProportionally:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleProportionally");
|
||||
imageSize = scaleProportionally (realImageSize, cellFrame, NO);
|
||||
break;
|
||||
}
|
||||
case NSScaleToFit:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleToFit");
|
||||
imageSize = cellFrame.size;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case NSScaleNone:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleNone");
|
||||
imageSize = realImageSize;
|
||||
break;
|
||||
}
|
||||
case NSImageScaleProportionallyUpOrDown:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSImageScaleProportionallyUpOrDown");
|
||||
imageSize = scaleProportionally (realImageSize, cellFrame, YES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
imageSize = [self _scaleImageWithSize: realImageSize
|
||||
toFitInSize: cellFrame.size
|
||||
scalingType: _imageScaling];
|
||||
|
||||
switch (_imageAlignment)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue