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

inputbuffer.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: inputbuffer.cpp,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 
00015 #include "Core/precomp.h"
00016 #include "API/Display/Input/input.h"
00017 #include "API/Display/Input/key.h"
00018 #include "API/Display/Input/inputbuffer.h"
00019 #include "API/Display/Input/keyboard.h"
00020 
00021 CL_InputBuffer::CL_InputBuffer()
00022 {
00023         device = CL_Input::keyboards[0];
00024 
00025         slot_button_press = CL_Input::sig_button_press.connect(CL_CreateSlot(this, &CL_InputBuffer::on_button_press));
00026         slot_button_release = CL_Input::sig_button_release.connect(CL_CreateSlot(this, &CL_InputBuffer::on_button_release));
00027 }
00028 
00029 CL_InputBuffer::CL_InputBuffer(CL_InputDevice *device)
00030 {
00031         this->device = device;
00032 
00033         slot_button_press = CL_Input::sig_button_press.connect(CL_CreateSlot(this, &CL_InputBuffer::on_button_press));
00034         slot_button_release = CL_Input::sig_button_release.connect(CL_CreateSlot(this, &CL_InputBuffer::on_button_release));
00035 }
00036 
00037 CL_InputBuffer::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 {
00041         device = CL_Input::keyboards[0];
00042 
00043         slot_key_down = sig_key_down.connect(CL_CreateSlot(this, &CL_InputBuffer::on_key_down));
00044         slot_key_up = sig_key_up.connect(CL_CreateSlot(this, &CL_InputBuffer::on_key_up));
00045 }
00046 
00047 CL_InputBuffer::~CL_InputBuffer()
00048 {
00049 }
00050 
00051 CL_Key CL_InputBuffer::peek_key() const
00052 {
00053         if (buffer.empty())
00054         {
00055                 CL_Key key;
00056                 key.state = CL_Key::NoKey;
00057                 return key;
00058         }
00059 
00060         return buffer.front();
00061 }
00062 
00063 CL_Key CL_InputBuffer::get_key()
00064 {
00065         if (buffer.empty())
00066         {
00067                 CL_Key key;
00068                 key.state = CL_Key::NoKey;
00069                 return key;
00070         }
00071         
00072         CL_Key key = buffer.front();
00073         buffer.pop();
00074         return key;
00075 }
00076 
00077 int CL_InputBuffer::keys_left()
00078 {
00079         return buffer.size();
00080 }
00081 
00082 void CL_InputBuffer::clear()
00083 {
00084         while (!buffer.empty()) buffer.pop();
00085 }
00086 
00087 void CL_InputBuffer::on_button_press(
00088         CL_InputDevice *device,
00089         const CL_Key &key)
00090 {
00091         if (this->device != device) return; // wrong device.
00092 
00093         buffer.push(key);
00094 }
00095 
00096 void CL_InputBuffer::on_button_release(
00097         CL_InputDevice *device,
00098         const CL_Key &key)
00099 {
00100         if (this->device != device) return; // wrong device.
00101 
00102         buffer.push(key);
00103 }
00104 
00105 void CL_InputBuffer::on_key_down(CL_Component *, CL_InputDevice *device, CL_Key key, bool &retval)
00106 {
00107         if (this->device != device) return; // wrong device.
00108         buffer.push(key);
00109 }
00110 
00111 void CL_InputBuffer::on_key_up(CL_Component *, CL_InputDevice *device, CL_Key key)
00112 {
00113         if (this->device != device) return; // wrong device.
00114         buffer.push(key);
00115 }

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