File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6767- (NSString *)imageGamma ;
6868- (NSString *)imageProgressive ;
6969
70+ - (void )scaleImageFromPopup : (id )sender ;
71+
7072@end
7173
7274@interface NSObject (ImageWindowDelegates)
Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments