From 143f8a78170065fc46afba1eaf987258e9c9f99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 15 Jan 2016 08:23:10 -0800 Subject: [core] Added padding option to CameraOptions Moved EdgeInsets to geo.hpp so CameraOptions and Transform can refer to it. Added a padding option to CameraOptions that alters the frame of reference for the center option. Added optional padding parameters to LatLng getters and setters. Working towards #2600. --- include/mbgl/map/camera.hpp | 4 ++++ include/mbgl/map/map.hpp | 10 ++-------- include/mbgl/util/geo.hpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index 80734b76fd..32ad8f019f 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -17,6 +17,10 @@ struct CameraOptions { /** Coordinate at the center of the map. */ mapbox::util::optional center; + /** Padding around the interior of the view that affects the frame of + reference for `center`. */ + mapbox::util::optional padding; + /** Point of reference for `zoom` and `angle`, assuming an origin at the top-left corner of the view. */ mapbox::util::optional anchor; diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 3e52d57d19..3852bb7b6f 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -34,13 +34,6 @@ namespace util { template class Thread; } // namespace util -struct EdgeInsets { - double top = 0; - double left = 0; - double bottom = 0; - double right = 0; -}; - class Map : private util::noncopyable { friend class View; @@ -106,8 +99,9 @@ public: // Position void moveBy(const PrecisionPoint&, const Duration& = Duration::zero()); void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero()); + void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero()); void setLatLng(const LatLng&, const Duration& = Duration::zero()); - LatLng getLatLng() const; + LatLng getLatLng(const EdgeInsets& = {}) const; void resetPosition(); // Scale diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index e815456f22..db7d9c792e 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -108,6 +108,40 @@ enum class NorthOrientation : uint8_t { Leftwards, }; +/// The distance on each side between a rectangle and a rectangle within. +struct EdgeInsets { + double top = 0; ///< Number of pixels inset from the top edge. + double left = 0; ///< Number of pixels inset from the left edge. + double bottom = 0; ///< Number of pixels inset from the bottom edge. + double right = 0; ///< Number of pixels inset from the right edge. + + inline EdgeInsets() {} + + inline EdgeInsets(const double t, const double l, const double b, const double r) + : top(t), left(l), bottom(b), right(r) {} + + inline operator bool() const { + return top || left || bottom || right; + } + + inline void operator+=(const EdgeInsets& o) { + top += o.top; + left += o.left; + bottom += o.bottom; + right += o.right; + } + + inline EdgeInsets operator+(const EdgeInsets& o) const { + return { + top + o.top, left + o.left, bottom + o.bottom, right + o.right, + }; + } + + PrecisionPoint getCenter(uint16_t width, uint16_t height) const; + + void flip(); +}; + } // namespace mbgl #endif -- cgit v1.2.1