Fix some mouse bugs in WebAssembly/asm.js

- Emit mouse wheel release events
 - Set button masks, fixes #5092
This commit is contained in:
eska 2016-11-23 23:53:38 +01:00
parent 6d86a63648
commit 49e22aa83f
3 changed files with 17 additions and 5 deletions

View file

@ -66,11 +66,12 @@ static void _glut_mouse_button(int button, int state, int x, int y) {
if (ev.mouse_button.button_index<4) { if (ev.mouse_button.button_index<4) {
if (ev.mouse_button.pressed) { if (ev.mouse_button.pressed) {
_mouse_button_mask|=1<<ev.mouse_button.button_index; _mouse_button_mask |= 1 << (ev.mouse_button.button_index-1);
} else { } else {
_mouse_button_mask&=~(1<<ev.mouse_button.button_index); _mouse_button_mask &= ~(1 << (ev.mouse_button.button_index-1));
} }
} }
ev.mouse_button.button_mask=_mouse_button_mask;
uint32_t m = glutGetModifiers(); uint32_t m = glutGetModifiers();
ev.mouse_button.mod.alt=(m&GLUT_ACTIVE_ALT)!=0; ev.mouse_button.mod.alt=(m&GLUT_ACTIVE_ALT)!=0;
@ -79,6 +80,11 @@ static void _glut_mouse_button(int button, int state, int x, int y) {
os->push_input(ev); os->push_input(ev);
if (ev.mouse_button.button_index==BUTTON_WHEEL_UP || ev.mouse_button.button_index==BUTTON_WHEEL_DOWN) {
// GLUT doesn't send release events for mouse wheel, so send manually
ev.mouse_button.pressed=false;
os->push_input(ev);
}
} }
@ -162,7 +168,6 @@ int main(int argc, char *argv[]) {
glutMouseFunc(_glut_mouse_button); glutMouseFunc(_glut_mouse_button);
glutMotionFunc(_glut_mouse_motion); glutMotionFunc(_glut_mouse_motion);
glutMotionFunc(_glut_mouse_motion);
glutPassiveMotionFunc(_glut_mouse_motion); glutPassiveMotionFunc(_glut_mouse_motion);

View file

@ -294,13 +294,15 @@ bool OS_JavaScript::is_mouse_grab_enabled() const {
//*sigh* technology has evolved so much since i was a kid.. //*sigh* technology has evolved so much since i was a kid..
return false; return false;
} }
Point2 OS_JavaScript::get_mouse_pos() const { Point2 OS_JavaScript::get_mouse_pos() const {
return Point2(); return input->get_mouse_pos();
} }
int OS_JavaScript::get_mouse_button_state() const { int OS_JavaScript::get_mouse_button_state() const {
return 0; return last_button_mask;
} }
void OS_JavaScript::set_window_title(const String& p_title) { void OS_JavaScript::set_window_title(const String& p_title) {
@ -422,6 +424,9 @@ void OS_JavaScript::push_input(const InputEvent& p_ev) {
if (ev.type==InputEvent::MOUSE_MOTION) { if (ev.type==InputEvent::MOUSE_MOTION) {
input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
} }
else if (ev.type==InputEvent::MOUSE_BUTTON) {
last_button_mask = ev.mouse_button.button_mask;
}
input->parse_input_event(p_ev); input->parse_input_event(p_ev);
} }
@ -760,6 +765,7 @@ OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, Get
gfx_init_func=p_gfx_init_func; gfx_init_func=p_gfx_init_func;
gfx_init_ud=p_gfx_init_ud; gfx_init_ud=p_gfx_init_ud;
last_button_mask=0;
main_loop=NULL; main_loop=NULL;
last_id=1; last_id=1;
gl_extensions=NULL; gl_extensions=NULL;

View file

@ -58,6 +58,7 @@ private:
Vector<TouchPos> touch; Vector<TouchPos> touch;
Point2 last_mouse; Point2 last_mouse;
int last_button_mask;
unsigned int last_id; unsigned int last_id;
GFXInitFunc gfx_init_func; GFXInitFunc gfx_init_func;
void*gfx_init_ud; void*gfx_init_ud;