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
|
/*
Demonstration of the CL_Mouse interface:
This example uses the old way of checking for mouse button presses.
Mousewheel and extra buttons are not supported with this method.
Check out the mouse example using signals for such features.
*/
#include <ClanLib/core.h>
#include <ClanLib/application.h>
#include <ClanLib/display.h>
class MouseApp : public CL_ClanApplication
{
public:
virtual char *get_title() { return "Mouse application"; }
virtual int main(int, char **)
{
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();
CL_ResourceManager *manager = new CL_ResourceManager("mouse.scr", false);
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();
// Loop until the user presses Escape
try
{
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();
if(CL_Mouse::left_pressed())
std::cout << "Left pressed" << std::endl;
if(CL_Mouse::middle_pressed())
std::cout << "Middle pressed" << std::endl;
if(CL_Mouse::right_pressed())
std::cout << "Right pressed" << std::endl;
}
}
catch (CL_Error err)
{
return 1;
}
// Unload all resources
// manager->unload_all_resources();
// Delete resource manager
delete manager;
CL_SetupDisplay::deinit();
CL_SetupCore::deinit();
return 0;
}
} app;
|