fix touchscreen controls again... oops.
the cursor now works with both mouse+touch as appropriate. add touchscreen events to the webgl port. built in menu now responds to up events instead of down events for mouse1. this makes it slightly easier to navigate the menu on touchscreens devices. don't fail to compile when GL_LINE_SMOOTH isn't defined. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4742 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
c6b8617d87
commit
0b7f9c3a5e
6 changed files with 68 additions and 18 deletions
|
@ -82,6 +82,7 @@ struct mouse_s
|
||||||
float wheeldelta;
|
float wheeldelta;
|
||||||
int down;
|
int down;
|
||||||
} ptr[MAXPOINTERS];
|
} ptr[MAXPOINTERS];
|
||||||
|
int touchcursor; //the cursor follows whichever finger was most recently pressed in preference to any mouse also on the same system
|
||||||
|
|
||||||
#define MAXJOYAXIS 6
|
#define MAXJOYAXIS 6
|
||||||
#define MAXJOYSTICKS 4
|
#define MAXJOYSTICKS 4
|
||||||
|
@ -176,6 +177,7 @@ void IN_Commands(void)
|
||||||
while (events_used != events_avail)
|
while (events_used != events_avail)
|
||||||
{
|
{
|
||||||
ev = &eventlist[events_used & (EVENTQUEUELENGTH-1)];
|
ev = &eventlist[events_used & (EVENTQUEUELENGTH-1)];
|
||||||
|
|
||||||
switch(ev->type)
|
switch(ev->type)
|
||||||
{
|
{
|
||||||
case IEV_KEYDOWN:
|
case IEV_KEYDOWN:
|
||||||
|
@ -183,6 +185,18 @@ void IN_Commands(void)
|
||||||
//on touchscreens, mouse1 is used as up/down state. we have to emulate actual mouse clicks based upon distance moved, so we can get movement events.
|
//on touchscreens, mouse1 is used as up/down state. we have to emulate actual mouse clicks based upon distance moved, so we can get movement events.
|
||||||
if (ev->keyboard.scancode == K_MOUSE1 && ev->devid < MAXPOINTERS && (ptr[ev->devid].type == M_TOUCH))
|
if (ev->keyboard.scancode == K_MOUSE1 && ev->devid < MAXPOINTERS && (ptr[ev->devid].type == M_TOUCH))
|
||||||
{
|
{
|
||||||
|
if (ev->type == IEV_KEYDOWN)
|
||||||
|
{
|
||||||
|
float fl;
|
||||||
|
touchcursor = ev->devid;
|
||||||
|
fl = ptr[ev->devid].oldpos[0] * vid.width / vid.pixelwidth;
|
||||||
|
mousecursor_x = bound(0, fl, vid.width-1);
|
||||||
|
fl = ptr[ev->devid].oldpos[1] * vid.height / vid.pixelheight;
|
||||||
|
mousecursor_y = bound(0, fl, vid.height-1);
|
||||||
|
}
|
||||||
|
else if (touchcursor == ev->devid)
|
||||||
|
touchcursor = 0; //revert it to the mouse, or whatever device was 0.
|
||||||
|
|
||||||
if (Key_MouseShouldBeFree())
|
if (Key_MouseShouldBeFree())
|
||||||
ptr[ev->devid].down = 0;
|
ptr[ev->devid].down = 0;
|
||||||
else if (ptr[ev->devid].down)
|
else if (ptr[ev->devid].down)
|
||||||
|
@ -191,7 +205,7 @@ void IN_Commands(void)
|
||||||
Key_Event(ev->devid, ev->keyboard.scancode, ev->keyboard.unicode, ev->type == IEV_KEYDOWN);
|
Key_Event(ev->devid, ev->keyboard.scancode, ev->keyboard.unicode, ev->type == IEV_KEYDOWN);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ptr[ev->devid].down == 1 || ptr[ev->devid].moveddist < m_slidethreshold.value)
|
if (ptr[ev->devid].down == 1 && ptr[ev->devid].moveddist < m_slidethreshold.value)
|
||||||
{
|
{
|
||||||
ptr[ev->devid].down = 2;
|
ptr[ev->devid].down = 2;
|
||||||
Key_Event(ev->devid, K_MOUSE1, 0, true);
|
Key_Event(ev->devid, K_MOUSE1, 0, true);
|
||||||
|
@ -205,12 +219,15 @@ void IN_Commands(void)
|
||||||
Key_Event(ev->devid, ev->keyboard.scancode, ev->keyboard.unicode, ev->type == IEV_KEYDOWN);
|
Key_Event(ev->devid, ev->keyboard.scancode, ev->keyboard.unicode, ev->type == IEV_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case IEV_JOYAXIS:
|
case IEV_JOYAXIS:
|
||||||
|
if (ev->devid < MAXJOYSTICKS && ev->joy.axis < MAXJOYAXIS)
|
||||||
|
{
|
||||||
#ifdef CSQC_DAT
|
#ifdef CSQC_DAT
|
||||||
if (CSQC_JoystickAxis(ev->joy.axis, ev->joy.value, ev->devid))
|
if (CSQC_JoystickAxis(ev->joy.axis, ev->joy.value, ev->devid))
|
||||||
joy[ev->devid].axis[ev->joy.axis] = 0;
|
joy[ev->devid].axis[ev->joy.axis] = 0;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
joy[ev->devid].axis[ev->joy.axis] = ev->joy.value;
|
joy[ev->devid].axis[ev->joy.axis] = ev->joy.value;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case IEV_MOUSEDELTA:
|
case IEV_MOUSEDELTA:
|
||||||
if (ev->devid < MAXPOINTERS)
|
if (ev->devid < MAXPOINTERS)
|
||||||
|
@ -237,7 +254,7 @@ void IN_Commands(void)
|
||||||
break;
|
break;
|
||||||
case IEV_MOUSEABS:
|
case IEV_MOUSEABS:
|
||||||
/*mouse cursors only really work with one pointer*/
|
/*mouse cursors only really work with one pointer*/
|
||||||
if (ev->devid == 0)
|
if (ev->devid == touchcursor)
|
||||||
{
|
{
|
||||||
float fl;
|
float fl;
|
||||||
fl = ev->mouse.x * vid.width / vid.pixelwidth;
|
fl = ev->mouse.x * vid.width / vid.pixelwidth;
|
||||||
|
@ -347,7 +364,7 @@ void IN_MoveMouse(struct mouse_s *mouse, float *movements, int pnum)
|
||||||
|
|
||||||
if (Key_MouseShouldBeFree())
|
if (Key_MouseShouldBeFree())
|
||||||
{
|
{
|
||||||
if (mx || my)
|
if ((mx || my) && mouse->type != M_TOUCH)
|
||||||
{
|
{
|
||||||
mousecursor_x += mx;
|
mousecursor_x += mx;
|
||||||
mousecursor_y += my;
|
mousecursor_y += my;
|
||||||
|
@ -364,15 +381,14 @@ void IN_MoveMouse(struct mouse_s *mouse, float *movements, int pnum)
|
||||||
mousecursor_y = vid.height - 1;
|
mousecursor_y = vid.height - 1;
|
||||||
mx=my=0;
|
mx=my=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PEXT_CSQC
|
|
||||||
CSQC_MousePosition(mousecursor_x, mousecursor_y, mouse->qdeviceid);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mousecursor_x += mx;
|
if (mouse->type != M_TOUCH)
|
||||||
mousecursor_y += my;
|
{
|
||||||
|
mousecursor_x += mx;
|
||||||
|
mousecursor_y += my;
|
||||||
|
}
|
||||||
#ifdef VM_UI
|
#ifdef VM_UI
|
||||||
if (UI_MousePosition(mx, my))
|
if (UI_MousePosition(mx, my))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2207,7 +2207,10 @@ void Key_Event (int devid, int key, unsigned int unicode, qboolean down)
|
||||||
bl = bindcmdlevel[bkey][modifierstate];
|
bl = bindcmdlevel[bkey][modifierstate];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
key_repeats[key] = 0;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1351,7 +1351,8 @@ void M_Keydown (int key, int unicode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case m_complex:
|
case m_complex:
|
||||||
M_Complex_Key (key, unicode);
|
if (key != K_MOUSE1) //mouse clicks are deferred until the release event. this is for touch screens and aiming.
|
||||||
|
M_Complex_Key (key, unicode);
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1379,6 +1380,12 @@ void M_Keyup (int key, int unicode)
|
||||||
{
|
{
|
||||||
switch (m_state)
|
switch (m_state)
|
||||||
{
|
{
|
||||||
|
#ifndef NOBUITINMENUS
|
||||||
|
case m_complex:
|
||||||
|
if (key == K_MOUSE1)
|
||||||
|
M_Complex_Key (key, unicode);
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
#ifdef PLUGINS
|
#ifdef PLUGINS
|
||||||
case m_plugin:
|
case m_plugin:
|
||||||
Plug_Menu_Event (2, key);
|
Plug_Menu_Event (2, key);
|
||||||
|
|
|
@ -501,6 +501,7 @@ void R_SetupGL (float stereooffset)
|
||||||
qglLoadMatrixf(r_refdef.m_view);
|
qglLoadMatrixf(r_refdef.m_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef GL_LINE_SMOOTH
|
||||||
if (!gl_config.gles && r_wireframe_smooth.modified)
|
if (!gl_config.gles && r_wireframe_smooth.modified)
|
||||||
{
|
{
|
||||||
r_wireframe_smooth.modified = false;
|
r_wireframe_smooth.modified = false;
|
||||||
|
@ -517,6 +518,7 @@ void R_SetupGL (float stereooffset)
|
||||||
qglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
|
qglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (!gl_config.gles && gl_dither.modified)
|
if (!gl_config.gles && gl_dither.modified)
|
||||||
{
|
{
|
||||||
gl_dither.modified = false;
|
gl_dither.modified = false;
|
||||||
|
|
|
@ -117,8 +117,30 @@ mergeInto(LibraryManager.library,
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'touchstart':
|
||||||
|
case 'touchend':
|
||||||
|
case 'touchcancel':
|
||||||
|
case 'touchleave':
|
||||||
|
case 'touchmove':
|
||||||
|
var touches = event.changedTouches;
|
||||||
|
for (var i = 0; i < touches.length; i++)
|
||||||
|
{
|
||||||
|
var t = touches[i];
|
||||||
|
if (FTEC.evcb.mouse)
|
||||||
|
Runtime.dynCall('viidddd', FTEC.evcb.mouse, [t.identifier+1, true, t.pageX, t.pageY, 0, Math.sqrt(t.radiusX*t.radiusX+t.radiusY*t.radiusY)]);
|
||||||
|
if (FTEC.evcb.button)
|
||||||
|
{
|
||||||
|
if (event.type == 'touchstart')
|
||||||
|
Runtime.dynCall('viii', FTEC.evcb.button, [t.identifier+1, 1, 0]);
|
||||||
|
else if (event.type != 'touchmove')
|
||||||
|
Runtime.dynCall('viii', FTEC.evcb.button, [t.identifier+1, 0, 0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log(event);
|
console.log(event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -133,7 +155,7 @@ mergeInto(LibraryManager.library,
|
||||||
if (!FTEC.donecb)
|
if (!FTEC.donecb)
|
||||||
{
|
{
|
||||||
FTEC.donecb = 1;
|
FTEC.donecb = 1;
|
||||||
['mousedown', 'mouseup', 'mousemove', 'wheel', 'mousewheel', 'mouseout', 'keypress', 'keydown', 'keyup'].forEach(function(event)
|
['mousedown', 'mouseup', 'mousemove', 'wheel', 'mousewheel', 'mouseout', 'keypress', 'keydown', 'keyup', 'touchstart', 'touchend', 'touchcancel', 'touchleave', 'touchmove'].forEach(function(event)
|
||||||
{
|
{
|
||||||
Module['canvas'].addEventListener(event, FTEC.handleevent, true);
|
Module['canvas'].addEventListener(event, FTEC.handleevent, true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -131,12 +131,12 @@ static void DOM_ButtonEvent(int devid, int down, int button)
|
||||||
//fixme: the event is a float. we ignore that.
|
//fixme: the event is a float. we ignore that.
|
||||||
while(button < 0)
|
while(button < 0)
|
||||||
{
|
{
|
||||||
IN_KeyEvent(0, true, K_MWHEELUP, 0);
|
IN_KeyEvent(devid, true, K_MWHEELUP, 0);
|
||||||
button += 1;
|
button += 1;
|
||||||
}
|
}
|
||||||
while(button > 0)
|
while(button > 0)
|
||||||
{
|
{
|
||||||
IN_KeyEvent(0, true, K_MWHEELDOWN, 0);
|
IN_KeyEvent(devid, true, K_MWHEELDOWN, 0);
|
||||||
button -= 1;
|
button -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ static void DOM_ButtonEvent(int devid, int down, int button)
|
||||||
else if (button == 1)
|
else if (button == 1)
|
||||||
button = 2;
|
button = 2;
|
||||||
|
|
||||||
IN_KeyEvent(0, down, K_MOUSE1+button, 0);
|
IN_KeyEvent(devid, down, K_MOUSE1+button, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void DOM_HashChanged(char *loc)
|
void DOM_HashChanged(char *loc)
|
||||||
|
|
Loading…
Reference in a new issue