diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-12-09 15:09:42 +0100 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-01-15 15:02:11 +0200 |
commit | 62b0f4cde289e5918c41d5b69b0a03baa6821862 (patch) | |
tree | 2042319da9abd756564dcbba7812d4868a177800 /include/mbgl | |
parent | 4b171cccf1c4012f8962b022f86c4ac8d73f09df (diff) | |
download | qtlocation-mapboxgl-62b0f4cde289e5918c41d5b69b0a03baa6821862.tar.gz |
[core] Add stretches and content to style::Image
Diffstat (limited to 'include/mbgl')
-rw-r--r-- | include/mbgl/style/image.hpp | 46 | ||||
-rw-r--r-- | include/mbgl/util/exception.hpp | 6 |
2 files changed, 48 insertions, 4 deletions
diff --git a/include/mbgl/style/image.hpp b/include/mbgl/style/image.hpp index ff3bfedf46..bbea081c71 100644 --- a/include/mbgl/style/image.hpp +++ b/include/mbgl/style/image.hpp @@ -2,15 +2,52 @@ #include <mbgl/util/image.hpp> #include <mbgl/util/immutable.hpp> +#include <mbgl/util/optional.hpp> #include <string> +#include <utility> +#include <vector> namespace mbgl { namespace style { +using ImageStretch = std::pair<float, float>; +using ImageStretches = std::vector<ImageStretch>; + +class ImageContent { +public: + float left; + float top; + float right; + float bottom; + + bool operator==(const ImageContent& rhs) const { + return left == rhs.left && top == rhs.top && right == rhs.right && bottom == rhs.bottom; + } +}; + class Image { public: - Image(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false); + Image(std::string id, + PremultipliedImage&&, + float pixelRatio, + bool sdf, + ImageStretches stretchX = {}, + ImageStretches stretchY = {}, + optional<ImageContent> content = nullopt); + Image(std::string id, + PremultipliedImage&& image, + float pixelRatio, + ImageStretches stretchX = {}, + ImageStretches stretchY = {}, + optional<ImageContent> content = nullopt) + : Image(std::move(id), + std::move(image), + pixelRatio, + false, + std::move(stretchX), + std::move(stretchY), + std::move(content)) {} Image(const Image&); std::string getID() const; @@ -23,6 +60,13 @@ public: // Whether this image should be interpreted as a signed distance field icon. bool isSdf() const; + // Stretch areas of this image. + const ImageStretches& getStretchX() const; + const ImageStretches& getStretchY() const; + + // The space where text can be fit into this image. + const ImageContent& getContent() const; + class Impl; Immutable<Impl> baseImpl; }; diff --git a/include/mbgl/util/exception.hpp b/include/mbgl/util/exception.hpp index a9804e96c5..f0d7c64f42 100644 --- a/include/mbgl/util/exception.hpp +++ b/include/mbgl/util/exception.hpp @@ -10,9 +10,9 @@ struct Exception : std::runtime_error { Exception(const std::string &msg) : std::runtime_error(msg) {} }; -struct SpriteImageException : Exception { - SpriteImageException(const char *msg) : Exception(msg) {} - SpriteImageException(const std::string &msg) : Exception(msg) {} +struct StyleImageException : Exception { + StyleImageException(const char *msg) : Exception(msg) {} + StyleImageException(const std::string &msg) : Exception(msg) {} }; struct MisuseException : Exception { |