diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_symbol.cpp | 6 |
6 files changed, 54 insertions, 15 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 0747606fc6..a4f9422184 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -34,7 +34,7 @@ enum class RenderState { class Map::Impl : public Style::Observer { public: - Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode); + Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode); void onResourceLoaded() override; void onResourceError(std::exception_ptr) override; @@ -76,16 +76,16 @@ public: bool loading = false; }; -Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode) - : impl(std::make_unique<Impl>(view, fileSource, mapMode, contextMode, constrainMode)) { +Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode, ViewportMode viewportMode) + : impl(std::make_unique<Impl>(view, fileSource, mapMode, contextMode, constrainMode, viewportMode)) { view.initialize(this); update(Update::Dimensions); } -Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, ConstrainMode constrainMode_) +Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, ConstrainMode constrainMode_, ViewportMode viewportMode_) : view(view_), fileSource(fileSource_), - transform(view, constrainMode_), + transform(view, constrainMode_, viewportMode_), mode(mode_), contextMode(contextMode_), pixelRatio(view.getPixelRatio()), @@ -638,6 +638,17 @@ ConstrainMode Map::getConstrainMode() const { return impl->transform.getConstrainMode(); } +#pragma mark - Viewport mode + +void Map::setViewportMode(mbgl::ViewportMode mode) { + impl->transform.setViewportMode(mode); + update(Update::Repaint); +} + +ViewportMode Map::getViewportMode() const { + return impl->transform.getViewportMode(); +} + #pragma mark - Projection double Map::getMetersPerPixelAtLatitude(double lat, double zoom) const { diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 69a644c7d9..958f9d9b63 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -36,9 +36,9 @@ static double _normalizeAngle(double angle, double anchorAngle) return angle; } -Transform::Transform(View &view_, ConstrainMode constrainMode) +Transform::Transform(View &view_, ConstrainMode constrainMode, ViewportMode viewportMode) : view(view_) - , state(constrainMode) + , state(constrainMode, viewportMode) { } @@ -555,6 +555,16 @@ ConstrainMode Transform::getConstrainMode() const { return state.getConstrainMode(); } +#pragma mark - Viewport mode + +void Transform::setViewportMode(mbgl::ViewportMode mode) { + state.viewportMode = mode; +} + +ViewportMode Transform::getViewportMode() const { + return state.getViewportMode(); +} + #pragma mark - Transition void Transform::startTransition(const CameraOptions& camera, diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 7d3bdceb99..cd2d7a33f3 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -20,7 +20,7 @@ class View; class Transform : private util::noncopyable { public: - Transform(View&, ConstrainMode); + Transform(View&, ConstrainMode, ViewportMode); // Map view bool resize(std::array<uint16_t, 2> size); @@ -132,11 +132,15 @@ public: // North Orientation void setNorthOrientation(NorthOrientation); NorthOrientation getNorthOrientation() const; - + // Constrain mode void setConstrainMode(ConstrainMode); ConstrainMode getConstrainMode() const; + // Viewport mode + void setViewportMode(ViewportMode); + ViewportMode getViewportMode() const; + // Transitions bool inTransition() const; Update updateTransitions(const TimePoint& now); diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index 2813d6334e..0b8d831e54 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -7,8 +7,9 @@ namespace mbgl { -TransformState::TransformState(ConstrainMode constrainMode_) +TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewportMode_) : constrainMode(constrainMode_) + , viewportMode(viewportMode_) { } @@ -39,7 +40,8 @@ void TransformState::getProjMatrix(mat4& projMatrix) const { // After the rotateX, z values are in pixel units. Convert them to // altitude unites. 1 altitude unit = the screen height. - matrix::scale(projMatrix, projMatrix, 1, -1, 1.0f / (rotatedNorth() ? getWidth() : getHeight())); + const bool flippedY = viewportMode == ViewportMode::FlippedY; + matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1.0f / (rotatedNorth() ? getWidth() : getHeight())); using NO = NorthOrientation; switch (getNorthOrientation()) { @@ -89,6 +91,12 @@ ConstrainMode TransformState::getConstrainMode() const { return constrainMode; } +#pragma mark - ViewportMode + +ViewportMode TransformState::getViewportMode() const { + return viewportMode; +} + #pragma mark - Position LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const { diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index b9acad66f1..970dda2613 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -18,7 +18,7 @@ class TransformState { friend class Transform; public: - TransformState(ConstrainMode = ConstrainMode::HeightOnly); + TransformState(ConstrainMode = ConstrainMode::HeightOnly, ViewportMode = ViewportMode::Default); // Matrix void matrixFor(mat4&, const UnwrappedTileID&) const; @@ -31,10 +31,13 @@ public: // North Orientation NorthOrientation getNorthOrientation() const; double getNorthOrientationAngle() const; - + // Constrain mode ConstrainMode getConstrainMode() const; + // Viewport mode + ViewportMode getViewportMode() const; + // Position LatLng getLatLng(LatLng::WrapMode = LatLng::Unwrapped) const; double pixel_x() const; @@ -99,6 +102,7 @@ private: private: ConstrainMode constrainMode; + ViewportMode viewportMode; // animation state bool rotating = false; diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index a48c70866c..42355493a5 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -51,7 +51,8 @@ void Painter::renderSDF(SymbolBucket &bucket, gammaScale = 1.0f; matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle()); } - matrix::scale(exMatrix, exMatrix, s, s, 1); + const bool flippedY = !skewed && state.getViewportMode() == ViewportMode::FlippedY; + matrix::scale(exMatrix, exMatrix, s, flippedY ? -s : s, 1); // If layerStyle.size > bucket.info.fontSize then labels may collide float fontSize = paintSize; @@ -217,7 +218,8 @@ void Painter::renderSymbol(SymbolBucket& bucket, matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle()); s = state.getAltitude(); } - matrix::scale(exMatrix, exMatrix, s, s, 1); + const bool flippedY = !skewed && state.getViewportMode() == ViewportMode::FlippedY; + matrix::scale(exMatrix, exMatrix, s, flippedY ? -s : s, 1); matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f); |