InputManager.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "InputManager.hpp"
00023 #include "InputHandler.hpp"
00024 #include "util/error/Log.hpp"
00025 
00026 
00027 namespace se_ogre {
00028     InputManager
00029     ::InputManager() : handlerCount_(0), handlerStackPos_(-1) {
00030         for(int i = 0; i < MODIFIER_COUNT; ++i) {
00031             isModifierDown_[i] = false;
00032         }
00033     }
00034 
00035     InputManager
00036     ::~InputManager() {
00037     }
00038 
00039 
00040     InputHandler* InputManager
00041     ::active() {
00042         if(handlerStackPos_ < 0) {
00043             //LogFatal("No active input control");
00044             return 0;
00045         }
00046         return handlerStack_[ handlerStackPos_ ];
00047     }
00048 
00049 
00050     InputHandler* InputManager
00051     ::below() {
00052         if(handlerStackPos_ < 1) {
00053             return 0;
00054         }
00055         return handlerStack_[ handlerStackPos_ - 1 ];
00056     }
00057 
00058 
00059     void InputManager
00060     ::push(InputHandler* handler) {
00061         Assert(handlerStackPos_ + 1 < MAX_STACK_SIZE);
00062         LogWarning(handler->name() << " pushed");
00063         if(handlerStackPos_ >= 0) {
00064             handlerStack_[ handlerStackPos_ ]->lostFocusEvent();
00065         }
00066         ++handlerStackPos_;
00067         handlerStack_[ handlerStackPos_ ] = handler;
00068         handlerStack_[ handlerStackPos_ ]->grabbedFocusEvent();
00069     }
00070 
00071 
00072     void InputManager
00073     ::push(const char* name) {
00074         InputHandler* h = handler(name);
00075         Assert(h && "No input handler with that name");
00076         push(h);
00077     }
00078 
00079 
00080     void InputManager
00081     ::pop() {
00082         Assert(handlerStackPos_ >= 0 && "Stack already empty");
00083         LogWarning(handlerStack_[ handlerStackPos_ ]->name() << " popped");
00084         handlerStack_[ handlerStackPos_ ]->lostFocusEvent();
00085         --handlerStackPos_;
00086         if(handlerStackPos_ >= 0) {
00087             handlerStack_[ handlerStackPos_ ]->grabbedFocusEvent();
00088         }
00089     }
00090 
00091 
00092     void InputManager
00093     ::add(InputHandler* handler) {
00094         Assert(!hasHandler(handler->name()));
00095         Assert(handlerCount_ < MAX_HANDLER_COUNT );
00096         handlers_[ handlerCount_++ ] = handler;
00097     }
00098 
00099 
00100     void InputManager
00101     ::remove(InputHandler* handler) {
00102         for(int i = 0; i < handlerCount_; ++i) {
00103             if(handlers_[ i ] == handler) {
00104                 handlers_[ i ] = handlers_[ --handlerCount_ ];
00105                 break;
00106             }
00107         }
00108     }
00109 
00110 
00111     InputHandler* InputManager
00112     ::handler(const char* name) {
00113         for(int i = 0; i < handlerCount_; ++i) {
00114             if(strcmp(name, handlers_[ i ]->name()) == 0) {
00115                 return handlers_[ i ];
00116             }
00117         }
00118         return 0;
00119     }
00120 
00121 
00122     bool InputManager
00123     ::hasHandler(const char* name) {
00124         return (handler(name) != 0);
00125     }
00126 }
00127 

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:05 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo