Skip to content

Instantly share code, notes, and snippets.

@visigoth
Created November 25, 2010 20:55
Show Gist options
  • Select an option

  • Save visigoth/715903 to your computer and use it in GitHub Desktop.

Select an option

Save visigoth/715903 to your computer and use it in GitHub Desktop.
@interface HostView : NSView {
NSView *_docView;
CGFloat _scale;
}
@property (assign) CGFloat scale;
@end
@implementation HostView
@synthesize scale=_scale;
- (void)updateFrame {
NSRect frame = _docView.frame;
frame.size.width = frame.size.width * _scale;
frame.size.height = frame.size.height * _scale;
self.frame = frame;
}
- (void)setScale:(CGFloat)f {
_scale = f;
[docView scaleUnitSquareToSize:NSMakeSize(_scale, _scale)];
[self updateFrame];
}
- (void)documentFrameChanged:(NSNotification *)n {
[self updateFrame];
}
- (void)initWithDocumentView:(NSView *)docView {
_scale = 1.0;
_docView = [docView retain];
[self addSubview:_docView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(documentFrameChanged:) name:NSViewFrameDidChangeNotification object:_docView];
[self updateFrame];
}
- (void)dealloc {
[_docView release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment