Subversion Repositories eduke32

Rev

Rev 5380 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5964 hendricks2 1
 
194 terminx 2
#import <Cocoa/Cocoa.h>
3
 
5964 hendricks2 4
#include "compat.h"
194 terminx 5
#include "baselayer.h"
5964 hendricks2 6
#include "build.h"
7
#include "editor.h"
194 terminx 8
 
5964 hendricks2 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
}
79
 
2429 helixhorne 80
static id nsapp;
81
 
5964 hendricks2 82
static struct {
83
    int fullscreen;
84
    int xdim2d, ydim2d;
85
    int xdim3d, ydim3d, bpp3d;
86
    int forcesetup;
87
} settings;
88
 
89
@interface StartupWindow : NSWindow <NSWindowDelegate>
194 terminx 90
{
5964 hendricks2 91
    NSMutableArray *modeslist2d;
92
    NSMutableArray *modeslist3d;
2431 helixhorne 93
 
5964 hendricks2 94
    NSButton *alwaysShowButton;
95
    NSButton *fullscreenButton;
96
    NSTextView *messagesView;
97
    NSTabView *tabView;
98
    NSTabViewItem *tabViewItemSetup;
99
    NSTabViewItem *tabViewItemMessageLog;
100
    NSPopUpButton *videoMode2DPUButton;
101
    NSPopUpButton *videoMode3DPUButton;
102
 
103
    NSButton *cancelButton;
104
    NSButton *startButton;
194 terminx 105
}
106
 
5964 hendricks2 107
- (StartupWindow *)init;
194 terminx 108
 
5964 hendricks2 109
- (void)dealloc;
110
- (void)populateVideoModes:(BOOL)firstTime;
194 terminx 111
 
5964 hendricks2 112
- (void)fullscreenClicked:(id)sender;
113
 
114
- (void)cancel:(id)sender;
115
- (void)start:(id)sender;
116
 
194 terminx 117
- (void)setupRunMode;
118
- (void)setupMessagesMode;
5964 hendricks2 119
 
194 terminx 120
- (void)putsMessage:(NSString *)str;
5964 hendricks2 121
 
194 terminx 122
@end
123
 
5964 hendricks2 124
@implementation StartupWindow : NSWindow
194 terminx 125
 
5964 hendricks2 126
- (StartupWindow *)init
194 terminx 127
{
5964 hendricks2 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;
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];
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
 
313
- (BOOL) windowShouldClose:(id)sender
314
{
4647 hendricks2 315
    UNREFERENCED_PARAMETER(sender);
5964 hendricks2 316
 
317
    [nsapp abortModal];
318
 
319
    return YES;
194 terminx 320
}
321
 
5964 hendricks2 322
- (void)dealloc
194 terminx 323
{
5964 hendricks2 324
    [modeslist3d release];
325
    [super dealloc];
326
}
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
 
406
- (void)fullscreenClicked:(id)sender
407
{
4647 hendricks2 408
    UNREFERENCED_PARAMETER(sender);
4644 hendricks2 409
 
5964 hendricks2 410
    [self populateVideoModes:NO];
194 terminx 411
}
412
 
5964 hendricks2 413
- (void)cancel:(id)sender
194 terminx 414
{
4647 hendricks2 415
    UNREFERENCED_PARAMETER(sender);
4644 hendricks2 416
 
2431 helixhorne 417
    [nsapp abortModal];
194 terminx 418
}
419
 
5964 hendricks2 420
- (void)start:(id)sender
194 terminx 421
{
4647 hendricks2 422
    UNREFERENCED_PARAMETER(sender);
4644 hendricks2 423
 
5964 hendricks2 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
 
439
    settings.forcesetup = [alwaysShowButton state] == NSOnState;
440
 
2431 helixhorne 441
    [nsapp stopModal];
194 terminx 442
}
443
 
444
- (void)setupRunMode
445
{
5964 hendricks2 446
    getvalidmodes();
194 terminx 447
 
5964 hendricks2 448
    [fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)];
449
    [alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)];
450
    [self populateVideoModes:YES];
451
 
2431 helixhorne 452
    // enable all the controls on the Configuration page
5964 hendricks2 453
    NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
2431 helixhorne 454
    NSControl *control;
2537 hendricks2 455
    while ((control = [enumerator nextObject]))
5964 hendricks2 456
    {
457
        if ([control respondsToSelector:@selector(setEnabled:)])
458
            [control setEnabled:true];
459
    }
194 terminx 460
 
2431 helixhorne 461
    [cancelButton setEnabled:true];
462
    [startButton setEnabled:true];
463
 
5964 hendricks2 464
    [tabView selectTabViewItem:tabViewItemSetup];
465
    [NSCursor unhide]; // Why should I need to do this?
194 terminx 466
}
467
 
468
- (void)setupMessagesMode
469
{
5964 hendricks2 470
    [tabView selectTabViewItem:tabViewItemMessageLog];
194 terminx 471
 
2431 helixhorne 472
    // disable all the controls on the Configuration page except "always show", so the
473
    // user can enable it if they want to while waiting for something else to happen
5964 hendricks2 474
    NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
2431 helixhorne 475
    NSControl *control;
5964 hendricks2 476
    while ((control = [enumerator nextObject]))
477
    {
478
        if (control != alwaysShowButton && [control respondsToSelector:@selector(setEnabled:)])
479
            [control setEnabled:false];
2431 helixhorne 480
    }
194 terminx 481
 
2431 helixhorne 482
    [cancelButton setEnabled:false];
483
    [startButton setEnabled:false];
194 terminx 484
}
485
 
486
- (void)putsMessage:(NSString *)str
487
{
2431 helixhorne 488
    NSRange end;
489
    NSTextStorage *text = [messagesView textStorage];
490
    BOOL shouldAutoScroll;
194 terminx 491
 
2431 helixhorne 492
    shouldAutoScroll = ((int)NSMaxY([messagesView bounds]) == (int)NSMaxY([messagesView visibleRect]));
194 terminx 493
 
2431 helixhorne 494
    end.location = [text length];
495
    end.length = 0;
194 terminx 496
 
2431 helixhorne 497
    [text beginEditing];
498
    [messagesView replaceCharactersInRange:end withString:str];
499
    [text endEditing];
500
 
501
    if (shouldAutoScroll) {
502
        end.location = [text length];
503
        end.length = 0;
504
        [messagesView scrollRangeToVisible:end];
505
    }
194 terminx 506
}
507
 
508
@end
509
 
5964 hendricks2 510
static StartupWindow *startwin = nil;
194 terminx 511
 
512
int startwin_open(void)
513
{
5964 hendricks2 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
2429 helixhorne 516
    nsapp = [NSApplication sharedApplication];
517
 
2431 helixhorne 518
    if (startwin != nil) return 1;
194 terminx 519
 
5964 hendricks2 520
    startwin = [[StartupWindow alloc] init];
2431 helixhorne 521
    if (startwin == nil) return -1;
194 terminx 522
 
2431 helixhorne 523
    [startwin setupMessagesMode];
524
 
525
    return 0;
194 terminx 526
}
527
 
528
int startwin_close(void)
529
{
2431 helixhorne 530
    if (startwin == nil) return 1;
194 terminx 531
 
2431 helixhorne 532
    [startwin close];
5964 hendricks2 533
    [startwin release];
2431 helixhorne 534
    startwin = nil;
194 terminx 535
 
2431 helixhorne 536
    return 0;
194 terminx 537
}
538
 
539
int startwin_puts(const char *s)
540
{
2431 helixhorne 541
    NSString *ns;
194 terminx 542
 
2431 helixhorne 543
    if (!s) return -1;
544
    if (startwin == nil) return 1;
194 terminx 545
 
5964 hendricks2 546
    ns = [NSString stringWithUTF8String:s];
2431 helixhorne 547
    [startwin putsMessage:ns];
548
    [ns release];
194 terminx 549
 
2431 helixhorne 550
    return 0;
194 terminx 551
}
552
 
553
int startwin_settitle(const char *s)
554
{
2431 helixhorne 555
    NSString *ns;
194 terminx 556
 
2431 helixhorne 557
    if (!s) return -1;
558
    if (startwin == nil) return 1;
559
 
5964 hendricks2 560
    ns = [NSString stringWithUTF8String:s];
2431 helixhorne 561
    [startwin setTitle:ns];
562
    [ns release];
563
 
564
    return 0;
194 terminx 565
}
566
 
567
int startwin_idle(void *v)
568
{
4647 hendricks2 569
    UNREFERENCED_PARAMETER(v);
4644 hendricks2 570
 
5964 hendricks2 571
    if (startwin) [startwin displayIfNeeded];
2431 helixhorne 572
    return 0;
194 terminx 573
}
574
 
5964 hendricks2 575
 
194 terminx 576
int startwin_run(void)
577
{
2431 helixhorne 578
    int retval;
579
 
580
    if (startwin == nil) return 0;
581
 
5964 hendricks2 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
 
2431 helixhorne 590
    [startwin setupRunMode];
591
 
5964 hendricks2 592
    switch ([nsapp runModalForWindow:startwin]) {
5380 hendricks2 593
#ifdef MAC_OS_X_VERSION_10_9
594
        case NSModalResponseStop: retval = 1; break;
595
        case NSModalResponseAbort: retval = 0; break;
596
#else
2431 helixhorne 597
        case NSRunStoppedResponse: retval = 1; break;
598
        case NSRunAbortedResponse: retval = 0; break;
5380 hendricks2 599
#endif
2431 helixhorne 600
        default: retval = -1;
601
    }
602
 
603
    [startwin setupMessagesMode];
604
 
5964 hendricks2 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
 
2431 helixhorne 615
    return retval;
194 terminx 616
}