File: mousesignal.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,798 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
/*
	Demonstration of the CL_Mouse interface:
*/

#include <ClanLib/core.h>
#include <ClanLib/display.h>
#include <ClanLib/application.h>
#include <strstream>

class MouseSignalApp : public CL_ClanApplication
{
public:
	virtual char *get_title() { return "Mouse application"; }

	void on_button_press(CL_InputDevice *device, const CL_Key &key)
	{
		std::strstream button;

		switch(key.id) {
		case CL_MOUSE_LEFTBUTTON:
			button << "Mouse left button";
			break;
		case CL_MOUSE_MIDDLEBUTTON:
			button << "Mouse middle button";
			break;
		case CL_MOUSE_RIGHTBUTTON:
			button << "Mouse right button";
			break;
		case CL_MOUSE_THUMBBUTTON:
			button << "Mouse thumb button";
			break;
		case CL_MOUSE_WHEELBUTTON:
			button << "Mouse wheel button";
			break;
		case CL_MOUSE_WHEELUP:
			button << "Mouse wheel up";
			break;
		case CL_MOUSE_WHEELDOWN:
			button << "Mouse wheel down";
			break;
		case CL_KEY_LCTRL:
			button << "Left control";
			break;
		default:
			button << key.id;
//			return;
		}

		button << " pressed at " << key.x << "," << key.y << '\0';
		std::cout << button.str() << std::endl;
	}

	virtual int main(int, char **)
	{
		// Create a console window for text-output if not available
		CL_ConsoleWindow console("Console");
		console.redirect_stdio();

		try
		{
			CL_SetupCore::init();
			CL_SetupDisplay::init();

			// Set mode: 320x240 16 bpp
			CL_Display::set_videomode(320, 240, 16, false);
			
			// Make sure the display is black at startup:
			CL_Display::clear_display();

			// Open the resource file containing our custom mouse cursor resource
			CL_ResourceManager *manager = new CL_ResourceManager("mouse.scr", false);
			
			// Set the mouse cursor to use a custom mouse provided in our resource file
			CL_MouseCursor::set_cursor(CL_MouseCursorProvider::load("sur_cursor", manager));

			CL_Display::clear_display();
			CL_Display::flip_display();
			CL_Display::clear_display();
			CL_Display::flip_display();
			
			CL_Slot button = CL_Input::sig_button_press.connect(
				this, &MouseSignalApp::on_button_press);

			// Loop until the user presses Escape
			while (CL_Keyboard::get_keycode(CL_KEY_ESCAPE) == false)
			{
				// Clear display
				CL_Display::clear_display(0.0f, 0.0f, 0.5f, 1.0f);
			
				// Flip front and backbuffer - this makes the changes visible
				CL_Display::flip_display();
			
				CL_System::sleep(10);
				
				// Update keyboard input and handle system events
				CL_System::keep_alive();
			}

			// Delete resource manager
			delete manager;

			CL_SetupDisplay::deinit();
			CL_SetupCore::deinit();
		}
		catch (CL_Error err)
		{
			std::cout << "Exception caught: " << err.message.c_str() << std::endl;
		}

		// Display console close message and wait for a key
		console.display_close_message();

		return 0;
	}
} app;