Skip to content

Commit

Permalink
xrUICore/TrackBar/UITrackBar.h|cpp: extract slider moving code to Ste…
Browse files Browse the repository at this point in the history
…pLeft/StepRight methods
  • Loading branch information
Xottab-DUTY committed Jan 10, 2025
1 parent 5c14bfe commit e5870b1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
62 changes: 36 additions & 26 deletions src/xrUICore/TrackBar/UITrackBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,12 @@ bool CUITrackBar::OnMouseAction(float x, float y, EUIMessages mouse_action)
}
case WINDOW_MOUSE_WHEEL_UP:
{
if (m_b_is_float)
{
m_f_val -= GetInvert() ? -m_f_step : m_f_step;
clamp(m_f_val, m_f_min, m_f_max);
}
else
{
m_i_val -= GetInvert() ? -m_i_step : m_i_step;
clamp(m_i_val, m_i_min, m_i_max);
}
GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, NULL);
UpdatePos();
OnChangedOptValue();
StepLeft();
break;
}
case WINDOW_MOUSE_WHEEL_DOWN:
{
if (m_b_is_float)
{
m_f_val += GetInvert() ? -m_f_step : m_f_step;
clamp(m_f_val, m_f_min, m_f_max);
}
else
{
m_i_val += GetInvert() ? -m_i_step : m_i_step;
clamp(m_i_val, m_i_min, m_i_max);
}
GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, NULL);
UpdatePos();
OnChangedOptValue();
StepRight();
break;
}
default:
Expand Down Expand Up @@ -242,6 +218,40 @@ void CUITrackBar::Enable(bool status)
m_pSlider->Enable(m_bIsEnabled);
}

void CUITrackBar::StepLeft()
{
if (m_b_is_float)
{
m_f_val -= GetInvert() ? -m_f_step : m_f_step;
clamp(m_f_val, m_f_min, m_f_max);
}
else
{
m_i_val -= GetInvert() ? -m_i_step : m_i_step;
clamp(m_i_val, m_i_min, m_i_max);
}
GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, nullptr);
UpdatePos();
OnChangedOptValue();
}

void CUITrackBar::StepRight()
{
if (m_b_is_float)
{
m_f_val += GetInvert() ? -m_f_step : m_f_step;
clamp(m_f_val, m_f_min, m_f_max);
}
else
{
m_i_val += GetInvert() ? -m_i_step : m_i_step;
clamp(m_i_val, m_i_min, m_i_max);
}
GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, nullptr);
UpdatePos();
OnChangedOptValue();
}

void CUITrackBar::UpdatePosRelativeToMouse()
{
float _bkf = 0.0f;
Expand Down
3 changes: 3 additions & 0 deletions src/xrUICore/TrackBar/UITrackBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class XRUICORE_API CUITrackBar final : public CUI_IB_FrameLineWnd, public CUIOpt
void SetOptIBounds(int imin, int imax);
void SetOptFBounds(float fmin, float fmax);

void StepLeft();
void StepRight();

pcstr GetDebugType() override { return "CUITrackBar"; }

CUIStatic* m_static;
Expand Down

0 comments on commit e5870b1

Please sign in to comment.