summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-07-23 14:09:24 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-07-23 14:10:33 +0300
commit0e602385967612a2d231d3006765cfcbce65fd71 (patch)
tree99eabe18030fbcc877fb39e94013f4d7d0235410
parent45d65c4b491615e0ff0c1ec0a89324159bc1dc97 (diff)
downloadqtlocation-mapboxgl-0e602385967612a2d231d3006765cfcbce65fd71.tar.gz
[glfw] Added 'addRandomLineAnnotations'
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp2
-rw-r--r--platform/default/glfw_view.cpp31
2 files changed, 28 insertions, 5 deletions
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 83d00a24dd..38ab922414 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -44,6 +44,7 @@ public:
void report(float duration);
private:
+ mbgl::Color makeRandomColor() const;
mbgl::Point<double> makeRandomPoint() const;
static std::shared_ptr<const mbgl::SpriteImage>
makeSpriteImage(int width, int height, float pixelRatio);
@@ -51,6 +52,7 @@ private:
void nextOrientation();
void addRandomPointAnnotations(int count);
+ void addRandomLineAnnotations(int count);
void addRandomShapeAnnotations(int count);
void addRandomCustomPointAnnotations(int count);
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 7bf40496f6..863f42ec76 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -103,6 +103,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
printf("\n");
printf("- Press `Q` to remove annotations\n");
printf("- Press `P` to add a random custom runtime imagery annotation\n");
+ printf("- Press `L` to add a random line annotation\n");
printf("- Press `W` to pop the last-added annotation off\n");
printf("\n");
printf("- `Control` + mouse drag to rotate\n");
@@ -164,9 +165,12 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
case GLFW_KEY_Q:
view->clearAnnotations();
break;
- case GLFW_KEY_P: {
+ case GLFW_KEY_P:
view->addRandomCustomPointAnnotations(1);
- } break;
+ break;
+ case GLFW_KEY_L:
+ view->addRandomLineAnnotations(1);
+ break;
case GLFW_KEY_A: {
// XXX Fix precision loss in flyTo:
// https://github.com/mapbox/mapbox-gl-native/issues/4298
@@ -207,6 +211,13 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
}
}
+mbgl::Color GLFWView::makeRandomColor() const {
+ const float r = 1.0f * (float(std::rand()) / RAND_MAX);
+ const float g = 1.0f * (float(std::rand()) / RAND_MAX);
+ const float b = 1.0f * (float(std::rand()) / RAND_MAX);
+ return { r, g, b, 1.0f };
+}
+
mbgl::Point<double> GLFWView::makeRandomPoint() const {
const double x = width * double(std::rand()) / RAND_MAX;
const double y = height * double(std::rand()) / RAND_MAX;
@@ -264,16 +275,26 @@ void GLFWView::addRandomCustomPointAnnotations(int count) {
}
void GLFWView::addRandomPointAnnotations(int count) {
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < count; ++i) {
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), "default_marker" }));
}
}
+void GLFWView::addRandomLineAnnotations(int count) {
+ for (int i = 0; i < count; ++i) {
+ mbgl::LineString<double> lineString;
+ for (int j = 0; j < 3; ++j) {
+ lineString.push_back(makeRandomPoint());
+ }
+ annotationIDs.push_back(map->addAnnotation(mbgl::LineAnnotation { lineString, 1.0f, 2.0f, { makeRandomColor() } }));
+ }
+}
+
void GLFWView::addRandomShapeAnnotations(int count) {
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < count; ++i) {
mbgl::Polygon<double> triangle;
triangle.push_back({ makeRandomPoint(), makeRandomPoint(), makeRandomPoint() });
- annotationIDs.push_back(map->addAnnotation(mbgl::FillAnnotation { triangle, .1 }));
+ annotationIDs.push_back(map->addAnnotation(mbgl::FillAnnotation { triangle, 0.5f, { makeRandomColor() }, { makeRandomColor() } }));
}
}