Mac: Port the startup window to entirely programmatic code. Death to nibs!

git-svn-id: https://svn.eduke32.com/eduke32@5964 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2016-12-26 06:02:22 +00:00
parent e520f74894
commit dc1bbcd419
17 changed files with 779 additions and 392 deletions

View file

@ -1,89 +1,482 @@
#import <Cocoa/Cocoa.h>
#include "compat.h"
#include "baselayer.h"
#include "build.h"
#include "editor.h"
static CGRect CGRectChangeXY(CGRect const rect, CGFloat const x, CGFloat const y)
{
return CGRectMake(x, y, rect.size.width, rect.size.height);
}
static CGRect CGSizeAddXY(CGSize const size, CGFloat const x, CGFloat const y)
{
return CGRectMake(x, y, size.width, size.height);
}
#if 0
static CGFloat CGRightEdge(CGRect rect)
{
return rect.origin.x + rect.size.width;
}
static CGFloat CGTopEdge(CGRect rect)
{
return rect.origin.y + rect.size.height;
}
#endif
static void setFontToSmall(id control)
{
[control setFont:[NSFont fontWithDescriptor:[[control font] fontDescriptor] size:[NSFont smallSystemFontSize]]];
}
static void setControlToSmall(id control)
{
#ifdef MAC_OS_X_VERSION_10_12
[control setControlSize:NSControlSizeSmall];
#else
[control setControlSize:NSSmallControlSize];
#endif
}
static NSTextField * makeLabel(NSString * labelText)
{
NSTextField *textField = [[NSTextField alloc] init];
setFontToSmall(textField);
setControlToSmall([textField cell]);
[textField setStringValue:labelText];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[textField sizeToFit];
return textField;
}
static NSButton * makeCheckbox(NSString * labelText)
{
NSButton *checkbox = [[NSButton alloc] init];
setFontToSmall(checkbox);
setControlToSmall([checkbox cell]);
[checkbox setTitle:labelText];
[checkbox setButtonType:NSSwitchButton];
[checkbox sizeToFit];
return checkbox;
}
static NSPopUpButton * makeComboBox(void)
{
NSPopUpButton *comboBox = [[NSPopUpButton alloc] init];
[comboBox setPullsDown:NO];
setFontToSmall(comboBox);
setControlToSmall([comboBox cell]);
[comboBox setBezelStyle:NSRoundedBezelStyle];
[comboBox setPreferredEdge:NSMaxYEdge];
[[comboBox cell] setArrowPosition:NSPopUpArrowAtCenter];
[comboBox sizeToFit];
return comboBox;
}
static id nsapp;
@interface StartupWinController : NSWindowController
{
IBOutlet NSButton *alwaysShowButton;
IBOutlet NSButton *fullscreenButton;
IBOutlet NSTextView *messagesView;
IBOutlet NSTabView *tabView;
IBOutlet NSComboBox *videoModeCbox;
static struct {
int fullscreen;
int xdim2d, ydim2d;
int xdim3d, ydim3d, bpp3d;
int forcesetup;
} settings;
IBOutlet NSButton *cancelButton;
IBOutlet NSButton *startButton;
@interface StartupWindow : NSWindow <NSWindowDelegate>
{
NSMutableArray *modeslist2d;
NSMutableArray *modeslist3d;
NSButton *alwaysShowButton;
NSButton *fullscreenButton;
NSTextView *messagesView;
NSTabView *tabView;
NSTabViewItem *tabViewItemSetup;
NSTabViewItem *tabViewItemMessageLog;
NSPopUpButton *videoMode2DPUButton;
NSPopUpButton *videoMode3DPUButton;
NSButton *cancelButton;
NSButton *startButton;
}
- (IBAction)alwaysShowClicked:(id)sender;
- (IBAction)fullscreenClicked:(id)sender;
- (StartupWindow *)init;
- (IBAction)cancel:(id)sender;
- (IBAction)start:(id)sender;
- (void)dealloc;
- (void)populateVideoModes:(BOOL)firstTime;
- (void)fullscreenClicked:(id)sender;
- (void)cancel:(id)sender;
- (void)start:(id)sender;
- (void)setupRunMode;
- (void)setupMessagesMode;
- (void)putsMessage:(NSString *)str;
- (void)setTitle:(NSString *)str;
@end
@implementation StartupWinController
@implementation StartupWindow : NSWindow
- (IBAction)alwaysShowClicked:(id)sender
- (StartupWindow *)init
{
UNREFERENCED_PARAMETER(sender);
NSUInteger const style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
CGRect const windowFrame = CGRectMake(0, 0, 480, 280);
self = [super initWithContentRect:windowFrame styleMask:style backing:NSBackingStoreBuffered defer:NO];
if (self)
{
// window properties
[self setDelegate:self];
[self setReleasedWhenClosed:NO];
#if defined MAC_OS_X_VERSION_10_6 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
[self setPreventsApplicationTerminationWhenModal:NO];
#else
SEL selector = @selector(setPreventsApplicationTerminationWhenModal:);
if ([self respondsToSelector:selector])
{
BOOL argument = NO;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:self];
[invocation setArgument:&argument atIndex:2];
[invocation invoke];
[invocation release];
}
#endif
#if defined MAC_OS_X_VERSION_10_3 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3
[self setContentMinSize:[[self contentView] frame].size];
#else
[self setMinSize:[NSWindow frameRectForContentRect:[[self contentView] frame] styleMask:[self styleMask]].size];
#endif
// image on the left
CGRect const imageFrame = CGRectMake(0, 0, 100, 280);
NSImageView * imageView = [[NSImageView alloc] initWithFrame:imageFrame];
#ifdef MAC_OS_X_VERSION_10_5
[imageView setImageScaling:NSImageScaleNone];
#else
[imageView setImageScaling:NSScaleNone];
#endif
[imageView setImage:[NSImage imageNamed:@"build"]];
[[self contentView] addSubview:imageView];
[imageView setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable];
// buttons
CGFloat const buttonWidth = 80;
CGFloat const buttonHeight = 32;
CGRect const startButtonFrame = CGRectMake(windowFrame.size.width - buttonWidth, 0, buttonWidth, buttonHeight);
startButton = [[NSButton alloc] initWithFrame:startButtonFrame];
[[self contentView] addSubview:startButton];
[startButton setTitle:@"Start"];
[startButton setTarget:self];
[startButton setAction:@selector(start:)];
[startButton setBezelStyle:NSRoundedBezelStyle];
[startButton setKeyEquivalent:@"\r"];
[startButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
CGRect const cancelButtonFrame = CGRectMake(startButtonFrame.origin.x - buttonWidth, 0, buttonWidth, buttonHeight);
cancelButton = [[NSButton alloc] initWithFrame:cancelButtonFrame];
[[self contentView] addSubview:cancelButton];
[cancelButton setTitle:@"Cancel"];
[cancelButton setTarget:self];
[cancelButton setAction:@selector(cancel:)];
[cancelButton setBezelStyle:NSRoundedBezelStyle];
[cancelButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
// tab frame
CGRect const tabViewFrame = CGRectMake(imageFrame.size.width, buttonHeight, windowFrame.size.width - imageFrame.size.width, windowFrame.size.height - buttonHeight - 5);
tabView = [[NSTabView alloc] initWithFrame:tabViewFrame];
[[self contentView] addSubview:tabView];
setFontToSmall(tabView);
setControlToSmall(tabView);
[tabView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
// setup tab
tabViewItemSetup = [[NSTabViewItem alloc] init];
[tabView addTabViewItem:tabViewItemSetup];
[tabViewItemSetup setLabel:@"Setup"];
CGRect const tabViewItemSetupFrame = [[tabViewItemSetup view] frame];
// always show checkbox
alwaysShowButton = makeCheckbox(@"Always show this window at startup");
[[tabViewItemSetup view] addSubview:alwaysShowButton];
CGSize const alwaysShowButtonSize = [alwaysShowButton frame].size;
CGRect const alwaysShowButtonFrame = CGSizeAddXY(alwaysShowButtonSize, tabViewItemSetupFrame.size.width - alwaysShowButtonSize.width, 0);
[alwaysShowButton setFrame:alwaysShowButtonFrame];
[alwaysShowButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
// video mode selectors and labels
NSTextField * label2DVideoMode = makeLabel(@"2D Video mode:");
[[tabViewItemSetup view] addSubview:label2DVideoMode];
CGSize const label2DVideoModeSize = [label2DVideoMode frame].size;
[label2DVideoMode setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
NSTextField * label3DVideoMode = makeLabel(@"3D Video mode:");
[[tabViewItemSetup view] addSubview:label3DVideoMode];
CGSize const label3DVideoModeSize = [label3DVideoMode frame].size;
[label3DVideoMode setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
fullscreenButton = makeCheckbox(@"Fullscreen");
[[tabViewItemSetup view] addSubview:fullscreenButton];
CGSize const fullscreenButtonSize = [fullscreenButton frame].size;
[fullscreenButton setAction:@selector(fullscreenClicked:)];
[fullscreenButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
CGFloat const labelsVideoModeRightEdge = max(label2DVideoModeSize.width, label3DVideoModeSize.width);
videoMode2DPUButton = makeComboBox();
[[tabViewItemSetup view] addSubview:videoMode2DPUButton];
CGSize const videoMode2DPUButtonSize = [videoMode2DPUButton frame].size;
CGFloat const videoMode2DButtonX = labelsVideoModeRightEdge;
CGRect const videoMode2DPUButtonFrame = CGRectMake(videoMode2DButtonX, tabViewItemSetupFrame.size.height - videoMode2DPUButtonSize.height, tabViewItemSetupFrame.size.width - videoMode2DButtonX - fullscreenButtonSize.width, videoMode2DPUButtonSize.height);
[videoMode2DPUButton setFrame:videoMode2DPUButtonFrame];
[videoMode2DPUButton setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
videoMode3DPUButton = makeComboBox();
[[tabViewItemSetup view] addSubview:videoMode3DPUButton];
CGSize const videoMode3DPUButtonSize = [videoMode3DPUButton frame].size;
CGFloat const videoMode3DButtonX = labelsVideoModeRightEdge;
CGRect const videoMode3DPUButtonFrame = CGRectMake(videoMode3DButtonX, videoMode2DPUButtonFrame.origin.y - videoMode3DPUButtonSize.height, tabViewItemSetupFrame.size.width - videoMode3DButtonX - fullscreenButtonSize.width, videoMode3DPUButtonSize.height);
[videoMode3DPUButton setFrame:videoMode3DPUButtonFrame];
[videoMode3DPUButton setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
CGRect const label2DVideoModeFrame = CGSizeAddXY(label2DVideoModeSize, 0, videoMode2DPUButtonFrame.origin.y + rintf((videoMode2DPUButtonSize.height - label2DVideoModeSize.height) * 0.5f) + 1);
[label2DVideoMode setFrame:label2DVideoModeFrame];
CGRect const label3DVideoModeFrame = CGSizeAddXY(label3DVideoModeSize, 0, videoMode3DPUButtonFrame.origin.y + rintf((videoMode3DPUButtonSize.height - label3DVideoModeSize.height) * 0.5f) + 1);
[label3DVideoMode setFrame:label3DVideoModeFrame];
CGRect const fullscreenButtonFrame = CGSizeAddXY(fullscreenButtonSize, tabViewItemSetupFrame.size.width - fullscreenButtonSize.width, videoMode3DPUButtonFrame.origin.y + rintf((videoMode3DPUButtonSize.height - fullscreenButtonSize.height) * 0.5f) + 1);
[fullscreenButton setFrame:fullscreenButtonFrame];
// message log tab
tabViewItemMessageLog = [[NSTabViewItem alloc] init];
[tabView addTabViewItem:tabViewItemMessageLog];
[tabViewItemMessageLog setLabel:@"Message Log"];
CGRect const tabViewItemMessageLogFrame = [[tabViewItemMessageLog view] frame];
// message log
NSScrollView * messagesScrollView = [[NSScrollView alloc] initWithFrame:CGRectChangeXY(tabViewItemMessageLogFrame, 0, 0)];
[[tabViewItemMessageLog view] addSubview:messagesScrollView];
[messagesScrollView setBorderType:NSBezelBorder];
[messagesScrollView setHasVerticalScroller:YES];
[messagesScrollView setHasHorizontalScroller:NO];
setControlToSmall([[messagesScrollView verticalScroller] cell]);
NSSize const messagesScrollViewContentSize = [messagesScrollView contentSize];
[messagesScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
messagesView = [[NSTextView alloc] initWithFrame:CGRectMake(0, 0, messagesScrollViewContentSize.width, messagesScrollViewContentSize.height)];
[messagesScrollView setDocumentView:messagesView];
[messagesView setEditable:NO];
[messagesView setRichText:NO];
setFontToSmall(messagesView);
[messagesView setMinSize:CGSizeMake(0.0, messagesScrollViewContentSize.height)];
[messagesView setMaxSize:CGSizeMake(FLT_MAX, FLT_MAX)];
[messagesView setVerticallyResizable:YES];
[messagesView setHorizontallyResizable:NO];
[messagesView setAutoresizingMask:NSViewWidthSizable];
[[messagesView textContainer] setContainerSize:CGSizeMake(messagesScrollViewContentSize.width, FLT_MAX)];
[[messagesView textContainer] setWidthTracksTextView:YES];
}
return self;
}
- (IBAction)fullscreenClicked:(id)sender
- (BOOL)canBecomeKeyWindow
{
return YES;
}
- (BOOL)canBecomeMainWindow
{
return YES;
}
- (BOOL) windowShouldClose:(id)sender
{
UNREFERENCED_PARAMETER(sender);
// XXX: recalculate the video modes list to take into account the fullscreen status
[nsapp abortModal];
return YES;
}
- (IBAction)cancel:(id)sender
- (void)dealloc
{
[modeslist3d release];
[super dealloc];
}
- (void)populateVideoModes:(BOOL)firstTime
{
int i, mode3d, fullscreen = ([fullscreenButton state] == NSOnState);
int mode2d, idx2d = -1;
int idx3d = -1;
int xdim2d = 0, ydim2d = 0;
int const bpp2d = 8;
int xdim = 0, ydim = 0, bpp = 0;
if (firstTime) {
xdim2d = settings.xdim2d;
ydim2d = settings.ydim2d;
xdim = settings.xdim3d;
ydim = settings.ydim3d;
bpp = settings.bpp3d;
} else {
mode2d = [[modeslist2d objectAtIndex:[videoMode2DPUButton indexOfSelectedItem]] intValue];
if (mode2d >= 0) {
xdim2d = validmode[mode2d].xdim;
ydim2d = validmode[mode2d].ydim;
}
mode3d = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue];
if (mode3d >= 0) {
xdim = validmode[mode3d].xdim;
ydim = validmode[mode3d].ydim;
bpp = validmode[mode3d].bpp;
}
}
mode2d = checkvideomode(&xdim2d, &ydim2d, bpp2d, fullscreen, 1);
[modeslist2d release];
[videoMode2DPUButton removeAllItems];
modeslist2d = [[NSMutableArray alloc] init];
for (i = 0; i < validmodecnt; i++) {
if (fullscreen == validmode[i].fs) {
if (i == mode2d) idx2d = [modeslist2d count];
[modeslist2d addObject:[NSNumber numberWithInt:i]];
[videoMode2DPUButton addItemWithTitle:[NSString stringWithFormat:@"%d %C %d",
validmode[i].xdim, 0xd7, validmode[i].ydim]];
}
}
if (idx2d >= 0) [videoMode2DPUButton selectItemAtIndex:idx2d];
mode3d = checkvideomode(&xdim, &ydim, bpp, fullscreen, 1);
if (mode3d < 0) {
int i, cd[] = { 32, 24, 16, 15, 8, 0 };
for (i=0; cd[i]; ) { if (cd[i] >= bpp) i++; else break; }
for ( ; cd[i]; i++) {
mode3d = checkvideomode(&xdim, &ydim, cd[i], fullscreen, 1);
if (mode3d < 0) continue;
break;
}
}
[modeslist3d release];
[videoMode3DPUButton removeAllItems];
modeslist3d = [[NSMutableArray alloc] init];
for (i = 0; i < validmodecnt; i++) {
if (fullscreen == validmode[i].fs) {
if (i == mode3d) idx3d = [modeslist3d count];
[modeslist3d addObject:[NSNumber numberWithInt:i]];
[videoMode3DPUButton addItemWithTitle:[NSString stringWithFormat:@"%d %C %d %d-bpp",
validmode[i].xdim, 0xd7, validmode[i].ydim, validmode[i].bpp]];
}
}
if (idx3d >= 0) [videoMode3DPUButton selectItemAtIndex:idx3d];
}
- (void)fullscreenClicked:(id)sender
{
UNREFERENCED_PARAMETER(sender);
[self populateVideoModes:NO];
}
- (void)cancel:(id)sender
{
UNREFERENCED_PARAMETER(sender);
[nsapp abortModal];
}
- (IBAction)start:(id)sender
- (void)start:(id)sender
{
UNREFERENCED_PARAMETER(sender);
// XXX: write the states of the form controls to their respective homes
int mode2d = [[modeslist2d objectAtIndex:[videoMode2DPUButton indexOfSelectedItem]] intValue];
if (mode2d >= 0) {
settings.xdim2d = validmode[mode2d].xdim;
settings.ydim2d = validmode[mode2d].ydim;
settings.fullscreen = validmode[mode2d].fs;
}
int mode = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue];
if (mode >= 0) {
settings.xdim3d = validmode[mode].xdim;
settings.ydim3d = validmode[mode].ydim;
settings.bpp3d = validmode[mode].bpp;
settings.fullscreen = validmode[mode].fs;
}
settings.forcesetup = [alwaysShowButton state] == NSOnState;
[nsapp stopModal];
}
- (void)setupRunMode
{
// XXX: populate the lists and set everything up to represent the current options
getvalidmodes();
[fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)];
[alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)];
[self populateVideoModes:YES];
// enable all the controls on the Configuration page
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
NSControl *control;
while ((control = [enumerator nextObject]))
[control setEnabled:true];
{
if ([control respondsToSelector:@selector(setEnabled:)])
[control setEnabled:true];
}
[cancelButton setEnabled:true];
[startButton setEnabled:true];
[tabView selectTabViewItemAtIndex:0];
[tabView selectTabViewItem:tabViewItemSetup];
[NSCursor unhide]; // Why should I need to do this?
}
- (void)setupMessagesMode
{
[tabView selectTabViewItemAtIndex:1];
[tabView selectTabViewItem:tabViewItemMessageLog];
// disable all the controls on the Configuration page except "always show", so the
// user can enable it if they want to while waiting for something else to happen
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
NSControl *control;
while ((control = [enumerator nextObject])) {
if (control == alwaysShowButton) continue;
[control setEnabled:false];
while ((control = [enumerator nextObject]))
{
if (control != alwaysShowButton && [control respondsToSelector:@selector(setEnabled:)])
[control setEnabled:false];
}
[cancelButton setEnabled:false];
@ -112,25 +505,21 @@ static id nsapp;
}
}
- (void)setTitle:(NSString *)str
{
[[self window] setTitle:str];
}
@end
static StartupWinController *startwin = nil;
static StartupWindow *startwin = nil;
int startwin_open(void)
{
// fix for "ld: absolute address to symbol _NSApp in a different linkage unit not supported"
// (OS X 10.6) when building for PPC
nsapp = [NSApplication sharedApplication];
if (startwin != nil) return 1;
startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.editor"];
startwin = [[StartupWindow alloc] init];
if (startwin == nil) return -1;
[startwin showWindow:nil];
[startwin setupMessagesMode];
return 0;
@ -141,6 +530,7 @@ int startwin_close(void)
if (startwin == nil) return 1;
[startwin close];
[startwin release];
startwin = nil;
return 0;
@ -153,7 +543,7 @@ int startwin_puts(const char *s)
if (!s) return -1;
if (startwin == nil) return 1;
ns = [[NSString alloc] initWithUTF8String:s];
ns = [NSString stringWithUTF8String:s];
[startwin putsMessage:ns];
[ns release];
@ -167,7 +557,7 @@ int startwin_settitle(const char *s)
if (!s) return -1;
if (startwin == nil) return 1;
ns = [[NSString alloc] initWithUTF8String:s];
ns = [NSString stringWithUTF8String:s];
[startwin setTitle:ns];
[ns release];
@ -178,19 +568,28 @@ int startwin_idle(void *v)
{
UNREFERENCED_PARAMETER(v);
if (startwin) [[startwin window] displayIfNeeded];
if (startwin) [startwin displayIfNeeded];
return 0;
}
int startwin_run(void)
{
int retval;
if (startwin == nil) return 0;
settings.fullscreen = fullscreen;
settings.xdim2d = xdim2d;
settings.ydim2d = ydim2d;
settings.xdim3d = xdimgame;
settings.ydim3d = ydimgame;
settings.bpp3d = bppgame;
settings.forcesetup = forcesetup;
[startwin setupRunMode];
switch ([nsapp runModalForWindow:[startwin window]]) {
switch ([nsapp runModalForWindow:startwin]) {
#ifdef MAC_OS_X_VERSION_10_9
case NSModalResponseStop: retval = 1; break;
case NSModalResponseAbort: retval = 0; break;
@ -203,5 +602,15 @@ int startwin_run(void)
[startwin setupMessagesMode];
if (retval) {
fullscreen = settings.fullscreen;
xdim2d = settings.xdim2d;
ydim2d = settings.ydim2d;
xdimgame = settings.xdim3d;
ydimgame = settings.ydim3d;
bppgame = settings.bpp3d;
forcesetup = settings.forcesetup;
}
return retval;
}

View file

@ -170,11 +170,7 @@
0008EA1B19F1AE820091588D /* m32vars.c in Sources */ = {isa = PBXBuildFile; fileRef = 0008EA1319F1AE820091588D /* m32vars.c */; };
0008EA1C19F1AE820091588D /* sounds_mapster32.c in Sources */ = {isa = PBXBuildFile; fileRef = 0008EA1419F1AE820091588D /* sounds_mapster32.c */; };
0008EA2019F1AEFC0091588D /* eduke32.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0008EA1D19F1AEFC0091588D /* eduke32.icns */; };
0008EA2119F1AEFC0091588D /* game.osxmain.nib in Resources */ = {isa = PBXBuildFile; fileRef = 0008EA1E19F1AEFC0091588D /* game.osxmain.nib */; };
0008EA2219F1AEFC0091588D /* startwin.game.nib in Resources */ = {isa = PBXBuildFile; fileRef = 0008EA1F19F1AEFC0091588D /* startwin.game.nib */; };
0008EA2319F1AF010091588D /* eduke32.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0008EA1D19F1AEFC0091588D /* eduke32.icns */; };
0008EA2619F1AF220091588D /* build.osxmain.nib in Resources */ = {isa = PBXBuildFile; fileRef = 0008EA2419F1AF220091588D /* build.osxmain.nib */; };
0008EA2719F1AF220091588D /* startwin.editor.nib in Resources */ = {isa = PBXBuildFile; fileRef = 0008EA2519F1AF220091588D /* startwin.editor.nib */; };
0008EA6319F1B04F0091588D /* callbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008EA5019F1B04F0091588D /* callbacks.h */; settings = {ATTRIBUTES = (Public, ); }; };
0008EA6419F1B04F0091588D /* enet.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008EA5119F1B04F0091588D /* enet.h */; settings = {ATTRIBUTES = (Public, ); }; };
0008EA6519F1B04F0091588D /* list.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008EA5219F1B04F0091588D /* list.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -740,10 +736,6 @@
0008EA1419F1AE820091588D /* sounds_mapster32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sounds_mapster32.c; path = ../../source/sounds_mapster32.c; sourceTree = SOURCE_ROOT; };
0008EA1519F1AE820091588D /* sounds_mapster32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sounds_mapster32.h; path = ../../source/sounds_mapster32.h; sourceTree = SOURCE_ROOT; };
0008EA1D19F1AEFC0091588D /* eduke32.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = eduke32.icns; path = bundles/EDuke32.app/Contents/Resources/eduke32.icns; sourceTree = SOURCE_ROOT; };
0008EA1E19F1AEFC0091588D /* game.osxmain.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = game.osxmain.nib; path = bundles/EDuke32.app/Contents/Resources/game.osxmain.nib; sourceTree = SOURCE_ROOT; };
0008EA1F19F1AEFC0091588D /* startwin.game.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = startwin.game.nib; path = bundles/EDuke32.app/Contents/Resources/startwin.game.nib; sourceTree = SOURCE_ROOT; };
0008EA2419F1AF220091588D /* build.osxmain.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = build.osxmain.nib; path = bundles/Mapster32.app/Contents/Resources/build.osxmain.nib; sourceTree = SOURCE_ROOT; };
0008EA2519F1AF220091588D /* startwin.editor.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = startwin.editor.nib; path = bundles/Mapster32.app/Contents/Resources/startwin.editor.nib; sourceTree = SOURCE_ROOT; };
0008EA4919F1B0020091588D /* libENet.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libENet.a; sourceTree = BUILT_PRODUCTS_DIR; };
0008EA5019F1B04F0091588D /* callbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = callbacks.h; path = ../../source/enet/include/enet/callbacks.h; sourceTree = SOURCE_ROOT; };
0008EA5119F1B04F0091588D /* enet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = enet.h; path = ../../source/enet/include/enet/enet.h; sourceTree = SOURCE_ROOT; };
@ -1077,8 +1069,6 @@
000C487319F35517006E6B52 /* iOS */,
0008EA1D19F1AEFC0091588D /* eduke32.icns */,
20C214691B02C19800917E58 /* game.png */,
0008EA1E19F1AEFC0091588D /* game.osxmain.nib */,
0008EA1F19F1AEFC0091588D /* startwin.game.nib */,
0008EA0D19F1AE820091588D /* astub.c */,
0008EA0E19F1AE820091588D /* m32common.c */,
0008EA0F19F1AE820091588D /* m32def.c */,
@ -1319,8 +1309,6 @@
20CEFB111E08A86B0077879C /* 2d.c */,
00970E3319F207F000873EB9 /* a-c.c */,
20C2146E1B02C1D800917E58 /* build.png */,
0008EA2419F1AF220091588D /* build.osxmain.nib */,
0008EA2519F1AF220091588D /* startwin.editor.nib */,
0008E8DC19F1AC530091588D /* baselayer.c */,
0008E8DD19F1AC530091588D /* build.c */,
0008E8DE19F1AC530091588D /* cache1d.c */,
@ -1933,9 +1921,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0008EA2119F1AEFC0091588D /* game.osxmain.nib in Resources */,
20C2146A1B02C19800917E58 /* game.png in Resources */,
0008EA2219F1AEFC0091588D /* startwin.game.nib in Resources */,
0008EA2019F1AEFC0091588D /* eduke32.icns in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -1945,9 +1931,7 @@
buildActionMask = 2147483647;
files = (
20C2146F1B02C1D800917E58 /* build.png in Resources */,
0008EA2719F1AF220091588D /* startwin.editor.nib in Resources */,
0008EA2319F1AF010091588D /* eduke32.icns in Resources */,
0008EA2619F1AF220091588D /* build.osxmain.nib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -34,8 +34,6 @@
<string>public.app-category.action-games</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright Voidpoint, LLC</string>
<key>NSMainNibFile</key>
<string>game.osxmain</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>

View file

@ -1,7 +0,0 @@
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{CLASS = SDLMain; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
);
IBVersion = 1;
}

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>563 86 356 240 0 0 1280 938 </string>
<key>IBEditorPositions</key>
<dict>
<key>29</key>
<string>581 456 159 44 0 0 1280 938 </string>
</dict>
<key>IBFramework Version</key>
<string>364.0</string>
<key>IBOpenObjects</key>
<array>
<integer>29</integer>
</array>
<key>IBSystem Version</key>
<string>7W98</string>
</dict>
</plist>

View file

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBClasses</key>
<array>
<dict>
<key>CLASS</key>
<string>FirstResponder</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
<dict>
<key>ACTIONS</key>
<dict>
<key>alwaysShowClicked</key>
<string>id</string>
<key>cancel</key>
<string>id</string>
<key>fullscreenClicked</key>
<string>id</string>
<key>start</key>
<string>id</string>
</dict>
<key>CLASS</key>
<string>StartupWinController</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>alwaysShowButton</key>
<string>NSButton</string>
<key>cancelButton</key>
<string>NSButton</string>
<key>fullscreenButton</key>
<string>NSButton</string>
<key>gameList</key>
<string>NSScrollView</string>
<key>messagesView</key>
<string>NSTextView</string>
<key>soundQualityPUButton</key>
<string>NSPopUpButton</string>
<key>startButton</key>
<string>NSButton</string>
<key>tabView</key>
<string>NSTabView</string>
<key>videoMode3DPUButton</key>
<string>NSPopUpButton</string>
</dict>
<key>SUPERCLASS</key>
<string>NSWindowController</string>
</dict>
</array>
<key>IBVersion</key>
<string>1</string>
</dict>
</plist>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBFramework Version</key>
<string>677</string>
<key>IBLastKnownRelativeProjectPath</key>
<string>duke3d.xcodeproj</string>
<key>IBOldestOS</key>
<integer>3</integer>
<key>IBOpenObjects</key>
<array>
<integer>35</integer>
</array>
<key>IBSystem Version</key>
<string>9J61</string>
<key>targetFramework</key>
<string>IBCocoaFramework</string>
</dict>
</plist>

View file

@ -32,8 +32,6 @@
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright Voidpoint, LLC</string>
<key>NSMainNibFile</key>
<string>build.osxmain</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>

View file

@ -1,7 +0,0 @@
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{CLASS = SDLMain; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
);
IBVersion = 1;
}

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>567 77 356 240 0 0 1280 938 </string>
<key>IBEditorPositions</key>
<dict>
<key>29</key>
<string>562 525 257 44 0 0 1280 938 </string>
</dict>
<key>IBFramework Version</key>
<string>364.0</string>
<key>IBOpenObjects</key>
<array>
<integer>29</integer>
</array>
<key>IBSystem Version</key>
<string>7W98</string>
</dict>
</plist>

View file

@ -1,22 +0,0 @@
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{
ACTIONS = {alwaysShowClicked = id; cancel = id; fullscreenClicked = id; start = id; };
CLASS = StartupWinController;
LANGUAGE = ObjC;
OUTLETS = {
alwaysShowButton = NSButton;
cancelButton = NSButton;
fullscreenButton = NSButton;
messagesView = NSTextView;
startButton = NSButton;
tabView = NSTabView;
videoMode2DPUButton = NSPopUpButton;
videoMode3DPUButton = NSPopUpButton;
};
SUPERCLASS = NSWindowController;
}
);
IBVersion = 1;
}

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>111 188 356 240 0 0 1280 938 </string>
<key>IBFramework Version</key>
<string>446.1</string>
<key>IBOpenObjects</key>
<array>
<integer>23</integer>
</array>
<key>IBSystem Version</key>
<string>8R218</string>
</dict>
</plist>

View file

@ -1,4 +1,3 @@
// Objective-C programmers shall recoil in fear at this mess
#import <Cocoa/Cocoa.h>
@ -14,6 +13,77 @@
#import "GrpFile.game.h"
#import "GameListSource.game.h"
static CGRect CGRectChangeXY(CGRect const rect, CGFloat const x, CGFloat const y)
{
return CGRectMake(x, y, rect.size.width, rect.size.height);
}
static CGRect CGSizeAddXY(CGSize const size, CGFloat const x, CGFloat const y)
{
return CGRectMake(x, y, size.width, size.height);
}
#if 0
static CGFloat CGRightEdge(CGRect rect)
{
return rect.origin.x + rect.size.width;
}
#endif
static CGFloat CGTopEdge(CGRect rect)
{
return rect.origin.y + rect.size.height;
}
static void setFontToSmall(id control)
{
[control setFont:[NSFont fontWithDescriptor:[[control font] fontDescriptor] size:[NSFont smallSystemFontSize]]];
}
static void setControlToSmall(id control)
{
#ifdef MAC_OS_X_VERSION_10_12
[control setControlSize:NSControlSizeSmall];
#else
[control setControlSize:NSSmallControlSize];
#endif
}
static NSTextField * makeLabel(NSString * labelText)
{
NSTextField *textField = [[NSTextField alloc] init];
setFontToSmall(textField);
setControlToSmall([textField cell]);
[textField setStringValue:labelText];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[textField sizeToFit];
return textField;
}
static NSButton * makeCheckbox(NSString * labelText)
{
NSButton *checkbox = [[NSButton alloc] init];
setFontToSmall(checkbox);
setControlToSmall([checkbox cell]);
[checkbox setTitle:labelText];
[checkbox setButtonType:NSSwitchButton];
[checkbox sizeToFit];
return checkbox;
}
static NSPopUpButton * makeComboBox(void)
{
NSPopUpButton *comboBox = [[NSPopUpButton alloc] init];
[comboBox setPullsDown:NO];
setFontToSmall(comboBox);
setControlToSmall([comboBox cell]);
[comboBox setBezelStyle:NSRoundedBezelStyle];
[comboBox setPreferredEdge:NSMaxYEdge];
[[comboBox cell] setArrowPosition:NSPopUpArrowAtCenter];
[comboBox sizeToFit];
return comboBox;
}
static id nsapp;
static struct {
@ -21,51 +91,258 @@ static struct {
int fullscreen;
int xdim3d, ydim3d, bpp3d;
int forcesetup;
int samplerate, bitspersample, channels;
} settings;
static struct soundQuality_t {
int frequency;
int samplesize;
int channels;
} * soundQualities = 0;
@interface StartupWinController : NSWindowController
@interface StartupWindow : NSWindow <NSWindowDelegate>
{
NSMutableArray *modeslist3d;
GameListSource *gamelistsrc;
IBOutlet NSButton *alwaysShowButton;
IBOutlet NSButton *fullscreenButton;
IBOutlet NSTextView *messagesView;
IBOutlet NSTabView *tabView;
IBOutlet NSPopUpButton *videoMode3DPUButton;
IBOutlet NSPopUpButton *soundQualityPUButton;
IBOutlet NSScrollView *gameList;
NSButton *alwaysShowButton;
NSButton *fullscreenButton;
NSTextView *messagesView;
NSTabView *tabView;
NSTabViewItem *tabViewItemSetup;
NSTabViewItem *tabViewItemMessageLog;
NSPopUpButton *videoMode3DPUButton;
NSScrollView *gameList;
IBOutlet NSButton *cancelButton;
IBOutlet NSButton *startButton;
NSButton *cancelButton;
NSButton *startButton;
}
- (StartupWindow *)init;
- (void)dealloc;
- (void)populateVideoModes:(BOOL)firstTime;
- (void)populateSoundQuality:(BOOL)firstTime;
- (IBAction)alwaysShowClicked:(id)sender;
- (IBAction)fullscreenClicked:(id)sender;
- (void)fullscreenClicked:(id)sender;
- (IBAction)cancel:(id)sender;
- (IBAction)start:(id)sender;
- (void)cancel:(id)sender;
- (void)start:(id)sender;
- (void)setupRunMode;
- (void)setupMessagesMode;
- (void)putsMessage:(NSString *)str;
- (void)setTitle:(NSString *)str;
@end
@implementation StartupWinController
@implementation StartupWindow : NSWindow
- (StartupWindow *)init
{
NSUInteger const style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
CGRect const windowFrame = CGRectMake(0, 0, 480, 280);
self = [super initWithContentRect:windowFrame styleMask:style backing:NSBackingStoreBuffered defer:NO];
if (self)
{
// window properties
[self setDelegate:self];
[self setReleasedWhenClosed:NO];
#if defined MAC_OS_X_VERSION_10_6 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
[self setPreventsApplicationTerminationWhenModal:NO];
#else
SEL selector = @selector(setPreventsApplicationTerminationWhenModal:);
if ([self respondsToSelector:selector])
{
BOOL argument = NO;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:self];
[invocation setArgument:&argument atIndex:2];
[invocation invoke];
[invocation release];
}
#endif
#if defined MAC_OS_X_VERSION_10_3 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3
[self setContentMinSize:[[self contentView] frame].size];
#else
[self setMinSize:[NSWindow frameRectForContentRect:[[self contentView] frame] styleMask:[self styleMask]].size];
#endif
// image on the left
CGRect const imageFrame = CGRectMake(0, 0, 100, 280);
NSImageView * imageView = [[NSImageView alloc] initWithFrame:imageFrame];
#ifdef MAC_OS_X_VERSION_10_5
[imageView setImageScaling:NSImageScaleNone];
#else
[imageView setImageScaling:NSScaleNone];
#endif
[imageView setImage:[NSImage imageNamed:@"game"]];
[[self contentView] addSubview:imageView];
[imageView setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable];
// buttons
CGFloat const buttonWidth = 80;
CGFloat const buttonHeight = 32;
CGRect const startButtonFrame = CGRectMake(windowFrame.size.width - buttonWidth, 0, buttonWidth, buttonHeight);
startButton = [[NSButton alloc] initWithFrame:startButtonFrame];
[[self contentView] addSubview:startButton];
[startButton setTitle:@"Start"];
[startButton setTarget:self];
[startButton setAction:@selector(start:)];
[startButton setBezelStyle:NSRoundedBezelStyle];
[startButton setKeyEquivalent:@"\r"];
[startButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
CGRect const cancelButtonFrame = CGRectMake(startButtonFrame.origin.x - buttonWidth, 0, buttonWidth, buttonHeight);
cancelButton = [[NSButton alloc] initWithFrame:cancelButtonFrame];
[[self contentView] addSubview:cancelButton];
[cancelButton setTitle:@"Cancel"];
[cancelButton setTarget:self];
[cancelButton setAction:@selector(cancel:)];
[cancelButton setBezelStyle:NSRoundedBezelStyle];
[cancelButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
// tab frame
CGRect const tabViewFrame = CGRectMake(imageFrame.size.width, buttonHeight, windowFrame.size.width - imageFrame.size.width, windowFrame.size.height - buttonHeight - 5);
tabView = [[NSTabView alloc] initWithFrame:tabViewFrame];
[[self contentView] addSubview:tabView];
setFontToSmall(tabView);
setControlToSmall(tabView);
[tabView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
// setup tab
tabViewItemSetup = [[NSTabViewItem alloc] init];
[tabView addTabViewItem:tabViewItemSetup];
[tabViewItemSetup setLabel:@"Setup"];
CGRect const tabViewItemSetupFrame = [[tabViewItemSetup view] frame];
// always show checkbox
alwaysShowButton = makeCheckbox(@"Always show this window at startup");
[[tabViewItemSetup view] addSubview:alwaysShowButton];
CGSize const alwaysShowButtonSize = [alwaysShowButton frame].size;
CGRect const alwaysShowButtonFrame = CGSizeAddXY(alwaysShowButtonSize, tabViewItemSetupFrame.size.width - alwaysShowButtonSize.width, 0);
[alwaysShowButton setFrame:alwaysShowButtonFrame];
[alwaysShowButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
// video mode selectors and labels
NSTextField * labelVideoMode = makeLabel(@"Video mode:");
[[tabViewItemSetup view] addSubview:labelVideoMode];
CGSize const labelVideoModeSize = [labelVideoMode frame].size;
[labelVideoMode setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
fullscreenButton = makeCheckbox(@"Fullscreen");
[[tabViewItemSetup view] addSubview:fullscreenButton];
CGSize const fullscreenButtonSize = [fullscreenButton frame].size;
[fullscreenButton setAction:@selector(fullscreenClicked:)];
[fullscreenButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
videoMode3DPUButton = makeComboBox();
[[tabViewItemSetup view] addSubview:videoMode3DPUButton];
CGSize const videoMode3DPUButtonSize = [videoMode3DPUButton frame].size;
CGFloat const videoMode3DButtonX = labelVideoModeSize.width; // CGRightEdge(labelVideoModeFrame);
CGRect const videoMode3DPUButtonFrame = CGRectMake(videoMode3DButtonX, tabViewItemSetupFrame.size.height - videoMode3DPUButtonSize.height, tabViewItemSetupFrame.size.width - videoMode3DButtonX - fullscreenButtonSize.width, videoMode3DPUButtonSize.height);
[videoMode3DPUButton setFrame:videoMode3DPUButtonFrame];
[videoMode3DPUButton setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
CGRect const labelVideoModeFrame = CGSizeAddXY(labelVideoModeSize, 0, videoMode3DPUButtonFrame.origin.y + rintf((videoMode3DPUButtonSize.height - labelVideoModeSize.height) * 0.5f) + 1);
[labelVideoMode setFrame:labelVideoModeFrame];
CGRect const fullscreenButtonFrame = CGSizeAddXY(fullscreenButtonSize, tabViewItemSetupFrame.size.width - fullscreenButtonSize.width, videoMode3DPUButtonFrame.origin.y + rintf((videoMode3DPUButtonSize.height - fullscreenButtonSize.height) * 0.5f) + 1);
[fullscreenButton setFrame:fullscreenButtonFrame];
// game selector and label
NSTextField * labelGame = makeLabel(@"Game:");
[[tabViewItemSetup view] addSubview:labelGame];
CGSize const labelGameSize = [labelGame frame].size;
CGRect const labelGameFrame = CGSizeAddXY(labelGameSize, 0, videoMode3DPUButtonFrame.origin.y - labelGameSize.height);
[labelGame setFrame:labelGameFrame];
[labelGame setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
CGFloat const gameListVerticalPadding = 3;
CGFloat const gameListY = CGTopEdge(alwaysShowButtonFrame) + gameListVerticalPadding;
CGRect const gameListFrame = CGRectMake(0, gameListY, tabViewItemSetupFrame.size.width, labelGameFrame.origin.y - gameListY - gameListVerticalPadding);
gameList = [[NSScrollView alloc] initWithFrame:gameListFrame];
[[tabViewItemSetup view] addSubview:gameList];
[gameList setBorderType:NSBezelBorder];
[gameList setHasVerticalScroller:YES];
[gameList setHasHorizontalScroller:NO];
setControlToSmall([[gameList verticalScroller] cell]);
NSSize const gameListContentSize = [gameList contentSize];
[gameList setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
NSTableView * gameListTable = [[NSTableView alloc] initWithFrame:NSMakeRect(0, 0, gameListContentSize.width, gameListContentSize.height)];
[gameList setDocumentView:gameListTable];
NSTableColumn * nameColumn = [[NSTableColumn alloc] initWithIdentifier:@"0"];
[gameListTable addTableColumn:nameColumn];
NSTableColumn * fileColumn = [[NSTableColumn alloc] initWithIdentifier:@"1"];
[gameListTable addTableColumn:fileColumn];
[nameColumn setEditable:NO];
[[nameColumn headerCell] setStringValue:@"Name"];
[nameColumn setWidth:gameListContentSize.width * (2.f/3.f)];
[fileColumn setEditable:NO];
[[fileColumn headerCell] setStringValue:@"File"];
[gameListTable sizeLastColumnToFit];
[gameListTable setAutoresizingMask:NSViewWidthSizable];
// message log tab
tabViewItemMessageLog = [[NSTabViewItem alloc] init];
[tabView addTabViewItem:tabViewItemMessageLog];
[tabViewItemMessageLog setLabel:@"Message Log"];
CGRect const tabViewItemMessageLogFrame = [[tabViewItemMessageLog view] frame];
// message log
NSScrollView * messagesScrollView = [[NSScrollView alloc] initWithFrame:CGRectChangeXY(tabViewItemMessageLogFrame, 0, 0)];
[[tabViewItemMessageLog view] addSubview:messagesScrollView];
[messagesScrollView setBorderType:NSBezelBorder];
[messagesScrollView setHasVerticalScroller:YES];
[messagesScrollView setHasHorizontalScroller:NO];
setControlToSmall([[messagesScrollView verticalScroller] cell]);
NSSize const messagesScrollViewContentSize = [messagesScrollView contentSize];
[messagesScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
messagesView = [[NSTextView alloc] initWithFrame:CGRectMake(0, 0, messagesScrollViewContentSize.width, messagesScrollViewContentSize.height)];
[messagesScrollView setDocumentView:messagesView];
[messagesView setEditable:NO];
[messagesView setRichText:NO];
setFontToSmall(messagesView);
[messagesView setMinSize:CGSizeMake(0.0, messagesScrollViewContentSize.height)];
[messagesView setMaxSize:CGSizeMake(FLT_MAX, FLT_MAX)];
[messagesView setVerticallyResizable:YES];
[messagesView setHorizontallyResizable:NO];
[messagesView setAutoresizingMask:NSViewWidthSizable];
[[messagesView textContainer] setContainerSize:CGSizeMake(messagesScrollViewContentSize.width, FLT_MAX)];
[[messagesView textContainer] setWidthTracksTextView:YES];
}
return self;
}
- (BOOL)canBecomeKeyWindow
{
return YES;
}
- (BOOL)canBecomeMainWindow
{
return YES;
}
- (BOOL) windowShouldClose:(id)sender
{
UNREFERENCED_PARAMETER(sender);
[nsapp abortModal];
return YES;
}
- (void)dealloc
{
@ -121,82 +398,21 @@ static struct soundQuality_t {
if (idx3d >= 0) [videoMode3DPUButton selectItemAtIndex:idx3d];
}
- (void)populateSoundQuality:(BOOL)firstTime
{
int i, curidx = -1;
[soundQualityPUButton removeAllItems];
for (i = 0; soundQualities[i].frequency > 0; i++) {
const char *ch;
switch (soundQualities[i].channels) {
case 1: ch = "Mono"; break;
case 2: ch = "Stereo"; break;
default: ch = "?"; break;
}
NSString *s = [NSString stringWithFormat:@"%dkHz, %d-bit, %s",
soundQualities[i].frequency / 1000,
soundQualities[i].samplesize,
ch
];
[soundQualityPUButton addItemWithTitle:s];
if (firstTime &&
soundQualities[i].frequency == settings.samplerate &&
soundQualities[i].samplesize == settings.bitspersample &&
soundQualities[i].channels == settings.channels) {
curidx = i;
}
}
if (firstTime && curidx < 0) {
soundQualities[i].frequency = settings.samplerate;
soundQualities[i].samplesize = settings.bitspersample;
soundQualities[i].channels = settings.channels;
const char *ch;
switch (soundQualities[i].channels) {
case 1: ch = "Mono"; break;
case 2: ch = "Stereo"; break;
default: ch = "?"; break;
}
NSString *s = [NSString stringWithFormat:@"%dkHz, %d-bit, %s",
soundQualities[i].frequency / 1000,
soundQualities[i].samplesize,
ch
];
[soundQualityPUButton addItemWithTitle:s];
curidx = i++;
soundQualities[i].frequency = -1;
}
if (curidx >= 0) {
[soundQualityPUButton selectItemAtIndex:curidx];
}
}
- (IBAction)alwaysShowClicked:(id)sender
{
UNREFERENCED_PARAMETER(sender);
}
- (IBAction)fullscreenClicked:(id)sender
- (void)fullscreenClicked:(id)sender
{
UNREFERENCED_PARAMETER(sender);
[self populateVideoModes:NO];
}
- (IBAction)cancel:(id)sender
- (void)cancel:(id)sender
{
UNREFERENCED_PARAMETER(sender);
[nsapp abortModal];
}
- (IBAction)start:(id)sender
- (void)start:(id)sender
{
UNREFERENCED_PARAMETER(sender);
@ -208,13 +424,6 @@ static struct soundQuality_t {
settings.fullscreen = validmode[mode].fs;
}
int quality = [soundQualityPUButton indexOfSelectedItem];
if (quality >= 0) {
settings.samplerate = soundQualities[quality].frequency;
settings.bitspersample = soundQualities[quality].samplesize;
settings.channels = soundQualities[quality].channels;
}
int row = [[gameList documentView] selectedRow];
if (row >= 0) {
settings.grp = [[gamelistsrc grpAtIndex:row] entryptr];
@ -232,21 +441,24 @@ static struct soundQuality_t {
[fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)];
[alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)];
[self populateVideoModes:YES];
[self populateSoundQuality:YES];
// enable all the controls on the Configuration page
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
NSControl *control;
while ((control = [enumerator nextObject])) [control setEnabled:true];
while ((control = [enumerator nextObject]))
{
if ([control respondsToSelector:@selector(setEnabled:)])
[control setEnabled:true];
}
gamelistsrc = [[GameListSource alloc] init];
[[gameList documentView] setDataSource:gamelistsrc];
[[gameList documentView] deselectAll:nil];
int row = [gamelistsrc findIndexForGrpname:[NSString stringWithCString:settings.grp->filename encoding:NSUTF8StringEncoding]];
int row = [gamelistsrc findIndexForGrpname:[NSString stringWithUTF8String:settings.grp->filename]];
if (row >= 0) {
[[gameList documentView] scrollRowToVisible:row];
#if defined(MAC_OS_X_VERSION_10_3) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3)
#if defined MAC_OS_X_VERSION_10_3 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3
[[gameList documentView] selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
#else
[[gameList documentView] selectRow:row byExtendingSelection:NO];
@ -256,21 +468,22 @@ static struct soundQuality_t {
[cancelButton setEnabled:true];
[startButton setEnabled:true];
[tabView selectTabViewItemAtIndex:0];
[tabView selectTabViewItem:tabViewItemSetup];
[NSCursor unhide]; // Why should I need to do this?
}
- (void)setupMessagesMode
{
[tabView selectTabViewItemAtIndex:2];
[tabView selectTabViewItem:tabViewItemMessageLog];
// disable all the controls on the Configuration page except "always show", so the
// user can enable it if they want to while waiting for something else to happen
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
NSEnumerator *enumerator = [[[tabViewItemSetup view] subviews] objectEnumerator];
NSControl *control;
while ((control = [enumerator nextObject])) {
if (control == alwaysShowButton) continue;
[control setEnabled:false];
while ((control = [enumerator nextObject]))
{
if (control != alwaysShowButton && [control respondsToSelector:@selector(setEnabled:)])
[control setEnabled:false];
}
[cancelButton setEnabled:false];
@ -299,14 +512,9 @@ static struct soundQuality_t {
}
}
- (void)setTitle:(NSString *)str
{
[[self window] setTitle:str];
}
@end
static StartupWinController *startwin = nil;
static StartupWindow *startwin = nil;
int startwin_open(void)
{
@ -316,39 +524,10 @@ int startwin_open(void)
if (startwin != nil) return 1;
startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.game"];
startwin = [[StartupWindow alloc] init];
if (startwin == nil) return -1;
{
static int soundQualityFrequencies[] = { 48000, 44100, 32000, 24000, 22050 };
static int soundQualitySampleSizes[] = { 16, 8 };
static int soundQualityChannels[] = { 2, 1 };
size_t f, b, c, i;
i = sizeof(soundQualityFrequencies) *
sizeof(soundQualitySampleSizes) *
sizeof(soundQualityChannels) /
sizeof(int) + 2; // one for the terminator, one for a custom setting
soundQualities = (struct soundQuality_t *) malloc(i * sizeof(struct soundQuality_t));
i = 0;
for (c = 0; c < sizeof(soundQualityChannels) / sizeof(int); c++) {
for (b = 0; b < sizeof(soundQualitySampleSizes) / sizeof(int); b++) {
for (f = 0; f < sizeof(soundQualityFrequencies) / sizeof(int); f++) {
soundQualities[i].frequency = soundQualityFrequencies[f];
soundQualities[i].samplesize = soundQualitySampleSizes[b];
soundQualities[i].channels = soundQualityChannels[c];
i++;
}
}
}
soundQualities[i].frequency = -1;
}
[startwin setupMessagesMode];
[startwin showWindow:nil];
return 0;
}
@ -361,8 +540,6 @@ int startwin_close(void)
[startwin release];
startwin = nil;
free(soundQualities);
return 0;
}
@ -373,7 +550,7 @@ int startwin_puts(const char *s)
if (!s) return -1;
if (startwin == nil) return 1;
ns = [[NSString alloc] initWithUTF8String:s];
ns = [NSString stringWithUTF8String:s];
[startwin putsMessage:ns];
[ns release];
@ -387,7 +564,7 @@ int startwin_settitle(const char *s)
if (!s) return -1;
if (startwin == nil) return 1;
ns = [[NSString alloc] initWithUTF8String:s];
ns = [NSString stringWithUTF8String:s];
[startwin setTitle:ns];
[ns release];
@ -398,7 +575,7 @@ int startwin_idle(void *v)
{
UNREFERENCED_PARAMETER(v);
if (startwin) [[startwin window] displayIfNeeded];
if (startwin) [startwin displayIfNeeded];
return 0;
}
@ -413,15 +590,12 @@ int startwin_run(void)
settings.xdim3d = ud.config.ScreenWidth;
settings.ydim3d = ud.config.ScreenHeight;
settings.bpp3d = ud.config.ScreenBPP;
settings.samplerate = ud.config.MixRate;
settings.bitspersample = ud.config.NumBits;
settings.channels = ud.config.NumChannels;
settings.forcesetup = ud.config.ForceSetup;
settings.grp = g_selectedGrp;
[startwin setupRunMode];
switch ([nsapp runModalForWindow:[startwin window]]) {
switch ([nsapp runModalForWindow:startwin]) {
#ifdef MAC_OS_X_VERSION_10_9
case NSModalResponseStop: retval = 1; break;
case NSModalResponseAbort: retval = 0; break;
@ -439,9 +613,6 @@ int startwin_run(void)
ud.config.ScreenWidth = settings.xdim3d;
ud.config.ScreenHeight = settings.ydim3d;
ud.config.ScreenBPP = settings.bpp3d;
ud.config.MixRate = settings.samplerate;
ud.config.NumBits = settings.bitspersample;
ud.config.NumChannels = settings.channels;
ud.config.ForceSetup = settings.forcesetup;
g_selectedGrp = settings.grp;
}