home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / NextDeveloper / Examples / AppKit / BreakApp / BreakApp.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  3.4 KB  |  114 lines

  1. /*
  2.  * BreakApp.m, subclass of Application for BreakApp.
  3.  * Author: Ali Ozer
  4.  * Written for 1.0 July 89.
  5.  * Modified for 2.0 Sept 90; separated the panels into their own .nib files.
  6.  * Modified for 3.0 March 92
  7.  *
  8.  * This class manages the windows & such for the BreakApp application.
  9.  *
  10.  *  You may freely copy, distribute and reuse the code in this example.
  11.  *  NeXT disclaims any warranty of any kind, expressed or implied,
  12.  *  as to its fitness for any particular use.
  13.  */
  14.  
  15. #import <appkit/appkit.h>
  16. #import <libc.h>
  17.  
  18. #import "BreakApp.h"
  19. #import "BreakView.h"
  20.  
  21.  
  22. @implementation BreakApp
  23.  
  24. + new
  25. {
  26.     self = [super new];
  27.     [self setDelegate:self];    // For appDidHide:
  28.     return self;
  29. }
  30.    
  31. // appDidInit is called as the first thing in the run loop of the 
  32. // application. At this point, everything is created, but we haven't entered
  33. // the event loop yet. appDidInit: initializes a few things and
  34. // calls the gotoFirstLevel: method of the BreakView instance to get
  35. // started on a new game.
  36.  
  37. - appDidInit:app 
  38. {
  39.     NXRect gameWindowFrame, controlWindowFrame;
  40.  
  41.     [gameWindow setDelegate:self];            // For windowDidMiniaturize:
  42.     [gameWindow setExcludedFromWindowsMenu:YES];    // We do this by hand (in IB)
  43.     [controlWindow removeFromEventMask:NX_KEYDOWNMASK|NX_KEYUPMASK];
  44.  
  45.     // Put the control window right next to the game window (game window is
  46.     // set to come up "right" automatically on different sized screens).
  47.     [gameWindow getFrame:&gameWindowFrame];
  48.     [controlWindow getFrame:&controlWindowFrame];
  49.     NX_Y(&controlWindowFrame) = NX_MAXY(&gameWindowFrame) - NX_HEIGHT(&controlWindowFrame);
  50.     NX_X(&controlWindowFrame) = NX_X(&gameWindowFrame) - NX_WIDTH(&controlWindowFrame) - 2.0;
  51.     [controlWindow moveTo:NX_X(&controlWindowFrame) :NX_Y(&controlWindowFrame)];
  52.  
  53.     [game gotoFirstLevel:self];
  54.  
  55.     [controlWindow orderFront:self];
  56.     [gameWindow makeKeyAndOrderFront:self];
  57.  
  58.     return self;
  59. }
  60.  
  61. // appDidHide is called when the application is hidden. It doesn't
  62. // make sense to run the game while the application is running, also,
  63. // in case the boss walks by you want to be able to hit just Command-h and
  64. // have the game hide and pause at the same time. This way the boss won't
  65. // ask where "ping-ping" noises are coming from and you will not have lost
  66. // a high-score game.
  67.  
  68. - appDidHide:app
  69. {
  70.    [game stop:self];
  71.    return self;
  72. }
  73.  
  74. // We do pretty much the same if the user miniaturizes the game window.
  75.  
  76. - windowDidMiniaturize:window
  77. {
  78.    if (window == gameWindow) [game stop:self];
  79.    return self;
  80. }
  81.  
  82. // printGame: allows us to print the game window. We could've just connected
  83. // the "Print..." menu item to the window's smartPrintPSCode:; however, we
  84. // wanted to be able to change the title to reflect the status.
  85.  
  86. - printGame:sender
  87. {
  88.     char *savedTitle = NXCopyStringBuffer([gameWindow title]);
  89.     char statusString[100];
  90.  
  91.     sprintf (statusString, NXLocalString ("Score: %d  Level: %d", NULL, "Score and level to be shown when the game window is printed"), [game score], [game level]);
  92.     [gameWindow setTitle:statusString];
  93.     [gameWindow smartPrintPSCode:sender];
  94.     [gameWindow setTitle:savedTitle];
  95.     free (savedTitle);
  96.  
  97.     return self;
  98. }
  99.  
  100.  
  101. // Method to load the .nib file for the info panel.
  102.  
  103. - showInfo:sender
  104. {
  105.     if (!infoPanel) {
  106.     [self loadNibSection:"Info.nib" owner:self withNames:NO];
  107.     }
  108.     [infoPanel makeKeyAndOrderFront:sender];
  109.     return self;
  110. }
  111.  
  112.  
  113. @end
  114.