縮小率を右下に表示するようにした。後々の縮小保存で使うつもり。
実装では情報表示用に専用のカスタムビューを用意した。
SimpleViewerInfoView.h
@interface SimpleViewerInfoView : NSView {
CGFloat _ratio;
}
- (void)setRatio:(CGFloat)ratio;
@end
文字描画はこんな感じ。
SimpleViewerInfoView.m
#define INFORMATION_OFFSET_X 20.0
#define INFORMATION_OFFSET_Y 4.0
- (void)drawRect:(NSRect)rect {
int ratio_str = (int)(_ratio*100);
NSString *info = [NSString stringWithFormat:@"%d%%", ratio_str];
NSMutableDictionary *stringAttributes = [NSMutableDictionary dictionary];
[stringAttributes setObject:[NSFont boldSystemFontOfSize:12.0]
forKey: NSFontAttributeName];
[stringAttributes setObject:[NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:1.00]
forKey:NSForegroundColorAttributeName];
[stringAttributes setObject:[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.75]
forKey:NSStrokeColorAttributeName];
[stringAttributes setObject:[NSNumber numberWithFloat: -1.5]
forKey:NSStrokeWidthAttributeName];
NSSize size = [info sizeWithAttributes:stringAttributes];
NSRect bounds = [self bounds];
NSPoint p = NSMakePoint(bounds.size.width - size.width - INFORMATION_OFFSET_X,
INFORMATION_OFFSET_Y);
[NSGraphicsContext saveGraphicsState];
[info drawAtPoint:p withAttributes: stringAttributes];
[NSGraphicsContext restoreGraphicsState];
}
後はこれをパネルの conten viewへ張りつけ(addView:)てやれば良い。