home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / window / main.cpp next >
Encoding:
C/C++ Source or Header  |  1993-07-10  |  3.3 KB  |  153 lines

  1. // --------------------------------------------------------------------------
  2. // File:        MAIN.HPP
  3. // Path:        ...\REHACK\WINDOW\MAIN.CPP
  4. // Version:        0.01
  5. // Author:        Pat Reilly
  6. // CIS Id:        71333,2764
  7. // Created On:    
  8. // Modified On:
  9. // Description:
  10. // Tabs:        4
  11. // --------------------------------------------------------------------------
  12.  
  13. #include <stdio.h>
  14. #include "..\game\game.hpp"
  15. #include "..\event\event.hpp"
  16.  
  17. // Example program using the window classes, event queue, and (temp) mouse
  18. //    class for REHACK. MOUSE.CPP requires Borland's BC++ to compile; if using
  19. //    MSC++, you will have to modify it.
  20. //
  21. // Program requires a mouse to work or you won't be able to exit the program
  22. //    (there's no Keyboard class yet). All this program does is to trap mouse
  23. //    (positional device) events; on a LB depress, the cursor changes; on a
  24. //    LB release, it changes back. On a LB double-click, the program quits.
  25.  
  26. // Add functionality (ability to quit <g>) to Game by deriving a new class.
  27.  
  28. class MyGame : public Game
  29. {
  30. public:
  31.  
  32.     MyGame();
  33.     ~MyGame();
  34.  
  35.     virtual void handle(Event&);
  36. };
  37.  
  38. // Mouse masks for demo.
  39. word normalMask[] = {
  40.     0,0,0,0,0,0,0,0,
  41.     0,0,0,0,0,0,0,0,
  42.     0x0FF0,
  43.     0x3FFC,
  44.     0x7FFE,
  45.     0x7FFE,
  46.     0xE187,
  47.     0xFFFF,
  48.     0xFFFF,
  49.     0xFFFF,
  50.     0xFFFF,
  51.     0xFFFF,
  52.     0xFFFF,
  53.     0xFFFF,
  54.     0x7FFE,
  55.     0x7FFE,
  56.     0x3FFC,
  57.     0x0FF0
  58.     };
  59.  
  60. word altMask[] = {
  61.     0,0,0,0,0,0,0,0,
  62.     0,0,0,0,0,0,0,0,
  63.     0x0FF0,
  64.     0x3FFC,
  65.     0x7FFE,
  66.     0x799E,
  67.     0xF99F,
  68.     0xFFFF,
  69.     0xFFFF,
  70.     0xFC3F,
  71.     0xFBDF,
  72.     0xF7EF,
  73.     0xF7EF,
  74.     0xF7EF,
  75.     0x77EE,
  76.     0x7BDE,
  77.     0x3C3C,
  78.     0x0FF0
  79.     };
  80. Point mcHotSpot = { -8, -8 };
  81.  
  82. // Constructor: just set to graphics mode and init the mouse.
  83. MyGame::MyGame() : Game(Rect(0,0, 320,200)), GameInit(0,0,0,0,0)
  84. {
  85.     // Set video mode to 320x200x256
  86.     _AX = 0x0013;
  87.     asm    int 0x10;
  88.  
  89.     // Mouse driver want a vga screen width.
  90.     mouse.setBounds(Rect(0,0, 639,199));
  91.     mouse.setCursor(mcHotSpot, normalMask);
  92.     mouse.show();
  93. }
  94.  
  95. // Destructor: restore text mode.
  96. MyGame::~MyGame()
  97. {
  98.     // Restore MODE CO80 screen.
  99.     _AX = 3;
  100.     asm int 0x10;
  101. }
  102.  
  103. // Event handler: quit on mouse LB double-click. On normal LB down, set
  104. //    mouse cursor to altMask; on LB up, set cursor to normalMask.
  105. void MyGame::handle(Event& event)
  106. {
  107.     // Perform normal event handling.
  108.     Game::handle(event);
  109.  
  110.     if((event.type & PosDeviceBtnDown) &&
  111.        (event.posDevice.buttons & LeftBtn))
  112.         {
  113.         // LB double clicked.
  114.         if(event.posDevice.dblClicked)
  115.             stopRunning(IdQuit);
  116.         // LB down -set cursor to alt mask.
  117.         else
  118.             mouse.setCursor(mcHotSpot, altMask);
  119.         event.clear();
  120.         }
  121.     else if((event.type & PosDeviceBtnUp) &&
  122.             (event.posDevice.buttons & LeftBtn) == 0)
  123.         {
  124.         // LB up - set cursor to normal mask.
  125.         mouse.setCursor(mcHotSpot, normalMask);
  126.         event.clear();
  127.         }
  128.     else if ( event.type & Key )
  129.     {
  130.         // escape key also exits
  131.         if ( event.key.charScanValue.scan == scanESC )
  132.             stopRunning( IdQuit );
  133.         else
  134.         {
  135.             mouse.hide();
  136.             printf( "%s, Scan: %X, Code: %X, Char: '%c'\n",
  137.                     event.type & KeyDown ? "KeyDown" : "KeyUp  ",
  138.                     event.key.charScanValue.scan,
  139.                     event.key.charScanValue.code,
  140.                     event.key.charScanValue.code );
  141.             mouse.show();
  142.         }
  143.     }
  144.  
  145. }
  146.  
  147. int main()
  148. {
  149.     MyGame game;    // make a game.
  150.     game.run();        // run it.
  151.     return 0;
  152. }
  153.