Skip to content

Commit

Permalink
Add horizontal mouse wheel support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrikpowell committed Dec 1, 2024
1 parent d965029 commit 2b4e71f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 21 deletions.
47 changes: 34 additions & 13 deletions prboom2/src/SDL/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,17 @@ int I_SDLtoDoomMouseState(Uint32 buttonstate)
;
}

static event_t delay_event;

static void I_GetEvent(void)
{
event_t event;

SDL_Event SDLEvent;
SDL_Event *Event = &SDLEvent;

I_DelayEvent();

while (SDL_PollEvent(Event))
{
switch (Event->type) {
Expand Down Expand Up @@ -361,26 +365,33 @@ static void I_GetEvent(void)
case SDL_MOUSEWHEEL:
if (mouse_enabled && window_focused)
{
int button = -1;

if (Event->wheel.y > 0)
{
event.data1.i = KEYD_MWHEELUP;

event.type = ev_keydown;
D_PostEvent(&event);

event.type = ev_keyup;
D_PostEvent(&event);
button = KEYD_MWHEELUP;
}
else if (Event->wheel.y < 0)
{
event.data1.i = KEYD_MWHEELDOWN;
button = KEYD_MWHEELDOWN;
}
else if (Event->wheel.x < 0)
{
button = KEYD_MWHEELLEFT;
}
else if (Event->wheel.x > 0)
{
button = KEYD_MWHEELRIGHT;
}

event.type = ev_keydown;
D_PostEvent(&event);
// post a button down event
event.data1.i = button;
event.type = ev_mouseb_down;
D_PostEvent(&event);

event.type = ev_keyup;
D_PostEvent(&event);
}
// hold button for one tic, required for checks in G_BuildTiccmd
delay_event.data1.i = button;
delay_event.type = ev_mouseb_up;
}
break;

Expand Down Expand Up @@ -422,6 +433,16 @@ static void I_GetEvent(void)
}
}

// Pulled from Woof
void I_DelayEvent(void)
{
if (delay_event.data1.i)
{
D_PostEvent(&delay_event);
delay_event.data1.i = 0;
}
}

//
// I_StartTic
//
Expand Down
6 changes: 3 additions & 3 deletions prboom2/src/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ dboolean AM_Responder
}
else if (
dsda_InputActivated(dsda_input_map_zoomout) ||
(map_wheel_zoom && ev->type == ev_keydown && ev->data1.i == KEYD_MWHEELDOWN)
(map_wheel_zoom && ev->type == ev_mouseb_down && ev->data1.i == KEYD_MWHEELDOWN)
)
{
mtof_zoommul = M_ZOOMOUT;
Expand All @@ -1085,7 +1085,7 @@ dboolean AM_Responder
}
else if (
dsda_InputActivated(dsda_input_map_zoomin) ||
(map_wheel_zoom && ev->type == ev_keydown && ev->data1.i == KEYD_MWHEELUP)
(map_wheel_zoom && ev->type == ev_mouseb_down && ev->data1.i == KEYD_MWHEELUP)
)
{
mtof_zoommul = M_ZOOMIN;
Expand Down Expand Up @@ -1164,7 +1164,7 @@ dboolean AM_Responder
dsda_InputDeactivated(dsda_input_map_zoomout) ||
dsda_InputDeactivated(dsda_input_map_zoomin) ||
(
map_wheel_zoom && ev->type == ev_keyup &&
map_wheel_zoom && ev->type == ev_mouseb_up &&
(ev->data1.i == KEYD_MWHEELDOWN || ev->data1.i == KEYD_MWHEELUP)
)
)
Expand Down
2 changes: 2 additions & 0 deletions prboom2/src/d_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ typedef enum
{
ev_keydown,
ev_keyup,
ev_mouseb_down,
ev_mouseb_up,
ev_mouse,
ev_mousemotion,
ev_joystick,
Expand Down
2 changes: 1 addition & 1 deletion prboom2/src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void D_PostEvent(event_t *ev)
// use key is used for seeing the current frame
if (
!dsda_InputActivated(dsda_input_use) && !dsda_InputActivated(dsda_input_demo_skip) &&
(ev->type == ev_keydown || ev->type == ev_keyup) // is this condition important?
(ev->type == ev_keydown || ev->type == ev_keyup || ev->type == ev_mouseb_down || ev->type == ev_mouseb_up) // is this condition important?
)
{
return;
Expand Down
2 changes: 2 additions & 0 deletions prboom2/src/doomdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ typedef enum {
#define KEYD_MOUSE3 (0x80 + 0x62)
#define KEYD_MWHEELUP (0x80 + 0x6b)
#define KEYD_MWHEELDOWN (0x80 + 0x6c)
#define KEYD_MWHEELLEFT (0X80 + 0X6d)
#define KEYD_MWHEELRIGHT (0X80 + 0X6e)

// phares 3/20/98:
//
Expand Down
12 changes: 12 additions & 0 deletions prboom2/src/dsda/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ void dsda_InputTrackEvent(event_t* ev) {
case ev_keyup:
dsda_InputTrackKeyUp(ev);
break;
case ev_mouseb_down:
dsda_InputTrackKeyDown(ev);
break;
case ev_mouseb_up:
dsda_InputTrackKeyUp(ev);
break;
case ev_mouse:
dsda_InputTrackButtons(mousebuttons, MAX_MOUSE_BUTTONS, ev);
break;
Expand Down Expand Up @@ -142,6 +148,12 @@ void dsda_InputTrackGameEvent(event_t* ev) {
case ev_keyup:
dsda_InputTrackGameKeyUp(ev);
break;
case ev_mouseb_down:
dsda_InputTrackGameKeyDown(ev);
break;
case ev_mouseb_up:
dsda_InputTrackGameKeyUp(ev);
break;
case ev_mouse:
dsda_InputTrackGameButtons(mousebuttons, MAX_MOUSE_BUTTONS, ev);
break;
Expand Down
2 changes: 1 addition & 1 deletion prboom2/src/f_finale.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void F_CastTicker (void)

dboolean F_CastResponder (event_t* ev)
{
if (ev->type != ev_keydown)
if (ev->type != ev_keydown && ev->type != ev_mouseb_down)
return false;

if (castdeath)
Expand Down
6 changes: 6 additions & 0 deletions prboom2/src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,12 @@ dboolean G_Responder (event_t* ev)
case ev_keydown:
return true; // eat key down events

case ev_mouseb_up:
return true;

case ev_mouseb_down:
return true;

case ev_mousemotion:
{
double value;
Expand Down
2 changes: 1 addition & 1 deletion prboom2/src/heretic/f_finale.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dboolean F_BlockingInput(void)

dboolean Heretic_F_Responder(event_t * event)
{
if (event->type != ev_keydown)
if (event->type != ev_keydown && event->type != ev_mouseb_down)
{
return false;
}
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void I_SetPalette(int pal); /* CPhipps - pass down palette number */
void I_QueueFrameCapture(void);
void I_QueueScreenshot(void);
void I_HandleCapture(void);
void I_DelayEvent(void);

void I_FinishUpdate (void);

Expand Down
6 changes: 4 additions & 2 deletions prboom2/src/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3993,6 +3993,8 @@ int M_GetKeyString(int c,int offset)
case KEYD_PAUSE: s = "PAUS"; break;
case KEYD_MWHEELDOWN: s = "MWDN"; break;
case KEYD_MWHEELUP: s = "MWUP"; break;
case KEYD_MWHEELLEFT: s = "MWLT"; break;
case KEYD_MWHEELRIGHT: s = "MWRT"; break;
case KEYD_PRINTSC: s = "PRSC"; break;
case 0: s = "NONE"; break;
default: s = "JUNK"; break;
Expand Down Expand Up @@ -5622,14 +5624,14 @@ int M_EventToCharacter(event_t* ev)
}
}
}
else if (ev->type == ev_keydown)
else if (ev->type == ev_keydown || ev->type == ev_mouseb_down)
{
if (ev->data1.i == KEYD_RSHIFT) // phares 4/11/98
shiftdown = true;

return ev->data1.i;
}
else if (ev->type == ev_keyup)
else if (ev->type == ev_keyup || ev->type == ev_mouseb_up)
{
if (ev->data1.i == KEYD_RSHIFT) // phares 4/11/98
shiftdown = false;
Expand Down

0 comments on commit 2b4e71f

Please sign in to comment.