MeshLib Documentation
Loading...
Searching...
No Matches
MRSplashWindow.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewerFwd.h"
4#include <string>
5#include <functional>
6#include <atomic>
7#include <thread>
8#include <memory>
9
10struct GLFWwindow;
11struct ImGuiContext;
12
13namespace MR
14{
15
16// Base class to run splash window in new thread
17// override it's private functions and provide it Viever::LaunchParams
18class MRVIEWER_CLASS SplashWindow
19{
20public:
21 MRVIEWER_API SplashWindow( std::string name );
22
23 // Thread should be stopped before destructor
24 MRVIEWER_API virtual ~SplashWindow();
25
26 // Starts splash window in new thread, non blocking
27 // window will be closed in destructor of this class, or if `frame_` func returns false. or manually with `stop` function
28 MRVIEWER_API void start();
29
30 // Closes splash window if it is still opened
31 MRVIEWER_API void stop();
32
33 // Returns minimum time in seconds, splash screen to be present
34 virtual float minimumTimeSec() const { return 2.f; }
35
36protected:
37 std::string name_;
38
39 GLFWwindow* window_{ nullptr };
40 ImGuiContext* guiContext_{ nullptr };
41
42 std::atomic<bool> terminate_{ false };
43private:
44 // This function is called in main thread right after splash thread is started
45 virtual void afterStart_() {}
46 // This function is called in main thread right before splash thread is stopped
47 virtual void beforeStop_() {}
48
49 // This is called first (for window decoration, etc.), splash thread
50 virtual void setup_() const = 0;
51 // This is called right after window is created to make some initial actions (for example load splash texture), splash thread
52 virtual void postInit_() {}
53 // This is called after 'postInit_' (and on dpi change) to resize and reposition window, splash thread
54 virtual void positioning_( float hdpiScale ) = 0;
55 // This is called after 'positioning_' to reload font, splash thread
56 virtual void reloadFont_( float hdpiScale, float pixelRatio ) = 0;
57 // This is called each frame, return false to close splash, splash thread
58 virtual bool frame_( float scaling ) = 0;
59 // This is called right before GLWF and ImGui contexts are destructed (needed to clear some GL data), splash thread
60 virtual void preDestruct_() {}
61 // This is called right after GLWF and ImGui contexts are destructed and right before closing splash (restore Menu ImGui context, etc.), splash thread
62 virtual void postDestruct_() {}
63
64 std::thread thread_;
65};
66
67#ifndef __EMSCRIPTEN__
68class MRVIEWER_CLASS DefaultSplashWindow final : public SplashWindow
69{
70public:
71 MRVIEWER_API DefaultSplashWindow();
72private:
73 virtual void setup_() const override;
74 virtual void postInit_() override;
75 virtual void positioning_( float hdpiScale ) override;
76 virtual void reloadFont_( float hdpiScale, float pixelRatio ) override;
77 virtual bool frame_( float scaling ) override;
78 virtual void preDestruct_() override;
79
80 std::shared_ptr<ImGuiImage> splashImage_;
81 std::string versionStr_;
82};
83#endif
84}
Definition MRSplashWindow.h:69
MRVIEWER_API DefaultSplashWindow()
Definition MRSplashWindow.h:19
virtual float minimumTimeSec() const
Definition MRSplashWindow.h:34
MRVIEWER_API void stop()
MRVIEWER_API SplashWindow(std::string name)
std::string name_
Definition MRSplashWindow.h:37
virtual MRVIEWER_API ~SplashWindow()
MRVIEWER_API void start()
Definition MRCameraOrientationPlugin.h:8