Subversion Repositories eduke32

Rev

Rev 5380 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5380 Rev 5964
Line 1... Line -...
1
// Objective-C programmers shall recoil in fear at this mess
-
 
2
1
3
#import <Cocoa/Cocoa.h>
2
#import <Cocoa/Cocoa.h>
4
3
5
#include "duke3d.h"
4
#include "duke3d.h"
6
#include "game.h"
5
#include "game.h"
Line 12... Line 11...
12
#include "grpscan.h"
11
#include "grpscan.h"
13
12
14
#import "GrpFile.game.h"
13
#import "GrpFile.game.h"
15
#import "GameListSource.game.h"
14
#import "GameListSource.game.h"
16
15
-
 
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
17
static id nsapp;
87
static id nsapp;
18
88
19
static struct {
89
static struct {
20
    grpfile_t const * grp;
90
    grpfile_t const * grp;
21
    int fullscreen;
91
    int fullscreen;
22
    int xdim3d, ydim3d, bpp3d;
92
    int xdim3d, ydim3d, bpp3d;
23
    int forcesetup;
93
    int forcesetup;
24
    int samplerate, bitspersample, channels;
-
 
25
} settings;
94
} settings;
26
95
27
static struct soundQuality_t {
-
 
28
    int frequency;
-
 
29
    int samplesize;
-
 
30
    int channels;
-
 
31
} * soundQualities = 0;
-
 
32
-
 
33
-
 
34
@interface StartupWinController : NSWindowController
96
@interface StartupWindow : NSWindow <NSWindowDelegate>
35
{
97
{
36
    NSMutableArray *modeslist3d;
98
    NSMutableArray *modeslist3d;
37
    GameListSource *gamelistsrc;
99
    GameListSource *gamelistsrc;
38
100
39
    IBOutlet NSButton *alwaysShowButton;
101
    NSButton *alwaysShowButton;
40
    IBOutlet NSButton *fullscreenButton;
102
    NSButton *fullscreenButton;
41
    IBOutlet NSTextView *messagesView;
103
    NSTextView *messagesView;
42
    IBOutlet NSTabView *tabView;
104
    NSTabView *tabView;
-
 
105
    NSTabViewItem *tabViewItemSetup;
43
    IBOutlet NSPopUpButton *videoMode3DPUButton;
106
    NSTabViewItem *tabViewItemMessageLog;
44
    IBOutlet NSPopUpButton *soundQualityPUButton;
107
    NSPopUpButton *videoMode3DPUButton;
45
    IBOutlet NSScrollView *gameList;
108
    NSScrollView *gameList;
46
109
47
    IBOutlet NSButton *cancelButton;
110
    NSButton *cancelButton;
48
    IBOutlet NSButton *startButton;
111
    NSButton *startButton;
49
}
112
}
50
113
-
 
114
- (StartupWindow *)init;
-
 
115
51
- (void)dealloc;
116
- (void)dealloc;
52
- (void)populateVideoModes:(BOOL)firstTime;
117
- (void)populateVideoModes:(BOOL)firstTime;
53
- (void)populateSoundQuality:(BOOL)firstTime;
-
 
54
118
55
- (IBAction)alwaysShowClicked:(id)sender;
-
 
56
- (IBAction)fullscreenClicked:(id)sender;
119
- (void)fullscreenClicked:(id)sender;
57
120
58
- (IBAction)cancel:(id)sender;
121
- (void)cancel:(id)sender;
59
- (IBAction)start:(id)sender;
122
- (void)start:(id)sender;
60
123
61
- (void)setupRunMode;
124
- (void)setupRunMode;
62
- (void)setupMessagesMode;
125
- (void)setupMessagesMode;
-
 
126
63
- (void)putsMessage:(NSString *)str;
127
- (void)putsMessage:(NSString *)str;
64
- (void)setTitle:(NSString *)str;
-
 
65
128
66
@end
129
@end
67
130
-
 
131
@implementation StartupWindow : NSWindow
-
 
132
-
 
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);
68
@implementation StartupWinController
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
}
69
346
70
- (void)dealloc
347
- (void)dealloc
71
{
348
{
72
    [gamelistsrc release];
349
    [gamelistsrc release];
73
    [modeslist3d release];
350
    [modeslist3d release];
Line 119... Line 396...
119
    }
396
    }
120
397
121
    if (idx3d >= 0) [videoMode3DPUButton selectItemAtIndex:idx3d];
398
    if (idx3d >= 0) [videoMode3DPUButton selectItemAtIndex:idx3d];
122
}
399
}
123
400
124
- (void)populateSoundQuality:(BOOL)firstTime
-
 
125
{
-
 
126
    int i, curidx = -1;
-
 
127
-
 
128
    [soundQualityPUButton removeAllItems];
-
 
129
-
 
130
    for (i = 0; soundQualities[i].frequency > 0; i++) {
-
 
131
        const char *ch;
-
 
132
        switch (soundQualities[i].channels) {
-
 
133
            case 1: ch = "Mono"; break;
-
 
134
            case 2: ch = "Stereo"; break;
-
 
135
            default: ch = "?"; break;
-
 
136
        }
-
 
137
-
 
138
        NSString *s = [NSString stringWithFormat:@"%dkHz, %d-bit, %s",
-
 
139
                            soundQualities[i].frequency / 1000,
-
 
140
                            soundQualities[i].samplesize,
-
 
141
                            ch
-
 
142
                     ];
-
 
143
        [soundQualityPUButton addItemWithTitle:s];
-
 
144
-
 
145
        if (firstTime &&
-
 
146
            soundQualities[i].frequency == settings.samplerate &&
-
 
147
            soundQualities[i].samplesize == settings.bitspersample &&
-
 
148
            soundQualities[i].channels == settings.channels) {
-
 
149
            curidx = i;
-
 
150
        }
-
 
151
    }
-
 
152
-
 
153
    if (firstTime && curidx < 0) {
-
 
154
        soundQualities[i].frequency = settings.samplerate;
-
 
155
        soundQualities[i].samplesize = settings.bitspersample;
-
 
156
        soundQualities[i].channels = settings.channels;
-
 
157
-
 
158
        const char *ch;
-
 
159
        switch (soundQualities[i].channels) {
-
 
160
            case 1: ch = "Mono"; break;
-
 
161
            case 2: ch = "Stereo"; break;
-
 
162
            default: ch = "?"; break;
-
 
163
        }
-
 
164
        NSString *s = [NSString stringWithFormat:@"%dkHz, %d-bit, %s",
-
 
165
                       soundQualities[i].frequency / 1000,
-
 
166
                       soundQualities[i].samplesize,
-
 
167
                       ch
-
 
168
                       ];
-
 
169
        [soundQualityPUButton addItemWithTitle:s];
-
 
170
-
 
171
        curidx = i++;
-
 
172
        soundQualities[i].frequency = -1;
-
 
173
    }
-
 
174
-
 
175
    if (curidx >= 0) {
-
 
176
        [soundQualityPUButton selectItemAtIndex:curidx];
-
 
177
    }
-
 
178
}
-
 
179
-
 
180
- (IBAction)alwaysShowClicked:(id)sender
-
 
181
{
-
 
182
    UNREFERENCED_PARAMETER(sender);
-
 
183
}
-
 
184
-
 
185
- (IBAction)fullscreenClicked:(id)sender
401
- (void)fullscreenClicked:(id)sender
186
{
402
{
187
    UNREFERENCED_PARAMETER(sender);
403
    UNREFERENCED_PARAMETER(sender);
188
404
189
    [self populateVideoModes:NO];
405
    [self populateVideoModes:NO];
190
}
406
}
191
407
192
- (IBAction)cancel:(id)sender
408
- (void)cancel:(id)sender
193
{
409
{
194
    UNREFERENCED_PARAMETER(sender);
410
    UNREFERENCED_PARAMETER(sender);
195
411
196
    [nsapp abortModal];
412
    [nsapp abortModal];
197
}
413
}
198
414
199
- (IBAction)start:(id)sender
415
- (void)start:(id)sender
200
{
416
{
201
    UNREFERENCED_PARAMETER(sender);
417
    UNREFERENCED_PARAMETER(sender);
202
418
203
    int mode = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue];
419
    int mode = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue];
204
    if (mode >= 0) {
420
    if (mode >= 0) {
Line 206... Line 422...
206
        settings.ydim3d = validmode[mode].ydim;
422
        settings.ydim3d = validmode[mode].ydim;
207
        settings.bpp3d = validmode[mode].bpp;
423
        settings.bpp3d = validmode[mode].bpp;
208
        settings.fullscreen = validmode[mode].fs;
424
        settings.fullscreen = validmode[mode].fs;
209
    }
425
    }
210
426
211
    int quality = [soundQualityPUButton indexOfSelectedItem];
-
 
212
    if (quality >= 0) {
-
 
213
        settings.samplerate = soundQualities[quality].frequency;
-
 
214
        settings.bitspersample = soundQualities[quality].samplesize;
-
 
215
        settings.channels = soundQualities[quality].channels;
-
 
216
    }
-
 
217
-
 
218
    int row = [[gameList documentView] selectedRow];
427
    int row = [[gameList documentView] selectedRow];
219
    if (row >= 0) {
428
    if (row >= 0) {
220
        settings.grp = [[gamelistsrc grpAtIndex:row] entryptr];
429
        settings.grp = [[gamelistsrc grpAtIndex:row] entryptr];
221
    }
430
    }
222
431
Line 230... Line 439...
230
    getvalidmodes();
439
    getvalidmodes();
231
440
232
    [fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)];
441
    [fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)];
233
    [alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)];
442
    [alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)];
234
    [self populateVideoModes:YES];
443
    [self populateVideoModes:YES];
235
    [self populateSoundQuality:YES];
-
 
236
444
237
    // enable all the controls on the Configuration page
445
    // enable all the controls on the Configuration page
238
    NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
446
    NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
239
    NSControl *control;
447
    NSControl *control;
240
    while ((control = [enumerator nextObject])) [control setEnabled:true];
448
    while ((control = [enumerator nextObject]))
-
 
449
    {
-
 
450
        if ([control respondsToSelector:@selector(setEnabled:)])
-
 
451
            [control setEnabled:true];
-
 
452
    }
241
453
242
    gamelistsrc = [[GameListSource alloc] init];
454
    gamelistsrc = [[GameListSource alloc] init];
243
    [[gameList documentView] setDataSource:gamelistsrc];
455
    [[gameList documentView] setDataSource:gamelistsrc];
244
    [[gameList documentView] deselectAll:nil];
456
    [[gameList documentView] deselectAll:nil];
245
457
246
    int row = [gamelistsrc findIndexForGrpname:[NSString stringWithCString:settings.grp->filename encoding:NSUTF8StringEncoding]];
458
    int row = [gamelistsrc findIndexForGrpname:[NSString stringWithUTF8String:settings.grp->filename]];
247
    if (row >= 0) {
459
    if (row >= 0) {
248
        [[gameList documentView] scrollRowToVisible:row];
460
        [[gameList documentView] scrollRowToVisible:row];
249
#if defined(MAC_OS_X_VERSION_10_3) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3)
461
#if defined MAC_OS_X_VERSION_10_3 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3
250
        [[gameList documentView] selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
462
        [[gameList documentView] selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
251
#else
463
#else
252
        [[gameList documentView] selectRow:row byExtendingSelection:NO];
464
        [[gameList documentView] selectRow:row byExtendingSelection:NO];
253
#endif
465
#endif
254
    }
466
    }
255
467
256
    [cancelButton setEnabled:true];
468
    [cancelButton setEnabled:true];
257
    [startButton setEnabled:true];
469
    [startButton setEnabled:true];
258
470
259
    [tabView selectTabViewItemAtIndex:0];
471
    [tabView selectTabViewItem:tabViewItemSetup];
260
    [NSCursor unhide]; // Why should I need to do this?
472
    [NSCursor unhide]; // Why should I need to do this?
261
}
473
}
262
474
263
- (void)setupMessagesMode
475
- (void)setupMessagesMode
264
{
476
{
265
    [tabView selectTabViewItemAtIndex:2];
477
    [tabView selectTabViewItem:tabViewItemMessageLog];
266
478
267
    // disable all the controls on the Configuration page except "always show", so the
479
    // disable all the controls on the Configuration page except "always show", so the
268
    // user can enable it if they want to while waiting for something else to happen
480
    // user can enable it if they want to while waiting for something else to happen
269
    NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
481
    NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
270
    NSControl *control;
482
    NSControl *control;
271
    while ((control = [enumerator nextObject])) {
483
    while ((control = [enumerator nextObject]))
-
 
484
    {
272
        if (control == alwaysShowButton) continue;
485
        if (control != alwaysShowButton && [control respondsToSelector:@selector(setEnabled:)])
273
        [control setEnabled:false];
486
            [control setEnabled:false];
274
    }
487
    }
275
488
276
    [cancelButton setEnabled:false];
489
    [cancelButton setEnabled:false];
277
    [startButton setEnabled:false];
490
    [startButton setEnabled:false];
Line 297... Line 510...
297
        end.length = 0;
510
        end.length = 0;
298
        [messagesView scrollRangeToVisible:end];
511
        [messagesView scrollRangeToVisible:end];
299
    }
512
    }
300
}
513
}
301
514
302
- (void)setTitle:(NSString *)str
-
 
303
{
-
 
304
    [[self window] setTitle:str];
-
 
305
}
-
 
306
-
 
307
@end
515
@end
308
516
309
static StartupWinController *startwin = nil;
517
static StartupWindow *startwin = nil;
310
518
311
int startwin_open(void)
519
int startwin_open(void)
312
{
520
{
313
    // fix for "ld: absolute address to symbol _NSApp in a different linkage unit not supported"
521
    // fix for "ld: absolute address to symbol _NSApp in a different linkage unit not supported"
314
    // (OS X 10.6) when building for PPC
522
    // (OS X 10.6) when building for PPC
315
    nsapp = [NSApplication sharedApplication];
523
    nsapp = [NSApplication sharedApplication];
316
524
317
    if (startwin != nil) return 1;
525
    if (startwin != nil) return 1;
318
526
319
    startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.game"];
527
    startwin = [[StartupWindow alloc] init];
320
    if (startwin == nil) return -1;
528
    if (startwin == nil) return -1;
321
529
322
    {
-
 
323
        static int soundQualityFrequencies[] = { 48000, 44100, 32000, 24000, 22050 };
-
 
324
        static int soundQualitySampleSizes[] = { 16, 8 };
-
 
325
        static int soundQualityChannels[]    = { 2, 1 };
-
 
326
        size_t f, b, c, i;
-
 
327
-
 
328
        i = sizeof(soundQualityFrequencies) *
-
 
329
            sizeof(soundQualitySampleSizes) *
-
 
330
            sizeof(soundQualityChannels) /
-
 
331
            sizeof(int) + 2;    // one for the terminator, one for a custom setting
-
 
332
        soundQualities = (struct soundQuality_t *) malloc(i * sizeof(struct soundQuality_t));
-
 
333
-
 
334
        i = 0;
-
 
335
        for (c = 0; c < sizeof(soundQualityChannels) / sizeof(int); c++) {
-
 
336
            for (b = 0; b < sizeof(soundQualitySampleSizes) / sizeof(int); b++) {
-
 
337
                for (f = 0; f < sizeof(soundQualityFrequencies) / sizeof(int); f++) {
-
 
338
                    soundQualities[i].frequency = soundQualityFrequencies[f];
-
 
339
                    soundQualities[i].samplesize = soundQualitySampleSizes[b];
-
 
340
                    soundQualities[i].channels = soundQualityChannels[c];
-
 
341
-
 
342
                    i++;
-
 
343
                }
-
 
344
            }
-
 
345
        }
-
 
346
-
 
347
        soundQualities[i].frequency = -1;
-
 
348
    }
-
 
349
-
 
350
    [startwin setupMessagesMode];
530
    [startwin setupMessagesMode];
351
    [startwin showWindow:nil];
-
 
352
531
353
    return 0;
532
    return 0;
354
}
533
}
355
534
356
int startwin_close(void)
535
int startwin_close(void)
Line 359... Line 538...
359
538
360
    [startwin close];
539
    [startwin close];
361
    [startwin release];
540
    [startwin release];
362
    startwin = nil;
541
    startwin = nil;
363
542
364
    free(soundQualities);
-
 
365
-
 
366
    return 0;
543
    return 0;
367
}
544
}
368
545
369
int startwin_puts(const char *s)
546
int startwin_puts(const char *s)
370
{
547
{
371
    NSString *ns;
548
    NSString *ns;
372
549
373
    if (!s) return -1;
550
    if (!s) return -1;
374
    if (startwin == nil) return 1;
551
    if (startwin == nil) return 1;
375
552
376
    ns = [[NSString alloc] initWithUTF8String:s];
553
    ns = [NSString stringWithUTF8String:s];
377
    [startwin putsMessage:ns];
554
    [startwin putsMessage:ns];
378
    [ns release];
555
    [ns release];
379
556
380
    return 0;
557
    return 0;
381
}
558
}
Line 385... Line 562...
385
    NSString *ns;
562
    NSString *ns;
386
563
387
    if (!s) return -1;
564
    if (!s) return -1;
388
    if (startwin == nil) return 1;
565
    if (startwin == nil) return 1;
389
566
390
    ns = [[NSString alloc] initWithUTF8String:s];
567
    ns = [NSString stringWithUTF8String:s];
391
    [startwin setTitle:ns];
568
    [startwin setTitle:ns];
392
    [ns release];
569
    [ns release];
393
570
394
    return 0;
571
    return 0;
395
}
572
}
396
573
397
int startwin_idle(void *v)
574
int startwin_idle(void *v)
398
{
575
{
399
    UNREFERENCED_PARAMETER(v);
576
    UNREFERENCED_PARAMETER(v);
400
577
401
    if (startwin) [[startwin window] displayIfNeeded];
578
    if (startwin) [startwin displayIfNeeded];
402
    return 0;
579
    return 0;
403
}
580
}
404
581
405
582
406
int startwin_run(void)
583
int startwin_run(void)
Line 411... Line 588...
411
588
412
    settings.fullscreen = ud.config.ScreenMode;
589
    settings.fullscreen = ud.config.ScreenMode;
413
    settings.xdim3d = ud.config.ScreenWidth;
590
    settings.xdim3d = ud.config.ScreenWidth;
414
    settings.ydim3d = ud.config.ScreenHeight;
591
    settings.ydim3d = ud.config.ScreenHeight;
415
    settings.bpp3d = ud.config.ScreenBPP;
592
    settings.bpp3d = ud.config.ScreenBPP;
416
    settings.samplerate = ud.config.MixRate;
-
 
417
    settings.bitspersample = ud.config.NumBits;
-
 
418
    settings.channels = ud.config.NumChannels;
-
 
419
    settings.forcesetup = ud.config.ForceSetup;
593
    settings.forcesetup = ud.config.ForceSetup;
420
    settings.grp = g_selectedGrp;
594
    settings.grp = g_selectedGrp;
421
595
422
    [startwin setupRunMode];
596
    [startwin setupRunMode];
423
597
424
    switch ([nsapp runModalForWindow:[startwin window]]) {
598
    switch ([nsapp runModalForWindow:startwin]) {
425
#ifdef MAC_OS_X_VERSION_10_9
599
#ifdef MAC_OS_X_VERSION_10_9
426
        case NSModalResponseStop: retval = 1; break;
600
        case NSModalResponseStop: retval = 1; break;
427
        case NSModalResponseAbort: retval = 0; break;
601
        case NSModalResponseAbort: retval = 0; break;
428
#else
602
#else
429
        case NSRunStoppedResponse: retval = 1; break;
603
        case NSRunStoppedResponse: retval = 1; break;
Line 437... Line 611...
437
    if (retval) {
611
    if (retval) {
438
        ud.config.ScreenMode = settings.fullscreen;
612
        ud.config.ScreenMode = settings.fullscreen;
439
        ud.config.ScreenWidth = settings.xdim3d;
613
        ud.config.ScreenWidth = settings.xdim3d;
440
        ud.config.ScreenHeight = settings.ydim3d;
614
        ud.config.ScreenHeight = settings.ydim3d;
441
        ud.config.ScreenBPP = settings.bpp3d;
615
        ud.config.ScreenBPP = settings.bpp3d;
442
        ud.config.MixRate = settings.samplerate;
-
 
443
        ud.config.NumBits = settings.bitspersample;
-
 
444
        ud.config.NumChannels = settings.channels;
-
 
445
        ud.config.ForceSetup = settings.forcesetup;
616
        ud.config.ForceSetup = settings.forcesetup;
446
        g_selectedGrp = settings.grp;
617
        g_selectedGrp = settings.grp;
447
    }
618
    }
448
619
449
    return retval;
620
    return retval;