Skip to content

Commit

Permalink
CUITrackBar: support gamepad interaction (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 10, 2025
1 parent e5870b1 commit 2556b8b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
70 changes: 59 additions & 11 deletions src/xrUICore/TrackBar/UITrackBar.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.hpp"
#include "UITrackBar.h"
#include "Buttons/UI3tButton.h"
#include "Cursor/UICursor.h"
#include "XML/UITextureMaster.h"
#include "xrEngine/xr_input.h"

Expand Down Expand Up @@ -30,12 +31,12 @@ CUITrackBar::CUITrackBar()

m_b_mouse_capturer = false;

//UI().Focus().RegisterFocusable(this);
UI().Focus().RegisterFocusable(this);
}

CUITrackBar::~CUITrackBar()
{
//UI().Focus().UnregisterFocusable(this);
UI().Focus().UnregisterFocusable(this);
}

bool CUITrackBar::OnMouseAction(float x, float y, EUIMessages mouse_action)
Expand All @@ -51,35 +52,82 @@ bool CUITrackBar::OnMouseAction(float x, float y, EUIMessages mouse_action)
if (pInput->iGetAsyncKeyState(MOUSE_1))
UpdatePosRelativeToMouse();
}
break;
return true;
}
case WINDOW_LBUTTON_DOWN:
{
m_b_mouse_capturer = m_bCursorOverWindow;
if (m_b_mouse_capturer)
UpdatePosRelativeToMouse();

break;
return true;
}
case WINDOW_LBUTTON_UP:
{
m_b_mouse_capturer = false;
break;
return true;
}
case WINDOW_MOUSE_WHEEL_UP:
{
StepLeft();
break;
return true;
}
case WINDOW_MOUSE_WHEEL_DOWN:
{
StepRight();
break;
return true;
}
default:
break;
};
return true;
} // switch (mouse_action)

return false;
}

bool CUITrackBar::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
CUIWindow::OnKeyboardAction(dik, keyboard_action);

if (CursorOverWindow() && keyboard_action == WINDOW_KEY_PRESSED)
{
switch (GetBindedAction(dik, EKeyContext::UI))
{
case kUI_MOVE_LEFT:
StepLeft();
UI().GetUICursor().WarpToWindow(m_pSlider);
return true;
case kUI_MOVE_RIGHT:
StepRight();
UI().GetUICursor().WarpToWindow(m_pSlider);
return true;
}
}

return false;
}

bool CUITrackBar::OnControllerAction(int axis, float x, float y, EUIMessages controller_action)
{
CUIWindow::OnControllerAction(axis, x, y, controller_action);

if (CursorOverWindow() && IsBinded(kUI_MOVE, axis, EKeyContext::UI))
{
if (fis_zero(y))
{
if (x < 0)
{
StepLeft();
UI().GetUICursor().WarpToWindow(m_pSlider);
return true;
}
else
{
StepRight();
UI().GetUICursor().WarpToWindow(m_pSlider);
return true;
}
}
}

return false;
}

void CUITrackBar::InitTrackBar(Fvector2 pos, Fvector2 size)
Expand Down
2 changes: 2 additions & 0 deletions src/xrUICore/TrackBar/UITrackBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class XRUICORE_API CUITrackBar final : public CUI_IB_FrameLineWnd, public CUIOpt
virtual void Draw();
virtual void Update();
virtual bool OnMouseAction(float x, float y, EUIMessages mouse_action);
bool OnKeyboardAction(int dik, EUIMessages keyboard_action) override;
bool OnControllerAction(int axis, float x, float y, EUIMessages controller_action) override;
virtual void OnMessage(LPCSTR message);
// CUIWindow
void InitTrackBar(Fvector2 pos, Fvector2 size);
Expand Down

0 comments on commit 2556b8b

Please sign in to comment.