Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[glfw] Added 'addRandomLineAnnotations' #5774

Merged
merged 1 commit into from
Jul 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mbgl/platform/default/glfw_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class GLFWView : public mbgl::View {
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);

void nextOrientation();

void addRandomPointAnnotations(int count);
void addRandomLineAnnotations(int count);
void addRandomShapeAnnotations(int count);
void addRandomCustomPointAnnotations(int count);

Expand Down
31 changes: 26 additions & 5 deletions platform/default/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be called addRandomCustomLineAnnotations for consistency with Point?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or the other way around

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that is meant to be custom point because we're using a random, custom sprite image for the point symbols, whereas in this line annotation we use regular, non-custom line annotations.

break;
case GLFW_KEY_A: {
// XXX Fix precision loss in flyTo:
// https://github.com/mapbox/mapbox-gl-native/issues/4298
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() } }));
}
}

Expand Down