1
0
Fork 0
forked from fte/fteqw

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:
Spoike 2014-09-02 06:01:03 +00:00
parent c6b8617d87
commit 0b7f9c3a5e
6 changed files with 68 additions and 18 deletions

View file

@ -82,6 +82,7 @@ struct mouse_s
float wheeldelta;
int down;
} 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 MAXJOYSTICKS 4
@ -176,6 +177,7 @@ void IN_Commands(void)
while (events_used != events_avail)
{
ev = &eventlist[events_used & (EVENTQUEUELENGTH-1)];
switch(ev->type)
{
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.
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())
ptr[ev->devid].down = 0;
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);
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;
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);
break;
case IEV_JOYAXIS:
if (ev->devid < MAXJOYSTICKS && ev->joy.axis < MAXJOYAXIS)
{
#ifdef CSQC_DAT
if (CSQC_JoystickAxis(ev->joy.axis, ev->joy.value, ev->devid))
joy[ev->devid].axis[ev->joy.axis] = 0;
else
#endif
joy[ev->devid].axis[ev->joy.axis] = ev->joy.value;
}
break;
case IEV_MOUSEDELTA:
if (ev->devid < MAXPOINTERS)
@ -237,7 +254,7 @@ void IN_Commands(void)
break;
case IEV_MOUSEABS:
/*mouse cursors only really work with one pointer*/
if (ev->devid == 0)
if (ev->devid == touchcursor)
{
float fl;
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 (mx || my)
if ((mx || my) && mouse->type != M_TOUCH)
{
mousecursor_x += mx;
mousecursor_y += my;
@ -364,15 +381,14 @@ void IN_MoveMouse(struct mouse_s *mouse, float *movements, int pnum)
mousecursor_y = vid.height - 1;
mx=my=0;
}
#ifdef PEXT_CSQC
CSQC_MousePosition(mousecursor_x, mousecursor_y, mouse->qdeviceid);
#endif
}
else
{
if (mouse->type != M_TOUCH)
{
mousecursor_x += mx;
mousecursor_y += my;
}
#ifdef VM_UI
if (UI_MousePosition(mx, my))
{

View file

@ -2207,9 +2207,12 @@ void Key_Event (int devid, int key, unsigned int unicode, qboolean down)
bl = bindcmdlevel[bkey][modifierstate];
}
else
{
key_repeats[key] = 0;
return;
}
}
}
if (!dc)
dc = "";

View file

@ -1351,6 +1351,7 @@ void M_Keydown (int key, int unicode)
return;
case m_complex:
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;
#endif
@ -1379,6 +1380,12 @@ void M_Keyup (int key, int unicode)
{
switch (m_state)
{
#ifndef NOBUITINMENUS
case m_complex:
if (key == K_MOUSE1)
M_Complex_Key (key, unicode);
return;
#endif
#ifdef PLUGINS
case m_plugin:
Plug_Menu_Event (2, key);

View file

@ -501,6 +501,7 @@ void R_SetupGL (float stereooffset)
qglLoadMatrixf(r_refdef.m_view);
}
#ifdef GL_LINE_SMOOTH
if (!gl_config.gles && r_wireframe_smooth.modified)
{
r_wireframe_smooth.modified = false;
@ -517,6 +518,7 @@ void R_SetupGL (float stereooffset)
qglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
}
}
#endif
if (!gl_config.gles && gl_dither.modified)
{
gl_dither.modified = false;

View file

@ -117,8 +117,30 @@ mergeInto(LibraryManager.library,
event.preventDefault();
}
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:
console.log(event);
break;
}
}
},
@ -133,7 +155,7 @@ mergeInto(LibraryManager.library,
if (!FTEC.donecb)
{
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);
});

View file

@ -131,12 +131,12 @@ static void DOM_ButtonEvent(int devid, int down, int button)
//fixme: the event is a float. we ignore that.
while(button < 0)
{
IN_KeyEvent(0, true, K_MWHEELUP, 0);
IN_KeyEvent(devid, true, K_MWHEELUP, 0);
button += 1;
}
while(button > 0)
{
IN_KeyEvent(0, true, K_MWHEELDOWN, 0);
IN_KeyEvent(devid, true, K_MWHEELDOWN, 0);
button -= 1;
}
}
@ -148,7 +148,7 @@ static void DOM_ButtonEvent(int devid, int down, int button)
else if (button == 1)
button = 2;
IN_KeyEvent(0, down, K_MOUSE1+button, 0);
IN_KeyEvent(devid, down, K_MOUSE1+button, 0);
}
}
void DOM_HashChanged(char *loc)