[core] Added ConstrainMode::{HeightOnly,WidthAndHeight}

ConstrainMode gives flexibility to our engine to choose between
constraining both vertically and horizontally, or just vertically
(default behavior).

Constrain in both axis means we can no longer pan the map beyond the map
boundaries. This fixes an issue where e.g. annotations disappear upon
crossing the map boundaries.
This commit is contained in:
Bruno de Oliveira Abinader
2015-11-17 17:19:54 +02:00
parent cb9b397985
commit adfac6f061
9 changed files with 93 additions and 33 deletions

View File

@@ -34,8 +34,9 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
Transform::Transform(View &view_)
Transform::Transform(View &view_, ConstrainMode constrainMode)
: view(view_)
, state(constrainMode)
{
}
@@ -48,7 +49,7 @@ bool Transform::resize(const std::array<uint16_t, 2> size) {
state.width = size[0];
state.height = size[1];
state.constrain(state.scale, state.y);
state.constrain(state.scale, state.x, state.y);
view.notifyMapChange(MapChangeRegionDidChange);
@@ -105,7 +106,7 @@ void Transform::_moveBy(const PrecisionPoint& point, const Duration& duration) {
double x = state.x + std::cos(state.angle) * point.x + std::sin( state.angle) * point.y;
double y = state.y + std::cos(state.angle) * point.y + std::sin(-state.angle) * point.x;
state.constrain(state.scale, y);
state.constrain(state.scale, x, y);
CameraOptions options;
options.duration = duration;
@@ -239,7 +240,7 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
double x = xn;
double y = yn;
state.constrain(scale, y);
state.constrain(scale, x, y);
double angle = _normalizeAngle(new_angle, state.angle);
state.angle = _normalizeAngle(state.angle, angle);