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