Debian Codegraph @

Tests/InputButtonTest/main.cpp

raw
1 #include <ClanLib/application.h>
2 #include <ClanLib/core.h>
3 #include <ClanLib/display.h>
4 #include <ClanLib/gl.h>
5
6 /////////////////////////////////////////////////////////////////////////////
7 // Application class
8
9 class Application : public CL_ClanApplication
10 {
11 public:
12 int main(int argc, char** argv);
13
14 private:
15 void inputbutton_test();
16 } app;
17
18 /////////////////////////////////////////////////////////////////////////////
19 // Application main entry point:
20
21 int Application::main(int argc, char** argv)
22 {
23 CL_ConsoleWindow debug_console("Debug console");
24 debug_console.redirect_stdio();
25
26 try
27 {
28 CL_SetupCore::init();
29 CL_SetupDisplay::init();
30 CL_SetupGL::init();
31
32 CL_DisplayWindow window("ClanLib InputButton test program", 800, 600, false, true);
33
34 inputbutton_test();
35
36 CL_SetupDisplay::deinit();
37 CL_SetupCore::deinit();
38 }
39 catch (CL_Error error)
40 {
41 std::cout << "Uncaught error: " << error.message.c_str() << std::endl;
42 debug_console.wait_for_key();
43 }
44
45 return 0;
46 }
47
48 void Application::inputbutton_test()
49 {
50 CL_InputButton move_forward, move_left, move_right, fire;
51
52 move_forward.bind(CL_KeyBinding(CL_KEY_UP, CL_Keyboard::get_device()));
53 move_forward.bind(CL_KeyBinding(CL_MOUSE_RIGHT, CL_Mouse::get_device()));
54 move_left.bind(CL_KeyBinding(CL_KEY_LEFT, CL_Keyboard::get_device()));
55 move_right.bind(CL_KeyBinding(CL_KEY_RIGHT, CL_Keyboard::get_device()));
56 fire.bind(CL_KeyBinding(CL_MOUSE_LEFT, CL_Mouse::get_device()));
57 fire.bind(CL_KeyBinding(CL_KEY_SPACE, CL_Keyboard::get_device()));
58
59 while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
60 {
61 CL_Display::clear();
62
63 if(move_forward.peek_pressed())
64 std::cout << "Move forward " << move_forward.pop_pressed() << std::endl;
65 if(move_left.peek_pressed())
66 std::cout << "Move left " << move_left.pop_pressed() << std::endl;
67 if(move_right.peek_pressed())
68 std::cout << "Move right " << move_right.pop_pressed() << std::endl;
69 if(fire.peek_pressed())
70 std::cout << "Fire " << fire.pop_pressed() << std::endl;
71
72 CL_Display::flip();
73 CL_System::keep_alive(10);
74 }
75 }