Rev 5380 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5380 | Rev 5964 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | ||
1 | #import <Cocoa/Cocoa.h>
|
2 | #import <Cocoa/Cocoa.h>
|
2 | 3 | ||
- | 4 | #include "compat.h"
|
|
3 | #include "baselayer.h"
|
5 | #include "baselayer.h"
|
- | 6 | #include "build.h"
|
|
- | 7 | #include "editor.h"
|
|
- | 8 | ||
- | 9 | static CGRect CGRectChangeXY(CGRect const rect, CGFloat const x, CGFloat const y) |
|
- | 10 | {
|
|
- | 11 | return CGRectMake(x, y, rect.size.width, rect.size.height); |
|
- | 12 | }
|
|
- | 13 | static CGRect CGSizeAddXY(CGSize const size, CGFloat const x, CGFloat const y) |
|
- | 14 | {
|
|
- | 15 | return CGRectMake(x, y, size.width, size.height); |
|
- | 16 | }
|
|
- | 17 | #if 0
|
|
- | 18 | static CGFloat CGRightEdge(CGRect rect) |
|
- | 19 | {
|
|
- | 20 | return rect.origin.x + rect.size.width; |
|
- | 21 | }
|
|
- | 22 | static CGFloat CGTopEdge(CGRect rect) |
|
- | 23 | {
|
|
- | 24 | return rect.origin.y + rect.size.height; |
|
- | 25 | }
|
|
- | 26 | #endif |
|
- | 27 | ||
- | 28 | static void setFontToSmall(id control) |
|
- | 29 | {
|
|
- | 30 | [control setFont:[NSFont fontWithDescriptor:[[control font] fontDescriptor] size:[NSFont smallSystemFontSize]]]; |
|
- | 31 | }
|
|
- | 32 | ||
- | 33 | static void setControlToSmall(id control) |
|
- | 34 | {
|
|
- | 35 | #ifdef MAC_OS_X_VERSION_10_12 |
|
- | 36 | [control setControlSize:NSControlSizeSmall]; |
|
- | 37 | #else |
|
- | 38 | [control setControlSize:NSSmallControlSize]; |
|
- | 39 | #endif |
|
- | 40 | }
|
|
- | 41 | ||
- | 42 | static NSTextField * makeLabel(NSString * labelText) |
|
- | 43 | {
|
|
- | 44 | NSTextField *textField = [[NSTextField alloc] init]; |
|
- | 45 | setFontToSmall(textField); |
|
- | 46 | setControlToSmall([textField cell]); |
|
- | 47 | [textField setStringValue:labelText]; |
|
- | 48 | [textField setBezeled:NO]; |
|
- | 49 | [textField setDrawsBackground:NO]; |
|
- | 50 | [textField setEditable:NO]; |
|
- | 51 | [textField setSelectable:NO]; |
|
- | 52 | [textField sizeToFit]; |
|
- | 53 | return textField;
|
|
- | 54 | }
|
|
- | 55 | ||
- | 56 | static NSButton * makeCheckbox(NSString * labelText) |
|
- | 57 | {
|
|
- | 58 | NSButton *checkbox = [[NSButton alloc] init]; |
|
- | 59 | setFontToSmall(checkbox); |
|
- | 60 | setControlToSmall([checkbox cell]); |
|
- | 61 | [checkbox setTitle:labelText]; |
|
- | 62 | [checkbox setButtonType:NSSwitchButton]; |
|
- | 63 | [checkbox sizeToFit]; |
|
- | 64 | return checkbox;
|
|
- | 65 | }
|
|
- | 66 | ||
- | 67 | static NSPopUpButton * makeComboBox(void) |
|
- | 68 | {
|
|
- | 69 | NSPopUpButton *comboBox = [[NSPopUpButton alloc] init]; |
|
- | 70 | [comboBox setPullsDown:NO]; |
|
- | 71 | setFontToSmall(comboBox); |
|
- | 72 | setControlToSmall([comboBox cell]); |
|
- | 73 | [comboBox setBezelStyle:NSRoundedBezelStyle]; |
|
- | 74 | [comboBox setPreferredEdge:NSMaxYEdge]; |
|
- | 75 | [[comboBox cell] setArrowPosition:NSPopUpArrowAtCenter]; |
|
- | 76 | [comboBox sizeToFit]; |
|
- | 77 | return comboBox;
|
|
- | 78 | }
|
|
4 | 79 | ||
5 | static id nsapp; |
80 | static id nsapp; |
6 | 81 | ||
- | 82 | static struct { |
|
- | 83 | int fullscreen; |
|
- | 84 | int xdim2d, ydim2d; |
|
- | 85 | int xdim3d, ydim3d, bpp3d; |
|
- | 86 | int forcesetup; |
|
- | 87 | } settings;
|
|
- | 88 | ||
7 | @interface StartupWinController : NSWindowController |
89 | @interface StartupWindow : NSWindow <NSWindowDelegate> |
8 | {
|
90 | {
|
- | 91 | NSMutableArray *modeslist2d; |
|
- | 92 | NSMutableArray *modeslist3d; |
|
- | 93 | ||
9 | IBOutlet NSButton *alwaysShowButton; |
94 | NSButton *alwaysShowButton; |
10 | IBOutlet NSButton *fullscreenButton; |
95 | NSButton *fullscreenButton; |
11 | IBOutlet NSTextView *messagesView; |
96 | NSTextView *messagesView; |
12 | IBOutlet NSTabView *tabView; |
97 | NSTabView *tabView; |
- | 98 | NSTabViewItem *tabViewItemSetup; |
|
- | 99 | NSTabViewItem *tabViewItemMessageLog; |
|
- | 100 | NSPopUpButton *videoMode2DPUButton; |
|
13 | IBOutlet NSComboBox *videoModeCbox; |
101 | NSPopUpButton *videoMode3DPUButton; |
14 | 102 | ||
15 | IBOutlet NSButton *cancelButton; |
103 | NSButton *cancelButton; |
16 | IBOutlet NSButton *startButton; |
104 | NSButton *startButton; |
17 | }
|
105 | }
|
18 | 106 | ||
19 | - (IBAction)alwaysShowClicked:(id)sender; |
- | |
20 | - (IBAction)fullscreenClicked:(id)sender; |
107 | - (StartupWindow *)init; |
21 | 108 | ||
- | 109 | - (void)dealloc; |
|
- | 110 | - (void)populateVideoModes:(BOOL)firstTime; |
|
- | 111 | ||
- | 112 | - (void)fullscreenClicked:(id)sender; |
|
- | 113 | ||
22 | - (IBAction)cancel:(id)sender; |
114 | - (void)cancel:(id)sender; |
23 | - (IBAction)start:(id)sender; |
115 | - (void)start:(id)sender; |
24 | 116 | ||
25 | - (void)setupRunMode; |
117 | - (void)setupRunMode; |
26 | - (void)setupMessagesMode; |
118 | - (void)setupMessagesMode; |
- | 119 | ||
27 | - (void)putsMessage:(NSString *)str; |
120 | - (void)putsMessage:(NSString *)str; |
28 | - (void)setTitle:(NSString *)str; |
- | |
- | 121 | ||
29 | @end
|
122 | @end
|
30 | 123 | ||
- | 124 | @implementation StartupWindow : NSWindow |
|
- | 125 | ||
- | 126 | - (StartupWindow *)init |
|
- | 127 | {
|
|
- | 128 | NSUInteger const style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; |
|
- | 129 | CGRect const windowFrame = CGRectMake(0, 0, 480, 280); |
|
- | 130 | self = [super initWithContentRect:windowFrame styleMask:style backing:NSBackingStoreBuffered defer:NO]; |
|
- | 131 | ||
- | 132 | if (self) |
|
- | 133 | {
|
|
- | 134 | // window properties |
|
- | 135 | [self setDelegate:self]; |
|
- | 136 | [self setReleasedWhenClosed:NO]; |
|
- | 137 | #if defined MAC_OS_X_VERSION_10_6 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 |
|
- | 138 | [self setPreventsApplicationTerminationWhenModal:NO]; |
|
- | 139 | #else |
|
- | 140 | SEL selector = @selector(setPreventsApplicationTerminationWhenModal:); |
|
- | 141 | if ([self respondsToSelector:selector]) |
|
- | 142 | {
|
|
- | 143 | BOOL argument = NO; |
|
- | 144 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:selector]]; |
|
- | 145 | [invocation setSelector:selector]; |
|
- | 146 | [invocation setTarget:self]; |
|
- | 147 | [invocation setArgument:&argument atIndex:2]; |
|
- | 148 | [invocation invoke]; |
|
- | 149 | [invocation release]; |
|
- | 150 | }
|
|
- | 151 | #endif |
|
- | 152 | #if defined MAC_OS_X_VERSION_10_3 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3 |
|
- | 153 | [self setContentMinSize:[[self contentView] frame].size]; |
|
- | 154 | #else |
|
- | 155 | [self setMinSize:[NSWindow frameRectForContentRect:[[self contentView] frame] styleMask:[self styleMask]].size]; |
|
- | 156 | #endif |
|
- | 157 | ||
- | 158 | ||
- | 159 | // image on the left |
|
- | 160 | CGRect const imageFrame = CGRectMake(0, 0, 100, 280); |
|
- | 161 | NSImageView * imageView = [[NSImageView alloc] initWithFrame:imageFrame]; |
|
- | 162 | #ifdef MAC_OS_X_VERSION_10_5 |
|
- | 163 | [imageView setImageScaling:NSImageScaleNone]; |
|
- | 164 | #else |
|
- | 165 | [imageView setImageScaling:NSScaleNone]; |
|
- | 166 | #endif |
|
- | 167 | [imageView setImage:[NSImage imageNamed:@"build"]]; |
|
- | 168 | [[self contentView] addSubview:imageView]; |
|
- | 169 | [imageView setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable]; |
|
- | 170 | ||
- | 171 | ||
- | 172 | // buttons |
|
- | 173 | CGFloat const buttonWidth = 80;
|
|
- | 174 | CGFloat const buttonHeight = 32;
|
|
- | 175 | ||
- | 176 | CGRect const startButtonFrame = CGRectMake(windowFrame.size.width - buttonWidth, 0, buttonWidth, buttonHeight); |
|
- | 177 | startButton = [[NSButton alloc] initWithFrame:startButtonFrame]; |
|
- | 178 | [[self contentView] addSubview:startButton]; |
|
- | 179 | [startButton setTitle:@"Start"]; |
|
- | 180 | [startButton setTarget:self]; |
|
- | 181 | [startButton setAction:@selector(start:)]; |
|
- | 182 | [startButton setBezelStyle:NSRoundedBezelStyle]; |
|
- | 183 | [startButton setKeyEquivalent:@"\r"]; |
|
- | 184 | [startButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin]; |
|
- | 185 | ||
- | 186 | CGRect const cancelButtonFrame = CGRectMake(startButtonFrame.origin.x - buttonWidth, 0, buttonWidth, buttonHeight); |
|
- | 187 | cancelButton = [[NSButton alloc] initWithFrame:cancelButtonFrame]; |
|
- | 188 | [[self contentView] addSubview:cancelButton]; |
|
- | 189 | [cancelButton setTitle:@"Cancel"]; |
|
- | 190 | [cancelButton setTarget:self]; |
|
- | 191 | [cancelButton setAction:@selector(cancel:)]; |
|
- | 192 | [cancelButton setBezelStyle:NSRoundedBezelStyle]; |
|
- | 193 | [cancelButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin]; |
|
- | 194 | ||
- | 195 | ||
- | 196 | // tab frame |
|
- | 197 | CGRect const tabViewFrame = CGRectMake(imageFrame.size.width, buttonHeight, windowFrame.size.width - imageFrame.size.width, windowFrame.size.height - buttonHeight - 5); |
|
- | 198 | tabView = [[NSTabView alloc] initWithFrame:tabViewFrame]; |
|
- | 199 | [[self contentView] addSubview:tabView]; |
|
- | 200 | setFontToSmall(tabView); |
|
- | 201 | setControlToSmall(tabView); |
|
- | 202 | [tabView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
|
- | 203 | ||
- | 204 | ||
- | 205 | // setup tab |
|
- | 206 | ||
- | 207 | tabViewItemSetup = [[NSTabViewItem alloc] init]; |
|
- | 208 | [tabView addTabViewItem:tabViewItemSetup]; |
|
- | 209 | [tabViewItemSetup setLabel:@"Setup"]; |
|
- | 210 | CGRect const tabViewItemSetupFrame = [[tabViewItemSetup view] frame]; |
|
- | 211 | ||
- | 212 | ||
- | 213 | // always show checkbox |
|
- | 214 | alwaysShowButton = makeCheckbox(@"Always show this window at startup"); |
|
- | 215 | [[tabViewItemSetup view] addSubview:alwaysShowButton]; |
|
- | 216 | CGSize const alwaysShowButtonSize = [alwaysShowButton frame].size; |
|
- | 217 | CGRect const alwaysShowButtonFrame = CGSizeAddXY(alwaysShowButtonSize, tabViewItemSetupFrame.size.width - alwaysShowButtonSize.width, 0); |
|
- | 218 | [alwaysShowButton setFrame:alwaysShowButtonFrame]; |
|
- | 219 | [alwaysShowButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin]; |
|
- | 220 | ||
- | 221 | ||
- | 222 | // video mode selectors and labels |
|
- | 223 | NSTextField * label2DVideoMode = makeLabel(@"2D Video mode:"); |
|
- | 224 | [[tabViewItemSetup view] addSubview:label2DVideoMode]; |
|
- | 225 | CGSize const label2DVideoModeSize = [label2DVideoMode frame].size; |
|
- | 226 | [label2DVideoMode setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
|
- | 227 | ||
- | 228 | NSTextField * label3DVideoMode = makeLabel(@"3D Video mode:"); |
|
- | 229 | [[tabViewItemSetup view] addSubview:label3DVideoMode]; |
|
- | 230 | CGSize const label3DVideoModeSize = [label3DVideoMode frame].size; |
|
- | 231 | [label3DVideoMode setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
|
- | 232 | ||
- | 233 | fullscreenButton = makeCheckbox(@"Fullscreen"); |
|
- | 234 | [[tabViewItemSetup view] addSubview:fullscreenButton]; |
|
- | 235 | CGSize const fullscreenButtonSize = [fullscreenButton frame].size; |
|
- | 236 | [fullscreenButton setAction:@selector(fullscreenClicked:)]; |
|
- | 237 | [fullscreenButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
|
- | 238 | ||
- | 239 | CGFloat const labelsVideoModeRightEdge = max(label2DVideoModeSize.width, label3DVideoModeSize.width); |
|
- | 240 | ||
- | 241 | videoMode2DPUButton = makeComboBox(); |
|
- | 242 | [[tabViewItemSetup view] addSubview:videoMode2DPUButton]; |
|
- | 243 | CGSize const videoMode2DPUButtonSize = [videoMode2DPUButton frame].size; |
|
- | 244 | CGFloat const videoMode2DButtonX = labelsVideoModeRightEdge; |
|
- | 245 | CGRect const videoMode2DPUButtonFrame = CGRectMake(videoMode2DButtonX, tabViewItemSetupFrame.size.height - videoMode2DPUButtonSize.height, tabViewItemSetupFrame.size.width - videoMode2DButtonX - fullscreenButtonSize.width, videoMode2DPUButtonSize.height); |
|
- | 246 | [videoMode2DPUButton setFrame:videoMode2DPUButtonFrame]; |
|
- | 247 | [videoMode2DPUButton setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
|
- | 248 | ||
- | 249 | videoMode3DPUButton = makeComboBox(); |
|
- | 250 | [[tabViewItemSetup view] addSubview:videoMode3DPUButton]; |
|
- | 251 | CGSize const videoMode3DPUButtonSize = [videoMode3DPUButton frame].size; |
|
- | 252 | CGFloat const videoMode3DButtonX = labelsVideoModeRightEdge; |
|
31 | @implementation StartupWinController |
253 | CGRect const videoMode3DPUButtonFrame = CGRectMake(videoMode3DButtonX, videoMode2DPUButtonFrame.origin.y - videoMode3DPUButtonSize.height, tabViewItemSetupFrame.size.width - videoMode3DButtonX - fullscreenButtonSize.width, videoMode3DPUButtonSize.height); |
- | 254 | [videoMode3DPUButton setFrame:videoMode3DPUButtonFrame]; |
|
- | 255 | [videoMode3DPUButton setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
|
- | 256 | ||
- | 257 | CGRect const label2DVideoModeFrame = CGSizeAddXY(label2DVideoModeSize, 0, videoMode2DPUButtonFrame.origin.y + rintf((videoMode2DPUButtonSize.height - label2DVideoModeSize.height) * 0.5f) + 1); |
|
- | 258 | [label2DVideoMode setFrame:label2DVideoModeFrame]; |
|
- | 259 | ||
- | 260 | CGRect const label3DVideoModeFrame = CGSizeAddXY(label3DVideoModeSize, 0, videoMode3DPUButtonFrame.origin.y + rintf((videoMode3DPUButtonSize.height - label3DVideoModeSize.height) * 0.5f) + 1); |
|
- | 261 | [label3DVideoMode setFrame:label3DVideoModeFrame]; |
|
- | 262 | ||
- | 263 | CGRect const fullscreenButtonFrame = CGSizeAddXY(fullscreenButtonSize, tabViewItemSetupFrame.size.width - fullscreenButtonSize.width, videoMode3DPUButtonFrame.origin.y + rintf((videoMode3DPUButtonSize.height - fullscreenButtonSize.height) * 0.5f) + 1); |
|
- | 264 | [fullscreenButton setFrame:fullscreenButtonFrame]; |
|
32 | 265 | ||
- | 266 | ||
- | 267 | // message log tab |
|
- | 268 | ||
- | 269 | tabViewItemMessageLog = [[NSTabViewItem alloc] init]; |
|
- | 270 | [tabView addTabViewItem:tabViewItemMessageLog]; |
|
- | 271 | [tabViewItemMessageLog setLabel:@"Message Log"]; |
|
- | 272 | CGRect const tabViewItemMessageLogFrame = [[tabViewItemMessageLog view] frame]; |
|
- | 273 | ||
- | 274 | ||
- | 275 | // message log |
|
- | 276 | NSScrollView * messagesScrollView = [[NSScrollView alloc] initWithFrame:CGRectChangeXY(tabViewItemMessageLogFrame, 0, 0)]; |
|
- | 277 | [[tabViewItemMessageLog view] addSubview:messagesScrollView]; |
|
- | 278 | [messagesScrollView setBorderType:NSBezelBorder]; |
|
- | 279 | [messagesScrollView setHasVerticalScroller:YES]; |
|
- | 280 | [messagesScrollView setHasHorizontalScroller:NO]; |
|
- | 281 | setControlToSmall([[messagesScrollView verticalScroller] cell]); |
|
- | 282 | NSSize const messagesScrollViewContentSize = [messagesScrollView contentSize]; |
|
- | 283 | [messagesScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
|
- | 284 | ||
- | 285 | messagesView = [[NSTextView alloc] initWithFrame:CGRectMake(0, 0, messagesScrollViewContentSize.width, messagesScrollViewContentSize.height)]; |
|
- | 286 | [messagesScrollView setDocumentView:messagesView]; |
|
- | 287 | [messagesView setEditable:NO]; |
|
- | 288 | [messagesView setRichText:NO]; |
|
- | 289 | setFontToSmall(messagesView); |
|
- | 290 | [messagesView setMinSize:CGSizeMake(0.0, messagesScrollViewContentSize.height)]; |
|
- | 291 | [messagesView setMaxSize:CGSizeMake(FLT_MAX, FLT_MAX)]; |
|
- | 292 | [messagesView setVerticallyResizable:YES]; |
|
- | 293 | [messagesView setHorizontallyResizable:NO]; |
|
- | 294 | [messagesView setAutoresizingMask:NSViewWidthSizable]; |
|
- | 295 | ||
- | 296 | [[messagesView textContainer] setContainerSize:CGSizeMake(messagesScrollViewContentSize.width, FLT_MAX)]; |
|
- | 297 | [[messagesView textContainer] setWidthTracksTextView:YES]; |
|
- | 298 | }
|
|
- | 299 | ||
- | 300 | return self;
|
|
- | 301 | }
|
|
- | 302 | ||
- | 303 | - (BOOL)canBecomeKeyWindow |
|
- | 304 | {
|
|
- | 305 | return YES;
|
|
- | 306 | }
|
|
- | 307 | ||
- | 308 | - (BOOL)canBecomeMainWindow |
|
- | 309 | {
|
|
- | 310 | return YES;
|
|
- | 311 | }
|
|
- | 312 | ||
33 | - (IBAction)alwaysShowClicked:(id)sender |
313 | - (BOOL) windowShouldClose:(id)sender |
34 | {
|
314 | {
|
35 | UNREFERENCED_PARAMETER(sender); |
315 | UNREFERENCED_PARAMETER(sender); |
- | 316 | ||
- | 317 | [nsapp abortModal]; |
|
- | 318 | ||
- | 319 | return YES;
|
|
- | 320 | }
|
|
- | 321 | ||
- | 322 | - (void)dealloc |
|
- | 323 | {
|
|
- | 324 | [modeslist3d release]; |
|
- | 325 | [super dealloc]; |
|
36 | }
|
326 | }
|
37 | 327 | ||
- | 328 | - (void)populateVideoModes:(BOOL)firstTime |
|
- | 329 | {
|
|
- | 330 | int i, mode3d, fullscreen = ([fullscreenButton state] == NSOnState); |
|
- | 331 | int mode2d, idx2d = -1;
|
|
- | 332 | int idx3d = -1;
|
|
- | 333 | int xdim2d = 0, ydim2d = 0; |
|
- | 334 | int const bpp2d = 8;
|
|
- | 335 | int xdim = 0, ydim = 0, bpp = 0; |
|
- | 336 | ||
- | 337 | if (firstTime) { |
|
- | 338 | xdim2d = settings.xdim2d;
|
|
- | 339 | ydim2d = settings.ydim2d;
|
|
- | 340 | xdim = settings.xdim3d;
|
|
- | 341 | ydim = settings.ydim3d;
|
|
- | 342 | bpp = settings.bpp3d;
|
|
- | 343 | } else { |
|
- | 344 | mode2d = [[modeslist2d objectAtIndex:[videoMode2DPUButton indexOfSelectedItem]] intValue]; |
|
- | 345 | if (mode2d >= 0) { |
|
- | 346 | xdim2d = validmode[mode2d].xdim; |
|
- | 347 | ydim2d = validmode[mode2d].ydim; |
|
- | 348 | }
|
|
- | 349 | ||
- | 350 | mode3d = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue]; |
|
- | 351 | if (mode3d >= 0) { |
|
- | 352 | xdim = validmode[mode3d].xdim; |
|
- | 353 | ydim = validmode[mode3d].ydim; |
|
- | 354 | bpp = validmode[mode3d].bpp; |
|
- | 355 | }
|
|
- | 356 | }
|
|
- | 357 | ||
- | 358 | ||
- | 359 | mode2d = checkvideomode(&xdim2d, &ydim2d, bpp2d, fullscreen, 1); |
|
- | 360 | ||
- | 361 | [modeslist2d release]; |
|
- | 362 | [videoMode2DPUButton removeAllItems]; |
|
- | 363 | ||
- | 364 | modeslist2d = [[NSMutableArray alloc] init]; |
|
- | 365 | ||
- | 366 | for (i = 0; i < validmodecnt; i++) { |
|
- | 367 | if (fullscreen == validmode[i].fs) { |
|
- | 368 | if (i == mode2d) idx2d = [modeslist2d count]; |
|
- | 369 | [modeslist2d addObject:[NSNumber numberWithInt:i]]; |
|
- | 370 | [videoMode2DPUButton addItemWithTitle:[NSString stringWithFormat:@"%d %C %d", |
|
- | 371 | validmode[i].xdim, 0xd7, validmode[i].ydim]]; |
|
- | 372 | }
|
|
- | 373 | }
|
|
- | 374 | ||
- | 375 | if (idx2d >= 0) [videoMode2DPUButton selectItemAtIndex:idx2d]; |
|
- | 376 | ||
- | 377 | ||
- | 378 | mode3d = checkvideomode(&xdim, &ydim, bpp, fullscreen, 1); |
|
- | 379 | if (mode3d < 0) { |
|
- | 380 | int i, cd[] = { 32, 24, 16, 15, 8, 0 }; |
|
- | 381 | for (i=0; cd[i]; ) { if (cd[i] >= bpp) i++; else break; } |
|
- | 382 | for ( ; cd[i]; i++) { |
|
- | 383 | mode3d = checkvideomode(&xdim, &ydim, cd[i], fullscreen, 1); |
|
- | 384 | if (mode3d < 0) continue; |
|
- | 385 | break;
|
|
- | 386 | }
|
|
- | 387 | }
|
|
- | 388 | ||
- | 389 | [modeslist3d release]; |
|
- | 390 | [videoMode3DPUButton removeAllItems]; |
|
- | 391 | ||
- | 392 | modeslist3d = [[NSMutableArray alloc] init]; |
|
- | 393 | ||
- | 394 | for (i = 0; i < validmodecnt; i++) { |
|
- | 395 | if (fullscreen == validmode[i].fs) { |
|
- | 396 | if (i == mode3d) idx3d = [modeslist3d count]; |
|
- | 397 | [modeslist3d addObject:[NSNumber numberWithInt:i]]; |
|
- | 398 | [videoMode3DPUButton addItemWithTitle:[NSString stringWithFormat:@"%d %C %d %d-bpp", |
|
- | 399 | validmode[i].xdim, 0xd7, validmode[i].ydim, validmode[i].bpp]]; |
|
- | 400 | }
|
|
- | 401 | }
|
|
- | 402 | ||
- | 403 | if (idx3d >= 0) [videoMode3DPUButton selectItemAtIndex:idx3d]; |
|
- | 404 | }
|
|
- | 405 | ||
38 | - (IBAction)fullscreenClicked:(id)sender |
406 | - (void)fullscreenClicked:(id)sender |
39 | {
|
407 | {
|
40 | UNREFERENCED_PARAMETER(sender); |
408 | UNREFERENCED_PARAMETER(sender); |
41 | 409 | ||
42 | // XXX: recalculate the video modes list to take into account the fullscreen status |
410 | [self populateVideoModes:NO]; |
43 | }
|
411 | }
|
44 | 412 | ||
45 | - (IBAction)cancel:(id)sender |
413 | - (void)cancel:(id)sender |
46 | {
|
414 | {
|
47 | UNREFERENCED_PARAMETER(sender); |
415 | UNREFERENCED_PARAMETER(sender); |
48 | 416 | ||
49 | [nsapp abortModal]; |
417 | [nsapp abortModal]; |
50 | }
|
418 | }
|
51 | 419 | ||
52 | - (IBAction)start:(id)sender |
420 | - (void)start:(id)sender |
53 | {
|
421 | {
|
54 | UNREFERENCED_PARAMETER(sender); |
422 | UNREFERENCED_PARAMETER(sender); |
55 | 423 | ||
- | 424 | int mode2d = [[modeslist2d objectAtIndex:[videoMode2DPUButton indexOfSelectedItem]] intValue]; |
|
- | 425 | if (mode2d >= 0) { |
|
- | 426 | settings.xdim2d = validmode[mode2d].xdim; |
|
- | 427 | settings.ydim2d = validmode[mode2d].ydim; |
|
- | 428 | settings.fullscreen = validmode[mode2d].fs; |
|
- | 429 | }
|
|
- | 430 | ||
- | 431 | int mode = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue]; |
|
- | 432 | if (mode >= 0) { |
|
- | 433 | settings.xdim3d = validmode[mode].xdim; |
|
- | 434 | settings.ydim3d = validmode[mode].ydim; |
|
- | 435 | settings.bpp3d = validmode[mode].bpp; |
|
- | 436 | settings.fullscreen = validmode[mode].fs; |
|
- | 437 | }
|
|
- | 438 | ||
56 | // XXX: write the states of the form controls to their respective homes |
439 | settings.forcesetup = [alwaysShowButton state] == NSOnState; |
- | 440 | ||
57 | [nsapp stopModal]; |
441 | [nsapp stopModal]; |
58 | }
|
442 | }
|
59 | 443 | ||
60 | - (void)setupRunMode |
444 | - (void)setupRunMode |
61 | {
|
445 | {
|
- | 446 | getvalidmodes(); |
|
- | 447 | ||
- | 448 | [fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)]; |
|
62 | // XXX: populate the lists and set everything up to represent the current options |
449 | [alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)]; |
- | 450 | [self populateVideoModes:YES]; |
|
63 | 451 | ||
64 | // enable all the controls on the Configuration page |
452 | // enable all the controls on the Configuration page |
65 | NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator]; |
453 | NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator]; |
66 | NSControl *control; |
454 | NSControl *control; |
67 | while ((control = [enumerator nextObject])) |
455 | while ((control = [enumerator nextObject])) |
- | 456 | {
|
|
- | 457 | if ([control respondsToSelector:@selector(setEnabled:)]) |
|
68 | [control setEnabled:true]; |
458 | [control setEnabled:true]; |
- | 459 | }
|
|
69 | 460 | ||
70 | [cancelButton setEnabled:true]; |
461 | [cancelButton setEnabled:true]; |
71 | [startButton setEnabled:true]; |
462 | [startButton setEnabled:true]; |
72 | 463 | ||
73 | [tabView selectTabViewItemAtIndex:0]; |
464 | [tabView selectTabViewItem:tabViewItemSetup]; |
- | 465 | [NSCursor unhide]; // Why should I need to do this? |
|
74 | }
|
466 | }
|
75 | 467 | ||
76 | - (void)setupMessagesMode |
468 | - (void)setupMessagesMode |
77 | {
|
469 | {
|
78 | [tabView selectTabViewItemAtIndex:1]; |
470 | [tabView selectTabViewItem:tabViewItemMessageLog]; |
79 | 471 | ||
80 | // disable all the controls on the Configuration page except "always show", so the |
472 | // disable all the controls on the Configuration page except "always show", so the |
81 | // user can enable it if they want to while waiting for something else to happen |
473 | // user can enable it if they want to while waiting for something else to happen |
82 | NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator]; |
474 | NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator]; |
83 | NSControl *control; |
475 | NSControl *control; |
84 | while ((control = [enumerator nextObject])) { |
476 | while ((control = [enumerator nextObject])) |
- | 477 | {
|
|
85 | if (control == alwaysShowButton) continue; |
478 | if (control != alwaysShowButton && [control respondsToSelector:@selector(setEnabled:)]) |
86 | [control setEnabled:false]; |
479 | [control setEnabled:false]; |
87 | }
|
480 | }
|
88 | 481 | ||
89 | [cancelButton setEnabled:false]; |
482 | [cancelButton setEnabled:false]; |
90 | [startButton setEnabled:false]; |
483 | [startButton setEnabled:false]; |
Line 110... | Line 503... | ||
110 | end.length = 0; |
503 | end.length = 0; |
111 | [messagesView scrollRangeToVisible:end]; |
504 | [messagesView scrollRangeToVisible:end]; |
112 | }
|
505 | }
|
113 | }
|
506 | }
|
114 | 507 | ||
115 | - (void)setTitle:(NSString *)str |
- | |
116 | {
|
- | |
117 | [[self window] setTitle:str]; |
- | |
118 | }
|
- | |
119 | - | ||
120 | @end
|
508 | @end
|
121 | 509 | ||
122 | static StartupWinController *startwin = nil; |
510 | static StartupWindow *startwin = nil; |
123 | 511 | ||
124 | int startwin_open(void) |
512 | int startwin_open(void) |
125 | {
|
513 | {
|
- | 514 | // fix for "ld: absolute address to symbol _NSApp in a different linkage unit not supported" |
|
- | 515 | // (OS X 10.6) when building for PPC |
|
126 | nsapp = [NSApplication sharedApplication]; |
516 | nsapp = [NSApplication sharedApplication]; |
127 | 517 | ||
128 | if (startwin != nil) return 1; |
518 | if (startwin != nil) return 1; |
129 | 519 | ||
130 | startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.editor"]; |
520 | startwin = [[StartupWindow alloc] init]; |
131 | if (startwin == nil) return -1; |
521 | if (startwin == nil) return -1; |
132 | 522 | ||
133 | [startwin showWindow:nil]; |
- | |
134 | [startwin setupMessagesMode]; |
523 | [startwin setupMessagesMode]; |
135 | 524 | ||
136 | return 0; |
525 | return 0; |
137 | }
|
526 | }
|
138 | 527 | ||
139 | int startwin_close(void) |
528 | int startwin_close(void) |
140 | {
|
529 | {
|
141 | if (startwin == nil) return 1; |
530 | if (startwin == nil) return 1; |
142 | 531 | ||
143 | [startwin close]; |
532 | [startwin close]; |
- | 533 | [startwin release]; |
|
144 | startwin = nil; |
534 | startwin = nil; |
145 | 535 | ||
146 | return 0; |
536 | return 0; |
147 | }
|
537 | }
|
148 | 538 | ||
Line 151... | Line 541... | ||
151 | NSString *ns; |
541 | NSString *ns; |
152 | 542 | ||
153 | if (!s) return -1; |
543 | if (!s) return -1; |
154 | if (startwin == nil) return 1; |
544 | if (startwin == nil) return 1; |
155 | 545 | ||
156 | ns = [[NSString alloc] initWithUTF8String:s]; |
546 | ns = [NSString stringWithUTF8String:s]; |
157 | [startwin putsMessage:ns]; |
547 | [startwin putsMessage:ns]; |
158 | [ns release]; |
548 | [ns release]; |
159 | 549 | ||
160 | return 0; |
550 | return 0; |
161 | }
|
551 | }
|
Line 165... | Line 555... | ||
165 | NSString *ns; |
555 | NSString *ns; |
166 | 556 | ||
167 | if (!s) return -1; |
557 | if (!s) return -1; |
168 | if (startwin == nil) return 1; |
558 | if (startwin == nil) return 1; |
169 | 559 | ||
170 | ns = [[NSString alloc] initWithUTF8String:s]; |
560 | ns = [NSString stringWithUTF8String:s]; |
171 | [startwin setTitle:ns]; |
561 | [startwin setTitle:ns]; |
172 | [ns release]; |
562 | [ns release]; |
173 | 563 | ||
174 | return 0; |
564 | return 0; |
175 | }
|
565 | }
|
176 | 566 | ||
177 | int startwin_idle(void *v) |
567 | int startwin_idle(void *v) |
178 | {
|
568 | {
|
179 | UNREFERENCED_PARAMETER(v); |
569 | UNREFERENCED_PARAMETER(v); |
180 | 570 | ||
181 | if (startwin) [[startwin window] displayIfNeeded]; |
571 | if (startwin) [startwin displayIfNeeded]; |
182 | return 0; |
572 | return 0; |
183 | }
|
573 | }
|
184 | 574 | ||
- | 575 | ||
185 | int startwin_run(void) |
576 | int startwin_run(void) |
186 | {
|
577 | {
|
187 | int retval; |
578 | int retval; |
188 | 579 | ||
189 | if (startwin == nil) return 0; |
580 | if (startwin == nil) return 0; |
190 | 581 | ||
- | 582 | settings.fullscreen = fullscreen;
|
|
- | 583 | settings.xdim2d = xdim2d;
|
|
- | 584 | settings.ydim2d = ydim2d;
|
|
- | 585 | settings.xdim3d = xdimgame;
|
|
- | 586 | settings.ydim3d = ydimgame;
|
|
- | 587 | settings.bpp3d = bppgame;
|
|
- | 588 | settings.forcesetup = forcesetup;
|
|
- | 589 | ||
191 | [startwin setupRunMode]; |
590 | [startwin setupRunMode]; |
192 | 591 | ||
193 | switch ([nsapp runModalForWindow:[startwin window]]) { |
592 | switch ([nsapp runModalForWindow:startwin]) { |
194 | #ifdef MAC_OS_X_VERSION_10_9 |
593 | #ifdef MAC_OS_X_VERSION_10_9 |
195 | case NSModalResponseStop: retval = 1; break; |
594 | case NSModalResponseStop: retval = 1; break; |
196 | case NSModalResponseAbort: retval = 0; break; |
595 | case NSModalResponseAbort: retval = 0; break; |
197 | #else |
596 | #else |
198 | case NSRunStoppedResponse: retval = 1; break; |
597 | case NSRunStoppedResponse: retval = 1; break; |
Line 201... | Line 600... | ||
201 | default: retval = -1;
|
600 | default: retval = -1;
|
202 | }
|
601 | }
|
203 | 602 | ||
204 | [startwin setupMessagesMode]; |
603 | [startwin setupMessagesMode]; |
205 | 604 | ||
- | 605 | if (retval) { |
|
- | 606 | fullscreen = settings.fullscreen;
|
|
- | 607 | xdim2d = settings.xdim2d;
|
|
- | 608 | ydim2d = settings.ydim2d;
|
|
- | 609 | xdimgame = settings.xdim3d;
|
|
- | 610 | ydimgame = settings.ydim3d;
|
|
- | 611 | bppgame = settings.bpp3d;
|
|
- | 612 | forcesetup = settings.forcesetup;
|
|
- | 613 | }
|
|
- | 614 | ||
206 | return retval;
|
615 | return retval;
|
207 | }
|
616 | }
|