mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Added mouse wheel handling.
This commit is contained in:
parent
d536bb8c72
commit
0098be04d7
8 changed files with 45 additions and 19 deletions
|
@ -283,7 +283,7 @@ namespace entry
|
||||||
|
|
||||||
if (mouse->m_move)
|
if (mouse->m_move)
|
||||||
{
|
{
|
||||||
inputSetMousePos(mouse->m_mx, mouse->m_my);
|
inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -297,6 +297,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
_mouse->m_mx = mouse->m_mx;
|
_mouse->m_mx = mouse->m_mx;
|
||||||
_mouse->m_my = mouse->m_my;
|
_mouse->m_my = mouse->m_my;
|
||||||
|
_mouse->m_mz = mouse->m_mz;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -134,6 +134,7 @@ namespace entry
|
||||||
MouseState()
|
MouseState()
|
||||||
: m_mx(0)
|
: m_mx(0)
|
||||||
, m_my(0)
|
, m_my(0)
|
||||||
|
, m_mz(0)
|
||||||
{
|
{
|
||||||
for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
|
for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
|
||||||
{
|
{
|
||||||
|
@ -141,8 +142,9 @@ namespace entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t m_mx;
|
int32_t m_mx;
|
||||||
uint32_t m_my;
|
int32_t m_my;
|
||||||
|
int32_t m_mz;
|
||||||
uint8_t m_buttons[entry::MouseButton::Count];
|
uint8_t m_buttons[entry::MouseButton::Count];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -216,6 +216,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
m_eventQueue.postMouseEvent(xbutton.x
|
m_eventQueue.postMouseEvent(xbutton.x
|
||||||
, xbutton.y
|
, xbutton.y
|
||||||
|
, 0
|
||||||
, mb
|
, mb
|
||||||
, event.type == ButtonPress
|
, event.type == ButtonPress
|
||||||
);
|
);
|
||||||
|
@ -228,6 +229,7 @@ namespace entry
|
||||||
const XMotionEvent& xmotion = event.xmotion;
|
const XMotionEvent& xmotion = event.xmotion;
|
||||||
m_eventQueue.postMouseEvent(xmotion.x
|
m_eventQueue.postMouseEvent(xmotion.x
|
||||||
, xmotion.y
|
, xmotion.y
|
||||||
|
, 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -56,6 +56,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
int32_t m_mx;
|
int32_t m_mx;
|
||||||
int32_t m_my;
|
int32_t m_my;
|
||||||
|
int32_t m_mz;
|
||||||
MouseButton::Enum m_button;
|
MouseButton::Enum m_button;
|
||||||
bool m_down;
|
bool m_down;
|
||||||
bool m_move;
|
bool m_move;
|
||||||
|
@ -90,24 +91,26 @@ namespace entry
|
||||||
m_queue.push(ev);
|
m_queue.push(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void postMouseEvent(int32_t _mx, int32_t _my)
|
void postMouseEvent(int32_t _mx, int32_t _my, int32_t _mz)
|
||||||
{
|
{
|
||||||
MouseEvent* ev = new MouseEvent;
|
MouseEvent* ev = new MouseEvent;
|
||||||
ev->m_type = Event::Mouse;
|
ev->m_type = Event::Mouse;
|
||||||
ev->m_mx = _mx;
|
ev->m_mx = _mx;
|
||||||
ev->m_my = _my;
|
ev->m_my = _my;
|
||||||
|
ev->m_mz = _mz;
|
||||||
ev->m_button = MouseButton::None;
|
ev->m_button = MouseButton::None;
|
||||||
ev->m_down = false;
|
ev->m_down = false;
|
||||||
ev->m_move = true;
|
ev->m_move = true;
|
||||||
m_queue.push(ev);
|
m_queue.push(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void postMouseEvent(int32_t _mx, int32_t _my, MouseButton::Enum _button, bool _down)
|
void postMouseEvent(int32_t _mx, int32_t _my, int32_t _mz, MouseButton::Enum _button, bool _down)
|
||||||
{
|
{
|
||||||
MouseEvent* ev = new MouseEvent;
|
MouseEvent* ev = new MouseEvent;
|
||||||
ev->m_type = Event::Mouse;
|
ev->m_type = Event::Mouse;
|
||||||
ev->m_mx = _mx;
|
ev->m_mx = _mx;
|
||||||
ev->m_my = _my;
|
ev->m_my = _my;
|
||||||
|
ev->m_mz = _mz;
|
||||||
ev->m_button = _button;
|
ev->m_button = _button;
|
||||||
ev->m_down = _down;
|
ev->m_down = _down;
|
||||||
ev->m_move = false;
|
ev->m_move = false;
|
||||||
|
|
|
@ -186,7 +186,7 @@ namespace entry
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
const SDL_MouseMotionEvent& mev = event.motion;
|
const SDL_MouseMotionEvent& mev = event.motion;
|
||||||
m_eventQueue.postMouseEvent(mev.x, mev.y);
|
m_eventQueue.postMouseEvent(mev.x, mev.y, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ namespace entry
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
{
|
{
|
||||||
const SDL_MouseButtonEvent& mev = event.button;
|
const SDL_MouseButtonEvent& mev = event.button;
|
||||||
m_eventQueue.postMouseEvent(mev.x, mev.y, MouseButton::Left, mev.type == SDL_MOUSEBUTTONDOWN);
|
m_eventQueue.postMouseEvent(mev.x, mev.y, 0, MouseButton::Left, mev.type == SDL_MOUSEBUTTONDOWN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,16 @@ namespace entry
|
||||||
setMousePos(m_mx, m_my);
|
setMousePos(m_mx, m_my);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_eventQueue.postMouseEvent(mx, my);
|
m_eventQueue.postMouseEvent(mx, my, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_MOUSEWHEEL:
|
||||||
|
{
|
||||||
|
int32_t mx = GET_X_LPARAM(_lparam);
|
||||||
|
int32_t my = GET_Y_LPARAM(_lparam);
|
||||||
|
int32_t mz = GET_WHEEL_DELTA_WPARAM(_wparam);
|
||||||
|
m_eventQueue.postMouseEvent(mx, my, mz);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -384,7 +393,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
int32_t mx = GET_X_LPARAM(_lparam);
|
int32_t mx = GET_X_LPARAM(_lparam);
|
||||||
int32_t my = GET_Y_LPARAM(_lparam);
|
int32_t my = GET_Y_LPARAM(_lparam);
|
||||||
m_eventQueue.postMouseEvent(mx, my, MouseButton::Left, _id == WM_LBUTTONDOWN);
|
m_eventQueue.postMouseEvent(mx, my, 0, MouseButton::Left, _id == WM_LBUTTONDOWN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -394,7 +403,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
int32_t mx = GET_X_LPARAM(_lparam);
|
int32_t mx = GET_X_LPARAM(_lparam);
|
||||||
int32_t my = GET_Y_LPARAM(_lparam);
|
int32_t my = GET_Y_LPARAM(_lparam);
|
||||||
m_eventQueue.postMouseEvent(mx, my, MouseButton::Middle, _id == WM_MBUTTONDOWN);
|
m_eventQueue.postMouseEvent(mx, my, 0, MouseButton::Middle, _id == WM_MBUTTONDOWN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -404,7 +413,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
int32_t mx = GET_X_LPARAM(_lparam);
|
int32_t mx = GET_X_LPARAM(_lparam);
|
||||||
int32_t my = GET_Y_LPARAM(_lparam);
|
int32_t my = GET_Y_LPARAM(_lparam);
|
||||||
m_eventQueue.postMouseEvent(mx, my, MouseButton::Right, _id == WM_RBUTTONDOWN);
|
m_eventQueue.postMouseEvent(mx, my, 0, MouseButton::Right, _id == WM_RBUTTONDOWN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct Mouse
|
||||||
Mouse()
|
Mouse()
|
||||||
: m_width(1280)
|
: m_width(1280)
|
||||||
, m_height(720)
|
, m_height(720)
|
||||||
|
, m_wheelDelta(120)
|
||||||
, m_lock(false)
|
, m_lock(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -25,6 +26,7 @@ struct Mouse
|
||||||
{
|
{
|
||||||
m_norm[0] = 0.0f;
|
m_norm[0] = 0.0f;
|
||||||
m_norm[1] = 0.0f;
|
m_norm[1] = 0.0f;
|
||||||
|
m_norm[2] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(m_buttons, 0, sizeof(m_buttons) );
|
memset(m_buttons, 0, sizeof(m_buttons) );
|
||||||
|
@ -36,12 +38,14 @@ struct Mouse
|
||||||
m_height = _height;
|
m_height = _height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPos(int32_t _mx, int32_t _my)
|
void setPos(int32_t _mx, int32_t _my, int32_t _mz)
|
||||||
{
|
{
|
||||||
m_absolute[0] = _mx;
|
m_absolute[0] = _mx;
|
||||||
m_absolute[1] = _my;
|
m_absolute[1] = _my;
|
||||||
|
m_absolute[2] = _mz;
|
||||||
m_norm[0] = float(_mx)/float(m_width);
|
m_norm[0] = float(_mx)/float(m_width);
|
||||||
m_norm[1] = float(_my)/float(m_height);
|
m_norm[1] = float(_my)/float(m_height);
|
||||||
|
m_norm[2] = float(_mz)/float(m_wheelDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setButtonState(entry::MouseButton::Enum _button, uint8_t _state)
|
void setButtonState(entry::MouseButton::Enum _button, uint8_t _state)
|
||||||
|
@ -49,12 +53,13 @@ struct Mouse
|
||||||
m_buttons[_button] = _state;
|
m_buttons[_button] = _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t m_absolute[2];
|
int32_t m_absolute[3];
|
||||||
float m_norm[2];
|
float m_norm[3];
|
||||||
int32_t m_wheel;
|
int32_t m_wheel;
|
||||||
uint8_t m_buttons[entry::MouseButton::Count];
|
uint8_t m_buttons[entry::MouseButton::Count];
|
||||||
uint16_t m_width;
|
uint16_t m_width;
|
||||||
uint16_t m_height;
|
uint16_t m_height;
|
||||||
|
uint16_t m_wheelDelta;
|
||||||
bool m_lock;
|
bool m_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -197,9 +202,10 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
|
||||||
s_input.m_keyboard.setKeyState(_key, _modifiers, _down);
|
s_input.m_keyboard.setKeyState(_key, _modifiers, _down);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputSetMousePos(int32_t _mx, int32_t _my)
|
void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz)
|
||||||
{
|
{
|
||||||
s_input.m_mouse.setPos(_mx, _my);
|
DBG("%d, %d, %d", _mx, _my, _mz);
|
||||||
|
s_input.m_mouse.setPos(_mx, _my, _mz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state)
|
void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state)
|
||||||
|
@ -207,12 +213,14 @@ void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state)
|
||||||
s_input.m_mouse.setButtonState(_button, _state);
|
s_input.m_mouse.setButtonState(_button, _state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputGetMouse(float _mouse[2])
|
void inputGetMouse(float _mouse[3])
|
||||||
{
|
{
|
||||||
_mouse[0] = s_input.m_mouse.m_norm[0];
|
_mouse[0] = s_input.m_mouse.m_norm[0];
|
||||||
_mouse[1] = s_input.m_mouse.m_norm[1];
|
_mouse[1] = s_input.m_mouse.m_norm[1];
|
||||||
|
_mouse[2] = s_input.m_mouse.m_norm[2];
|
||||||
s_input.m_mouse.m_norm[0] = 0.0f;
|
s_input.m_mouse.m_norm[0] = 0.0f;
|
||||||
s_input.m_mouse.m_norm[1] = 0.0f;
|
s_input.m_mouse.m_norm[1] = 0.0f;
|
||||||
|
s_input.m_mouse.m_norm[2] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool inputIsMouseLocked()
|
bool inputIsMouseLocked()
|
||||||
|
@ -230,6 +238,7 @@ void inputSetMouseLock(bool _lock)
|
||||||
{
|
{
|
||||||
s_input.m_mouse.m_norm[0] = 0.0f;
|
s_input.m_mouse.m_norm[0] = 0.0f;
|
||||||
s_input.m_mouse.m_norm[1] = 0.0f;
|
s_input.m_mouse.m_norm[1] = 0.0f;
|
||||||
|
s_input.m_mouse.m_norm[2] = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down);
|
||||||
void inputSetMouseResolution(uint16_t _width, uint16_t _height);
|
void inputSetMouseResolution(uint16_t _width, uint16_t _height);
|
||||||
|
|
||||||
///
|
///
|
||||||
void inputSetMousePos(int32_t _mx, int32_t _my);
|
void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz);
|
||||||
|
|
||||||
///
|
///
|
||||||
void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state);
|
void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state);
|
||||||
|
@ -47,7 +47,7 @@ void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state);
|
||||||
void inputSetMouseLock(bool _lock);
|
void inputSetMouseLock(bool _lock);
|
||||||
|
|
||||||
///
|
///
|
||||||
void inputGetMouse(float _mouse[2]);
|
void inputGetMouse(float _mouse[3]);
|
||||||
|
|
||||||
///
|
///
|
||||||
bool inputIsMouseLocked();
|
bool inputIsMouseLocked();
|
||||||
|
|
Loading…
Reference in a new issue