diff --git a/src/app/app.cpp b/src/app/app.cpp index 94976a72..1ab3caa1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1069,11 +1069,8 @@ Event CApplication::ProcessSystemEvent() event.type = EVENT_MOUSE_WHEEL; auto data = MakeUnique(); - - if (m_private->currentEvent.wheel.y < 0) // TODO: properly use this value - data->dir = WHEEL_DOWN; - else - data->dir = WHEEL_UP; + data->y = m_private->currentEvent.wheel.y; + data->x = m_private->currentEvent.wheel.x; event.data = std::move(data); } @@ -1175,7 +1172,8 @@ void CApplication::LogEvent(const Event &event) case EVENT_MOUSE_WHEEL: { auto data = event.GetData(); - l->Trace(" dir = %s\n", (data->dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); + l->Trace(" y = %d\n", data->y); + l->Trace(" x = %d\n", data->x); break; } case EVENT_JOY_AXIS: diff --git a/src/common/event.h b/src/common/event.h index 0da15182..5b5680a4 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -648,8 +648,10 @@ struct MouseWheelEventData : public EventData return MakeUnique(*this); } - //! Wheel direction - WheelDirection dir = WHEEL_UP; + //! Amount scrolled vertically, positive value is away from the user + signed int y = 0; + //! Amount scrolled horizontally (if the mouse supports it), positive value is to the right + signed int x = 0; }; /** diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index abfac64c..df92d6a8 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1065,7 +1065,7 @@ bool CCamera::EventProcess(const Event &event) break; case EVENT_MOUSE_WHEEL: - EventMouseWheel(event.GetData()->dir); + EventMouseWheel(event.GetData()->y); break; default: @@ -1080,55 +1080,34 @@ bool CCamera::EventMouseMove(const Event &event) return true; } -void CCamera::EventMouseWheel(WheelDirection dir) +void CCamera::EventMouseWheel(int dir) { if (m_type == CAM_TYPE_BACK) { - if (dir == WHEEL_UP) - { - m_backDist -= 8.0f; - if (m_backDist < m_backMin) - m_backDist = m_backMin; - } - else if (dir == WHEEL_DOWN) - { - m_backDist += 8.0f; - if (m_backDist > 200.0f) - m_backDist = 200.0f; - } + m_backDist -= 8.0f*dir; + if (m_backDist < m_backMin) + m_backDist = m_backMin; + if (m_backDist > 200.0f) + m_backDist = 200.0f; } if ( m_type == CAM_TYPE_FIX || m_type == CAM_TYPE_PLANE ) { - if (dir == WHEEL_UP) - { - m_fixDist -= 8.0f; - if (m_fixDist < 10.0f) - m_fixDist = 10.0f; - } - else if (dir == WHEEL_DOWN) - { - m_fixDist += 8.0f; - if (m_fixDist > 200.0f) - m_fixDist = 200.0f; - } + m_fixDist -= 8.0f*dir; + if (m_fixDist < 10.0f) + m_fixDist = 10.0f; + if (m_fixDist > 200.0f) + m_fixDist = 200.0f; } if ( m_type == CAM_TYPE_VISIT ) { - if (dir == WHEEL_UP) - { - m_visitDist -= 8.0f; - if (m_visitDist < 20.0f) - m_visitDist = 20.0f; - } - else if (dir == WHEEL_DOWN) - { - m_visitDist += 8.0f; - if (m_visitDist > 200.0f) - m_visitDist = 200.0f; - } + m_visitDist -= 8.0f*dir; + if (m_visitDist < 20.0f) + m_visitDist = 20.0f; + if (m_visitDist > 200.0f) + m_visitDist = 200.0f; } } diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 10ea6606..52f84cd9 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -226,7 +226,7 @@ protected: //! Changes the camera according to the mouse moved bool EventMouseMove(const Event &event); //! Mouse wheel operation - void EventMouseWheel(WheelDirection dir); + void EventMouseWheel(int dir); //! Changes the camera according to the time elapsed bool EventFrame(const Event &event); //! Moves the point of view diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index a5535757..c2c67782 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -254,14 +254,7 @@ bool CEdit::EventProcess(const Event &event) Detect(event.mousePos)) { auto data = event.GetData(); - if (data->dir == WHEEL_UP) - { - Scroll(m_lineFirst - 3, true); - } - else - { - Scroll(m_lineFirst + 3, true); - } + Scroll(m_lineFirst - data->y, true); return true; } diff --git a/src/ui/controls/editvalue.cpp b/src/ui/controls/editvalue.cpp index ddd2cf55..48274792 100644 --- a/src/ui/controls/editvalue.cpp +++ b/src/ui/controls/editvalue.cpp @@ -184,20 +184,11 @@ bool CEditValue::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_UP && Detect(event.mousePos)) { - float value = GetValue()+m_stepValue; - if ( value > m_maxValue ) value = m_maxValue; - SetValue(value, true); - HiliteValue(event); - } - if ( event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_DOWN && - Detect(event.mousePos)) - { - float value = GetValue()-m_stepValue; + float value = GetValue() + (m_stepValue * event.GetData()->y); if ( value < m_minValue ) value = m_minValue; + if ( value > m_maxValue ) value = m_maxValue; SetValue(value, true); HiliteValue(event); } diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 3ad13b99..102e34bc 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -280,16 +280,11 @@ bool CList::EventProcess(const Event &event) if (event.type == EVENT_MOUSE_WHEEL && Detect(event.mousePos)) { auto data = event.GetData(); - if (data->dir == WHEEL_UP) - { - if (m_firstLine > 0) - m_firstLine--; - } - else - { - if (m_firstLine < m_totalLine - m_displayLine) - m_firstLine++; - } + m_firstLine -= data->y; + if (m_firstLine < 0) + m_firstLine = 0; + if (m_firstLine > m_totalLine - m_displayLine) + m_firstLine = m_totalLine - m_displayLine; UpdateScroll(); UpdateButton(); @@ -855,4 +850,3 @@ void CList::MoveScroll() } // namespace Ui - diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index 3c939ab3..3ac00ef3 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -273,18 +273,25 @@ bool CScroll::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_UP && - Detect(event.mousePos) && - m_buttonUp != nullptr) + Detect(event.mousePos)) { - m_event->AddEvent(Event(m_buttonUp->GetEventType())); - } - if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_DOWN && - Detect(event.mousePos) && - m_buttonDown != nullptr) - { - m_event->AddEvent(Event(m_buttonDown->GetEventType())); + auto data = event.GetData(); + if (data->y > 0) + { + if (m_buttonUp != nullptr) + { + for (int i = 0; i < data->y; i++) + m_event->AddEvent(Event(m_buttonUp->GetEventType())); + } + } + else + { + if (m_buttonDown != nullptr) + { + for (int i = 0; i < -(data->y); i++) + m_event->AddEvent(Event(m_buttonDown->GetEventType())); + } + } } return true; @@ -443,4 +450,3 @@ float CScroll::GetArrowStep() } } // namespace Ui - diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 07079210..dbaf1a69 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -338,19 +338,25 @@ bool CSlider::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_UP && - Detect(event.mousePos) && - m_buttonLeft != nullptr) + Detect(event.mousePos)) { - m_event->AddEvent(Event(m_buttonLeft->GetEventType())); - } - - if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_DOWN && - Detect(event.mousePos) && - m_buttonRight != nullptr) - { - m_event->AddEvent(Event(m_buttonRight->GetEventType())); + auto data = event.GetData(); + if (data->y > 0) + { + if (m_buttonLeft != nullptr) + { + for (int i = 0; i < data->y; i++) + m_event->AddEvent(Event(m_buttonLeft->GetEventType())); + } + } + else + { + if (m_buttonRight != nullptr) + { + for (int i = 0; i < -(data->y); i++) + m_event->AddEvent(Event(m_buttonRight->GetEventType())); + } + } } return true;