home *** CD-ROM | disk | FTP | other *** search
- // --------------------------------------------------------------------------
- // File: MAIN.HPP
- // Path: ...\REHACK\WINDOW\MAIN.CPP
- // Version: 0.01
- // Author: Pat Reilly
- // CIS Id: 71333,2764
- // Created On:
- // Modified On:
- // Description:
- // Tabs: 4
- // --------------------------------------------------------------------------
-
- #include <stdio.h>
- #include "..\game\game.hpp"
- #include "..\event\event.hpp"
-
- // Example program using the window classes, event queue, and (temp) mouse
- // class for REHACK. MOUSE.CPP requires Borland's BC++ to compile; if using
- // MSC++, you will have to modify it.
- //
- // Program requires a mouse to work or you won't be able to exit the program
- // (there's no Keyboard class yet). All this program does is to trap mouse
- // (positional device) events; on a LB depress, the cursor changes; on a
- // LB release, it changes back. On a LB double-click, the program quits.
-
- // Add functionality (ability to quit <g>) to Game by deriving a new class.
-
- class MyGame : public Game
- {
- public:
-
- MyGame();
- ~MyGame();
-
- virtual void handle(Event&);
- };
-
- // Mouse masks for demo.
- word normalMask[] = {
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0x0FF0,
- 0x3FFC,
- 0x7FFE,
- 0x7FFE,
- 0xE187,
- 0xFFFF,
- 0xFFFF,
- 0xFFFF,
- 0xFFFF,
- 0xFFFF,
- 0xFFFF,
- 0xFFFF,
- 0x7FFE,
- 0x7FFE,
- 0x3FFC,
- 0x0FF0
- };
-
- word altMask[] = {
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0x0FF0,
- 0x3FFC,
- 0x7FFE,
- 0x799E,
- 0xF99F,
- 0xFFFF,
- 0xFFFF,
- 0xFC3F,
- 0xFBDF,
- 0xF7EF,
- 0xF7EF,
- 0xF7EF,
- 0x77EE,
- 0x7BDE,
- 0x3C3C,
- 0x0FF0
- };
- Point mcHotSpot = { -8, -8 };
-
- // Constructor: just set to graphics mode and init the mouse.
- MyGame::MyGame() : Game(Rect(0,0, 320,200)), GameInit(0,0,0,0,0)
- {
- // Set video mode to 320x200x256
- _AX = 0x0013;
- asm int 0x10;
-
- // Mouse driver want a vga screen width.
- mouse.setBounds(Rect(0,0, 639,199));
- mouse.setCursor(mcHotSpot, normalMask);
- mouse.show();
- }
-
- // Destructor: restore text mode.
- MyGame::~MyGame()
- {
- // Restore MODE CO80 screen.
- _AX = 3;
- asm int 0x10;
- }
-
- // Event handler: quit on mouse LB double-click. On normal LB down, set
- // mouse cursor to altMask; on LB up, set cursor to normalMask.
- void MyGame::handle(Event& event)
- {
- // Perform normal event handling.
- Game::handle(event);
-
- if((event.type & PosDeviceBtnDown) &&
- (event.posDevice.buttons & LeftBtn))
- {
- // LB double clicked.
- if(event.posDevice.dblClicked)
- stopRunning(IdQuit);
- // LB down -set cursor to alt mask.
- else
- mouse.setCursor(mcHotSpot, altMask);
- event.clear();
- }
- else if((event.type & PosDeviceBtnUp) &&
- (event.posDevice.buttons & LeftBtn) == 0)
- {
- // LB up - set cursor to normal mask.
- mouse.setCursor(mcHotSpot, normalMask);
- event.clear();
- }
- else if ( event.type & Key )
- {
- // escape key also exits
- if ( event.key.charScanValue.scan == scanESC )
- stopRunning( IdQuit );
- else
- {
- mouse.hide();
- printf( "%s, Scan: %X, Code: %X, Char: '%c'\n",
- event.type & KeyDown ? "KeyDown" : "KeyUp ",
- event.key.charScanValue.scan,
- event.key.charScanValue.code,
- event.key.charScanValue.code );
- mouse.show();
- }
- }
-
- }
-
- int main()
- {
- MyGame game; // make a game.
- game.run(); // run it.
- return 0;
- }
-