- Add mouse events EMIE_MOUSE_DOUBLE_CLICK and EMIE_MOUSE_TRIPLE_CLICK for Linux, Win32 and SDL.

- Fix compiling of SDL on Linux (sorry, was my fault)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2468 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2009-07-12 03:54:01 +00:00
parent 63a3790722
commit 01339feefc
8 changed files with 135 additions and 12 deletions

View File

@ -543,7 +543,7 @@ bool CIrrDeviceLinux::createWindow()
attributes.event_mask |= PointerMotionMask |
ButtonPressMask | KeyPressMask |
ButtonReleaseMask | KeyReleaseMask;
if (!CreationParams.WindowId)
{
// create Window, either for Fullscreen or windowed mode
@ -577,7 +577,7 @@ bool CIrrDeviceLinux::createWindow()
InputOutput, visual->visual,
CWBorderPixel | CWColormap | CWEventMask,
&attributes);
CreationParams.WindowId = (void*)window;
Atom wmDelete;
@ -592,18 +592,18 @@ bool CIrrDeviceLinux::createWindow()
window = (Window)CreationParams.WindowId;
if (!CreationParams.IgnoreInput)
{
XCreateWindow(display,
XCreateWindow(display,
window,
0, 0, Width, Height, 0, visual->depth,
InputOutput, visual->visual,
CWBorderPixel | CWColormap | CWEventMask,
0, 0, Width, Height, 0, visual->depth,
InputOutput, visual->visual,
CWBorderPixel | CWColormap | CWEventMask,
&attributes);
}
XWindowAttributes wa;
XGetWindowAttributes(display, window, &wa);
CreationParams.WindowSize.Width = wa.width;
CreationParams.WindowSize.Height = wa.height;
CreationParams.Fullscreen = false;
CreationParams.Fullscreen = false;
ExternalWindow = true;
}
@ -880,7 +880,24 @@ bool CIrrDeviceLinux::run()
}
if (irrevent.MouseInput.Event != irr::EMIE_COUNT)
{
postEventFromUser(irrevent);
if ( irrevent.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
{
u32 clicks = checkSuccessiveClicks(irrevent.MouseInput.X, irrevent.MouseInput.Y);
if ( clicks == 2 )
{
irrevent.MouseInput.Event = EMIE_MOUSE_DOUBLE_CLICK;
postEventFromUser(irrevent);
}
else if ( clicks == 3 )
{
irrevent.MouseInput.Event = EMIE_MOUSE_TRIPLE_CLICK;
postEventFromUser(irrevent);
}
}
}
break;
case MappingNotify:

View File

@ -379,7 +379,24 @@ bool CIrrDeviceSDL::run()
irrevent.MouseInput.ButtonStates = MouseButtonStates;
if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED)
{
postEventFromUser(irrevent);
if ( irrevent.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
{
u32 clicks = checkSuccessiveClicks(irrevent.MouseInput.X, irrevent.MouseInput.Y);
if ( clicks == 2 )
{
irrevent.MouseInput.Event = EMIE_MOUSE_DOUBLE_CLICK;
postEventFromUser(irrevent);
}
else if ( clicks == 3 )
{
irrevent.MouseInput.Event = EMIE_MOUSE_TRIPLE_CLICK;
postEventFromUser(irrevent);
}
}
}
break;
case SDL_KEYDOWN:

View File

@ -15,7 +15,6 @@
namespace irr
{
//! constructor
CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
@ -171,6 +170,33 @@ bool CIrrDeviceStub::checkVersion(const char* version)
}
//! Compares to the last call of this function to return double and triple clicks.
u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY)
{
const s32 MAX_MOUSEMOVE = 3;
irr::u32 clickTime = getTimer()->getRealTime();
if ( (clickTime-MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime
&& core::abs_(MouseMultiClicks.LastClick.X - mouseX ) <= MAX_MOUSEMOVE
&& core::abs_(MouseMultiClicks.LastClick.Y - mouseY ) <= MAX_MOUSEMOVE
&& MouseMultiClicks.CountSuccessiveClicks < 3 )
{
++MouseMultiClicks.CountSuccessiveClicks;
}
else
{
MouseMultiClicks.CountSuccessiveClicks = 1;
}
MouseMultiClicks.LastClickTime = clickTime;
MouseMultiClicks.LastClick.X = mouseX;
MouseMultiClicks.LastClick.Y = mouseY;
return MouseMultiClicks.CountSuccessiveClicks;
}
//! send the event to the right receiver
bool CIrrDeviceStub::postEventFromUser(const SEvent& event)
{
@ -310,6 +336,18 @@ bool CIrrDeviceStub::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightn
return false;
}
//! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behaviour.
void CIrrDeviceStub::setDoubleClickTime( u32 timeMs )
{
MouseMultiClicks.DoubleClickTime = timeMs;
}
//! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.
u32 CIrrDeviceStub::getDoubleClickTime() const
{
return MouseMultiClicks.DoubleClickTime;
}
} // end namespace irr

View File

@ -116,6 +116,13 @@ namespace irr
//! Get the current Gamma Value for the Display
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast );
//! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behaviour.
//! When set to 0 no double- and tripleclicks will be generated.
virtual void setDoubleClickTime( u32 timeMs );
//! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.
virtual u32 getDoubleClickTime() const;
protected:
void createGUIAndScene();
@ -123,6 +130,10 @@ namespace irr
//! checks version of SDK and prints warning if there might be a problem
bool checkVersion(const char* version);
//! Compares to the last call of this function to return double and triple clicks.
//! \return Returns only 1,2 or 3. A 4th click will start with 1 again.
virtual u32 checkSuccessiveClicks(s32 mouseX, s32 mouseY);
video::IVideoDriver* VideoDriver;
gui::IGUIEnvironment* GUIEnvironment;
scene::ISceneManager* SceneManager;
@ -136,6 +147,19 @@ namespace irr
video::CVideoModeList VideoModeList;
SIrrlichtCreationParameters CreationParams;
struct SMouseMultiClicks
{
SMouseMultiClicks()
: DoubleClickTime(500), CountSuccessiveClicks(0), LastClickTime(0)
{}
u32 DoubleClickTime;
u32 CountSuccessiveClicks;
u32 LastClickTime;
core::position2di LastClick;
};
SMouseMultiClicks MouseMultiClicks;
void calculateGammaRamp ( u16 *ramp, f32 gamma, f32 relativebrightness, f32 relativecontrast );
void calculateGammaFromRamp ( f32 &gamma, const u16 *ramp );

View File

@ -162,7 +162,24 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
dev = getDeviceFromHWnd(hWnd);
if (dev)
{
dev->postEventFromUser(event);
if ( event.MouseInput.Event == irr::EMIE_LMOUSE_PRESSED_DOWN )
{
irr::u32 clicks = dev->checkSuccessiveClicks(event.MouseInput.X, event.MouseInput.Y);
if ( clicks == 2 )
{
event.MouseInput.Event = irr::EMIE_MOUSE_DOUBLE_CLICK;
dev->postEventFromUser(event);
}
else if ( clicks == 3 )
{
event.MouseInput.Event = irr::EMIE_MOUSE_TRIPLE_CLICK;
dev->postEventFromUser(event);
}
}
}
return 0;
}
@ -346,6 +363,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
Win32CursorControl = new CCursorControl(CreationParams.WindowSize, HWnd, CreationParams.Fullscreen);
CursorControl = Win32CursorControl;
// initialize doubleclicks with system values
MouseMultiClicks.DoubleClickTime = GetDoubleClickTime();
// create driver
createDriver();

View File

@ -81,6 +81,14 @@ namespace irr
//! Get the current Gamma Value for the Display
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast );
//! Compares to the last call of this function to return double and triple clicks.
//! \return Returns only 1,2 or 3. A 4th click will start with 1 again.
virtual u32 checkSuccessiveClicks(s32 mouseX, s32 mouseY)
{
// we just have to make it public
return CIrrDeviceStub::checkSuccessiveClicks(mouseX, mouseY);
}
//! Implementation of the win32 cursor control
class CCursorControl : public gui::ICursorControl
{

View File

@ -34,8 +34,8 @@ COSOperator::COSOperator(const c8* osversion, CIrrDeviceLinux* device)
: IrrDeviceLinux(device)
{
}
#endif
#else // not linux
// constructor
COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion)
{
@ -43,7 +43,7 @@ COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion)
setDebugName("COSOperator");
#endif
}
#endif
//! returns the current operating system version as string.
const wchar_t* COSOperator::getOperationSystemVersion() const

View File

@ -22,9 +22,8 @@ public:
// constructor
#if defined(_IRR_USE_LINUX_DEVICE_)
COSOperator(const c8* osversion, CIrrDeviceLinux* device);
#else
COSOperator(const c8* osversion);
#endif
COSOperator(const c8* osversion);
//! returns the current operation system version as string.
virtual const wchar_t* getOperationSystemVersion() const;