[colobot] 08/377: Refactored mouse wheel
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:33:52 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 07df35ca011952018a16b9e25504502ce83c128c
Author: krzys-h <krzys_h at interia.pl>
Date: Fri Sep 25 22:54:48 2015 +0200
Refactored mouse wheel
---
src/app/app.cpp | 10 +++-----
src/common/event.h | 6 +++--
src/graphics/engine/camera.cpp | 55 +++++++++++++-----------------------------
src/graphics/engine/camera.h | 2 +-
src/ui/controls/edit.cpp | 9 +------
src/ui/controls/editvalue.cpp | 13 ++--------
src/ui/controls/list.cpp | 16 ++++--------
src/ui/controls/scroll.cpp | 30 ++++++++++++++---------
src/ui/controls/slider.cpp | 30 ++++++++++++++---------
9 files changed, 70 insertions(+), 101 deletions(-)
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 94976a7..1ab3caa 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<MouseWheelEventData>();
-
- 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<MouseWheelEventData>();
- 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 0da1518..5b5680a 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -648,8 +648,10 @@ struct MouseWheelEventData : public EventData
return MakeUnique<MouseWheelEventData>(*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 abfac64..df92d6a 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<MouseWheelEventData>()->dir);
+ EventMouseWheel(event.GetData<MouseWheelEventData>()->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 10ea660..52f84cd 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 a553575..c2c6778 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<MouseWheelEventData>();
- 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 ddd2cf5..4827479 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<MouseWheelEventData>()->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<MouseWheelEventData>()->dir == WHEEL_DOWN &&
- Detect(event.mousePos))
- {
- float value = GetValue()-m_stepValue;
+ float value = GetValue() + (m_stepValue * event.GetData<MouseWheelEventData>()->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 3ad13b9..102e34b 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<MouseWheelEventData>();
- 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 3c939ab..3ac00ef 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<MouseWheelEventData>()->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<MouseWheelEventData>()->dir == WHEEL_DOWN &&
- Detect(event.mousePos) &&
- m_buttonDown != nullptr)
- {
- m_event->AddEvent(Event(m_buttonDown->GetEventType()));
+ auto data = event.GetData<MouseWheelEventData>();
+ 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 0707921..dbaf1a6 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<MouseWheelEventData>()->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<MouseWheelEventData>()->dir == WHEEL_DOWN &&
- Detect(event.mousePos) &&
- m_buttonRight != nullptr)
- {
- m_event->AddEvent(Event(m_buttonRight->GetEventType()));
+ auto data = event.GetData<MouseWheelEventData>();
+ 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;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list