Commit a6c241ee authored by bitplane's avatar bitplane

Made enum for mouse button state mask

Win32: Added X buttons to mouse. 
SDL: Swapped middle and right buttons, added button state mask and fixed unresolved external. 
GUI: Fixed scroll input in combo box.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2217 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a7f93092
...@@ -103,6 +103,18 @@ namespace irr ...@@ -103,6 +103,18 @@ namespace irr
EMIE_COUNT EMIE_COUNT
}; };
//! Masks for mouse button states
enum E_MOUSE_BUTTON_STATE_MASK
{
EMBSM_LEFT = 0x01,
EMBSM_RIGHT = 0x02,
EMBSM_MIDDLE = 0x04,
EMBSM_EXTRA1 = 0x08,
EMBSM_EXTRA2 = 0x10,
EMBSM_FORCE_32_BIT = 0x7fffffff
};
namespace gui namespace gui
{ {
...@@ -232,12 +244,19 @@ struct SEvent ...@@ -232,12 +244,19 @@ struct SEvent
/** Only valid if event was EMIE_MOUSE_WHEEL */ /** Only valid if event was EMIE_MOUSE_WHEEL */
f32 Wheel; f32 Wheel;
//! A bitmap of button states. You can use IsButtonPressed() to //! A bitmap of button states. You can use isButtonPressed() to determine
/** Only valid if event was EMIE_MOUSE_MOVED */ //! if a button is pressed or not.
//! Currently only valid if the event was EMIE_MOUSE_MOVED
u32 ButtonStates; u32 ButtonStates;
bool isLeftPressed () const { return 0 != ( ButtonStates & 0x0001 ); }
bool isRightPressed () const { return 0 != ( ButtonStates & 0x0002 ); } //! Is the left button pressed down?
bool isMiddlePressed () const { return 0 != ( ButtonStates & 0x0010 ); } bool isLeftPressed() const { return 0 != ( ButtonStates & EMBSM_LEFT ); }
//! Is the right button pressed down?
bool isRightPressed() const { return 0 != ( ButtonStates & EMBSM_RIGHT ); }
//! Is the middle button pressed down?
bool isMiddlePressed() const { return 0 != ( ButtonStates & EMBSM_MIDDLE ); }
//! Type of mouse event //! Type of mouse event
EMOUSE_INPUT_EVENT Event; EMOUSE_INPUT_EVENT Event;
......
...@@ -309,7 +309,7 @@ bool CGUIComboBox::OnEvent(const SEvent& event) ...@@ -309,7 +309,7 @@ bool CGUIComboBox::OnEvent(const SEvent& event)
case EMIE_MOUSE_WHEEL: case EMIE_MOUSE_WHEEL:
{ {
s32 oldSelected = Selected; s32 oldSelected = Selected;
setSelected( Selected +(event.MouseInput.Wheel < 0) ? 1 : -1); setSelected( Selected + ((event.MouseInput.Wheel < 0) ? 1 : -1));
if (Selected <0) if (Selected <0)
setSelected(0); setSelected(0);
......
...@@ -43,7 +43,7 @@ const char* wmDeleteWindow = "WM_DELETE_WINDOW"; ...@@ -43,7 +43,7 @@ const char* wmDeleteWindow = "WM_DELETE_WINDOW";
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), : CIrrDeviceStub(param),
Screen((SDL_Surface*)param.WindowId), SDL_Flags(SDL_HWSURFACE|SDL_ANYFORMAT), Screen((SDL_Surface*)param.WindowId), SDL_Flags(SDL_HWSURFACE|SDL_ANYFORMAT),
MouseX(0), MouseY(0), MouseX(0), MouseY(0), MouseButtonStates(0),
Width(param.WindowSize.Width), Height(param.WindowSize.Height), Width(param.WindowSize.Width), Height(param.WindowSize.Height),
Close(0), Resizeable(false), Close(0), Resizeable(false),
WindowHasFocus(false), WindowMinimized(false) WindowHasFocus(false), WindowMinimized(false)
...@@ -246,7 +246,6 @@ bool CIrrDeviceSDL::run() ...@@ -246,7 +246,6 @@ bool CIrrDeviceSDL::run()
os::Timer::tick(); os::Timer::tick();
SEvent irrevent; SEvent irrevent;
irrevent.MouseInput.ButtonStates = -1;
SDL_Event SDL_event; SDL_Event SDL_event;
while ( !Close && SDL_PollEvent( &SDL_event ) ) while ( !Close && SDL_PollEvent( &SDL_event ) )
...@@ -258,6 +257,7 @@ bool CIrrDeviceSDL::run() ...@@ -258,6 +257,7 @@ bool CIrrDeviceSDL::run()
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
MouseX = irrevent.MouseInput.X = SDL_event.motion.x; MouseX = irrevent.MouseInput.X = SDL_event.motion.x;
MouseY = irrevent.MouseInput.Y = SDL_event.motion.y; MouseY = irrevent.MouseInput.Y = SDL_event.motion.y;
irrevent.MouseInput.ButtonStates = MouseButtonStates;
postEventFromUser(irrevent); postEventFromUser(irrevent);
break; break;
...@@ -273,22 +273,58 @@ bool CIrrDeviceSDL::run() ...@@ -273,22 +273,58 @@ bool CIrrDeviceSDL::run()
switch(SDL_event.button.button) switch(SDL_event.button.button)
{ {
case 1: case SDL_BUTTON_LEFT:
irrevent.MouseInput.Event = if (SDL_event.type == SDL_MOUSEBUTTONDOWN)
(SDL_event.type == SDL_MOUSEBUTTONDOWN) ? irr::EMIE_LMOUSE_PRESSED_DOWN : irr::EMIE_LMOUSE_LEFT_UP; {
irrevent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
MouseButtonStates |= irr::EMBSM_LEFT;
}
else
{
irrevent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
MouseButtonStates &= !irr::EMBSM_LEFT;
}
break;
case SDL_BUTTON_RIGHT:
if (SDL_event.type == SDL_MOUSEBUTTONDOWN)
{
irrevent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
MouseButtonStates |= irr::EMBSM_RIGHT;
}
else
{
irrevent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
MouseButtonStates &= !irr::EMBSM_RIGHT;
}
break;
case SDL_BUTTON_MIDDLE:
if (SDL_event.type == SDL_MOUSEBUTTONDOWN)
{
irrevent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN;
MouseButtonStates |= irr::EMBSM_MIDDLE;
}
else
{
irrevent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP;
MouseButtonStates &= !irr::EMBSM_MIDDLE;
}
break; break;
case 2: case SDL_BUTTON_WHEELUP:
irrevent.MouseInput.Event = irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
(SDL_event.type == SDL_MOUSEBUTTONDOWN) ? irr::EMIE_RMOUSE_PRESSED_DOWN : irr::EMIE_RMOUSE_LEFT_UP; irrevent.MouseInput.Wheel = 1.0f;
break; break;
case 3: case SDL_BUTTON_WHEELDOWN:
irrevent.MouseInput.Event = irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
(SDL_event.type == SDL_MOUSEBUTTONDOWN) ? irr::EMIE_MMOUSE_PRESSED_DOWN : irr::EMIE_MMOUSE_LEFT_UP; irrevent.MouseInput.Wheel = -1.0f;
break; break;
} }
irrevent.MouseInput.ButtonStates = MouseButtonStates;
if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED) if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED)
postEventFromUser(irrevent); postEventFromUser(irrevent);
break; break;
...@@ -828,7 +864,7 @@ void CIrrDeviceSDL::createKeyMap() ...@@ -828,7 +864,7 @@ void CIrrDeviceSDL::createKeyMap()
KeyMap.sort(); KeyMap.sort();
} }
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param) extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param)
{ {
CIrrDeviceSDL* dev = new CIrrDeviceSDL(param); CIrrDeviceSDL* dev = new CIrrDeviceSDL(param);
......
...@@ -177,6 +177,7 @@ namespace irr ...@@ -177,6 +177,7 @@ namespace irr
#endif #endif
s32 MouseX, MouseY; s32 MouseX, MouseY;
u32 MouseButtonStates;
u32 Width, Height; u32 Width, Height;
......
...@@ -135,7 +135,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -135,7 +135,16 @@ 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.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON | MK_MBUTTON ); // left and right mouse buttons
event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON);
// middle and extra buttons
if (wParam & MK_MBUTTON)
event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE;
if (wParam & MK_XBUTTON1)
event.MouseInput.ButtonStates |= irr::EMBSM_EXTRA1;
if (wParam & MK_XBUTTON2)
event.MouseInput.ButtonStates |= irr::EMBSM_EXTRA2;
event.MouseInput.Wheel = 0.f; event.MouseInput.Wheel = 0.f;
// wheel // wheel
......
...@@ -279,6 +279,6 @@ namespace irr ...@@ -279,6 +279,6 @@ namespace irr
} // end namespace irr } // end namespace irr
#endif #endif // _IRR_USE_WINDOWS_DEVICE_
#endif #endif // __C_IRR_DEVICE_WIN32_H_INCLUDED__
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