|
|
@@ -25,6 +25,7 @@
|
|
|
#include "../render/Canvas.h"
|
|
|
#include "../render/IImage.h"
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
|
|
+#include "../eventsSDL/InputHandler.h"
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
|
@@ -82,6 +83,14 @@ void BasicMapView::showAll(Canvas & to)
|
|
|
render(to, true);
|
|
|
}
|
|
|
|
|
|
+void MapView::tick(uint32_t msPassed)
|
|
|
+{
|
|
|
+ if(settings["adventure"]["smoothDragging"].Bool())
|
|
|
+ postSwipe(msPassed);
|
|
|
+
|
|
|
+ BasicMapView::tick(msPassed);
|
|
|
+}
|
|
|
+
|
|
|
void MapView::show(Canvas & to)
|
|
|
{
|
|
|
actions->setContext(controller->getContext());
|
|
|
@@ -94,6 +103,9 @@ MapView::MapView(const Point & offset, const Point & dimensions)
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
actions = std::make_shared<MapViewActions>(*this, model);
|
|
|
actions->setContext(controller->getContext());
|
|
|
+
|
|
|
+ // catch min 6 frames
|
|
|
+ postSwipeCatchIntervalMs = std::max(100, static_cast<int>(6.0 * 1000.0 * (1.0 / settings["video"]["targetfps"].Float())));
|
|
|
}
|
|
|
|
|
|
void MapView::onMapLevelSwitched()
|
|
|
@@ -115,9 +127,50 @@ void MapView::onMapScrolled(const Point & distance)
|
|
|
|
|
|
void MapView::onMapSwiped(const Point & viewPosition)
|
|
|
{
|
|
|
+ if(settings["adventure"]["smoothDragging"].Bool())
|
|
|
+ swipeHistory.push_back(std::pair<uint32_t, Point>(GH.input().getTicks(), viewPosition));
|
|
|
+
|
|
|
controller->setViewCenter(model->getMapViewCenter() + viewPosition, model->getLevel());
|
|
|
}
|
|
|
|
|
|
+void MapView::postSwipe(uint32_t msPassed)
|
|
|
+{
|
|
|
+ if(!actions->dragActive)
|
|
|
+ {
|
|
|
+ if(swipeHistory.size() > 1)
|
|
|
+ {
|
|
|
+ Point diff = Point(0, 0);
|
|
|
+ std::pair<uint32_t, Point> firstAccepted;
|
|
|
+ uint32_t now = GH.input().getTicks();
|
|
|
+ for (auto & x : swipeHistory) {
|
|
|
+ if(now - x.first < postSwipeCatchIntervalMs) { // only the last x ms are catched
|
|
|
+ if(firstAccepted.first == 0)
|
|
|
+ firstAccepted = x;
|
|
|
+ diff += x.second;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ uint32_t timediff = swipeHistory.back().first - firstAccepted.first;
|
|
|
+
|
|
|
+ if(diff.length() > 0 && timediff > 0)
|
|
|
+ {
|
|
|
+ postSwipeAngle = diff.angle();
|
|
|
+ postSwipeSpeed = static_cast<double>(diff.length()) / static_cast<double>(timediff); // unit: pixel/millisecond
|
|
|
+ }
|
|
|
+ }
|
|
|
+ swipeHistory.clear();
|
|
|
+ } else
|
|
|
+ postSwipeSpeed = 0.0;
|
|
|
+ if(postSwipeSpeed > postSwipeMinimalSpeed) {
|
|
|
+ double len = postSwipeSpeed * static_cast<double>(msPassed);
|
|
|
+ Point delta = Point(len * cos(postSwipeAngle), len * sin(postSwipeAngle));
|
|
|
+
|
|
|
+ controller->setViewCenter(model->getMapViewCenter() + delta, model->getLevel());
|
|
|
+
|
|
|
+ postSwipeSpeed /= 1 + msPassed * postSwipeSlowdownSpeed;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void MapView::onCenteredTile(const int3 & tile)
|
|
|
{
|
|
|
controller->setViewCenter(tile);
|