mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Allow zooming with mouse wheel
This commit is contained in:
parent
3e9da333cf
commit
9e3bc87a6b
@ -800,7 +800,7 @@ void AdventureMapInterface::hotkeySwitchMapLevel()
|
||||
|
||||
void AdventureMapInterface::hotkeyZoom(int delta)
|
||||
{
|
||||
widget->getMapView()->onMapZoomLevelChanged( 1.0 + delta / 10.0);
|
||||
widget->getMapView()->onMapZoomLevelChanged(delta);
|
||||
}
|
||||
|
||||
void AdventureMapInterface::onScreenResize()
|
||||
|
@ -154,9 +154,9 @@ void MapView::onViewWorldActivated(uint32_t tileSize)
|
||||
controller->setTileSize(Point(tileSize, tileSize));
|
||||
}
|
||||
|
||||
void MapView::onMapZoomLevelChanged(double zoomFactor)
|
||||
void MapView::onMapZoomLevelChanged(int stepsChange)
|
||||
{
|
||||
controller->modifyTileSize(zoomFactor);
|
||||
controller->modifyTileSize(stepsChange);
|
||||
}
|
||||
|
||||
void MapView::onViewMapActivated()
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
void onViewWorldActivated(uint32_t tileSize);
|
||||
|
||||
/// Changes zoom level / tile size of current view by specified factor
|
||||
void onMapZoomLevelChanged(double zoomFactor);
|
||||
void onMapZoomLevelChanged(int stepsChange);
|
||||
|
||||
/// Switches view from View World mode back to standard view
|
||||
void onViewMapActivated();
|
||||
|
@ -29,7 +29,7 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
|
||||
pos.w = model->getPixelsVisibleDimensions().x;
|
||||
pos.h = model->getPixelsVisibleDimensions().y;
|
||||
|
||||
addUsedEvents(LCLICK | RCLICK | MCLICK | HOVER | MOVE);
|
||||
addUsedEvents(LCLICK | RCLICK | MCLICK | HOVER | MOVE | WHEEL);
|
||||
}
|
||||
|
||||
bool MapViewActions::swipeEnabled() const
|
||||
@ -92,6 +92,13 @@ void MapViewActions::mouseMoved(const Point & cursorPosition)
|
||||
handleSwipeMove(cursorPosition);
|
||||
}
|
||||
|
||||
void MapViewActions::wheelScrolled(bool down, bool in)
|
||||
{
|
||||
if (!in)
|
||||
return;
|
||||
adventureInt->hotkeyZoom(down ? -1 : +1);
|
||||
}
|
||||
|
||||
void MapViewActions::handleSwipeMove(const Point & cursorPosition)
|
||||
{
|
||||
// unless swipe is enabled, swipe move only works with middle mouse button
|
||||
|
@ -42,4 +42,5 @@ public:
|
||||
void clickMiddle(tribool down, bool previousState) override;
|
||||
void hover(bool on) override;
|
||||
void mouseMoved(const Point & cursorPosition) override;
|
||||
void wheelScrolled(bool down, bool in) override;
|
||||
};
|
||||
|
@ -75,15 +75,23 @@ void MapViewController::setTileSize(const Point & tileSize)
|
||||
setViewCenter(model->getMapViewCenter(), model->getLevel());
|
||||
}
|
||||
|
||||
void MapViewController::modifyTileSize(double zoomFactor)
|
||||
void MapViewController::modifyTileSize(int stepsChange)
|
||||
{
|
||||
Point currentZoom = model->getSingleTileSize();
|
||||
Point desiredZoom = currentZoom * zoomFactor;
|
||||
// we want to zoom in/out in fixed 10% steps, to allow player to return back to exactly 100% zoom just by scrolling
|
||||
// so, zooming in for 5 steps will put game at 1.1^5 = 1.61 scale
|
||||
// try to determine current zooming level and change it by requested number of steps
|
||||
double currentZoomFactor = model->getSingleTileSize().x / 32.0;
|
||||
double currentZoomSteps = std::round(std::log(currentZoomFactor) / std::log(1.1));
|
||||
double newZoomSteps = currentZoomSteps + stepsChange;
|
||||
double newZoomFactor = std::pow(1.1, newZoomSteps);
|
||||
|
||||
if (desiredZoom == currentZoom && zoomFactor < 1.0)
|
||||
Point currentZoom = model->getSingleTileSize();
|
||||
Point desiredZoom = Point(32,32) * newZoomFactor;
|
||||
|
||||
if (desiredZoom == currentZoom && stepsChange < 0)
|
||||
desiredZoom -= Point(1,1);
|
||||
|
||||
if (desiredZoom == currentZoom && zoomFactor > 1.0)
|
||||
if (desiredZoom == currentZoom && stepsChange > 0)
|
||||
desiredZoom += Point(1,1);
|
||||
|
||||
Point minimal = model->getSingleTileSizeLowerLimit();
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
void setViewCenter(const int3 & position);
|
||||
void setViewCenter(const Point & position, int level);
|
||||
void setTileSize(const Point & tileSize);
|
||||
void modifyTileSize(double zoomFactor);
|
||||
void modifyTileSize(int stepsChange);
|
||||
void tick(uint32_t timePassed);
|
||||
void afterRender();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user