mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
Add the necessary plumbing to sdlayer to detect mousedown, mouseup, and dragging.
git-svn-id: https://svn.eduke32.com/eduke32@4853 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
bfb3614b92
commit
598e33319c
8 changed files with 80 additions and 35 deletions
|
@ -101,8 +101,18 @@ extern int32_t GetKey(int32_t key);
|
|||
extern void SetKey(int32_t key, int32_t state);
|
||||
|
||||
// mouse
|
||||
extern int32_t mousex, mousey, mouseb, mouseabsx, mouseabsy;
|
||||
extern int32_t mousex, mousey, mouseb;
|
||||
extern vec2_t mouseabs;
|
||||
extern uint8_t mousepressstate;
|
||||
extern uint8_t mousegrab, moustat, mouseinwindow, AppMouseGrab;
|
||||
enum
|
||||
{
|
||||
Mouse_Idle = 0,
|
||||
Mouse_Pressed = 1,
|
||||
Mouse_Held = 2,
|
||||
Mouse_Released = 3,
|
||||
};
|
||||
extern int32_t mousepressstateadvance(void);
|
||||
|
||||
// joystick
|
||||
extern int32_t *joyaxis, *joyhat, joyb;
|
||||
|
@ -161,7 +171,7 @@ void uninitmouse(void);
|
|||
void grabmouse(char a);
|
||||
void AppGrabMouse(char a);
|
||||
void readmousexy(int32_t *x, int32_t *y);
|
||||
int32_t readmouseabsxy(int32_t *x, int32_t *y);
|
||||
int32_t readmouseabsxy(vec2_t * const destination, vec2_t const * const source);
|
||||
void readmousebstatus(int32_t *b);
|
||||
void readjoybstatus(int32_t *b);
|
||||
void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur);
|
||||
|
|
|
@ -285,22 +285,6 @@ extern "C" {
|
|||
|
||||
#endif // __cplusplus
|
||||
|
||||
typedef struct {
|
||||
int32_t x, y;
|
||||
} vec2_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t x, y, z;
|
||||
} vec3_t;
|
||||
|
||||
typedef struct {
|
||||
float x, y;
|
||||
} vec2f_t;
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} vec3f_t;
|
||||
|
||||
// Links to various ABIs specifying (or documenting non-normatively) the
|
||||
// alignment requirements of aggregates:
|
||||
//
|
||||
|
|
|
@ -590,6 +590,24 @@ typedef intptr_t ssize_t;
|
|||
typedef int32_t bssize_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int32_t x, y;
|
||||
} vec2_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t x, y, z;
|
||||
} vec3_t;
|
||||
|
||||
typedef struct {
|
||||
float x, y;
|
||||
} vec2f_t;
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} vec3f_t;
|
||||
|
||||
|
||||
#if RAND_MAX == 32767
|
||||
FORCE_INLINE uint16_t system_15bit_rand(void) { return (uint16_t)rand(); }
|
||||
#else // RAND_MAX > 32767, assumed to be of the form 2^k - 1
|
||||
|
|
|
@ -15,8 +15,27 @@ uint8_t keyfifoplc, keyfifoend, keyasciififoplc, keyasciififoend;
|
|||
char keyremap[KEYSTATUSSIZ];
|
||||
int32_t keyremapinit=0;
|
||||
char key_names[NUMKEYS][24];
|
||||
int32_t mousex=0,mousey=0,mouseb=0,mouseabsx=0,mouseabsy=0;
|
||||
int32_t mousex=0,mousey=0,mouseb=0;
|
||||
vec2_t mouseabs;
|
||||
uint8_t mousepressstate;
|
||||
uint8_t moustat = 0, mousegrab = 0, mouseinwindow = 1, AppMouseGrab = 1;
|
||||
|
||||
int32_t mousepressstateadvance(void)
|
||||
{
|
||||
if (mousepressstate == Mouse_Pressed)
|
||||
{
|
||||
mousepressstate = Mouse_Held;
|
||||
return 1;
|
||||
}
|
||||
else if (mousepressstate == Mouse_Released)
|
||||
{
|
||||
mousepressstate = Mouse_Idle;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t *joyaxis = NULL, joyb=0, *joyhat = NULL;
|
||||
char joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0;
|
||||
int32_t joyaxespresent=0;
|
||||
|
@ -105,7 +124,7 @@ void readmousexy(int32_t *x, int32_t *y)
|
|||
mousex = mousey = 0;
|
||||
}
|
||||
|
||||
int32_t readmouseabsxy(int32_t *x, int32_t *y)
|
||||
int32_t readmouseabsxy(vec2_t * const destination, vec2_t const * const source)
|
||||
{
|
||||
int32_t xwidth;
|
||||
|
||||
|
@ -114,8 +133,8 @@ int32_t readmouseabsxy(int32_t *x, int32_t *y)
|
|||
|
||||
xwidth = max(scale(240<<16, xdim, ydim), 320<<16);
|
||||
|
||||
*x = scale(mouseabsx, xwidth, xdim) - ((xwidth>>1) - (320<<15));
|
||||
*y = scale(mouseabsy, 200<<16, ydim);
|
||||
destination->x = scale(source->x, xwidth, xdim) - ((xwidth>>1) - (320<<15));
|
||||
destination->y = scale(source->y, 200<<16, ydim);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1718,6 +1718,11 @@ int32_t handleevents_peekkeys(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void handleevents_updatemousestate(uint8_t state)
|
||||
{
|
||||
mousepressstate = state == SDL_RELEASED ? Mouse_Released : Mouse_Pressed;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// handleevents() -- process the SDL message queue
|
||||
|
@ -1732,8 +1737,8 @@ int32_t handleevents_sdlcommon(SDL_Event *ev)
|
|||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
#ifndef GEKKO
|
||||
mouseabsx = ev->motion.x;
|
||||
mouseabsy = ev->motion.y;
|
||||
mouseabs.x = ev->motion.x;
|
||||
mouseabs.y = ev->motion.y;
|
||||
#endif
|
||||
// SDL <VER> doesn't handle relative mouse movement correctly yet as the cursor still clips to the
|
||||
// screen edges
|
||||
|
@ -1762,7 +1767,7 @@ int32_t handleevents_sdlcommon(SDL_Event *ev)
|
|||
switch (ev->button.button)
|
||||
{
|
||||
default: j = -1; break;
|
||||
case SDL_BUTTON_LEFT: j = 0; break;
|
||||
case SDL_BUTTON_LEFT: j = 0; handleevents_updatemousestate(ev->button.state); break;
|
||||
case SDL_BUTTON_RIGHT: j = 1; break;
|
||||
case SDL_BUTTON_MIDDLE: j = 2; break;
|
||||
|
||||
|
@ -1849,6 +1854,11 @@ int32_t handleevents_sdlcommon(SDL_Event *ev)
|
|||
joyb |= 1 << ev->jbutton.button;
|
||||
else
|
||||
joyb &= ~(1 << ev->jbutton.button);
|
||||
|
||||
#ifdef GEKKO
|
||||
if (ev->jbutton.button == 0) // WII_A
|
||||
handleevents_updatemousestate(ev->jbutton.state);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -568,8 +568,8 @@ int32_t handleevents_pollsdl(void)
|
|||
if (ev.motion.state & SDL_BUTTON_X2MASK)
|
||||
{
|
||||
// the absolute values are used to draw the crosshair
|
||||
mouseabsx = ev.motion.x;
|
||||
mouseabsy = ev.motion.y;
|
||||
mouseabs.x = ev.motion.x;
|
||||
mouseabs.y = ev.motion.y;
|
||||
// hack: reduce the scale of the "relative" motions
|
||||
// to make it act more like a real mouse
|
||||
ev.motion.xrel /= 16;
|
||||
|
|
|
@ -3739,17 +3739,17 @@ void G_DisplayRest(int32_t smoothratio)
|
|||
|
||||
if (a == 0 || a > 1)
|
||||
{
|
||||
int32_t x = 160<<16, y = 100<<16;
|
||||
vec2_t crosshairpos = { 160<<16, 100<<16 };
|
||||
|
||||
if (a == 0)
|
||||
a = CROSSHAIR;
|
||||
|
||||
rotatesprite_win(x-(g_player[myconnectindex].ps->look_ang<<15),y,scale(65536,ud.crosshairscale,100),
|
||||
rotatesprite_win(crosshairpos.x-(g_player[myconnectindex].ps->look_ang<<15),crosshairpos.y,scale(65536,ud.crosshairscale,100),
|
||||
0,a,0,CROSSHAIR_PAL,2+1);
|
||||
|
||||
#ifdef GEKKO
|
||||
if (readmouseabsxy(&x, &y))
|
||||
rotatesprite_win(x,y,scale(65536,ud.crosshairscale,100),0,a,0,CROSSHAIR_PAL,2+1);
|
||||
if ((g_player[myconnectindex].ps->gm&MODE_MENU) == 0 && readmouseabsxy(&crosshairpos, &mouseabs))
|
||||
rotatesprite_win(crosshairpos.x,crosshairpos.y,scale(65536,ud.crosshairscale,100),0,a,0,CROSSHAIR_PAL,2+1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3163,13 +3163,13 @@ static inline int32_t M_UpdateScreenOK(MenuID_t cm)
|
|||
|
||||
#define M_MOUSETIMEOUT 120
|
||||
static int32_t m_mouselastactivity;
|
||||
static vec2_t m_prevmousepos, m_mousepos;
|
||||
static vec2_t m_prevmousepos, m_mousepos, m_mousedownpos;
|
||||
|
||||
void M_OpenMenu(size_t playerID)
|
||||
{
|
||||
g_player[playerID].ps->gm |= MODE_MENU;
|
||||
|
||||
readmouseabsxy(&m_prevmousepos.x, &m_prevmousepos.y);
|
||||
readmouseabsxy(&m_prevmousepos, &mouseabs);
|
||||
m_mouselastactivity = -M_MOUSETIMEOUT;
|
||||
|
||||
AppGrabMouse(0);
|
||||
|
@ -4881,6 +4881,10 @@ void M_DisplayMenus(void)
|
|||
if (!M_IsTextInput(m_currentMenu) && KB_KeyPressed(sc_Q))
|
||||
M_ChangeMenuAnimate(MENU_QUIT, MA_Advance);
|
||||
|
||||
int32_t mousestatus = readmouseabsxy(&m_mousepos, &mouseabs);
|
||||
if (mousestatus && mousepressstate == Mouse_Pressed)
|
||||
m_mousedownpos = m_mousepos;
|
||||
|
||||
M_RunMenuInput(m_currentMenu);
|
||||
|
||||
VM_OnEvent(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek);
|
||||
|
@ -4911,9 +4915,9 @@ void M_DisplayMenus(void)
|
|||
if (VM_HaveEvent(EVENT_DISPLAYMENUREST))
|
||||
VM_OnEvent(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek);
|
||||
|
||||
if (readmouseabsxy(&m_mousepos.x, &m_mousepos.y))
|
||||
if (mousestatus)
|
||||
{
|
||||
if (m_mousepos.x != m_prevmousepos.x || m_mousepos.y != m_prevmousepos.y)
|
||||
if (((totalclock - m_mouselastactivity < M_MOUSETIMEOUT) && mousepressstateadvance()) || m_mousepos.x != m_prevmousepos.x || m_mousepos.y != m_prevmousepos.y)
|
||||
{
|
||||
m_prevmousepos = m_mousepos;
|
||||
m_mouselastactivity = totalclock;
|
||||
|
|
Loading…
Reference in a new issue