Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf88246

Browse files
committed
Scale the image to be displayed on the button
1 parent c29c773 commit bf88246

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/_macosx.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
4040
#define COMPILING_FOR_10_6
4141
#endif
42+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
43+
#define COMPILING_FOR_10_7
44+
#endif
4245
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
4346
#define COMPILING_FOR_10_10
4447
#endif
@@ -4883,9 +4886,12 @@ -(void)save_figure:(id)sender
48834886

48844887
int i;
48854888
NSRect rect;
4889+
NSSize size;
4890+
NSSize scale;
48864891

48874892
const float gap = 2;
48884893
const int height = 36;
4894+
const int imagesize = 24;
48894895

48904896
const char* basedir;
48914897

@@ -4958,20 +4964,32 @@ -(void)save_figure:(id)sender
49584964
NSMomentaryLightButton,
49594965
NSMomentaryLightButton};
49604966

4967+
rect.origin.x = 0;
4968+
rect.origin.y = 0;
4969+
rect.size.width = imagesize;
4970+
rect.size.height = imagesize;
4971+
#ifdef COMPILING_FOR_10_7
4972+
rect = [window convertRectToBacking: rect];
4973+
#endif
4974+
size = rect.size;
4975+
scale.width = imagesize / size.width;
4976+
scale.height = imagesize / size.height;
4977+
49614978
rect.size.width = 32;
49624979
rect.size.height = 32;
49634980
rect.origin.x = gap;
49644981
rect.origin.y = 0.5*(height - rect.size.height);
4982+
49654983
for (i = 0; i < 7; i++)
49664984
{
4967-
const NSSize size = {24, 24};
49684985
NSString* filename = [dir stringByAppendingPathComponent: images[i]];
49694986
NSImage* image = [[NSImage alloc] initWithContentsOfFile: filename];
49704987
buttons[i] = [[NSButton alloc] initWithFrame: rect];
49714988
[image setSize: size];
49724989
[buttons[i] setBezelStyle: NSShadowlessSquareBezelStyle];
49734990
[buttons[i] setButtonType: buttontypes[i]];
49744991
[buttons[i] setImage: image];
4992+
[buttons[i] scaleUnitSquareToSize: scale];
49754993
[buttons[i] setImagePosition: NSImageOnly];
49764994
[buttons[i] setToolTip: tooltips[i]];
49774995
[[window contentView] addSubview: buttons[i]];

0 commit comments

Comments
 (0)