1//
2//  PXPreviewResizeSizeView.m
3//  Pixen-XCode
4//
5//  Created by Ian Henderson on Fri Jul 16 2004.
6//  Copyright (c) 2004 Open Sword Group. All rights reserved.
7//
8
9#import "PXPreviewResizeSizeView.h"
10
11
12@implementation PXPreviewResizeSizeView
13
14- initWithFrame:(NSRect)frame
15{
16	[super initWithFrame:frame];
17#ifdef __COCOA__
18	shadow = [[NSShadow alloc] init];
19	[shadow setShadowBlurRadius:5];
20	[shadow setShadowOffset:NSMakeSize(0, 0)];
21	[shadow setShadowColor:[NSColor blackColor]];
22#else
23#warning GNUstep TODO
24#endif
25	[self updateScale:0];
26	return self;
27}
28
29- (void)dealloc
30{
31#ifdef __COCOA__
32	[shadow release];
33#endif
34	[super dealloc];
35}
36
37- (void)updateScale:(float)scale
38{
39	if (scale > 100000) {
40		return;
41	}
42	[scaleString release];
43#ifdef __COCOA__
44	scaleString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d%%", (int)(scale * 100)] attributes:[NSDictionary dictionaryWithObjectsAndKeys:
45		[NSFont fontWithName:@"Verdana" size:20], NSFontAttributeName,
46		[NSColor whiteColor], NSForegroundColorAttributeName,
47		shadow, NSShadowAttributeName,
48		nil]];
49#else
50#warning GNUstep TODO
51#endif
52	[self setNeedsDisplay:YES];
53}
54
55- (void)drawRect:(NSRect)rect
56{
57	[[NSColor clearColor] set];
58	NSRectFill([self frame]);
59	NSBezierPath *background = [NSBezierPath bezierPath];
60	NSPoint stringPoint = [self frame].origin;
61	if ([self frame].size.height >= [self frame].size.width) {
62		[background appendBezierPathWithOvalInRect:[self frame]];
63	}
64	else if ([self frame].size.height < [self frame].size.width) {
65		NSRect leftSide = NSMakeRect([self frame].origin.x, [self frame].origin.y, [self frame].size.height, [self frame].size.height);
66		NSRect rightSide = NSMakeRect([self frame].origin.x + [self frame].size.width - [self frame].size.height, [self frame].origin.y, [self frame].size.height, [self frame].size.height);
67		NSRect middle = NSMakeRect([self frame].origin.x + ([self frame].size.height / 2.0f), [self frame].origin.y, [self frame].size.width - [self frame].size.height, [self frame].size.height);
68		[background appendBezierPathWithOvalInRect:leftSide];
69		[background appendBezierPathWithOvalInRect:rightSide];
70		[background appendBezierPathWithRect:middle];
71	}
72	stringPoint.x += ([self frame].size.width - [scaleString size].width) / 2;
73	stringPoint.y += ([self frame].size.height - [scaleString size].height) / 2 + [scaleString size].height / 9;
74	[[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:.5] set];
75	[background fill];
76	[scaleString drawAtPoint:stringPoint];
77}
78
79- (NSSize)scaleStringSize
80{
81	NSSize size = [scaleString size];
82	return NSMakeSize(size.width * 1.3, size.height);
83}
84
85@end
86