summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-05-11 13:45:27 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-05-18 12:07:21 +0200
commit002393bdead2f036982ea3adb8a13a3d58f3428a (patch)
tree73da2311cb98ec7f0acf6f6bf2b1f9858846000c /src
parent1d84a8964e39bd6a35de1dc64c03496bcdcf2c4f (diff)
downloadqtlocation-mapboxgl-002393bdead2f036982ea3adb8a13a3d58f3428a.tar.gz
[core] remove MockView and View dependency in Transform
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/change.hpp27
-rw-r--r--src/mbgl/map/map.cpp11
-rw-r--r--src/mbgl/map/transform.cpp30
-rw-r--r--src/mbgl/map/transform.hpp9
4 files changed, 61 insertions, 16 deletions
diff --git a/src/mbgl/map/change.hpp b/src/mbgl/map/change.hpp
new file mode 100644
index 0000000000..01adc497d3
--- /dev/null
+++ b/src/mbgl/map/change.hpp
@@ -0,0 +1,27 @@
+#ifndef MBGL_MAP_CHANGE
+#define MBGL_MAP_CHANGE
+
+#include <cstdint>
+
+namespace mbgl {
+
+enum MapChange : uint8_t {
+ MapChangeRegionWillChange = 0,
+ MapChangeRegionWillChangeAnimated = 1,
+ MapChangeRegionIsChanging = 2,
+ MapChangeRegionDidChange = 3,
+ MapChangeRegionDidChangeAnimated = 4,
+ MapChangeWillStartLoadingMap = 5,
+ MapChangeDidFinishLoadingMap = 6,
+ MapChangeDidFailLoadingMap = 7,
+ MapChangeWillStartRenderingFrame = 8,
+ MapChangeDidFinishRenderingFrame = 9,
+ MapChangeDidFinishRenderingFrameFullyRendered = 10,
+ MapChangeWillStartRenderingMap = 11,
+ MapChangeDidFinishRenderingMap = 12,
+ MapChangeDidFinishRenderingMapFullyRendered = 13,
+};
+
+} // namespace mbgl
+
+#endif
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 5773b3f658..0a6adfc565 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -83,10 +83,17 @@ Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode cont
update(Update::Dimensions);
}
-Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, ConstrainMode constrainMode_, ViewportMode viewportMode_)
+Map::Impl::Impl(View& view_,
+ FileSource& fileSource_,
+ MapMode mode_,
+ GLContextMode contextMode_,
+ ConstrainMode constrainMode_,
+ ViewportMode viewportMode_)
: view(view_),
fileSource(fileSource_),
- transform(view, constrainMode_, viewportMode_),
+ transform([this](MapChange change) { view.notifyMapChange(change); },
+ constrainMode_,
+ viewportMode_),
mode(mode_),
contextMode(contextMode_),
pixelRatio(view.getPixelRatio()),
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 4a40e13202..d2f32acb67 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -36,10 +36,10 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
-Transform::Transform(View &view_, ConstrainMode constrainMode, ViewportMode viewportMode)
- : view(view_)
- , state(constrainMode, viewportMode)
-{
+Transform::Transform(std::function<void(MapChange)> callback_,
+ ConstrainMode constrainMode,
+ ViewportMode viewportMode)
+ : callback(std::move(callback_)), state(constrainMode, viewportMode) {
}
#pragma mark - Map View
@@ -47,13 +47,17 @@ Transform::Transform(View &view_, ConstrainMode constrainMode, ViewportMode view
bool Transform::resize(const std::array<uint16_t, 2> size) {
if (state.width != size[0] || state.height != size[1]) {
- view.notifyMapChange(MapChangeRegionWillChange);
+ if (callback) {
+ callback(MapChangeRegionWillChange);
+ }
state.width = size[0];
state.height = size[1];
state.constrain(state.scale, state.x, state.y);
- view.notifyMapChange(MapChangeRegionDidChange);
+ if (callback) {
+ callback(MapChangeRegionDidChange);
+ }
return true;
} else {
@@ -560,8 +564,10 @@ void Transform::startTransition(const CameraOptions& camera,
}
bool isAnimated = duration != Duration::zero();
- view.notifyMapChange(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange);
-
+ if (callback) {
+ callback(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange);
+ }
+
// Associate the anchor, if given, with a coordinate.
optional<ScreenCoordinate> anchor = camera.anchor;
LatLng anchorLatLng;
@@ -590,7 +596,9 @@ void Transform::startTransition(const CameraOptions& camera,
if (animation.transitionFrameFn) {
animation.transitionFrameFn(t);
}
- view.notifyMapChange(MapChangeRegionIsChanging);
+ if (callback) {
+ callback(MapChangeRegionIsChanging);
+ }
} else {
transitionFinishFn();
transitionFinishFn = nullptr;
@@ -609,7 +617,9 @@ void Transform::startTransition(const CameraOptions& camera,
if (animation.transitionFinishFn) {
animation.transitionFinishFn();
}
- view.notifyMapChange(isAnimated ? MapChangeRegionDidChangeAnimated : MapChangeRegionDidChange);
+ if (callback) {
+ callback(isAnimated ? MapChangeRegionDidChangeAnimated : MapChangeRegionDidChange);
+ }
};
if (!isAnimated) {
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index cd2d7a33f3..8752af9b41 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -3,6 +3,7 @@
#include <mbgl/map/camera.hpp>
#include <mbgl/map/mode.hpp>
+#include <mbgl/map/change.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/util/chrono.hpp>
@@ -16,11 +17,11 @@
namespace mbgl {
-class View;
-
class Transform : private util::noncopyable {
public:
- Transform(View&, ConstrainMode, ViewportMode);
+ Transform(std::function<void(MapChange)> = nullptr,
+ ConstrainMode = ConstrainMode::HeightOnly,
+ ViewportMode = ViewportMode::Default);
// Map view
bool resize(std::array<uint16_t, 2> size);
@@ -163,7 +164,7 @@ public:
LatLng screenCoordinateToLatLng(const ScreenCoordinate&) const;
private:
- View &view;
+ std::function<void(MapChange)> callback;
TransformState state;