Skip to content

Commit 9e68f7b

Browse files
committed
Image scaling functionality is now complete.
1 parent 5c615fb commit 9e68f7b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Applications/Review/ImageWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
- (NSString *)imageGamma;
6868
- (NSString *)imageProgressive;
6969

70+
- (void)scaleImageFromPopup:(id)sender;
71+
7072
@end
7173

7274
@interface NSObject (ImageWindowDelegates)

Applications/Review/ImageWindow.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ - (id)initWithContentsOfFile:(NSString *)path
253253
[scalePopup addItemWithTitle:@"700%"];
254254
[scalePopup setAutoresizingMask:(NSViewMaxYMargin | NSViewMinXMargin)];
255255
[scalePopup selectItemWithTitle:@"100%"];
256+
[scalePopup setTarget:self];
257+
[scalePopup setAction:@selector(scaleImageFromPopup:)];
256258
scrollView.scaleView = scalePopup;
257259

258260
[box addSubview:scrollView];
@@ -315,6 +317,24 @@ - (id)initWithContentsOfFile:(NSString *)path
315317
return self;
316318
}
317319

320+
- (void)scaleImageFromPopup:(id)sender
321+
{
322+
NSString *title = [scalePopup titleOfSelectedItem];
323+
/* Parse the percentage value — strip the trailing '%' */
324+
double percent = [[title substringToIndex:[title length] - 1] doubleValue];
325+
double factor = percent / 100.0;
326+
327+
NSSize baseSize = NSMakeSize(_visibleRep.pixelsWide, _visibleRep.pixelsHigh);
328+
NSSize scaledSize = NSMakeSize(round(baseSize.width * factor),
329+
round(baseSize.height * factor));
330+
331+
/* Resize the image to the scaled size — NSImageView will stretch it */
332+
[_image setSize:scaledSize];
333+
[imageView setFrameSize:scaledSize];
334+
[imageView setImage:nil]; /* force redraw */
335+
[imageView setImage:_image];
336+
}
337+
318338
- (void)dealloc
319339
{
320340
RELEASE(_window);

0 commit comments

Comments
 (0)