|
|
Sample Programs from NeXSTEP 3.3
/*
* BreakApp.m, subclass of Application for BreakApp.
* Author: Ali Ozer
* Written for 1.0 July 89.
* Modified for 2.0 Sept 90; separated the panels into their own .nib files.
* Modified for 3.0 March 92
*
* This class manages the windows & such for the BreakApp application.
*
* You may freely copy, distribute and reuse the code in this example.
* NeXT disclaims any warranty of any kind, expressed or implied,
* as to its fitness for any particular use.
*/
#import <appkit/appkit.h>
#import <libc.h>
#import "BreakApp.h"
#import "BreakView.h"
@implementation BreakApp
+ new
{
self = [super new];
[self setDelegate:self]; // For appDidHide:
return self;
}
// appDidInit is called as the first thing in the run loop of the
// application. At this point, everything is created, but we haven't entered
// the event loop yet. appDidInit: initializes a few things and
// calls the gotoFirstLevel: method of the BreakView instance to get
// started on a new game.
- appDidInit:app
{
NXRect gameWindowFrame, controlWindowFrame;
[gameWindow setDelegate:self]; // For windowDidMiniaturize:
[gameWindow setExcludedFromWindowsMenu:YES]; // We do this by hand (in IB)
[controlWindow removeFromEventMask:NX_KEYDOWNMASK|NX_KEYUPMASK];
// Put the control window right next to the game window (game window is
// set to come up "right" automatically on different sized screens).
[gameWindow getFrame:&gameWindowFrame];
[controlWindow getFrame:&controlWindowFrame];
NX_Y(&controlWindowFrame) = NX_MAXY(&gameWindowFrame) - NX_HEIGHT(&controlWindowFrame);
NX_X(&controlWindowFrame) = NX_X(&gameWindowFrame) - NX_WIDTH(&controlWindowFrame) - 2.0;
[controlWindow moveTo:NX_X(&controlWindowFrame) :NX_Y(&controlWindowFrame)];
[game gotoFirstLevel:self];
[controlWindow orderFront:self];
[gameWindow makeKeyAndOrderFront:self];
return self;
}
// appDidHide is called when the application is hidden. It doesn't
// make sense to run the game while the application is running, also,
// in case the boss walks by you want to be able to hit just Command-h and
// have the game hide and pause at the same time. This way the boss won't
// ask where "ping-ping" noises are coming from and you will not have lost
// a high-score game.
- appDidHide:app
{
[game stop:self];
return self;
}
// We do pretty much the same if the user miniaturizes the game window.
- windowDidMiniaturize:window
{
if (window == gameWindow) [game stop:self];
return self;
}
// printGame: allows us to print the game window. We could've just connected
// the "Print..." menu item to the window's smartPrintPSCode:; however, we
// wanted to be able to change the title to reflect the status.
- printGame:sender
{
char *savedTitle = NXCopyStringBuffer([gameWindow title]);
char statusString[100];
sprintf (statusString, NXLocalString ("Score: %d Level: %d", NULL, "Score and level to be shown when the game window is printed"), [game score], [game level]);
[gameWindow setTitle:statusString];
[gameWindow smartPrintPSCode:sender];
[gameWindow setTitle:savedTitle];
free (savedTitle);
return self;
}
// Method to load the .nib file for the info panel.
- showInfo:sender
{
if (!infoPanel) {
[self loadNibSection:"Info.nib" owner:self withNames:NO];
}
[infoPanel makeKeyAndOrderFront:sender];
return self;
}
@end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.