1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#import "FractalWindow.h"
static int counter = 1;
static NSString *typestrs[] =
{ @"z^2+c", @"z^3+c", @"z^4+z+c",
@"c z (1-z)", @"((z^2+c-1)/(2*z+c-2))^2" };
static NSString *schemestrs[] =
{ @"Monochrome", @"Gray16", @"RGB8", @"RGB27" };
@implementation FractalWindow
+ (NSString *) typeToString:(FTYPE)ft
{
return typestrs[ft];
}
+ (NSString *) schemeToString:(CSCHEME)cs
{
return schemestrs[cs];
}
- (id)initWithType:(FTYPE)ft
{
if ((self = [super init]) != nil)
{
NSRect frame;
int m = (NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask);
view = [[FractalView alloc] initWithType:ft];
frame = [NSWindow frameRectForContentRect:[view frame]
styleMask:m];
window = [[NSWindow alloc] initWithContentRect:frame
styleMask:m
backing: NSBackingStoreRetained
defer:YES];
[window setMinSize:frame.size];
[window
setTitle:[[NSString alloc]
initWithFormat:@"#%u(%@)"
locale: nil, counter++,
[FractalWindow typeToString:ft]]];
[window setReleasedWhenClosed:NO];
[window setDelegate:self];
[window setFrame:frame display:YES];
[window setMaxSize:frame.size];
[window setContentView:view];
[window setReleasedWhenClosed:YES];
// RELEASE(view);
[window center];
[window orderFrontRegardless];
[window makeKeyWindow];
[window display];
}
return self;
}
- (void)dealloc
{
RELEASE(window);
[super dealloc];
}
- (id)delegate
{
return delegate;
}
- (void)setDelegate:(id)aDelegate
{
delegate = aDelegate;
}
- (id)window
{
return window;
}
-(void)saveAs:(id)sender
{
NSSavePanel *savePanel;
int result;
NSString *fname, *msg;
savePanel = [NSSavePanel savePanel];
[savePanel setRequiredFileType:@"tiff"];
result = [savePanel runModal];
if (result == NSOKButton)
{
fname = [savePanel filename];
if ([view writeTIFF:fname] == NO)
{
msg = [[NSString alloc]
initWithFormat:@"Couldn't write %@"
locale: nil, fname];
NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil);
}
}
[[NSCursor arrowCursor] set];
}
-(void)resolution:(id)sender
{
int tag = [sender tag];
NSRect frame;
if (tag == [view resolution])
{
return;
}
[window setContentView:nil];
[view setResolution:tag];
frame = [NSWindow frameRectForContentRect:[view frame]
styleMask:[window styleMask]];
frame.origin = [window frame].origin;
[window setMinSize:frame.size];
[window setMaxSize:frame.size];
[window setFrame:frame display:NO];
[window setContentView:view];
}
-(void)colorScheme:(id)sender
{
int tag = [sender tag];
if (tag == [view colorScheme])
{
return;
}
[view setColorScheme:tag];
}
-(void)zoomOp:(id)sender
{
[view zoomOp:[sender tag]];
}
@end
|