Hi all. I'm working on quake1 engine. I'm trying to get the mousexy in a video mode on a mouse click. In 800x600, it tells me the position of the mouse in terms of the pixel it's on. Quake has mouselook on/off, moves the view around. This is called every frame in glvidlinuxglx:
Code:
static void HandleEvents(void)
{
XEvent event;
qboolean dowarp = false;
int mwx = vid.width/2;
int mwy = vid.height/2;
if (!dpy)
return;
while (XPending(dpy)) {
XNextEvent(dpy, &event);
switch (event.type)
{
case KeyPress:
case KeyRelease:
Key_Event(XLateKey(&event.xkey), event.type == KeyPress);
break;
case MotionNotify:
if (mouse_active)
{
#ifdef USE_XF86_DGA
if (dgamouse)
{
mx += (event.xmotion.x + win_x) * 2;
my += (event.xmotion.y + win_y) * 2;
}
#else
if (true)
{
int xoffset = ((int)event.xmotion.x - mwx);
int yoffset = ((int)event.xmotion.y - mwy);
if(xoffset != 0 || yoffset != 0) {
mx += xoffset;
my += yoffset;
XSelectInput(dpy, win,
X_MASK & ~PointerMotionMask);
XWarpPointer(dpy, None, win, 0, 0, 0, 0,
mwx, mwy);
XSelectInput(dpy, win, X_MASK);
}
}
#endif
else
{
mx += ((int)event.xmotion.x - mwx) * 2;
my += ((int)event.xmotion.y - mwy) * 2;
#if 0 //ndef USE_XF86_DGA
mwx = event.xmotion.x;
mwy = event.xmotion.y;
#endif
if (mx || my)
dowarp = true;
}
}
break;
/*case ButtonPress:
b=-1;
if (event.xbutton.button == 1)
b = 0;
else if (event.xbutton.button == 2)
b = 2;
else if (event.xbutton.button == 3)
b = 1;
if (b>=0)
Key_Event(K_MOUSE1 + b, true);
break;
case ButtonRelease:
b=-1;
if (event.xbutton.button == 1)
b = 0;
else if (event.xbutton.button == 2)
b = 2;
else if (event.xbutton.button == 3)
b = 1;
if (b>=0)
Key_Event(K_MOUSE1 + b, false);
break;*/
case ButtonPress:
// mouse button pressed
switch(event.xbutton.button)
{
case 1:
Key_Event(K_MOUSE1, true);
break;
case 2:
Key_Event(K_MOUSE3, true);
break;
case 3:
Key_Event(K_MOUSE2, true);
break;
case 4:
Key_Event(K_MWHEELUP, true);
break;
case 5:
Key_Event(K_MWHEELDOWN, true);
break;
default:
Con_Printf("HandleEvents: ButtonPress gave value %d, 1-12 expected\n", event.xbutton.button);
break;
}
break;
case ButtonRelease:
// mouse button released
switch(event.xbutton.button)
{
case 1:
Key_Event(K_MOUSE1, false);
break;
case 2:
Key_Event(K_MOUSE3, false);
break;
case 3:
Key_Event(K_MOUSE2, false);
break;
case 4:
Key_Event(K_MWHEELUP, false);
break;
case 5:
Key_Event(K_MWHEELDOWN, false);
break;
default:
Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-12 expected\n", event.xbutton.button);
break;
}
break;
//end
case CreateNotify :
win_x = event.xcreatewindow.x;
win_y = event.xcreatewindow.y;
break;
case ConfigureNotify :
win_x = event.xconfigure.x;
win_y = event.xconfigure.y;
break;
}
}
if (dowarp) {
/* move the mouse to the window center again */
XWarpPointer(dpy, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
}
}
void IN_MouseMove (usercmd_t *cmd)
{
if (!mouse_avail)
return;
if (m_filter->value)
{
mx = (mx + old_mouse_x) * 0.5;
my = (my + old_mouse_y) * 0.5;
}
old_mouse_x = mx;
old_mouse_y = my;
mx *= sensitivity->value;
my *= sensitivity->value;
// add mouse X/Y movement to cmd
if ( (in_strafe.state & 1) || (lookstrafe->value && ((in_mlook.state & 1) ^ ((int)m_look->value & 1)) )) // 2001-12-16 M_LOOK cvar by Heffo/Maddes
cmd->sidemove += m_side->value * mx;
else
cl.viewangles[YAW] -= m_yaw->value * mx;
if ((in_mlook.state & 1) ^ ((int)m_look->value & 1)) // 2001-12-16 M_LOOK cvar by Heffo/Maddes
V_StopPitchDrift ();
if ( ((in_mlook.state & 1) ^ ((int)m_look->value & 1)) && !(in_strafe.state & 1)) // 2001-12-16 M_LOOK cvar by Heffo/Maddes
{
cl.viewangles[PITCH] += m_pitch->value * my;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
else
{
if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * my;
else
cmd->forwardmove -= m_forward->value * my;
}
mx = my = 0;
}
I tried to cut down the first to something more manageable so I could understand it.
Code:
void setmousexy (void)
{
XEvent event;
if (!dpy)
return;
while (XPending(dpy))
{
XNextEvent(dpy, &event);
if (event.type == MotionNotify)
{
mousex = (int)event.xmotion.x;
mousey = (int)event.xmotion.y;
}
}
}
Two problems, one there is a delay between the click and and getting the xy. The mousexy is offset right and down. That increases as you go from X=0/Y=0 to vid.width/vid.height.
On a menu screen this is checked:
Code:
//hydr_customhud from hyperdrive quake1 engine
case MENU_HUD_ARMOR_ICON:
if (keydown[K_MOUSE1])
{
sbar_armor_iconx->value= mousex;
Cvar_SetValue (sbar_armor_iconx, sbar_armor_iconx->value);
sbar_armor_icony->value= mousey;
Cvar_SetValue (sbar_armor_icony, sbar_armor_icony->value);
m_changesound = true;
}
break;
I still have to do this for windows. The cvar usage is working fine. It's mouse access that's the problem. Need help!
as