Skip to content

Commit

Permalink
Improved touch navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Feb 18, 2025
1 parent c80c3b4 commit 7e05f9b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
12 changes: 7 additions & 5 deletions Sources/Jazz2/UI/Menu/AboutSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ namespace Jazz2::UI::Menu
if (_touchSpeed > 0.0f) {
if (_touchStart == Vector2f::Zero) {
float scrollOffset = _scrollOffset + (_touchSpeed * (std::int32_t)_touchDirection * TouchKineticDivider * timeMult);
if (scrollOffset < 0.0f && _touchDirection == -1) {
if (scrollOffset < 0.0f && _touchDirection < 0) {
scrollOffset = 0.0f;
_touchDirection = 1;
_touchSpeed *= TouchKineticDamping;
} else if (scrollOffset > _maxScrollOffset && _touchDirection == 1) {
} else if (scrollOffset > _maxScrollOffset && _touchDirection > 0) {
scrollOffset = _maxScrollOffset;
_touchDirection = -1;
_touchSpeed *= TouchKineticDamping;
Expand Down Expand Up @@ -315,9 +315,11 @@ namespace Jazz2::UI::Menu
float delta = _touchLast.Y - touchMove.Y;
if (delta != 0.0f) {
_scrollOffset += delta;
std::uint8_t newDirection = (delta < 0.0f ? -1 : 1);
if (_touchDirection != newDirection) {
_touchDirection = newDirection;
if (delta < -0.1f && _touchDirection >= 0) {
_touchDirection = -1;
_touchSpeed = 0.0f;
} else if (delta > 0.1f && _touchDirection <= 0) {
_touchDirection = 1;
_touchSpeed = 0.0f;
}
_touchSpeed = (0.8f * _touchSpeed) + (0.2f * std::abs(delta) / TouchKineticDivider);
Expand Down
12 changes: 7 additions & 5 deletions Sources/Jazz2/UI/Menu/CustomLevelSelectSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ namespace Jazz2::UI::Menu
if (_touchSpeed > 0.0f) {
if (_touchStart == Vector2f::Zero && _availableHeight < _height) {
float y = _y + (_touchSpeed * (std::int32_t)_touchDirection * TouchKineticDivider * timeMult);
if (y < (_availableHeight - _height) && _touchDirection == -1) {
if (y < (_availableHeight - _height) && _touchDirection < 0) {
y = (_availableHeight - _height);
_touchDirection = 1;
_touchSpeed *= TouchKineticDamping;
} else if (y > 0.0f && _touchDirection == 1) {
} else if (y > 0.0f && _touchDirection > 0) {
y = 0.0f;
_touchDirection = -1;
_touchSpeed *= TouchKineticDamping;
Expand Down Expand Up @@ -234,9 +234,11 @@ namespace Jazz2::UI::Menu
float delta = touchMove.Y - _touchLast.Y;
if (delta != 0.0f) {
_y += delta;
std::uint8_t newDirection = (delta < 0.0f ? -1 : 1);
if (_touchDirection != newDirection) {
_touchDirection = newDirection;
if (delta < -0.1f && _touchDirection >= 0) {
_touchDirection = -1;
_touchSpeed = 0.0f;
} else if (delta > 0.1f && _touchDirection <= 0) {
_touchDirection = 1;
_touchSpeed = 0.0f;
}
_touchSpeed = (0.8f * _touchSpeed) + (0.2f * std::abs(delta) / TouchKineticDivider);
Expand Down
12 changes: 7 additions & 5 deletions Sources/Jazz2/UI/Menu/ScrollableMenuSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ namespace Jazz2::UI::Menu
if (_touchSpeed > 0.0f) {
if (_touchStart == Vector2f::Zero && _scrollable) {
float y = _y + (_touchSpeed * (std::int32_t)_touchDirection * TouchKineticDivider * timeMult);
if (y < (_availableHeight - _height) && _touchDirection == -1) {
if (y < (_availableHeight - _height) && _touchDirection < 0) {
y = float(_availableHeight - _height);
_touchDirection = 1;
_touchSpeed *= TouchKineticDamping;
} else if (y > 0.0f && _touchDirection == 1) {
} else if (y > 0.0f && _touchDirection > 0) {
y = 0.0f;
_touchDirection = -1;
_touchSpeed *= TouchKineticDamping;
Expand Down Expand Up @@ -268,9 +268,11 @@ namespace Jazz2::UI::Menu
float delta = touchMove.Y - _touchLast.Y;
if (delta != 0.0f) {
_y += std::int32_t(delta);
std::uint8_t newDirection = (delta < 0.0f ? -1 : 1);
if (_touchDirection != newDirection) {
_touchDirection = newDirection;
if (delta < -0.1f && _touchDirection >= 0) {
_touchDirection = -1;
_touchSpeed = 0.0f;
} else if (delta > 0.1f && _touchDirection <= 0) {
_touchDirection = 1;
_touchSpeed = 0.0f;
}
_touchSpeed = (0.8f * _touchSpeed) + (0.2f * std::abs(delta) / TouchKineticDivider);
Expand Down
12 changes: 7 additions & 5 deletions Sources/Jazz2/UI/Menu/ServerSelectSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ namespace Jazz2::UI::Menu
if (_touchSpeed > 0.0f) {
if (_touchStart == Vector2f::Zero && _availableHeight < _height) {
float y = _y + (_touchSpeed * (std::int32_t)_touchDirection * TouchKineticDivider * timeMult);
if (y < (_availableHeight - _height) && _touchDirection == -1) {
if (y < (_availableHeight - _height) && _touchDirection < 0) {
y = (_availableHeight - _height);
_touchDirection = 1;
_touchSpeed *= TouchKineticDamping;
} else if (y > 0.0f && _touchDirection == 1) {
} else if (y > 0.0f && _touchDirection > 0) {
y = 0.0f;
_touchDirection = -1;
_touchSpeed *= TouchKineticDamping;
Expand Down Expand Up @@ -216,9 +216,11 @@ namespace Jazz2::UI::Menu
float delta = touchMove.Y - _touchLast.Y;
if (delta != 0.0f) {
_y += delta;
std::uint8_t newDirection = (delta < 0.0f ? -1 : 1);
if (_touchDirection != newDirection) {
_touchDirection = newDirection;
if (delta < -0.1f && _touchDirection >= 0) {
_touchDirection = -1;
_touchSpeed = 0.0f;
} else if (delta > 0.1f && _touchDirection <= 0) {
_touchDirection = 1;
_touchSpeed = 0.0f;
}
_touchSpeed = (0.8f * _touchSpeed) + (0.2f * std::abs(delta) / TouchKineticDivider);
Expand Down

0 comments on commit 7e05f9b

Please sign in to comment.