Commit 01339fee authored by cutealien's avatar cutealien

- 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
parent 63a37907
...@@ -543,7 +543,7 @@ bool CIrrDeviceLinux::createWindow() ...@@ -543,7 +543,7 @@ bool CIrrDeviceLinux::createWindow()
attributes.event_mask |= PointerMotionMask | attributes.event_mask |= PointerMotionMask |
ButtonPressMask | KeyPressMask | ButtonPressMask | KeyPressMask |
ButtonReleaseMask | KeyReleaseMask; ButtonReleaseMask | KeyReleaseMask;
if (!CreationParams.WindowId) if (!CreationParams.WindowId)
{ {
// create Window, either for Fullscreen or windowed mode // create Window, either for Fullscreen or windowed mode
...@@ -577,7 +577,7 @@ bool CIrrDeviceLinux::createWindow() ...@@ -577,7 +577,7 @@ bool CIrrDeviceLinux::createWindow()
InputOutput, visual->visual, InputOutput, visual->visual,
CWBorderPixel | CWColormap | CWEventMask, CWBorderPixel | CWColormap | CWEventMask,
&attributes); &attributes);
CreationParams.WindowId = (void*)window; CreationParams.WindowId = (void*)window;
Atom wmDelete; Atom wmDelete;
...@@ -592,18 +592,18 @@ bool CIrrDeviceLinux::createWindow() ...@@ -592,18 +592,18 @@ bool CIrrDeviceLinux::createWindow()
window = (Window)CreationParams.WindowId; window = (Window)CreationParams.WindowId;
if (!CreationParams.IgnoreInput) if (!CreationParams.IgnoreInput)
{ {
XCreateWindow(display, XCreateWindow(display,
window, window,
0, 0, Width, Height, 0, visual->depth, 0, 0, Width, Height, 0, visual->depth,
InputOutput, visual->visual, InputOutput, visual->visual,
CWBorderPixel | CWColormap | CWEventMask, CWBorderPixel | CWColormap | CWEventMask,
&attributes); &attributes);
} }
XWindowAttributes wa; XWindowAttributes wa;
XGetWindowAttributes(display, window, &wa); XGetWindowAttributes(display, window, &wa);
CreationParams.WindowSize.Width = wa.width; CreationParams.WindowSize.Width = wa.width;
CreationParams.WindowSize.Height = wa.height; CreationParams.WindowSize.Height = wa.height;
CreationParams.Fullscreen = false; CreationParams.Fullscreen = false;
ExternalWindow = true; ExternalWindow = true;
} }
...@@ -880,7 +880,24 @@ bool CIrrDeviceLinux::run() ...@@ -880,7 +880,24 @@ bool CIrrDeviceLinux::run()
} }
if (irrevent.MouseInput.Event != irr::EMIE_COUNT) if (irrevent.MouseInput.Event != irr::EMIE_COUNT)
{
postEventFromUser(irrevent); 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; break;
case MappingNotify: case MappingNotify:
......
...@@ -379,7 +379,24 @@ bool CIrrDeviceSDL::run() ...@@ -379,7 +379,24 @@ bool CIrrDeviceSDL::run()
irrevent.MouseInput.ButtonStates = MouseButtonStates; irrevent.MouseInput.ButtonStates = MouseButtonStates;
if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED) if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED)
{
postEventFromUser(irrevent); 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; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
namespace irr namespace irr
{ {
//! constructor //! constructor
CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params) CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0), : IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
...@@ -171,6 +170,33 @@ bool CIrrDeviceStub::checkVersion(const char* version) ...@@ -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 //! send the event to the right receiver
bool CIrrDeviceStub::postEventFromUser(const SEvent& event) bool CIrrDeviceStub::postEventFromUser(const SEvent& event)
{ {
...@@ -310,6 +336,18 @@ bool CIrrDeviceStub::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightn ...@@ -310,6 +336,18 @@ bool CIrrDeviceStub::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightn
return false; 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 } // end namespace irr
...@@ -116,6 +116,13 @@ namespace irr ...@@ -116,6 +116,13 @@ namespace irr
//! Get the current Gamma Value for the Display //! Get the current Gamma Value for the Display
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ); 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: protected:
void createGUIAndScene(); void createGUIAndScene();
...@@ -123,6 +130,10 @@ namespace irr ...@@ -123,6 +130,10 @@ namespace irr
//! checks version of SDK and prints warning if there might be a problem //! checks version of SDK and prints warning if there might be a problem
bool checkVersion(const char* version); 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; video::IVideoDriver* VideoDriver;
gui::IGUIEnvironment* GUIEnvironment; gui::IGUIEnvironment* GUIEnvironment;
scene::ISceneManager* SceneManager; scene::ISceneManager* SceneManager;
...@@ -136,6 +147,19 @@ namespace irr ...@@ -136,6 +147,19 @@ namespace irr
video::CVideoModeList VideoModeList; video::CVideoModeList VideoModeList;
SIrrlichtCreationParameters CreationParams; 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 calculateGammaRamp ( u16 *ramp, f32 gamma, f32 relativebrightness, f32 relativecontrast );
void calculateGammaFromRamp ( f32 &gamma, const u16 *ramp ); void calculateGammaFromRamp ( f32 &gamma, const u16 *ramp );
......
...@@ -162,7 +162,24 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -162,7 +162,24 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
dev = getDeviceFromHWnd(hWnd); dev = getDeviceFromHWnd(hWnd);
if (dev) if (dev)
{
dev->postEventFromUser(event); 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; return 0;
} }
...@@ -346,6 +363,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) ...@@ -346,6 +363,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
Win32CursorControl = new CCursorControl(CreationParams.WindowSize, HWnd, CreationParams.Fullscreen); Win32CursorControl = new CCursorControl(CreationParams.WindowSize, HWnd, CreationParams.Fullscreen);
CursorControl = Win32CursorControl; CursorControl = Win32CursorControl;
// initialize doubleclicks with system values
MouseMultiClicks.DoubleClickTime = GetDoubleClickTime();
// create driver // create driver
createDriver(); createDriver();
......
...@@ -81,6 +81,14 @@ namespace irr ...@@ -81,6 +81,14 @@ namespace irr
//! Get the current Gamma Value for the Display //! Get the current Gamma Value for the Display
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ); 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 //! Implementation of the win32 cursor control
class CCursorControl : public gui::ICursorControl class CCursorControl : public gui::ICursorControl
{ {
......
...@@ -34,8 +34,8 @@ COSOperator::COSOperator(const c8* osversion, CIrrDeviceLinux* device) ...@@ -34,8 +34,8 @@ COSOperator::COSOperator(const c8* osversion, CIrrDeviceLinux* device)
: IrrDeviceLinux(device) : IrrDeviceLinux(device)
{ {
} }
#endif
#else // not linux
// constructor // constructor
COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion) COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion)
{ {
...@@ -43,7 +43,7 @@ COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion) ...@@ -43,7 +43,7 @@ COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion)
setDebugName("COSOperator"); setDebugName("COSOperator");
#endif #endif
} }
#endif
//! returns the current operating system version as string. //! returns the current operating system version as string.
const wchar_t* COSOperator::getOperationSystemVersion() const const wchar_t* COSOperator::getOperationSystemVersion() const
......
...@@ -22,9 +22,8 @@ public: ...@@ -22,9 +22,8 @@ public:
// constructor // constructor
#if defined(_IRR_USE_LINUX_DEVICE_) #if defined(_IRR_USE_LINUX_DEVICE_)
COSOperator(const c8* osversion, CIrrDeviceLinux* device); COSOperator(const c8* osversion, CIrrDeviceLinux* device);
#else
COSOperator(const c8* osversion);
#endif #endif
COSOperator(const c8* osversion);
//! returns the current operation system version as string. //! returns the current operation system version as string.
virtual const wchar_t* getOperationSystemVersion() const; virtual const wchar_t* getOperationSystemVersion() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment