| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | _______________________________________________________________________ |
| 39 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 40 | | |
| 41 | | $Revision: 1.1.1.1 $ |
| 42 | | |
| 43 | | Methods : TsField::handleKeyboard |
| 44 | | |
| 45 | | Author : Dave Immel |
| 46 | | |
| 47 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 48 | _______________________________________________________________________ |
| 49 | */ |
| 50 | |
| 51 | //--------------------------- Include ---------------------------------- |
| 52 | #include <Inventor/events/SoKeyboardEvent.h>cxx . . $ `<file>/lib/database/include/Inventor/events/SoKeyboardEvent.h`/ |
| 53 | #include <Inventor/events/SoSpaceballButtonEvent.h>cxx . . $ `<file>/lib/database/include/Inventor/events/SoSpaceballButtonEvent.h`/ |
| 54 | #include <Inventor/nodes/SoEventCallback.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoEventCallback.h`/ |
| 55 | #include <Inventor/nodes/SoSeparator.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoSeparator.h`/ |
| 56 | #include "TsField.h"cxx . . $ `<file>/apps/demos/drop/TsField.h`/ |
| 57 | |
| 58 | //////////////////////////////////////////////////////////////////////// |
| 59 | // |
| 60 | // Description: |
| 61 | // This routine handles all keyboard events that move the pieces as |
| 62 | // they fall. |
| 63 | // |
| 64 | // Use: private, static |
| 65 | |
| 66 | void |
| 67 | TsFieldcxx . . $ TsField#::handleKeyboardcxx . . $ TsField#handleKeyboard(49f19ea0a3c92bf1).( void *data, SoEventCallbackcxx . . $ SoEventCallback# *node ) |
| 68 | |
| 69 | // |
| 70 | //////////////////////////////////////////////////////////////////////// |
| 71 | { |
| 72 | TsFieldcxx . . $ TsField# *field = (TsFieldcxx . . $ TsField# *)data; |
| 73 | |
| 74 | if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), RETURN)) { |
| 75 | field->gameStartedcxx . . $ TsField#gameStarted. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 76 | field->handleReturnKeycxx . . $ TsField#handleReturnKey(49f6e7a06ebc5aa8).(); |
| 77 | node->setHandledcxx . . $ SoEventCallback#setHandled(49f6e7a06ebc5aa8).(); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | // If the game has been paused, don't accept any input. Just return. |
| 82 | // (Also, don't accept input if the game has not started.) |
| 83 | if (field->gamePausedcxx . . $ TsField#gamePaused. || !field->gameStartedcxx . . $ TsField#gameStarted.) { |
| 84 | node->setHandledcxx . . $ SoEventCallback#setHandled(49f6e7a06ebc5aa8).(); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), LEFT_ARROW)) |
| 89 | field->translationcxx . . $ TsField#translation(3e454b8ccf442868). (TS_X_AXIScxx . . $ TS_X_AXIS., -1); |
| 90 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), RIGHT_ARROW)) |
| 91 | field->translationcxx . . $ TsField#translation(3e454b8ccf442868). (TS_X_AXIScxx . . $ TS_X_AXIS., 1); |
| 92 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), UP_ARROW)) |
| 93 | field->translationcxx . . $ TsField#translation(3e454b8ccf442868). (TS_Z_AXIScxx . . $ TS_Z_AXIS., 1); |
| 94 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), DOWN_ARROW)) |
| 95 | field->translationcxx . . $ TsField#translation(3e454b8ccf442868). (TS_Z_AXIScxx . . $ TS_Z_AXIS., -1); |
| 96 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), F)) |
| 97 | field->rotationcxx . . $ TsField#rotation(3e454b8ccf442868). (TS_Z_AXIScxx . . $ TS_Z_AXIS., 1); |
| 98 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), S)) |
| 99 | field->rotationcxx . . $ TsField#rotation(3e454b8ccf442868). (TS_Z_AXIScxx . . $ TS_Z_AXIS., -1); |
| 100 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), D)) |
| 101 | field->rotationcxx . . $ TsField#rotation(3e454b8ccf442868). (TS_Y_AXIScxx . . $ TS_Y_AXIS., 1); |
| 102 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), C)) |
| 103 | field->rotationcxx . . $ TsField#rotation(3e454b8ccf442868). (TS_X_AXIScxx . . $ TS_X_AXIS., -1); |
| 104 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), E)) |
| 105 | field->rotationcxx . . $ TsField#rotation(3e454b8ccf442868). (TS_X_AXIScxx . . $ TS_X_AXIS., 1); |
| 106 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), SPACE)) |
| 107 | field->dropPiececxx . . $ TsField#dropPiece(49f6e7a06ebc5aa8).(); |
| 108 | else if (SO_KEY_PRESS_EVENTcxx . . $ `lib/database/include/Inventor/events/SoKeyboardEvent.h:65:9`!(node->getEvent(), H)) { |
| 109 | field->handleHelpKeycxx . . $ TsField#handleHelpKey(49f6e7a06ebc5aa8).(); |
| 110 | } |
| 111 | |
| 112 | node->setHandledcxx . . $ SoEventCallback#setHandled(49f6e7a06ebc5aa8).(); |
| 113 | } |
| 114 | |
| 115 | //////////////////////////////////////////////////////////////////////// |
| 116 | // |
| 117 | // Description: |
| 118 | // This routine handles the return key press. |
| 119 | // |
| 120 | // Use: public |
| 121 | |
| 122 | void |
| 123 | TsFieldcxx . . $ TsField#::handleReturnKeycxx . . $ TsField#handleReturnKey(49f6e7a06ebc5aa8).() |
| 124 | |
| 125 | // |
| 126 | //////////////////////////////////////////////////////////////////////// |
| 127 | { |
| 128 | // If help had been displayed, either start the first game |
| 129 | // or resume a game in progress. |
| 130 | if (helpDisplayedcxx . . $ TsField#helpDisplayed.) { |
| 131 | helpDisplayedcxx . . $ TsField#helpDisplayed. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 132 | helpRootcxx . . $ TsField#helpRoot.->removeChildcxx . . $ SoGroup#removeChild(da6c7544ccee32bd).(helpGroupcxx . . $ TsField#helpGroup.); //old:overRoot->removeChild(helpRoot) |
| 133 | if (isGameOvercxx . . $ TsField#isGameOver.) |
| 134 | startNewGamecxx . . $ TsField#startNewGame(49f6e7a06ebc5aa8).(); |
| 135 | else |
| 136 | resumeGamecxx . . $ TsField#resumeGame(49f6e7a06ebc5aa8).(); |
| 137 | } |
| 138 | else { |
| 139 | // Start a new game |
| 140 | startNewGamecxx . . $ TsField#startNewGame(49f6e7a06ebc5aa8).(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | //////////////////////////////////////////////////////////////////////// |
| 145 | // |
| 146 | // Description: |
| 147 | // This routine handles the H key press. |
| 148 | // |
| 149 | // Use: public |
| 150 | |
| 151 | void |
| 152 | TsFieldcxx . . $ TsField#::handleHelpKeycxx . . $ TsField#handleHelpKey(49f6e7a06ebc5aa8).() |
| 153 | |
| 154 | // |
| 155 | //////////////////////////////////////////////////////////////////////// |
| 156 | { |
| 157 | // If the help message is not displayed, add the help message geometry |
| 158 | // to the scene graph and pause the game. |
| 159 | if (!helpDisplayedcxx . . $ TsField#helpDisplayed.) { |
| 160 | helpRootcxx . . $ TsField#helpRoot.->addChildcxx . . $ SoGroup#addChild(da6c7544ccee32bd).(helpGroupcxx . . $ TsField#helpGroup.); //old: overRoot->addChild(helpRoot); |
| 161 | helpDisplayedcxx . . $ TsField#helpDisplayed. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 162 | pauseGamecxx . . $ TsField#pauseGame(49f6e7a06ebc5aa8).(); |
| 163 | } |
| 164 | } |