File: inputbuffer.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (115 lines) | stat: -rw-r--r-- 2,695 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
	$Id: inputbuffer.cpp,v 1.5 2001/12/16 19:18:08 mbn Exp $

	------------------------------------------------------------------------
	ClanLib, the platform independent game SDK.

	This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
	version 2. See COPYING for details.

	For a total list of contributers see CREDITS.

	------------------------------------------------------------------------
*/

#include "Core/precomp.h"
#include "API/Display/Input/input.h"
#include "API/Display/Input/key.h"
#include "API/Display/Input/inputbuffer.h"
#include "API/Display/Input/keyboard.h"

CL_InputBuffer::CL_InputBuffer()
{
	device = CL_Input::keyboards[0];

	slot_button_press = CL_Input::sig_button_press.connect(this, &CL_InputBuffer::on_button_press);
	slot_button_release = CL_Input::sig_button_release.connect(this, &CL_InputBuffer::on_button_release);
}

CL_InputBuffer::CL_InputBuffer(CL_InputDevice *device)
{
	this->device = device;

	slot_button_press = CL_Input::sig_button_press.connect(this, &CL_InputBuffer::on_button_press);
	slot_button_release = CL_Input::sig_button_release.connect(this, &CL_InputBuffer::on_button_release);
}

CL_InputBuffer::CL_InputBuffer(
	CL_Signal_v4<CL_Component *, CL_InputDevice *, CL_Key, bool &> &sig_key_down,
	CL_Signal_v3<CL_Component *, CL_InputDevice *, CL_Key> &sig_key_up)
{
	device = CL_Input::keyboards[0];

	slot_key_down = sig_key_down.connect(this, &CL_InputBuffer::on_key_down);
	slot_key_up = sig_key_up.connect(this, &CL_InputBuffer::on_key_up);
}

CL_InputBuffer::~CL_InputBuffer()
{
}

CL_Key CL_InputBuffer::peek_key() const
{
	if (buffer.empty())
	{
		CL_Key key;
		key.state = CL_Key::NoKey;
		return key;
	}

	return buffer.front();
}

CL_Key CL_InputBuffer::get_key()
{
	if (buffer.empty())
	{
		CL_Key key;
		key.state = CL_Key::NoKey;
		return key;
	}
	
	CL_Key key = buffer.front();
	buffer.pop();
	return key;
}

int CL_InputBuffer::keys_left()
{
	return buffer.size();
}

void CL_InputBuffer::clear()
{
	while (!buffer.empty()) buffer.pop();
}

void CL_InputBuffer::on_button_press(
	CL_InputDevice *device,
	const CL_Key &key)
{
	if (this->device != device) return; // wrong device.

	buffer.push(key);
}

void CL_InputBuffer::on_button_release(
	CL_InputDevice *device,
	const CL_Key &key)
{
	if (this->device != device) return; // wrong device.

	buffer.push(key);
}

void CL_InputBuffer::on_key_down(CL_Component *, CL_InputDevice *device, CL_Key key, bool &retval)
{
	if (this->device != device) return; // wrong device.
	buffer.push(key);
}

void CL_InputBuffer::on_key_up(CL_Component *, CL_InputDevice *device, CL_Key key)
{
	if (this->device != device) return; // wrong device.
	buffer.push(key);
}