[shared] Add forceChangeY parameter to normalize()

Change-Id: Iff5417cd765f3fd09825b81cb41f883530b39233
This commit is contained in:
Gabriel Ozouf
2020-11-13 11:49:12 +01:00
committed by LeaNumworks
parent bd302bb67b
commit 6e9195fafa
4 changed files with 10 additions and 6 deletions

View File

@@ -15,8 +15,8 @@ CurveViewRange::CurveViewRange(InteractiveCurveViewRangeDelegate * delegate) :
MemoizedCurveViewRange::protectedSetXMin(-k_displayLeftMarginRatio * xMax(), k_lowerMaxFloat, k_upperMaxFloat);
}
void CurveViewRange::normalize() {
Shared::InteractiveCurveViewRange::normalize();
void CurveViewRange::normalize(bool forceChangeY) {
Shared::InteractiveCurveViewRange::normalize(forceChangeY);
/* The X axis is not supposed to go into the negatives, save for a small
* margin. However, after normalizing, it could be the case. We thus shift

View File

@@ -8,7 +8,7 @@ namespace Sequence {
class CurveViewRange : public Shared::InteractiveCurveViewRange {
public:
CurveViewRange(Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr);
void normalize() override;
void normalize(bool forceChangeY = false) override;
private:
constexpr static float k_displayLeftMarginRatio = 0.1f;
};

View File

@@ -131,7 +131,7 @@ void InteractiveCurveViewRange::panWithVector(float x, float y) {
MemoizedCurveViewRange::protectedSetYMin(yMin() + y, k_lowerMaxFloat, k_upperMaxFloat);
}
void InteractiveCurveViewRange::normalize() {
void InteractiveCurveViewRange::normalize(bool forceChangeY) {
/* We center the ranges on the current range center, and put each axis so that
* 1cm = 2 current units. */
@@ -148,7 +148,11 @@ void InteractiveCurveViewRange::normalize() {
const float newYHalfRange = NormalizedYHalfRange(unit);
float normalizedYXRatio = newYHalfRange/newXHalfRange;
Zoom::SetToRatio(normalizedYXRatio, &newXMin, &newXMax, &newYMin, &newYMax);
/* Most of the time, we do not want to shrink, to avoid hiding parts of the
* function. However, when forceChangeY is true, we shrink if the Y range is
* the longer one. */
bool shrink = forceChangeY && (newYMax - newYMin) / (newXMax - newXMin) > normalizedYXRatio;
Zoom::SetToRatio(normalizedYXRatio, &newXMin, &newXMax, &newYMin, &newYMax, shrink);
m_xRange.setMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetXMax(newXMax, k_lowerMaxFloat, k_upperMaxFloat);

View File

@@ -52,7 +52,7 @@ public:
// Window
void zoom(float ratio, float x, float y);
void panWithVector(float x, float y);
virtual void normalize();
virtual void normalize(bool forceChangeY = false);
virtual void setDefault();
void centerAxisAround(Axis axis, float position);
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation, float pixelWidth);