Skip to content

Commit 9b57b16

Browse files
committed
Use clamp in SetZoomFactor
1 parent 242c110 commit 9b57b16

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libs/s25main/world/GameWorldView.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,9 @@ void GameWorldView::SetNextZoomFactor()
8888
CalcFxLx();
8989
}
9090

91-
void GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = true*/)
91+
float GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = true*/)
9292
{
93-
if(zoomFactor < ZOOM_FACTORS.front())
94-
targetZoomFactor_ = ZOOM_FACTORS.front();
95-
else if(zoomFactor > ZOOM_FACTORS.back())
96-
targetZoomFactor_ = ZOOM_FACTORS.back();
97-
else
98-
targetZoomFactor_ = zoomFactor;
93+
targetZoomFactor_ = std::clamp(zoomFactor, ZOOM_FACTORS.front(), ZOOM_FACTORS.back());
9994
if(targetZoomFactor_ > 1 - ZOOM_WHEEL_INCREMENT && targetZoomFactor_ < 1 + ZOOM_WHEEL_INCREMENT)
10095
targetZoomFactor_ = 1.f; // Snap to 100%
10196
if(!smoothTransition)
@@ -104,6 +99,7 @@ void GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = t
10499
updateEffectiveZoomFactor();
105100
CalcFxLx();
106101
}
102+
return targetZoomFactor_;
107103
}
108104

109105
float GameWorldView::GetCurrentTargetZoomFactor() const

libs/s25main/world/GameWorldView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ class GameWorldView
7878
Position GetPos() const { return origin_; }
7979
Extent GetSize() const { return size_; }
8080

81-
void SetZoomFactor(float zoomFactor, bool smoothTransition = true);
81+
/// Set target zoom factor and start zooming if smoothTransition is true
82+
/// Returns actual zoom factor used, potentially clamped
83+
float SetZoomFactor(float zoomFactor, bool smoothTransition = true);
8284
float GetCurrentTargetZoomFactor() const;
8385
void SetNextZoomFactor();
8486

0 commit comments

Comments
 (0)