Skip to content
Snippets Groups Projects
Commit fddd5c1b authored by Nils Speetzen's avatar Nils Speetzen :shrimp:
Browse files

added cache_window_size option

parent 1df3e4cf
No related branches found
No related tags found
1 merge request!134Add configure option cache_window_size
......@@ -244,7 +244,7 @@ void GlfwApp::init()
if (mCacheWindowSize)
{
// Restore window size
std::ifstream file("glfwapp.ini");
std::ifstream file(mCacheWindowSizeFilename);
if (file.good())
{
int w, h, x, y;
......@@ -755,7 +755,7 @@ void GlfwApp::internalCleanUp()
if (mCacheWindowSize)
{
// Save window size to disk
std::ofstream file("glfwapp.ini");
std::ofstream file(mCacheWindowSizeFilename);
if (file.good())
{
if (mInternalContext->isFullscreen())
......
......@@ -130,6 +130,8 @@ private:
bool mUsePipelineConfigGui = false; ///< if true, enables the pipeline scen configuration gui (only if pipeline is used, requires ImGui)
bool mCacheWindowSize = false; ///< if true, saves window size and position on close, and restores on next launch
std::string mCacheWindowSizeFilename = "glfwapp.ini"; /// Default -> cwd
std::string mCacheWindowSizeFilenameImGui = "imgui.ini"; /// Default -> cwd
double mCurrentTime = 0.0; ///< current frame time (starts with 0)
double mCurrentRenderDeltaTime = 0.0; ///< current delta time for the render(dt) call
......@@ -226,6 +228,8 @@ public:
GLOW_PROPERTY(UseDefaultCameraHandlingRight);
GLOW_PROPERTY(CacheWindowSize);
GLOW_PROPERTY(CacheWindowSizeFilename);
GLOW_PROPERTY(CacheWindowSizeFilenameImGui);
void setTitle(std::string const& title);
......
......@@ -178,10 +178,35 @@ void ViewerApp::init()
if (mSettings.headlessScreenshot)
setStartInvisible(true);
// set where to read and write the window position
// (empty location -> don't read or write)
if (mSettings.cacheWindowSizeFolder.empty())
{
setCacheWindowSize(false);
}
else
{
setCacheWindowSize(true);
setCacheWindowSizeFilename(mSettings.cacheWindowSizeFolder + "glfwapp.ini");
setCacheWindowSizeFilenameImGui(mSettings.cacheWindowSizeFolder + "imgui.ini");
}
sLastCloseInfo.closed_by_key = -1;
GlfwApp::init();
// set where to read and write the window position; part 2
// (ImGui Context has to be initialized already)
if(getGui() == Gui::ImGui)
{
if (!getCacheWindowSize())
ImGui::GetIO().IniFilename = nullptr;
else
{
ImGui::GetIO().IniFilename = getCacheWindowSizeFilenameImGui().c_str();
}
}
// create camera (before initial layout)
// (or take preserved camera)
bool newCamera;
......
......@@ -258,6 +258,14 @@ void configure(GeometricRenderable& r, Picker p)
r.setPicker(std::move(p));
}
void configure(Renderable&, const file_drop_handler& h) { detail::set_file_drop_handler(h.callback); }
void configure(Renderable&, file_drop_handler const& h)
{
detail::set_file_drop_handler(h.callback);
}
void configure(Renderable&, cache_window_size const& s)
{
detail::set_cache_window_size_folder(s.folder);
}
} // namespace glow::viewer
......@@ -156,6 +156,16 @@ struct file_drop_handler
explicit file_drop_handler(std::function<void(std::vector<std::string> const&)> f) : callback(f) {}
};
struct cache_window_size
{
std::string_view folder;
constexpr explicit cache_window_size(std::string_view folder)
: folder(folder)
{
}
};
// Config tags
inline auto constexpr no_grid = no_grid_t{};
inline auto constexpr no_left_mouse_control = no_left_mouse_control_t{};
......@@ -180,6 +190,7 @@ inline auto constexpr tonemap_exposure = tonemap_exposure_t{};
inline auto constexpr backface_culling = backface_culling_t{};
inline auto constexpr preserve_camera = preserve_camera_t{};
inline auto constexpr reuse_camera = reuse_camera_t{};
inline auto constexpr no_cache_window_size = cache_window_size("");
// passthrough configures for scene modification commands
void configure(Renderable&, no_grid_t b);
......@@ -217,6 +228,7 @@ void configure(Renderable&, close_keys const& k);
void configure(Renderable&, preserve_camera_t b);
void configure(Renderable&, reuse_camera_t b);
void configure(Renderable&, file_drop_handler const& h);
void configure(Renderable&, cache_window_size const& h);
/// custom scene configuration
void configure(Renderable&, std::function<void(SceneConfig&)> f);
......
#include "command_queue.hh"
#include <variant>
#include <filesystem>
#include <glow-extras/viewer/ViewerApp.hh>
#include <glow-extras/viewer/view.hh>
......@@ -292,3 +293,15 @@ void glow::viewer::detail::set_file_drop_handler(std::function<void(const std::v
{
sGlobalSettings.onDropFiles = std::move(callback);
}
void glow::viewer::detail::set_cache_window_size_folder(std::string_view s)
{
auto& folder = sGlobalSettings.cacheWindowSizeFolder;
folder = s;
if(!folder.empty() && !folder.ends_with("/")) folder.append("/");
if(!std::filesystem::exists(folder))
{
glow::warning() << "Target folder for window size caching does not exist! Defaulting to working directory.";
folder = "./";
}
}
......@@ -31,6 +31,7 @@ struct global_settings
bool rightMouseControlEnabled = true;
bool enableViewerUI = true;
std::string cacheWindowSizeFolder = "./";
bool has3D = false; ///< True iff we have 3D content (this is set automatically)
bool use_2d_controls() const { return controls2d_enabled || !has3D; }
......@@ -274,6 +275,7 @@ void set_subview_margin(int margin);
void set_subview_margin_color(tg::color3 color);
void set_headless_screenshot(tg::ivec2 resolution, int accum, std::string const& filename, GLenum format);
void set_file_drop_handler(std::function<void(std::vector<std::string> const&)> callback);
void set_cache_window_size_folder(std::string_view s);
// Returns true if the given command list contains one or more interactive instructions (and whose tree therefore must be rebuilt each frame)
bool is_interactive(command_queue const& commands);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment