Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

inputbuffer.h

Go to the documentation of this file.
00001 /*
00002         $Id: inputbuffer.h,v 1.3 2001/03/15 12:14:46 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00016 
00017 #ifndef header_inputbuffer
00018 #define header_inputbuffer
00019 
00020 #include <queue>
00021 #include "key.h"
00022 #include "../../signals.h"
00023 
00024 class CL_Component;
00025 
00026 class CL_InputBuffer
00027 //: Input buffer interface.
00028 // Use this class to read buffered keys from the keyboard (or any other device).
00029 {
00030 public:
00031         CL_InputBuffer();
00032         // Constructs an input buffer that attaches itself to the first keyboard.
00033 
00034         CL_InputBuffer(CL_InputDevice *device);
00035         // Constructs an input buffer that attaches itself to the specified device.
00036         
00037         CL_InputBuffer(
00038                 CL_Signal_v4<CL_Component *, CL_InputDevice *, CL_Key, bool &> &sig_key_down,
00039                 CL_Signal_v3<CL_Component *, CL_InputDevice *, CL_Key> &sig_key_up);
00040         // Constructs an input buffer that attaches itself to the specified signals.
00041         // Use it to buffer input from a GUI component.
00042 
00043         virtual ~CL_InputBuffer();
00044 
00045         CL_Key peek_key() const;
00046         // Returns the next key in the buffer, but unlike get_key() it does not
00047         // pop it from the input buffer.
00048 
00049         CL_Key get_key();
00050         // Pops the next key in the buffer and returns it.
00051 
00052         int keys_left();
00053         // Returns number of keys still available in the buffer.
00055 
00056         void clear();
00057         // Clears the buffer. After this, the buffer will not contain any keys.
00058 
00059 // implementation:
00060 private:
00061         CL_Slot slot_button_press;
00062         CL_Slot slot_button_release;
00063         CL_Slot slot_key_down;
00064         CL_Slot slot_key_up;
00065 
00066         void on_button_press(CL_InputDevice *device, const CL_Key &key);
00067         void on_button_release(CL_InputDevice *device, const CL_Key &key);
00068 
00069         void on_key_down(CL_Component *, CL_InputDevice *device, CL_Key key, bool &retval);
00070         void on_key_up(CL_Component *, CL_InputDevice *device, CL_Key key);
00071 
00072         std::queue<CL_Key> buffer;
00073         CL_InputDevice *device;
00074 };
00075 
00076 #endif

Generated at Wed Apr 4 19:54:00 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001