Skip to content

Commit 1f837a1

Browse files
committed
fix drag scrolling with black borders
1 parent a175db1 commit 1f837a1

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎src/Battlescape/BattlescapeState.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,12 @@ void BattlescapeState::mapOver(Action *action)
633633
action->getDetails()->motion.xrel / action->getXScale(),
634634
action->getDetails()->motion.yrel / action->getYScale(), false);
635635
delta = _map->getCamera()->getMapOffset() - delta;
636-
_cursorPosition.x = std::min(_game->getScreen()->getWidth() - (int)(Round(action->getXScale())), std::max(0, (int)(_cursorPosition.x + Round(delta.x * action->getXScale()))));
637-
_cursorPosition.y = std::min(_game->getScreen()->getHeight() - (int)(Round(action->getYScale())), std::max(0, (int)(_cursorPosition.y + Round(delta.y * action->getYScale()))));
636+
int barWidth = _game->getScreen()->getCursorLeftBlackBand();
637+
int barHeight = _game->getScreen()->getCursorTopBlackBand();
638+
int cursorX = _cursorPosition.x + Round(delta.x * action->getXScale());
639+
int cursorY = _cursorPosition.y + Round(delta.y * action->getYScale());
640+
_cursorPosition.x = std::min(_game->getScreen()->getWidth() - barWidth - (int)(Round(action->getXScale())), std::max(barWidth, cursorX));
641+
_cursorPosition.y = std::min(_game->getScreen()->getHeight() - barHeight - (int)(Round(action->getYScale())), std::max(barHeight, cursorY));
638642
action->getDetails()->motion.x = _cursorPosition.x;
639643
action->getDetails()->motion.y = _cursorPosition.y;
640644
}
@@ -1448,7 +1452,7 @@ inline void BattlescapeState::handle(Action *action)
14481452

14491453
if (_isMouseScrolling && !Options::battleDragScrollInvert)
14501454
{
1451-
_map->setSelectorPosition(_cursorPosition.x / action->getXScale(), _cursorPosition.y / action->getYScale());
1455+
_map->setSelectorPosition((_cursorPosition.x - _game->getScreen()->getCursorLeftBlackBand()) / action->getXScale(), (_cursorPosition.y - _game->getScreen()->getCursorTopBlackBand()) / action->getYScale());
14521456
}
14531457

14541458
if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN)

‎src/Battlescape/MiniMapView.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,12 @@ void MiniMapView::mouseOver(Action *action, State *state)
353353
else
354354
{
355355
Position delta(-scrollX, -scrollY, 0);
356-
_cursorPosition.x = Round(std::min(getX() + getWidth(), std::max(getX(), (int)(Round(_cursorPosition.x / action->getXScale()) + delta.x))) * action->getXScale());
357-
//std::min(Round(getWidth() * action->getXScale() + getX() * action->getXScale()), std::max(Round(getX() * action->getXScale()), _cursorPosition.x + Round(delta.x * action->getXScale())));
358-
_cursorPosition.y = Round(std::min(getY() + getHeight(), std::max(getY(), (int)(Round(_cursorPosition.y / action->getYScale()) + delta.y))) * action->getYScale());
359-
//std::min(Round(getHeight() * action->getYScale() + getY() * action->getYScale()), std::max(Round(getY() * action->getYScale()), _cursorPosition.y + Round(delta.y * action->getYScale())));
356+
int barWidth = Round(_game->getScreen()->getCursorLeftBlackBand() / action->getXScale());
357+
int barHeight = Round(_game->getScreen()->getCursorTopBlackBand() / action->getYScale());
358+
int cursorX = Round(_cursorPosition.x / action->getXScale() + delta.x);
359+
int cursorY = Round(_cursorPosition.y / action->getYScale() + delta.y);
360+
_cursorPosition.x = Round(std::min(getX() + getWidth() + barWidth, std::max(getX() + barWidth, cursorX)) * action->getXScale());
361+
_cursorPosition.y = Round(std::min(getY() + getHeight() + barHeight, std::max(getY() + barHeight, cursorY)) * action->getYScale());
360362
action->getDetails()->motion.x = _cursorPosition.x;
361363
action->getDetails()->motion.y = _cursorPosition.y;
362364
}

0 commit comments

Comments
 (0)