Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputBuffer.h @ 1195

Last change on this file since 1195 was 1195, checked in by rgrieder, 16 years ago
  • added OIS to the orxonox src directory
  • adapted VS files
File size: 4.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _InputBuffer_H__
30#define _InputBuffer_H__
31
32#include "CorePrereqs.h"
33
34#include <string>
35#include <list>
36
37#include "ois/OISKeyboard.h"
38
39namespace orxonox
40{
41    class _CoreExport InputBufferListener
42    {};
43
44    class _CoreExport InputBuffer : public OIS::KeyListener
45    {
46        struct InputBufferListenerTuple
47        {
48            InputBufferListener* listener_;
49            void (InputBufferListener::*function_)();
50            bool bListenToAllChanges_;
51            bool bOnlySingleInput_;
52            char char_;
53        };
54
55        public:
56            InputBuffer();
57
58            template <class T>
59            void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput)
60            {
61                struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '};
62                this->listeners_.insert(this->listeners_.end(), newListener);
63            }
64            template <class T>
65            void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput)
66            {
67                struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '};
68                this->listeners_.insert(this->listeners_.end(), newListener);
69            }
70
71            template <class T>
72            void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput)
73            {
74                struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};
75                this->listeners_.insert(this->listeners_.end(), newListener);
76            }
77            template <class T>
78            void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput)
79            {
80                struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};
81                this->listeners_.insert(this->listeners_.end(), newListener);
82            }
83
84            void set(const std::string& input);
85            void append(const std::string& input);
86            void append(const char& input);
87            void removeLast();
88            void clear();
89
90            void updated();
91            void updated(const char& update, bool bSingleInput);
92
93            inline std::string get() const
94                { return this->buffer_; }
95
96            /*inline void activate()
97                { this->setActivated(true); }
98            inline void deactivate()
99                { this->setActivated(false); }
100            inline void setActivated(bool bActivated)
101                { if (this->bActivated_ != bActivated) { this->bActivated_ = bActivated; this->activityChanged(); } else { this->bActivated_ = bActivated; } }
102            inline bool isActivated() const
103                { return this->bActivated_; }
104
105            void activityChanged() const;*/
106
107        private:
108            bool charIsAllowed(const char& input);
109
110            bool keyPressed(const OIS::KeyEvent &e);
111            bool keyReleased(const OIS::KeyEvent &e);
112
113            OIS::Keyboard* keyboard_;
114            //bool bActivated_;
115            std::string buffer_;
116            std::list<InputBufferListenerTuple> listeners_;
117            std::string allowedChars_;
118    };
119}
120
121#endif /* _InputBuffer_H__ */
Note: See TracBrowser for help on using the repository browser.