Sorry to bump an old thread. I've just been playing around with this (awesome stuff, by the way), and I've had a little success with the mouse in Darkplaces so thought I'd share it.
You can use setcursormode() to stop mouse input from moving the view in DP. This changes how getmousepos() works, though. Instead of getting relative mousemovements you get absolute mouse position. As Spike says, more recent builds of DP (after about August 2011) have CSQC_InputEvent get mouse input using eventttype == 2, but when you use setcursormode() you have to get mouse input using eventtype == 3.
One cool thing about using the absolute mouse position is that it will be the same spot as the prydon cursor, so you can easily go between client side menus and server side interaction with the environment. If you use relative mouse movement the two mouse cursors move differently, and wind up in different spots on the screen.
So here's what I did, I probably missed something important, but it's a start.
in CSQC_defs.qc add:
Code: Select all
vector oldmousemove, mouse_oldrealpos;
and
Code: Select all
void(float usecursor) setcursormode = #343;
Open csqc_parse.qc and find SetupMenu()
After the line:
Code: Select all
CSQCGUI_ClearMenu(); //Clear the current menu
add
Code: Select all
#ifdef WORKINDP
setcursormode(1); // stops the engine from using mouse input to move the view
#endif
testmenu bypasses SetupMenu(), so we need to put that code in there too. In gui_menus.qc find Menu_TestMenu() and put it in there as well.
After that, open gui_main.qc and find CSQCGUI_ClearMenu(), then add
Code: Select all
#ifdef WORKINDP
setcursormode(0); // allows mouse input to move the view
#endif
Open gui_drawhud.qc and find CSQC_UpdateView()
Find the code:
Code: Select all
#ifdef WORKINDP
// Since CSQC_InputEvent in DP does not pick up mouse movements, parse them here
if (in_menu) {
mousemoves = getmousepos();
if (mousemoves)
CSQC_InputEvent( 2, mousemoves_x, mousemoves_y );
}
#endif
unless you've put in avirox's fix a couple of posts above, in which case it'll look a little different
change this to:
Code: Select all
#ifdef WORKINDP
// Since CSQC_InputEvent in DP does not pick up mouse movements, parse them here
if (in_menu) {
mousemoves = getmousepos();
if (mousemoves != oldmousemove)
{
CSQC_InputEvent( 3, mousemoves_x, mousemoves_y ); //originally eventtype 2, changing to 3 for DP mouse support
oldmousemove = mousemoves;
}
}
#endif
Note, I'm using eventtype 3 instead of 2. If you're using one of the more recent builds of darkplaces you don't even need this section, you can just comment it all out.
In the same file, go to CSQC_InputEvent() and go to the end of the function. Near the end, just after the last "return TRUE"
Code: Select all
}
return TRUE;
}
// WE'LL BE INSERTING CODE HERE
}
return FALSE;
};
I've just copied the existing code for handling eventtype 2, changed it to eventtype 3 and changed it a little for absolute mouse positon, insert it at the spot mentioned above.
Code: Select all
#ifdef WORKINDP
if (eventtype == 3 && !(global_menu_flags & MFG_NOCURSOR))
{
if (testsize_one_z == TRUE)
{
if (edit_button)
{
edit_button.size_x += (param1 - mouse_oldrealpos_x);
edit_button.size_y += (param2 - mouse_oldrealpos_y);
}
}
else
{
mousepos_x = param1;
mousepos_y = param2;
if (edit_button)
{
edit_button.origin_x = mousepos_x + edit_button_offset_x;
edit_button.origin_y = mousepos_y + edit_button_offset_y;
}
}
mouse_oldrealpos_x = param1;
mouse_oldrealpos_y = param2;
return TRUE;
}
#endif
I should point out that I have no idea what the edit_button code is all about, I just guess that this would be the way to do it. There's some other code at the start of CSQC_InputEvent() to do with edit_view_mode in the case of eventtype 2 that I haven't copied for eventtype 3. This doesn't break anything that I've used, but it probably breaks something. If anybody understands it I'd love to know.