From 2b4e71faf718f51cbc5de1a35d6b3a42777afba4 Mon Sep 17 00:00:00 2001 From: Arsinikk Date: Sat, 30 Nov 2024 18:54:53 -0600 Subject: [PATCH 1/3] Add horizontal mouse wheel support --- prboom2/src/SDL/i_video.c | 47 ++++++++++++++++++++++++---------- prboom2/src/am_map.c | 6 ++--- prboom2/src/d_event.h | 2 ++ prboom2/src/d_main.c | 2 +- prboom2/src/doomdef.h | 2 ++ prboom2/src/dsda/input.c | 12 +++++++++ prboom2/src/f_finale.c | 2 +- prboom2/src/g_game.c | 6 +++++ prboom2/src/heretic/f_finale.c | 2 +- prboom2/src/i_video.h | 1 + prboom2/src/m_menu.c | 6 +++-- 11 files changed, 67 insertions(+), 21 deletions(-) diff --git a/prboom2/src/SDL/i_video.c b/prboom2/src/SDL/i_video.c index ac8fae201..18c897fe4 100644 --- a/prboom2/src/SDL/i_video.c +++ b/prboom2/src/SDL/i_video.c @@ -292,6 +292,8 @@ int I_SDLtoDoomMouseState(Uint32 buttonstate) ; } +static event_t delay_event; + static void I_GetEvent(void) { event_t event; @@ -299,6 +301,8 @@ static void I_GetEvent(void) SDL_Event SDLEvent; SDL_Event *Event = &SDLEvent; + I_DelayEvent(); + while (SDL_PollEvent(Event)) { switch (Event->type) { @@ -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; @@ -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 // diff --git a/prboom2/src/am_map.c b/prboom2/src/am_map.c index bb3615290..f91f9c5c9 100644 --- a/prboom2/src/am_map.c +++ b/prboom2/src/am_map.c @@ -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; @@ -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; @@ -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) ) ) diff --git a/prboom2/src/d_event.h b/prboom2/src/d_event.h index 8faaee3c2..6ee5bc1c0 100644 --- a/prboom2/src/d_event.h +++ b/prboom2/src/d_event.h @@ -48,6 +48,8 @@ typedef enum { ev_keydown, ev_keyup, + ev_mouseb_down, + ev_mouseb_up, ev_mouse, ev_mousemotion, ev_joystick, diff --git a/prboom2/src/d_main.c b/prboom2/src/d_main.c index d85474c40..41ff1b570 100644 --- a/prboom2/src/d_main.c +++ b/prboom2/src/d_main.c @@ -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; diff --git a/prboom2/src/doomdef.h b/prboom2/src/doomdef.h index 1b71a57e2..c5b43c9b2 100644 --- a/prboom2/src/doomdef.h +++ b/prboom2/src/doomdef.h @@ -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: // diff --git a/prboom2/src/dsda/input.c b/prboom2/src/dsda/input.c index 7455292d9..63a81939c 100644 --- a/prboom2/src/dsda/input.c +++ b/prboom2/src/dsda/input.c @@ -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; @@ -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; diff --git a/prboom2/src/f_finale.c b/prboom2/src/f_finale.c index 651e84868..631c12743 100644 --- a/prboom2/src/f_finale.c +++ b/prboom2/src/f_finale.c @@ -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) diff --git a/prboom2/src/g_game.c b/prboom2/src/g_game.c index d21f6ff4a..1323ebe2b 100644 --- a/prboom2/src/g_game.c +++ b/prboom2/src/g_game.c @@ -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; diff --git a/prboom2/src/heretic/f_finale.c b/prboom2/src/heretic/f_finale.c index dabba154f..d3a3e10aa 100644 --- a/prboom2/src/heretic/f_finale.c +++ b/prboom2/src/heretic/f_finale.c @@ -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; } diff --git a/prboom2/src/i_video.h b/prboom2/src/i_video.h index 2cacf3d34..8fb900137 100644 --- a/prboom2/src/i_video.h +++ b/prboom2/src/i_video.h @@ -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); diff --git a/prboom2/src/m_menu.c b/prboom2/src/m_menu.c index f62e9a6ec..3805a9600 100644 --- a/prboom2/src/m_menu.c +++ b/prboom2/src/m_menu.c @@ -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; @@ -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; From 3e0e792c9a9eae3523ac678ba25e385d1737c1f6 Mon Sep 17 00:00:00 2001 From: Arsinikk Date: Sun, 1 Dec 2024 07:20:42 -0600 Subject: [PATCH 2/3] Revert new mouse button type --- prboom2/src/SDL/i_video.c | 22 ++++------------------ prboom2/src/am_map.c | 6 +++--- prboom2/src/d_event.h | 2 -- prboom2/src/d_main.c | 2 +- prboom2/src/dsda/input.c | 12 ------------ prboom2/src/f_finale.c | 2 +- prboom2/src/g_game.c | 6 ------ prboom2/src/heretic/f_finale.c | 2 +- prboom2/src/i_video.h | 1 - prboom2/src/m_menu.c | 4 ++-- 10 files changed, 12 insertions(+), 47 deletions(-) diff --git a/prboom2/src/SDL/i_video.c b/prboom2/src/SDL/i_video.c index 18c897fe4..0cfc965e4 100644 --- a/prboom2/src/SDL/i_video.c +++ b/prboom2/src/SDL/i_video.c @@ -292,8 +292,6 @@ int I_SDLtoDoomMouseState(Uint32 buttonstate) ; } -static event_t delay_event; - static void I_GetEvent(void) { event_t event; @@ -301,8 +299,6 @@ static void I_GetEvent(void) SDL_Event SDLEvent; SDL_Event *Event = &SDLEvent; - I_DelayEvent(); - while (SDL_PollEvent(Event)) { switch (Event->type) { @@ -386,12 +382,12 @@ static void I_GetEvent(void) // post a button down event event.data1.i = button; - event.type = ev_mouseb_down; + event.type = ev_keydown; 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; + event.data1.i = button; + event.type = ev_keyup; + D_PostEvent(&event); } break; @@ -433,16 +429,6 @@ 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 // diff --git a/prboom2/src/am_map.c b/prboom2/src/am_map.c index f91f9c5c9..bb3615290 100644 --- a/prboom2/src/am_map.c +++ b/prboom2/src/am_map.c @@ -1073,7 +1073,7 @@ dboolean AM_Responder } else if ( dsda_InputActivated(dsda_input_map_zoomout) || - (map_wheel_zoom && ev->type == ev_mouseb_down && ev->data1.i == KEYD_MWHEELDOWN) + (map_wheel_zoom && ev->type == ev_keydown && ev->data1.i == KEYD_MWHEELDOWN) ) { mtof_zoommul = M_ZOOMOUT; @@ -1085,7 +1085,7 @@ dboolean AM_Responder } else if ( dsda_InputActivated(dsda_input_map_zoomin) || - (map_wheel_zoom && ev->type == ev_mouseb_down && ev->data1.i == KEYD_MWHEELUP) + (map_wheel_zoom && ev->type == ev_keydown && ev->data1.i == KEYD_MWHEELUP) ) { mtof_zoommul = M_ZOOMIN; @@ -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_mouseb_up && + map_wheel_zoom && ev->type == ev_keyup && (ev->data1.i == KEYD_MWHEELDOWN || ev->data1.i == KEYD_MWHEELUP) ) ) diff --git a/prboom2/src/d_event.h b/prboom2/src/d_event.h index 6ee5bc1c0..8faaee3c2 100644 --- a/prboom2/src/d_event.h +++ b/prboom2/src/d_event.h @@ -48,8 +48,6 @@ typedef enum { ev_keydown, ev_keyup, - ev_mouseb_down, - ev_mouseb_up, ev_mouse, ev_mousemotion, ev_joystick, diff --git a/prboom2/src/d_main.c b/prboom2/src/d_main.c index 41ff1b570..d85474c40 100644 --- a/prboom2/src/d_main.c +++ b/prboom2/src/d_main.c @@ -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 || ev->type == ev_mouseb_down || ev->type == ev_mouseb_up) // is this condition important? + (ev->type == ev_keydown || ev->type == ev_keyup) // is this condition important? ) { return; diff --git a/prboom2/src/dsda/input.c b/prboom2/src/dsda/input.c index 63a81939c..7455292d9 100644 --- a/prboom2/src/dsda/input.c +++ b/prboom2/src/dsda/input.c @@ -90,12 +90,6 @@ 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; @@ -148,12 +142,6 @@ 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; diff --git a/prboom2/src/f_finale.c b/prboom2/src/f_finale.c index 631c12743..651e84868 100644 --- a/prboom2/src/f_finale.c +++ b/prboom2/src/f_finale.c @@ -617,7 +617,7 @@ void F_CastTicker (void) dboolean F_CastResponder (event_t* ev) { - if (ev->type != ev_keydown && ev->type != ev_mouseb_down) + if (ev->type != ev_keydown) return false; if (castdeath) diff --git a/prboom2/src/g_game.c b/prboom2/src/g_game.c index 1323ebe2b..d21f6ff4a 100644 --- a/prboom2/src/g_game.c +++ b/prboom2/src/g_game.c @@ -1380,12 +1380,6 @@ 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; diff --git a/prboom2/src/heretic/f_finale.c b/prboom2/src/heretic/f_finale.c index d3a3e10aa..dabba154f 100644 --- a/prboom2/src/heretic/f_finale.c +++ b/prboom2/src/heretic/f_finale.c @@ -90,7 +90,7 @@ dboolean F_BlockingInput(void) dboolean Heretic_F_Responder(event_t * event) { - if (event->type != ev_keydown && event->type != ev_mouseb_down) + if (event->type != ev_keydown) { return false; } diff --git a/prboom2/src/i_video.h b/prboom2/src/i_video.h index 8fb900137..2cacf3d34 100644 --- a/prboom2/src/i_video.h +++ b/prboom2/src/i_video.h @@ -65,7 +65,6 @@ 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); diff --git a/prboom2/src/m_menu.c b/prboom2/src/m_menu.c index 3805a9600..95b87eb10 100644 --- a/prboom2/src/m_menu.c +++ b/prboom2/src/m_menu.c @@ -5624,14 +5624,14 @@ int M_EventToCharacter(event_t* ev) } } } - else if (ev->type == ev_keydown || ev->type == ev_mouseb_down) + else if (ev->type == ev_keydown) { if (ev->data1.i == KEYD_RSHIFT) // phares 4/11/98 shiftdown = true; return ev->data1.i; } - else if (ev->type == ev_keyup || ev->type == ev_mouseb_up) + else if (ev->type == ev_keyup) { if (ev->data1.i == KEYD_RSHIFT) // phares 4/11/98 shiftdown = false; From 6c20fecd58cc27a122b6054fc1aec27588a2a9bf Mon Sep 17 00:00:00 2001 From: Arsinikk Date: Sun, 1 Dec 2024 08:11:36 -0600 Subject: [PATCH 3/3] Simplify Mousewheel code --- prboom2/src/SDL/i_video.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/prboom2/src/SDL/i_video.c b/prboom2/src/SDL/i_video.c index 0cfc965e4..055fa8757 100644 --- a/prboom2/src/SDL/i_video.c +++ b/prboom2/src/SDL/i_video.c @@ -361,33 +361,29 @@ static void I_GetEvent(void) case SDL_MOUSEWHEEL: if (mouse_enabled && window_focused) { - int button = -1; + int mouseb; if (Event->wheel.y > 0) - { - button = KEYD_MWHEELUP; - } + mouseb = KEYD_MWHEELUP; else if (Event->wheel.y < 0) - { - button = KEYD_MWHEELDOWN; - } + mouseb = KEYD_MWHEELDOWN; else if (Event->wheel.x < 0) - { - button = KEYD_MWHEELLEFT; - } + mouseb = KEYD_MWHEELLEFT; else if (Event->wheel.x > 0) + mouseb = KEYD_MWHEELRIGHT; + else + mouseb = 0; + + if(mouseb) { - button = KEYD_MWHEELRIGHT; - } + event.data1.i = mouseb; - // post a button down event - event.data1.i = button; - event.type = ev_keydown; - D_PostEvent(&event); + event.type = ev_keydown; + D_PostEvent(&event); - event.data1.i = button; - event.type = ev_keyup; - D_PostEvent(&event); + event.type = ev_keyup; + D_PostEvent(&event); + } } break;