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
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
{
......@@ -232,12 +244,19 @@ struct SEvent
/** Only valid if event was EMIE_MOUSE_WHEEL */
f32 Wheel;
//! A bitmap of button states. You can use IsButtonPressed() to
/** Only valid if event was EMIE_MOUSE_MOVED */
//! A bitmap of button states. You can use isButtonPressed() to determine
//! if a button is pressed or not.
//! Currently only valid if the event was EMIE_MOUSE_MOVED
u32 ButtonStates;
bool isLeftPressed () const { return 0 != ( ButtonStates & 0x0001 ); }
bool isRightPressed () const { return 0 != ( ButtonStates & 0x0002 ); }
bool isMiddlePressed () const { return 0 != ( ButtonStates & 0x0010 ); }
//! Is the left button pressed down?
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
EMOUSE_INPUT_EVENT Event;
......
......@@ -309,7 +309,7 @@ bool CGUIComboBox::OnEvent(const SEvent& event)
case EMIE_MOUSE_WHEEL:
{
s32 oldSelected = Selected;
setSelected( Selected +(event.MouseInput.Wheel < 0) ? 1 : -1);
setSelected( Selected + ((event.MouseInput.Wheel < 0) ? 1 : -1));
if (Selected <0)
setSelected(0);
......
......@@ -43,7 +43,7 @@ const char* wmDeleteWindow = "WM_DELETE_WINDOW";
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param),
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),
Close(0), Resizeable(false),
WindowHasFocus(false), WindowMinimized(false)
......@@ -246,7 +246,6 @@ bool CIrrDeviceSDL::run()
os::Timer::tick();
SEvent irrevent;
irrevent.MouseInput.ButtonStates = -1;
SDL_Event SDL_event;
while ( !Close && SDL_PollEvent( &SDL_event ) )
......@@ -258,6 +257,7 @@ bool CIrrDeviceSDL::run()
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
MouseX = irrevent.MouseInput.X = SDL_event.motion.x;
MouseY = irrevent.MouseInput.Y = SDL_event.motion.y;
irrevent.MouseInput.ButtonStates = MouseButtonStates;
postEventFromUser(irrevent);
break;
......@@ -273,22 +273,58 @@ bool CIrrDeviceSDL::run()
switch(SDL_event.button.button)
{
case 1:
irrevent.MouseInput.Event =
(SDL_event.type == SDL_MOUSEBUTTONDOWN) ? irr::EMIE_LMOUSE_PRESSED_DOWN : irr::EMIE_LMOUSE_LEFT_UP;
case SDL_BUTTON_LEFT:
if (SDL_event.type == SDL_MOUSEBUTTONDOWN)
{
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;
case 2:
irrevent.MouseInput.Event =
(SDL_event.type == SDL_MOUSEBUTTONDOWN) ? irr::EMIE_RMOUSE_PRESSED_DOWN : irr::EMIE_RMOUSE_LEFT_UP;
case SDL_BUTTON_WHEELUP:
irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
irrevent.MouseInput.Wheel = 1.0f;
break;
case 3:
irrevent.MouseInput.Event =
(SDL_event.type == SDL_MOUSEBUTTONDOWN) ? irr::EMIE_MMOUSE_PRESSED_DOWN : irr::EMIE_MMOUSE_LEFT_UP;
case SDL_BUTTON_WHEELDOWN:
irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
irrevent.MouseInput.Wheel = -1.0f;
break;
}
irrevent.MouseInput.ButtonStates = MouseButtonStates;
if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED)
postEventFromUser(irrevent);
break;
......@@ -828,7 +864,7 @@ void CIrrDeviceSDL::createKeyMap()
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);
......
......@@ -177,6 +177,7 @@ namespace irr
#endif
s32 MouseX, MouseY;
u32 MouseButtonStates;
u32 Width, Height;
......
......@@ -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.X = (short)LOWORD(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;
// wheel
......
......@@ -279,6 +279,6 @@ namespace irr
} // end namespace irr
#endif
#endif
#endif // _IRR_USE_WINDOWS_DEVICE_
#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