stk-code_catmod/lib/irrlicht/tests/cursorSetVisible.cpp
hikerstk 974deca5e1 Added our own irrlicht version - not used atm.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11846 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2012-11-01 02:00:02 +00:00

71 lines
1.8 KiB
C++

// Copyright (C) 2008-2012 Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
using namespace irr;
using namespace core;
struct TrapMouseMoves : IEventReceiver
{
int MouseMovesReceived;
TrapMouseMoves() : MouseMovesReceived(0) { }
virtual bool OnEvent(const SEvent & event)
{
if(event.EventType == EET_MOUSE_INPUT_EVENT
&& event.MouseInput.Event == EMIE_MOUSE_MOVED)
MouseMovesReceived++;
return false;
}
};
/** This test verifies that setting the cursor visibility
only generates a mouse message when it actually changes */
bool cursorSetVisible(void)
{
IrrlichtDevice * device = createDevice(video::EDT_SOFTWARE, dimension2d<u32>(1, 1));
TrapMouseMoves moveTrapper;
device->setEventReceiver(&moveTrapper);
device->run();
gui::ICursorControl * cursor = device->getCursorControl();
// Move the cursor inside the Irrlicht window so that we get messages for it.
cursor->setPosition(0, 0);
device->run(); // Receive any messages
cursor->setVisible(false); // Should generate a mouse move
device->run(); // Receive any messages
cursor->setVisible(false); // Should not generate a mouse move
device->run(); // Receive any messages
cursor->setVisible(true); // Should generate a mouse move
device->run(); // Receive any messages
cursor->setVisible(true); // Should not generate a mouse move
device->run(); // Receive any messages
// We should get at most 3 messages: one for the setPosition(), and one for
// each actual change of visibility.
bool result = (moveTrapper.MouseMovesReceived <= 3);
device->closeDevice();
device->run();
device->drop();
if(!result)
{
logTestString("ERROR: cursorSetVisible received %d events.\n", moveTrapper.MouseMovesReceived);
assert_log(false);
}
return result;
}