mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 17:52:42 +00:00
* Headers/AppKit/NSImageCell.h:
* Source/NSImageCell.m: Add support for NSImageScaleProportionallyUpOrDown git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33309 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7383ae4b49
commit
54ff379877
3 changed files with 22 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
2011-06-15 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Headers/AppKit/NSImageCell.h:
|
||||
* Source/NSImageCell.m: Add support for NSImageScaleProportionallyUpOrDown
|
||||
|
||||
2011-06-14 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/NSImage.m: Use -bestRepresentationForRect:context:hints: in
|
||||
|
|
|
@ -47,9 +47,13 @@
|
|||
* or down) to fit exactly in the cell size.</p>
|
||||
*/
|
||||
typedef enum {
|
||||
NSScaleProportionally = 0,
|
||||
NSScaleToFit,
|
||||
NSScaleNone
|
||||
NSScaleProportionally = 0,
|
||||
NSScaleToFit = 1,
|
||||
NSScaleNone = 2,
|
||||
NSImageScaleProportionallyDown = 0,
|
||||
NSImageScaleAxesIndependently = 1,
|
||||
NSImageScaleNone = 2,
|
||||
NSImageScaleProportionallyUpOrDown = 3
|
||||
} NSImageScaling;
|
||||
|
||||
/**
|
||||
|
|
|
@ -172,7 +172,7 @@ yBottomInRect(NSSize innerSize, NSRect outerRect, BOOL flipped)
|
|||
}
|
||||
|
||||
static inline NSSize
|
||||
scaleProportionally(NSSize imageSize, NSRect canvasRect)
|
||||
scaleProportionally(NSSize imageSize, NSRect canvasRect, BOOL scaleUpOrDown)
|
||||
{
|
||||
float ratio;
|
||||
|
||||
|
@ -180,11 +180,8 @@ scaleProportionally(NSSize imageSize, NSRect canvasRect)
|
|||
ratio = MIN(NSWidth(canvasRect) / imageSize.width,
|
||||
NSHeight(canvasRect) / imageSize.height);
|
||||
|
||||
/* According to the API (see NSScaleProportionally), we should never
|
||||
* scale images up; we only scale them down. If you want your image
|
||||
* to scale both up and down, you should use NSScaleToFit.
|
||||
*/
|
||||
if (ratio < 1.0)
|
||||
/* Only scale down, unless scaleUpOrDown is YES */
|
||||
if (ratio < 1.0 || scaleUpOrDown)
|
||||
{
|
||||
imageSize.width *= ratio;
|
||||
imageSize.height *= ratio;
|
||||
|
@ -215,7 +212,7 @@ scaleProportionally(NSSize imageSize, NSRect canvasRect)
|
|||
case NSScaleProportionally:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleProportionally");
|
||||
imageSize = scaleProportionally (realImageSize, cellFrame);
|
||||
imageSize = scaleProportionally (realImageSize, cellFrame, NO);
|
||||
break;
|
||||
}
|
||||
case NSScaleToFit:
|
||||
|
@ -231,6 +228,12 @@ scaleProportionally(NSSize imageSize, NSRect canvasRect)
|
|||
imageSize = realImageSize;
|
||||
break;
|
||||
}
|
||||
case NSImageScaleProportionallyUpOrDown:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSImageScaleProportionallyUpOrDown");
|
||||
imageSize = scaleProportionally (realImageSize, cellFrame, YES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (_imageAlignment)
|
||||
|
|
Loading…
Reference in a new issue