mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
Fix zooming with keyboard shortcuts
This commit is contained in:
parent
11c00711f9
commit
16f963bed5
@ -886,9 +886,9 @@ void AdventureMapInterface::hotkeySwitchMapLevel()
|
||||
widget->getMapView()->onMapLevelSwitched();
|
||||
}
|
||||
|
||||
void AdventureMapInterface::hotkeyZoom(int delta)
|
||||
void AdventureMapInterface::hotkeyZoom(int delta, bool useDeadZone)
|
||||
{
|
||||
widget->getMapView()->onMapZoomLevelChanged(delta);
|
||||
widget->getMapView()->onMapZoomLevelChanged(delta, useDeadZone);
|
||||
}
|
||||
|
||||
void AdventureMapInterface::onScreenResize()
|
||||
|
@ -120,7 +120,7 @@ public:
|
||||
void hotkeyEndingTurn();
|
||||
void hotkeyNextTown();
|
||||
void hotkeySwitchMapLevel();
|
||||
void hotkeyZoom(int delta);
|
||||
void hotkeyZoom(int delta, bool useDeadZone);
|
||||
|
||||
/// Called by PlayerInterface when specified player is ready to start his turn
|
||||
void onHotseatWaitStarted(PlayerColor playerID);
|
||||
|
@ -94,8 +94,8 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
|
||||
{ EShortcut::ADVENTURE_VISIT_OBJECT, optionCanVisitObject(), [this]() { this->visitObject(); } },
|
||||
{ EShortcut::ADVENTURE_VIEW_SELECTED, optionInMapView(), [this]() { this->openObject(); } },
|
||||
{ EShortcut::ADVENTURE_MARKETPLACE, optionInMapView(), [this]() { this->showMarketplace(); } },
|
||||
{ EShortcut::ADVENTURE_ZOOM_IN, optionSidePanelActive(),[this]() { this->zoom(+1); } },
|
||||
{ EShortcut::ADVENTURE_ZOOM_OUT, optionSidePanelActive(),[this]() { this->zoom(-1); } },
|
||||
{ EShortcut::ADVENTURE_ZOOM_IN, optionSidePanelActive(),[this]() { this->zoom(+10); } },
|
||||
{ EShortcut::ADVENTURE_ZOOM_OUT, optionSidePanelActive(),[this]() { this->zoom(-10); } },
|
||||
{ EShortcut::ADVENTURE_ZOOM_RESET, optionSidePanelActive(),[this]() { this->zoom( 0); } },
|
||||
{ EShortcut::ADVENTURE_FIRST_TOWN, optionInMapView(), [this]() { this->firstTown(); } },
|
||||
{ EShortcut::ADVENTURE_NEXT_TOWN, optionInMapView(), [this]() { this->nextTown(); } },
|
||||
@ -442,7 +442,7 @@ void AdventureMapShortcuts::nextTown()
|
||||
|
||||
void AdventureMapShortcuts::zoom( int distance)
|
||||
{
|
||||
owner.hotkeyZoom(distance);
|
||||
owner.hotkeyZoom(distance, false);
|
||||
}
|
||||
|
||||
void AdventureMapShortcuts::nextObject()
|
||||
|
@ -239,9 +239,9 @@ void MapView::onViewWorldActivated(uint32_t tileSize)
|
||||
controller->setTileSize(Point(tileSize, tileSize));
|
||||
}
|
||||
|
||||
void MapView::onMapZoomLevelChanged(int stepsChange)
|
||||
void MapView::onMapZoomLevelChanged(int stepsChange, bool useDeadZone)
|
||||
{
|
||||
controller->modifyTileSize(stepsChange);
|
||||
controller->modifyTileSize(stepsChange, useDeadZone);
|
||||
}
|
||||
|
||||
void MapView::onViewMapActivated()
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
void onViewWorldActivated(uint32_t tileSize);
|
||||
|
||||
/// Changes zoom level / tile size of current view by specified factor
|
||||
void onMapZoomLevelChanged(int stepsChange);
|
||||
void onMapZoomLevelChanged(int stepsChange, bool useDeadZone);
|
||||
|
||||
/// Switches view from View World mode back to standard view
|
||||
void onViewMapActivated();
|
||||
|
@ -87,7 +87,7 @@ void MapViewActions::mouseMoved(const Point & cursorPosition, const Point & last
|
||||
|
||||
void MapViewActions::wheelScrolled(int distance)
|
||||
{
|
||||
adventureInt->hotkeyZoom(distance * 4);
|
||||
adventureInt->hotkeyZoom(distance * 4, true);
|
||||
}
|
||||
|
||||
void MapViewActions::mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance)
|
||||
@ -114,7 +114,7 @@ void MapViewActions::gesturePinch(const Point & centerPosition, double lastUpdat
|
||||
int oldZoomSteps = std::round(std::log(pinchZoomFactor) / std::log(1.01));
|
||||
|
||||
if (newZoomSteps != oldZoomSteps)
|
||||
adventureInt->hotkeyZoom(newZoomSteps - oldZoomSteps);
|
||||
adventureInt->hotkeyZoom(newZoomSteps - oldZoomSteps, true);
|
||||
|
||||
pinchZoomFactor = newZoom;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ void MapViewController::setTileSize(const Point & tileSize)
|
||||
setViewCenter(newViewCenter, model->getLevel());
|
||||
}
|
||||
|
||||
void MapViewController::modifyTileSize(int stepsChange)
|
||||
void MapViewController::modifyTileSize(int stepsChange, bool useDeadZone)
|
||||
{
|
||||
// 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
|
||||
@ -117,10 +117,13 @@ void MapViewController::modifyTileSize(int stepsChange)
|
||||
if (actualZoom != currentZoom)
|
||||
{
|
||||
targetTileSize = actualZoom;
|
||||
if(actualZoom.x >= defaultTileSize - zoomTileDeadArea && actualZoom.x <= defaultTileSize + zoomTileDeadArea)
|
||||
actualZoom.x = defaultTileSize;
|
||||
if(actualZoom.y >= defaultTileSize - zoomTileDeadArea && actualZoom.y <= defaultTileSize + zoomTileDeadArea)
|
||||
actualZoom.y = defaultTileSize;
|
||||
if (useDeadZone)
|
||||
{
|
||||
if(actualZoom.x >= defaultTileSize - zoomTileDeadArea && actualZoom.x <= defaultTileSize + zoomTileDeadArea)
|
||||
actualZoom.x = defaultTileSize;
|
||||
if(actualZoom.y >= defaultTileSize - zoomTileDeadArea && actualZoom.y <= defaultTileSize + zoomTileDeadArea)
|
||||
actualZoom.y = defaultTileSize;
|
||||
}
|
||||
|
||||
bool isInDeadZone = targetTileSize != actualZoom || actualZoom == Point(defaultTileSize, defaultTileSize);
|
||||
|
||||
|
@ -52,7 +52,7 @@ class MapViewController : public IMapObjectObserver
|
||||
|
||||
private:
|
||||
const int defaultTileSize = 32;
|
||||
const int zoomTileDeadArea = 5;
|
||||
const int zoomTileDeadArea = 4;
|
||||
Point targetTileSize = Point(32, 32);
|
||||
bool wasInDeadZone = true;
|
||||
|
||||
@ -91,7 +91,7 @@ public:
|
||||
void setViewCenter(const int3 & position);
|
||||
void setViewCenter(const Point & position, int level);
|
||||
void setTileSize(const Point & tileSize);
|
||||
void modifyTileSize(int stepsChange);
|
||||
void modifyTileSize(int stepsChange, bool useDeadZone);
|
||||
void tick(uint32_t timePassed);
|
||||
void afterRender();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user