#pragma once #include #include #include #include #include #include #if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) #include #endif #include struct GLFWwindow; class GLFWBackend; class GLFWRendererFrontend; class SnapshotObserver; namespace mbgl { namespace gfx { class RendererBackend; } // namespace gfx } // namespace mbgl class GLFWView : public mbgl::MapObserver { public: GLFWView(bool fullscreen, bool benchmark, const mbgl::ResourceOptions &options); ~GLFWView() override; float getPixelRatio() const; void setMap(mbgl::Map*); void setRenderFrontend(GLFWRendererFrontend*); mbgl::gfx::RendererBackend& getRendererBackend(); void setTestDirectory(std::string dir) { testDirectory = std::move(dir); }; // Callback called when the user presses the key mapped to style change. // The expected action is to set a new style, different to the current one. void setChangeStyleCallback(std::function callback); void setPauseResumeCallback(std::function callback) { pauseResumeCallback = std::move(callback); }; void setOnlineStatusCallback(std::function callback) { onlineStatusCallback = std::move(callback); } void setResetCacheCallback(std::function callback) { resetDatabaseCallback = std::move(callback); }; void setShouldClose(); void setWindowTitle(const std::string&); void run(); void invalidate(); mbgl::Size getSize() const; // mbgl::MapObserver implementation void onDidFinishLoadingStyle() override; void onWillStartRenderingFrame() override; protected: // mbgl::Backend implementation private: // Window callbacks static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods); static void onScroll(GLFWwindow *window, double xoffset, double yoffset); static void onWindowResize(GLFWwindow *window, int width, int height); static void onFramebufferResize(GLFWwindow *window, int width, int height); static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers); static void onMouseMove(GLFWwindow *window, double x, double y); static void onWindowFocus(GLFWwindow *window, int focused); // Internal void report(float duration); mbgl::Color makeRandomColor() const; mbgl::Point makeRandomPoint() const; static std::unique_ptr makeImage(const std::string& id, int width, int height, float pixelRatio); void nextOrientation(); void addRandomPointAnnotations(int count); void addRandomLineAnnotations(int count); void addRandomShapeAnnotations(int count); void addRandomCustomPointAnnotations(int count); void addAnimatedAnnotation(); void updateFreeCameraDemo(); void updateAnimatedAnnotations(); void toggleCustomSource(); void toggleLocationIndicatorLayer(); void cycleDebugOptions(); void clearAnnotations(); void popAnnotation(); void makeSnapshot(bool withOverlay = false); mbgl::AnnotationIDs annotationIDs; std::vector spriteIDs; mbgl::AnnotationIDs animatedAnnotationIDs; std::vector animatedAnnotationAddedTimes; private: void toggle3DExtrusions(bool visible); mbgl::Map* map = nullptr; GLFWRendererFrontend* rendererFrontend = nullptr; std::unique_ptr backend; std::string testDirectory = "."; double freeCameraDemoPhase = -1; mbgl::TimePoint freeCameraDemoStartTime; bool fullscreen = false; const bool benchmark = false; bool tracking = false; bool rotating = false; bool pitching = false; bool show3DExtrusions = false; // Frame timer int frames = 0; float frameTime = 0; double lastReported = 0; int width = 1024; int height = 768; float pixelRatio; double lastX = 0, lastY = 0; double lastClick = -1; std::function changeStyleCallback; std::function pauseResumeCallback; std::function onlineStatusCallback; std::function resetDatabaseCallback; std::function animateRouteCallback; mbgl::util::RunLoop runLoop; mbgl::util::Timer frameTick; GLFWwindow *window = nullptr; bool dirty = false; mbgl::optional featureID; std::unique_ptr snapshotter; std::unique_ptr snapshotterObserver; mbgl::ResourceOptions mapResourceOptions; #if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) bool puckFollowsCameraCenter = false; mbgl::style::LocationIndicatorLayer *puck = nullptr; #endif };