Commit 122084c7 authored by cutealien's avatar cutealien

- Set "ButtonStates" for mouse events also on Linux (was only for Windows formerly)

- Add Shift+Control states to mouse event


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2405 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 88f41622
...@@ -31,7 +31,7 @@ namespace irr ...@@ -31,7 +31,7 @@ namespace irr
EET_MOUSE_INPUT_EVENT, EET_MOUSE_INPUT_EVENT,
//! A key input event. //! A key input event.
/** Like mouse events, keyboard events are created by the device and passed to /** Like mouse events, keyboard events are created by the device and passed to
IrrlichtDevice::postEventFromUser. They take the same path as mouse events. */ IrrlichtDevice::postEventFromUser. They take the same path as mouse events. */
EET_KEY_INPUT_EVENT, EET_KEY_INPUT_EVENT,
...@@ -43,7 +43,7 @@ namespace irr ...@@ -43,7 +43,7 @@ namespace irr
Linux: Implemented, with POV hat issues. Linux: Implemented, with POV hat issues.
MacOS / Other: Not yet implemented. MacOS / Other: Not yet implemented.
*/ */
EET_JOYSTICK_INPUT_EVENT, EET_JOYSTICK_INPUT_EVENT,
//! A log event //! A log event
/** Log events are only passed to the user receiver if there is one. If they are absorbed by the /** Log events are only passed to the user receiver if there is one. If they are absorbed by the
...@@ -201,13 +201,13 @@ namespace irr ...@@ -201,13 +201,13 @@ namespace irr
//! A tree view node lost selection. See IGUITreeView::getLastEventNode(). //! A tree view node lost selection. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_DESELECT, EGET_TREEVIEW_NODE_DESELECT,
//! A tree view node was selected. See IGUITreeView::getLastEventNode(). //! A tree view node was selected. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_SELECT, EGET_TREEVIEW_NODE_SELECT,
//! A tree view node was expanded. See IGUITreeView::getLastEventNode(). //! A tree view node was expanded. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_EXPAND, EGET_TREEVIEW_NODE_EXPAND,
//! A tree view node was collapsed. See IGUITreeView::getLastEventNode(). //! A tree view node was collapsed. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_COLLAPS, EGET_TREEVIEW_NODE_COLLAPS,
...@@ -245,6 +245,12 @@ struct SEvent ...@@ -245,6 +245,12 @@ struct SEvent
/** Only valid if event was EMIE_MOUSE_WHEEL */ /** Only valid if event was EMIE_MOUSE_WHEEL */
f32 Wheel; f32 Wheel;
//! True if shift was also pressed
bool Shift:1;
//! True if ctrl was also pressed
bool Control:1;
//! A bitmap of button states. You can use isButtonPressed() to determine //! A bitmap of button states. You can use isButtonPressed() to determine
//! if a button is pressed or not. //! if a button is pressed or not.
//! Currently only valid if the event was EMIE_MOUSE_MOVED //! Currently only valid if the event was EMIE_MOUSE_MOVED
...@@ -283,12 +289,12 @@ struct SEvent ...@@ -283,12 +289,12 @@ struct SEvent
}; };
//! A joystick event. //! A joystick event.
/** Unlike other events, joystick events represent the result of polling /** Unlike other events, joystick events represent the result of polling
* each connected joystick once per run() of the device. Joystick events will * each connected joystick once per run() of the device. Joystick events will
* not be generated by default. If joystick support is available for the * not be generated by default. If joystick support is available for the
* active device, _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ is defined, and * active device, _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ is defined, and
* @ref IrrlichtDevice::activateJoysticks() has been called, an event of * @ref IrrlichtDevice::activateJoysticks() has been called, an event of
* this type will be generated once per joystick per @ref IrrlichtDevice::run() * this type will be generated once per joystick per @ref IrrlichtDevice::run()
* regardless of whether the state of the joystick has actually changed. */ * regardless of whether the state of the joystick has actually changed. */
struct SJoystickEvent struct SJoystickEvent
{ {
...@@ -311,16 +317,16 @@ struct SEvent ...@@ -311,16 +317,16 @@ struct SEvent
/** For AXIS_X, AXIS_Y, AXIS_Z, AXIS_R, AXIS_U and AXIS_V /** For AXIS_X, AXIS_Y, AXIS_Z, AXIS_R, AXIS_U and AXIS_V
* Values are in the range -32768 to 32767, with 0 representing * Values are in the range -32768 to 32767, with 0 representing
* the center position. You will receive the raw value from the * the center position. You will receive the raw value from the
* joystick, and so will usually want to implement a dead zone around * joystick, and so will usually want to implement a dead zone around
* the center of the range. Axes not supported by this joystick will * the center of the range. Axes not supported by this joystick will
* always have a value of 0. On Linux, POV hats are represented as axes, * always have a value of 0. On Linux, POV hats are represented as axes,
* usually the last two active axis. * usually the last two active axis.
*/ */
s16 Axis[NUMBER_OF_AXES]; s16 Axis[NUMBER_OF_AXES];
/** The POV represents the angle of the POV hat in degrees * 100, /** The POV represents the angle of the POV hat in degrees * 100,
* from 0 to 35,900. A value of 65535 indicates that the POV hat * from 0 to 35,900. A value of 65535 indicates that the POV hat
* is centered (or not present). * is centered (or not present).
* This value is only supported on Windows. On Linux, the POV hat * This value is only supported on Windows. On Linux, the POV hat
* will be sent as 2 axes instead. */ * will be sent as 2 axes instead. */
...@@ -340,7 +346,7 @@ struct SEvent ...@@ -340,7 +346,7 @@ struct SEvent
return (ButtonStates & (1 << button)) ? true : false; return (ButtonStates & (1 << button)) ? true : false;
} }
}; };
//! Any kind of log event. //! Any kind of log event.
struct SLogEvent struct SLogEvent
...@@ -399,7 +405,7 @@ struct SJoystickInfo ...@@ -399,7 +405,7 @@ struct SJoystickInfo
{ {
//! The ID of the joystick //! The ID of the joystick
/** This is an internal Irrlicht index; it does not map directly /** This is an internal Irrlicht index; it does not map directly
* to any particular hardware joystick. It corresponds to the * to any particular hardware joystick. It corresponds to the
* irr::SJoystickEvent Joystick ID. */ * irr::SJoystickEvent Joystick ID. */
u8 Joystick; u8 Joystick;
......
...@@ -786,6 +786,15 @@ bool CIrrDeviceLinux::run() ...@@ -786,6 +786,15 @@ bool CIrrDeviceLinux::run()
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
irrevent.MouseInput.X = event.xbutton.x; irrevent.MouseInput.X = event.xbutton.x;
irrevent.MouseInput.Y = event.xbutton.y; irrevent.MouseInput.Y = event.xbutton.y;
irrevent.MouseInput.Control = (event.xkey.state & ControlMask) != 0;
irrevent.MouseInput.Shift = (event.xkey.state & ShiftMask) != 0;
// mouse button states
irrevent.MouseInput.ButtonStates = (event.xbutton.state & Button1Mask) ? irr::EMBSM_LEFT : 0;
irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button3Mask) ? irr::EMBSM_RIGHT : 0;
irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button2Mask) ? irr::EMBSM_MIDDLE : 0;
irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button4Mask) ? irr::EMBSM_EXTRA1 : 0;
irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button5Mask) ? irr::EMBSM_EXTRA2 : 0;
postEventFromUser(irrevent); postEventFromUser(irrevent);
break; break;
...@@ -796,6 +805,16 @@ bool CIrrDeviceLinux::run() ...@@ -796,6 +805,16 @@ bool CIrrDeviceLinux::run()
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrevent.MouseInput.X = event.xbutton.x; irrevent.MouseInput.X = event.xbutton.x;
irrevent.MouseInput.Y = event.xbutton.y; irrevent.MouseInput.Y = event.xbutton.y;
irrevent.MouseInput.Control = (event.xkey.state & ControlMask) != 0;
irrevent.MouseInput.Shift = (event.xkey.state & ShiftMask) != 0;
// mouse button states
// This sets the state which the buttons had _prior_ to the event.
// So unlike on Windows the button which just got changed has still the old state here.
// We handle that below by flipping the corresponding bit later.
irrevent.MouseInput.ButtonStates = (event.xbutton.state & Button1Mask) ? irr::EMBSM_LEFT : 0;
irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button3Mask) ? irr::EMBSM_RIGHT : 0;
irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button2Mask) ? irr::EMBSM_MIDDLE : 0;
irrevent.MouseInput.Event = irr::EMIE_COUNT; irrevent.MouseInput.Event = irr::EMIE_COUNT;
...@@ -804,16 +823,19 @@ bool CIrrDeviceLinux::run() ...@@ -804,16 +823,19 @@ bool CIrrDeviceLinux::run()
case Button1: case Button1:
irrevent.MouseInput.Event = irrevent.MouseInput.Event =
(event.type == ButtonPress) ? irr::EMIE_LMOUSE_PRESSED_DOWN : irr::EMIE_LMOUSE_LEFT_UP; (event.type == ButtonPress) ? irr::EMIE_LMOUSE_PRESSED_DOWN : irr::EMIE_LMOUSE_LEFT_UP;
irrevent.MouseInput.ButtonStates ^= irr::EMBSM_LEFT;
break; break;
case Button3: case Button3:
irrevent.MouseInput.Event = irrevent.MouseInput.Event =
(event.type == ButtonPress) ? irr::EMIE_RMOUSE_PRESSED_DOWN : irr::EMIE_RMOUSE_LEFT_UP; (event.type == ButtonPress) ? irr::EMIE_RMOUSE_PRESSED_DOWN : irr::EMIE_RMOUSE_LEFT_UP;
irrevent.MouseInput.ButtonStates ^= irr::EMBSM_RIGHT;
break; break;
case Button2: case Button2:
irrevent.MouseInput.Event = irrevent.MouseInput.Event =
(event.type == ButtonPress) ? irr::EMIE_MMOUSE_PRESSED_DOWN : irr::EMIE_MMOUSE_LEFT_UP; (event.type == ButtonPress) ? irr::EMIE_MMOUSE_PRESSED_DOWN : irr::EMIE_MMOUSE_LEFT_UP;
irrevent.MouseInput.ButtonStates ^= irr::EMBSM_MIDDLE;
break; break;
case Button4: case Button4:
......
...@@ -134,6 +134,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -134,6 +134,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT) m->irrMessage; event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT) m->irrMessage;
event.MouseInput.X = (short)LOWORD(lParam); event.MouseInput.X = (short)LOWORD(lParam);
event.MouseInput.Y = (short)HIWORD(lParam); event.MouseInput.Y = (short)HIWORD(lParam);
event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0);
event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0);
// left and right mouse buttons // left and right mouse buttons
event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON);
// middle and extra buttons // middle and extra buttons
...@@ -560,8 +562,8 @@ void CIrrDeviceWin32::setWindowCaption(const wchar_t* text) ...@@ -560,8 +562,8 @@ void CIrrDeviceWin32::setWindowCaption(const wchar_t* text)
if (IsNonNTWindows) if (IsNonNTWindows)
{ {
const core::stringc s = text; const core::stringc s = text;
#ifdef WIN64 #ifdef WIN64
SetWindowTextA(HWnd, s.c_str()); SetWindowTextA(HWnd, s.c_str());
#else #else
SendMessageTimeout(HWnd, WM_SETTEXT, 0, SendMessageTimeout(HWnd, WM_SETTEXT, 0,
reinterpret_cast<LPARAM>(s.c_str()), reinterpret_cast<LPARAM>(s.c_str()),
...@@ -570,9 +572,9 @@ void CIrrDeviceWin32::setWindowCaption(const wchar_t* text) ...@@ -570,9 +572,9 @@ void CIrrDeviceWin32::setWindowCaption(const wchar_t* text)
} }
else else
{ {
#ifdef WIN64 #ifdef WIN64
SetWindowTextW(HWnd, text); SetWindowTextW(HWnd, text);
#else #else
SendMessageTimeoutW(HWnd, WM_SETTEXT, 0, SendMessageTimeoutW(HWnd, WM_SETTEXT, 0,
reinterpret_cast<LPARAM>(text), reinterpret_cast<LPARAM>(text),
SMTO_ABORTIFHUNG, 2000, &dwResult); SMTO_ABORTIFHUNG, 2000, &dwResult);
......
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