Set up mouse cursor display in menus, with idle timeout fully implemented. No functionality yet. DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@4738 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2014-11-17 07:39:12 +00:00
parent e5923955ef
commit 164d9ccb41
15 changed files with 158 additions and 93 deletions

View file

@ -101,7 +101,7 @@ extern void SetKey(int32_t key, int32_t state);
// mouse
extern int32_t mousex, mousey, mouseb, mouseabsx, mouseabsy;
extern uint8_t mousegrab, moustat;
extern uint8_t mousegrab, moustat, mouseinwindow, AppMouseGrab;
// joystick
extern int32_t *joyaxis, *joyhat, joyb;
@ -158,8 +158,9 @@ void bflushchars(void);
int32_t initmouse(void);
void uninitmouse(void);
void grabmouse(char a);
void AppGrabMouse(char a);
void readmousexy(int32_t *x, int32_t *y);
void readmouseabsxy(int32_t *x, int32_t *y);
int32_t readmouseabsxy(int32_t *x, int32_t *y);
void readmousebstatus(int32_t *b);
void readjoybstatus(int32_t *b);
void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur);

View file

@ -16,7 +16,7 @@ char remap[KEYSTATUSSIZ];
int32_t remapinit=0;
char key_names[NUMKEYS][24];
int32_t mousex=0,mousey=0,mouseb=0,mouseabsx=0,mouseabsy=0;
uint8_t moustat = 0, mousegrab = 0;
uint8_t moustat = 0, mousegrab = 0, mouseinwindow = 1, AppMouseGrab = 1;
int32_t *joyaxis = NULL, joyb=0, *joyhat = NULL;
char joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0;
int32_t joyaxespresent=0;
@ -104,24 +104,24 @@ void readmousexy(int32_t *x, int32_t *y)
mousex = mousey = 0;
}
void readmouseabsxy(int32_t *x, int32_t *y)
int32_t readmouseabsxy(int32_t *x, int32_t *y)
{
if (!moustat || !mousegrab || !appactive)
{
// no mouse, centre it
*x = xdim >> 1;
*y = ydim >> 1;
}
else
{
*x = mouseabsx;
*y = mouseabsy;
}
int32_t xwidth;
if (!moustat || !mouseinwindow)
return 0;
xwidth = max(scale(240<<16, xdim, ydim), 320<<16);
*x = scale(mouseabsx, xwidth, xdim) - ((xwidth>>1) - (320<<15));
*y = scale(mouseabsy, 200<<16, ydim);
return 1;
}
void readmousebstatus(int32_t *b)
{
if (!moustat || !mousegrab || !appactive) { *b = 0; return; }
if (!moustat || !appactive || !mouseinwindow) { *b = 0; return; }
*b = mouseb;
}

View file

@ -1429,7 +1429,7 @@ void OSD_CaptureInput(int32_t cap)
{
osd->flags = (osd->flags & ~(OSD_CAPTURE|OSD_CTRL|OSD_SHIFT)) | (-cap & OSD_CAPTURE);
grabmouse(cap == 0);
grabmouse(cap == 0 ? AppMouseGrab : 0);
onshowosd(cap);
if (cap)

View file

@ -251,7 +251,7 @@ void RI_PollDevices(BOOL loop)
int32_t initmouse(void)
{
if (moustat) return 0;
grabmouse(moustat = 1);
grabmouse(moustat = AppMouseGrab);
return 0;
}
@ -279,3 +279,7 @@ void grabmouse(char a)
SetCursorPos(pos.x, pos.y);
}
void AppGrabMouse(char a)
{
UNREFERENCED_PARAMETER(a);
}

View file

@ -910,8 +910,8 @@ const char *getjoyname(int32_t what, int32_t num)
//
int32_t initmouse(void)
{
moustat=1;
grabmouse(1); // FIXME - SA
moustat=AppMouseGrab;
grabmouse(AppMouseGrab); // FIXME - SA
return 0;
}
@ -966,7 +966,13 @@ void grabmouse(char a)
mousegrab = a;
}
mousex = mousey = 0;
mouseabsx = mouseabsy = 0;
}
void AppGrabMouse(char a)
{
grabmouse(a);
AppMouseGrab = mousegrab;
SDL_ShowCursor(SDL_DISABLE);
}
//
@ -1947,7 +1953,8 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
//if (c==8) setpalette(0,256,0);
if (regrab) grabmouse(1);
if (regrab)
grabmouse(AppMouseGrab);
return 0;
}
@ -2375,7 +2382,7 @@ int32_t handleevents(void)
case SDL_WINDOWEVENT_FOCUS_GAINED:
appactive = 1;
if (mousegrab && moustat)
grabmouse_low(1);
grabmouse_low(AppMouseGrab);
#ifdef _WIN32
if (backgroundidle)
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
@ -2397,6 +2404,12 @@ int32_t handleevents(void)
windowy = ev.window.data2;
}
break;
case SDL_WINDOWEVENT_ENTER:
mouseinwindow = 1;
break;
case SDL_WINDOWEVENT_LEAVE:
mouseinwindow = 0;
break;
}
break;
// #warning Using SDL 1.3 or 2.X
@ -2462,7 +2475,7 @@ int32_t handleevents(void)
if (mousegrab && moustat)
{
if (appactive)
grabmouse_low(1);
grabmouse_low(AppMouseGrab);
else
grabmouse_low(0);
}
@ -2474,6 +2487,8 @@ int32_t handleevents(void)
# endif
rv=-1;
}
if (ev.active.state & SDL_APPMOUSEFOCUS)
mouseinwindow = ev.active.gain;
break;
#endif // SDL version
@ -2536,25 +2551,29 @@ int32_t handleevents(void)
break;
case SDL_MOUSEMOTION:
#ifdef GEKKO
// check if it's a wiimote pointer pretending to be a mouse
if (ev.motion.state & SDL_BUTTON_X2MASK)
{
// the absolute values are used to draw the crosshair
mouseabsx = ev.motion.x;
mouseabsy = ev.motion.y;
// hack: reduce the scale of the "relative" motions
// to make it act more like a real mouse
ev.motion.xrel /= 16;
ev.motion.yrel /= 12;
}
#else
mouseabsx = ev.motion.x;
mouseabsy = ev.motion.y;
#endif
// SDL <VER> doesn't handle relative mouse movement correctly yet as the cursor still clips to the screen edges
// so, we call SDL_WarpMouse() to center the cursor and ignore the resulting motion event that occurs
// <VER> is 1.3 for PK, 1.2 for tueidj
if (appactive && mousegrab)
{
#ifdef GEKKO
// check if it's a wiimote pointer pretending to be a mouse
if (ev.motion.state & SDL_BUTTON_X2MASK)
{
// the absolute values are used to draw the crosshair
mouseabsx = ev.motion.x;
mouseabsy = ev.motion.y;
// hack: reduce the scale of the "relative" motions
// to make it act more like a real mouse
ev.motion.xrel /= 16;
ev.motion.yrel /= 12;
}
#endif
if (ev.motion.x != xdim>>1 || ev.motion.y != ydim>>1)
if (ev.motion.x != (xdim>>1) || ev.motion.y != (ydim>>1))
{
mousex += ev.motion.xrel;
mousey += ev.motion.yrel;

View file

@ -3536,7 +3536,7 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
{
if (regrabmouse)
{
grabmouse(1);
grabmouse(AppMouseGrab);
regrabmouse = 0;
}
ShowWindow(hWindow, SW_RESTORE);

View file

@ -55,9 +55,9 @@ static int32_t demo_synccompress=1, demorec_seeds=1, demo_hasseeds;
static void Demo_RestoreModes(int32_t menu)
{
if (menu)
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
else
g_player[myconnectindex].ps->gm &= ~MODE_MENU;
M_CloseMenu(myconnectindex);
g_player[myconnectindex].ps->gm &= ~MODE_GAME;
g_player[myconnectindex].ps->gm |= MODE_DEMO;
@ -561,7 +561,7 @@ RECHECK:
{
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
}
ready2send = 0;
@ -702,7 +702,7 @@ RECHECK:
corrupt:
OSD_Printf(OSD_ERROR "Demo %d is corrupt (code %d).\n", g_whichDemo-1, corruptcode);
nextdemo:
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
nextdemo_nomenu:
foundemo = 0;
ud.reccnt = 0;
@ -913,7 +913,7 @@ nextdemo_nomenu:
I_EscapeTriggerClear();
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
M_ChangeMenu(MENU_MAIN);
S_MenuSound();
}
@ -928,7 +928,10 @@ nextdemo_nomenu:
Net_SendMessage();
if ((g_player[myconnectindex].ps->gm&MODE_TYPE) != MODE_TYPE)
g_player[myconnectindex].ps->gm = MODE_MENU;
{
g_player[myconnectindex].ps->gm = 0;
M_OpenMenu(myconnectindex);
}
}
else
{

View file

@ -3280,7 +3280,6 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16
}
}
#define CROSSHAIR_PAL (MAXPALOOKUPS-RESERVEDPALS-1)
palette_t CrosshairColors = { 255, 255, 255, 0 };
palette_t DefaultCrosshairColors = { 0, 0, 0, 0 };
@ -3728,7 +3727,7 @@ void G_DisplayRest(int32_t smoothratio)
S_MenuSound();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2) ready2send = 0;
@ -3757,20 +3756,14 @@ void G_DisplayRest(int32_t smoothratio)
a = CROSSHAIR;
#ifdef GEKKO
readmouseabsxy(&x, &y);
if (x || y)
{
x >>= 1;
y = (y*5)/12;
}
else
if (!readmouseabsxy(&x, &y))
#endif
{
x = 160;
y = 100;
x = 160<<16;
y = 100<<16;
}
rotatesprite_win((x-(g_player[myconnectindex].ps->look_ang>>1))<<16,y<<16,scale(65536,ud.crosshairscale,100),
rotatesprite_win(x-(g_player[myconnectindex].ps->look_ang<<15),y,scale(65536,ud.crosshairscale,100),
0,a,0,CROSSHAIR_PAL,2+1);
}
}
@ -8883,7 +8876,7 @@ void G_HandleLocalKeys(void)
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2))
{
@ -8936,7 +8929,7 @@ FAKE_F2:
S_ClearSoundLocks();
// setview(0,0,xdim-1,ydim-1);
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2))
{
@ -8956,7 +8949,7 @@ FAKE_F3:
S_ClearSoundLocks();
// setview(0,0,xdim-1,ydim-1);
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 0;
@ -8972,7 +8965,7 @@ FAKE_F3:
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 0;
@ -9073,7 +9066,7 @@ FAKE_F3:
M_ChangeMenu(MENU_QUIT_INGAME);
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 0;
@ -9139,7 +9132,7 @@ FAKE_F3:
M_ChangeMenu(MENU_COLCORR_INGAME);
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 0;
@ -11090,7 +11083,8 @@ void G_BackToMenu(void)
boardfilename[0] = 0;
if (ud.recstat == 1) G_CloseDemoWrite();
ud.warp_on = 0;
g_player[myconnectindex].ps->gm = MODE_MENU;
g_player[myconnectindex].ps->gm = 0;
M_OpenMenu(myconnectindex);
M_ChangeMenu(MENU_MAIN);
KB_FlushKeyboardQueue();
G_UpdateAppTitle();
@ -11126,7 +11120,8 @@ static int32_t G_EndOfLevel(void)
{
if (!VOLUMEALL)
G_DoOrderScreen();
g_player[myconnectindex].ps->gm = MODE_MENU;
g_player[myconnectindex].ps->gm = 0;
M_OpenMenu(myconnectindex);
M_ChangeMenu(MENU_MAIN);
return 2;
}

View file

@ -293,6 +293,8 @@ extern int32_t voting;
//extern int8_t cheatbuf[MAXCHEATLEN],cheatbuflen;
#define CROSSHAIR_PAL (MAXPALOOKUPS-RESERVEDPALS-1)
extern palette_t CrosshairColors;
extern palette_t DefaultCrosshairColors;

View file

@ -989,7 +989,7 @@ static int32_t VM_ResetPlayer(int32_t g_p, int32_t g_flags)
{
if (g_lastSaveSlot >= 0 && ud.recstat != 2)
{
g_player[g_p].ps->gm |= MODE_MENU;
M_OpenMenu(g_p);
KB_ClearKeyDown(sc_Space);
I_AdvanceTriggerClear();
M_ChangeMenu(MENU_RESETPLAYER);

View file

@ -1775,6 +1775,10 @@ static void __fastcall VM_SetPlayer(int32_t lVar1, int32_t lLabelID, int32_t lVa
case PLAYER_SCREAM_VOICE:
ps->scream_voice=lVar1; return;
case PLAYER_GM:
if (!(ps->gm & MODE_MENU) && (lVar1 & MODE_MENU))
M_OpenMenu(iPlayer);
else if ((ps->gm & MODE_MENU) && !(lVar1 & MODE_MENU))
M_CloseMenu(iPlayer);
ps->gm=lVar1; return;
case PLAYER_ON_WARPING_SECTOR:
ps->on_warping_sector=lVar1; return;

View file

@ -3194,23 +3194,7 @@ void M_ChangeMenu(MenuID_t cm)
g_currentMenu = g_previousMenu;
}
else if (cm == MENU_CLOSE)
{
if (g_player[myconnectindex].ps->gm & MODE_GAME)
{
g_player[myconnectindex].ps->gm &= ~MODE_MENU;
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 1;
totalclock = ototalclock;
CAMERACLOCK = totalclock;
CAMERADIST = 65536;
m_animation.start = 0;
m_animation.length = 0;
}
walock[TILE_SAVESHOT] = 199;
G_UpdateScreenArea();
}
}
M_CloseMenu(myconnectindex);
else if (cm >= 0)
{
if ((g_player[myconnectindex].ps->gm&MODE_GAME) && cm == MENU_MAIN)
@ -3392,6 +3376,42 @@ static inline int32_t M_UpdateScreenOK(MenuID_t cm)
chances are you should scroll up.
*/
#define M_MOUSETIMEOUT 120
static int32_t m_mouselastactivity;
static vec2_t m_prevmousepos, m_mousepos;
void M_OpenMenu(size_t playerID)
{
g_player[playerID].ps->gm |= MODE_MENU;
readmouseabsxy(&m_prevmousepos.x, &m_prevmousepos.y);
m_mouselastactivity = -M_MOUSETIMEOUT;
AppGrabMouse(0);
}
void M_CloseMenu(size_t playerID)
{
if (g_player[playerID].ps->gm & MODE_GAME)
{
// The following lines are here so that you cannot close the menu when no game is running.
g_player[playerID].ps->gm &= ~MODE_MENU;
AppGrabMouse(1);
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 1;
totalclock = ototalclock;
CAMERACLOCK = totalclock;
CAMERADIST = 65536;
m_animation.start = 0;
m_animation.length = 0;
}
walock[TILE_SAVESHOT] = 199;
G_UpdateScreenArea();
}
}
static void M_BlackRectangle(int32_t x, int32_t y, int32_t width, int32_t height)
{
const int32_t xscale = scale(65536, width, tilesiz[0].x<<16), yscale = scale(65536, height, tilesiz[0].y<<16);
@ -4919,6 +4939,14 @@ void M_DisplayMenus(void)
return;
}
if (!M_IsTextInput(m_currentMenu) && KB_KeyPressed(sc_Q))
{
g_previousMenu = g_currentMenu;
M_ChangeMenuAnimate(MENU_QUIT, MA_Advance);
}
M_RunMenuInput(m_currentMenu);
VM_OnEvent(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek, -1, 0);
g_player[myconnectindex].ps->gm &= (0xff-MODE_TYPE);
@ -4930,12 +4958,6 @@ void M_DisplayMenus(void)
if (M_UpdateScreenOK(g_currentMenu))
G_UpdateScreenArea();
if (!M_IsTextInput(m_currentMenu) && KB_KeyPressed(sc_Q))
{
g_previousMenu = g_currentMenu;
M_ChangeMenuAnimate(MENU_QUIT, MA_Advance);
}
#if defined(USE_OPENGL) && defined(DROIDMENU)
gltexfiltermode = 1;
gltexapplyprops();
@ -4955,8 +4977,6 @@ void M_DisplayMenus(void)
else
M_RunMenu(m_currentMenu, origin);
M_RunMenuInput(m_currentMenu);
#if defined(USE_OPENGL) && defined(DROIDMENU)
gltexfiltermode = menufiltermode ? 5 : 2;
gltexapplyprops();
@ -4965,6 +4985,20 @@ void M_DisplayMenus(void)
if (VM_HaveEvent(EVENT_DISPLAYMENUREST))
VM_OnEvent(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek, -1, 0);
if (readmouseabsxy(&m_mousepos.x, &m_mousepos.y))
{
if (m_mousepos.x != m_prevmousepos.x || m_mousepos.y != m_prevmousepos.y)
{
m_prevmousepos = m_mousepos;
m_mouselastactivity = totalclock;
}
}
else
m_mouselastactivity = -M_MOUSETIMEOUT;
if (totalclock - m_mouselastactivity < M_MOUSETIMEOUT)
rotatesprite_win(m_mousepos.x,m_mousepos.y,65536,0,CROSSHAIR,0,CROSSHAIR_PAL,2|1);
if ((g_player[myconnectindex].ps->gm&MODE_MENU) != MODE_MENU)
{
G_UpdateScreenArea();

View file

@ -374,6 +374,8 @@ void M_ChangeMenuAnimate(int32_t cm, MenuAnimationType_t animtype);
int32_t M_IsTextInput(Menu_t *cm);
void G_CheckPlayerColor(int32_t *color,int32_t prev_color);
void M_Init(void);
void M_OpenMenu(size_t playerID);
void M_CloseMenu(size_t playerID);
void M_DisplayMenus(void);
#endif

View file

@ -136,7 +136,7 @@ static int32_t osdcmd_changelevel(const osdfuncparm_t *parm)
if ((GametypeFlags[ud.m_coop] & GAMETYPE_PLAYERSFRIENDLY) && !(GametypeFlags[ud.m_coop] & GAMETYPE_TDM))
ud.m_noexits = 0;
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
M_ChangeMenu(MENU_NETWAITVOTES);
}
*/
@ -272,7 +272,7 @@ static int32_t osdcmd_map(const osdfuncparm_t *parm)
if ((GametypeFlags[ud.m_coop] & GAMETYPE_PLAYERSFRIENDLY) && !(GametypeFlags[ud.m_coop] & GAMETYPE_TDM))
ud.m_noexits = 0;
g_player[myconnectindex].ps->gm |= MODE_MENU;
M_OpenMenu(myconnectindex);
M_ChangeMenu(MENU_NETWAITVOTES);
}
*/

View file

@ -1400,6 +1400,7 @@ end_vol4a:
p->zoom = 768;
#endif
p->gm = 0;
M_CloseMenu(0);
#if !defined LUNATIC
//AddLog("Newgame");