Skip to content

Commit 9a8eccb

Browse files
committed
Support horizontal mouse wheel scroll
1 parent be4712d commit 9a8eccb

14 files changed

+47
-30
lines changed

src/xrEngine/IInputReceiver.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using Ivector2 = _vector2<int>;
1717
class ENGINE_API IInputReceiver
1818
{
1919
public:
20+
virtual ~IInputReceiver() = default;
2021
static void IR_GetLastMouseDelta(Ivector2& p);
2122
static void IR_GetMousePosScreen(Ivector2& p);
2223
static void IR_GetMousePosReal(SDL_Window* m_sdlWnd, Ivector2& p);
@@ -31,16 +32,16 @@ class ENGINE_API IInputReceiver
3132
virtual void IR_OnDeactivate(void);
3233
virtual void IR_OnActivate(void);
3334

34-
virtual void IR_OnMousePress(int /*btn*/){};
35-
virtual void IR_OnMouseRelease(int /*btn*/){};
36-
virtual void IR_OnMouseHold(int /*btn*/){};
37-
virtual void IR_OnMouseWheel(int /*direction*/){};
38-
virtual void IR_OnMouseMove(int /*x*/, int /*y*/){};
39-
virtual void IR_OnMouseStop(int /*x*/, int /*y*/){};
35+
virtual void IR_OnMousePress(int /*btn*/) {}
36+
virtual void IR_OnMouseRelease(int /*btn*/) {}
37+
virtual void IR_OnMouseHold(int /*btn*/) {}
38+
virtual void IR_OnMouseWheel(int /*x*/, int /*y*/) {}
39+
virtual void IR_OnMouseMove(int /*x*/, int /*y*/) {}
40+
virtual void IR_OnMouseStop(int /*x*/, int /*y*/) {}
4041

41-
virtual void IR_OnKeyboardPress(int /*dik*/){};
42-
virtual void IR_OnKeyboardRelease(int /*dik*/){};
43-
virtual void IR_OnKeyboardHold(int /*dik*/){};
42+
virtual void IR_OnKeyboardPress(int /*dik*/) {}
43+
virtual void IR_OnKeyboardRelease(int /*dik*/) {}
44+
virtual void IR_OnKeyboardHold(int /*dik*/) {}
4445
};
4546

4647
ENGINE_API extern float psMouseSens;

src/xrEngine/xr_input.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ void CInput::MouseUpdate()
125125
cbStack.back()->IR_OnMousePress(event.button.button - 1);
126126
break;
127127
case SDL_MOUSEWHEEL:
128+
mouseMoved = true;
128129
timeStamp[2] = dwCurTime + event.wheel.timestamp;
129130
timeStamp[3] = dwCurTime + event.wheel.timestamp;
130131
offs[2] += event.wheel.y;
@@ -152,8 +153,8 @@ void CInput::MouseUpdate()
152153
{
153154
if (offs[0] || offs[1])
154155
cbStack.back()->IR_OnMouseMove(offs[0], offs[1]);
155-
if (offs[2])
156-
cbStack.back()->IR_OnMouseWheel(offs[2]);
156+
if (offs[2] || offs[3])
157+
cbStack.back()->IR_OnMouseWheel(offs[2], offs[3]);
157158
}
158159
else
159160
{

src/xrGame/Actor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class CActor : public CEntityAlive,
431431
virtual void IR_OnKeyboardPress(int dik);
432432
virtual void IR_OnKeyboardRelease(int dik);
433433
virtual void IR_OnKeyboardHold(int dik);
434-
virtual void IR_OnMouseWheel(int direction);
434+
virtual void IR_OnMouseWheel(int x, int y);
435435
virtual float GetLookFactor();
436436

437437
public:

src/xrGame/ActorInput.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,18 @@ void CActor::IR_OnKeyboardPress(int cmd)
199199
}
200200
}
201201

202-
void CActor::IR_OnMouseWheel(int direction)
202+
void CActor::IR_OnMouseWheel(int x, int y)
203203
{
204204
if (hud_adj_mode)
205205
{
206-
g_player_hud->tune(Ivector().set(0, 0, direction));
206+
g_player_hud->tune(Ivector().set(0, 0, x));
207207
return;
208208
}
209209

210-
if (inventory().Action((direction > 0) ? (u16)kWPN_ZOOM_DEC : (u16)kWPN_ZOOM_INC, CMD_START))
210+
if (inventory().Action((x > 0) ? (u16)kWPN_ZOOM_DEC : (u16)kWPN_ZOOM_INC, CMD_START))
211211
return;
212212

213-
if (direction > 0)
213+
if (x > 0)
214214
OnNextWeaponSlot();
215215
else
216216
OnPrevWeaponSlot();

src/xrGame/Level.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class CLevel : public IGame_Level, public IPureClient
298298
virtual void IR_OnMouseHold(int btn);
299299
virtual void IR_OnMouseMove(int, int);
300300
virtual void IR_OnMouseStop(int, int);
301-
virtual void IR_OnMouseWheel(int direction);
301+
virtual void IR_OnMouseWheel(int x, int y);
302302
virtual void IR_OnActivate(void);
303303
int get_RPID(LPCSTR name);
304304
// Game

src/xrGame/Level_input.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ extern float g_fTimeFactor;
4343

4444
#define CURRENT_ENTITY() (game ? ((GameID() == eGameIDSingle) ? CurrentEntity() : CurrentControlEntity()) : NULL)
4545

46-
void CLevel::IR_OnMouseWheel(int direction)
46+
void CLevel::IR_OnMouseWheel(int x, int y)
4747
{
4848
if (g_bDisableAllInput)
4949
return;
5050

5151
#ifdef INPUT_CALLBACKS
5252
/* avo: script callback */
5353
if (g_actor)
54-
g_actor->callback(GameObject::eMouseWheel)(direction);
54+
g_actor->callback(GameObject::eMouseWheel)(x);
5555
/* avo: end */
5656
#endif
57-
if (CurrentGameUI()->IR_UIOnMouseWheel(direction))
57+
if (CurrentGameUI()->IR_UIOnMouseWheel(x, y))
5858
return;
5959
if (Device.Paused()
6060
#ifdef DEBUG
@@ -67,7 +67,7 @@ void CLevel::IR_OnMouseWheel(int direction)
6767
{
6868
IInputReceiver* IR = smart_cast<IInputReceiver*>(smart_cast<CGameObject*>(CURRENT_ENTITY()));
6969
if (IR)
70-
IR->IR_OnMouseWheel(direction);
70+
IR->IR_OnMouseWheel(x, y);
7171
}
7272
}
7373

src/xrGame/MainMenu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,12 @@ void CMainMenu::IR_OnKeyboardHold(int dik)
371371
CDialogHolder::IR_UIOnKeyboardHold((SDL_Scancode)dik);
372372
};
373373

374-
void CMainMenu::IR_OnMouseWheel(int direction)
374+
void CMainMenu::IR_OnMouseWheel(int x, int y)
375375
{
376376
if (!IsActive())
377377
return;
378378

379-
CDialogHolder::IR_UIOnMouseWheel(direction);
379+
CDialogHolder::IR_UIOnMouseWheel(x, y);
380380
}
381381

382382
bool CMainMenu::OnRenderPPUI_query() { return IsActive() && !m_Flags.test(flGameSaveScreenshot) && b_shniaganeed_pp; }

src/xrGame/MainMenu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class CMainMenu : public IMainMenu,
150150
virtual void IR_OnKeyboardRelease(int dik);
151151
virtual void IR_OnKeyboardHold(int dik);
152152

153-
virtual void IR_OnMouseWheel(int direction);
153+
virtual void IR_OnMouseWheel(int x, int y);
154154

155155
bool OnRenderPPUI_query();
156156
void OnRenderPPUI_main();

src/xrGame/UIDialogHolder.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ bool CDialogHolder::IR_UIOnKeyboardHold(SDL_Scancode dik)
339339
return true;
340340
}
341341

342-
bool CDialogHolder::IR_UIOnMouseWheel(int direction)
342+
bool CDialogHolder::IR_UIOnMouseWheel(int x, int y)
343343
{
344344
CUIDialogWnd* TIR = TopInputReceiver();
345345
if (!TIR)
@@ -349,7 +349,18 @@ bool CDialogHolder::IR_UIOnMouseWheel(int direction)
349349

350350
Fvector2 pos = GetUICursor().GetCursorPosition();
351351

352-
TIR->OnMouseAction(pos.x, pos.y, (direction > 0) ? WINDOW_MOUSE_WHEEL_UP : WINDOW_MOUSE_WHEEL_DOWN);
352+
// Vertical scroll is in higher priority
353+
EUIMessages wheelMessage;
354+
if (x > 0)
355+
wheelMessage = WINDOW_MOUSE_WHEEL_UP;
356+
else if (x < 0)
357+
wheelMessage = WINDOW_MOUSE_WHEEL_DOWN;
358+
else if (y > 0)
359+
wheelMessage = WINDOW_MOUSE_WHEEL_RIGHT;
360+
else
361+
wheelMessage = WINDOW_MOUSE_WHEEL_LEFT;
362+
363+
TIR->OnMouseAction(pos.x, pos.y, wheelMessage);
353364
return true;
354365
}
355366

src/xrGame/UIDialogHolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ class CDialogHolder : public pureFrame
6262
virtual bool IR_UIOnKeyboardPress(SDL_Scancode dik);
6363
virtual bool IR_UIOnKeyboardRelease(SDL_Scancode dik);
6464
virtual bool IR_UIOnMouseMove(int dx, int dy);
65-
virtual bool IR_UIOnMouseWheel(int direction);
65+
virtual bool IR_UIOnMouseWheel(int x, int y);
6666
virtual bool IR_UIOnKeyboardHold(SDL_Scancode dik);
6767
};

0 commit comments

Comments
 (0)