[glfw] Added 'addRandomLineAnnotations'

This commit is contained in:
Bruno de Oliveira Abinader
2016-07-23 14:09:24 +03:00
parent 45d65c4b49
commit 0e60238596
2 changed files with 28 additions and 5 deletions

View File

@@ -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);

View File

@@ -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() } }));
}
}