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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/**
** Test application for ClanLib input devices
**/
#include <ClanLib/core.h>
#include <ClanLib/display.h>
#include <ClanLib/gl.h>
#include <ClanLib/gui.h>
#include <ClanLib/application.h>
class InputTest : public CL_ClanApplication
{
public:
CL_CommandLine argp;
int main(int argc, char** argv)
{
try
{
CL_SetupCore setup_core;
parse_options(argc, argv);
read_options();
}
catch (CL_Error& err)
{
std::cout << argv[0] << err.message << std::endl;
}
return 0;
}
void parse_options(int argc, char** argv)
{
argp.add_usage("[OPTIONS]... [FILES]...");
argp.add_doc("Test application ofr ClanLib input devices");
argp.add_option('l', "list", "", "List input devices");
argp.add_option('t', "test", "DEVICENAME", "Test the given device");
argp.add_option('a', "testall", "", "Test all devices");
argp.add_option('h', "help", "", "Print this help text");
argp.parse_args(argc, argv);
}
void read_options()
{
while (argp.next())
{
switch (argp.get_key())
{
case 'h':
argp.print_help();
break;
case 'a':
test_all();
break;
case 't':
test_device(argp.get_argument());
break;
case 'l':
list_devices();
break;
default:
std::cout << "Got " << argp.get_key() << " " << argp.get_argument() << std::endl;
break;
}
}
argp.print_help();
}
void show_device(CL_InputDevice device)
{
std::cout << "Name: " << device.get_name() << std::endl;
std::cout << "Device: " << device.get_device_name() << std::endl;
std::cout << "Type: " << device.get_type() << std::endl;
std::cout << "Buttons: " << device.get_button_count() << std::endl;
std::cout << "Axis: " << device.get_axis_count() << std::endl;
std::cout << std::endl;
}
void list_devices()
{
CL_SetupDisplay setup_display;
CL_SetupGL setup_gl;
CL_SetupGUI setup_gui;
CL_DisplayWindow display("Input Test", 640, 480);
CL_InputContext* ic = display.get_ic();
std::cout << "Device Overview:\n"
<< "================\n";
std::cout << "Joysticks: " << ic->get_joystick_count() << std::endl;
std::cout << "Mice: " << ic->get_mouse_count() << std::endl;
std::cout << "Keyboards: " << ic->get_keyboard_count() << std::endl;
std::cout << std::endl;
std::cout << "Detailed Device List:\n"
<< "================\n";
std::cout << std::endl;
std::cout << "Joysticks:\n"
<< "~~~~~~~~~~\n";
for(int i = 0; i < ic->get_joystick_count(); ++i)
show_device(ic->get_joystick(i));
std::cout << std::endl;
std::cout << "Mice:\n"
<< "~~~~~\n";
for(int i = 0; i < ic->get_mouse_count(); ++i)
show_device(ic->get_mouse(i));
std::cout << std::endl;
std::cout << "Keyboards:\n"
<< "~~~~~~~~~~\n";
for(int i = 0; i < ic->get_keyboard_count(); ++i)
show_device(ic->get_keyboard(i));
std::cout << std::endl;
}
void test_all()
{
CL_SetupDisplay setup_display;
CL_SetupGL setup_gl;
CL_SetupGUI setup_gui;
CL_DisplayWindow display("Input Test", 640, 480);
CL_InputContext* ic = display.get_ic();
std::vector<CL_Slot> slots;
for(int i = 0; i < ic->get_joystick_count(); ++i)
{
CL_InputDevice device = ic->get_joystick(i);
slots.push_back(device.sig_key_down().connect(this, &InputTest::key_down));
slots.push_back(device.sig_key_up().connect(this, &InputTest::key_up));
slots.push_back(device.sig_pointer_move().connect(this, &InputTest::pointer_move));
slots.push_back(device.sig_ball_move().connect(this, &InputTest::ball_move));
slots.push_back(device.sig_axis_move().connect(this, &InputTest::axis_move));
}
for(int i = 0; i < ic->get_mouse_count(); ++i)
{
CL_InputDevice device = ic->get_mouse(i);
slots.push_back(device.sig_key_down().connect(this, &InputTest::key_down));
slots.push_back(device.sig_key_up().connect(this, &InputTest::key_up));
slots.push_back(device.sig_pointer_move().connect(this, &InputTest::pointer_move));
slots.push_back(device.sig_ball_move().connect(this, &InputTest::ball_move));
slots.push_back(device.sig_axis_move().connect(this, &InputTest::axis_move));
}
for(int i = 0; i < ic->get_keyboard_count(); ++i)
{
CL_InputDevice device = ic->get_keyboard(i);
slots.push_back(device.sig_key_down().connect(this, &InputTest::key_down));
slots.push_back(device.sig_key_up().connect(this, &InputTest::key_up));
slots.push_back(device.sig_pointer_move().connect(this, &InputTest::pointer_move));
slots.push_back(device.sig_ball_move().connect(this, &InputTest::ball_move));
slots.push_back(device.sig_axis_move().connect(this, &InputTest::axis_move));
}
while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
{
CL_System::keep_alive(10);
}
}
void test_device(const std::string& devicename)
{
CL_SetupDisplay setup_display;
CL_SetupGL setup_gl;
CL_SetupGUI setup_gui;
CL_DisplayWindow display("Input Test", 640, 480);
CL_InputContext* ic = display.get_ic();
CL_InputDevice device = ic->get_device(devicename);
std::vector<CL_Slot> slots;
slots.push_back(device.sig_key_down().connect(this, &InputTest::key_down));
slots.push_back(device.sig_key_up().connect(this, &InputTest::key_up));
slots.push_back(device.sig_pointer_move().connect(this, &InputTest::pointer_move));
slots.push_back(device.sig_ball_move().connect(this, &InputTest::ball_move));
slots.push_back(device.sig_axis_move().connect(this, &InputTest::axis_move));
while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
{
CL_System::keep_alive(10);
}
}
void key_down(const CL_InputEvent& event)
{
std::cout << "key_down: " << event << std::endl;
}
void key_up(const CL_InputEvent& event)
{
std::cout << "key_up: " << event << std::endl;
}
void pointer_move(const CL_InputEvent& event)
{
std::cout << "pointer_move: " << event << std::endl;
}
void axis_move(const CL_InputEvent& event)
{
std::cout << "axis_move: " << event << std::endl;
}
void ball_move(const CL_InputEvent& event)
{
std::cout << "ball_move: " << event << std::endl;
}
} app;
/* EOF */
|