Skip to content

Commit cd149dd

Browse files
committed
load window size from prefs only if unspecified
1 parent 6722586 commit cd149dd

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

include/polyscope/context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ struct Context {
7575

7676
int bufferWidth = -1;
7777
int bufferHeight = -1;
78-
int windowWidth = 1280;
79-
int windowHeight = 720;
78+
int windowWidth = -1; // on init(), get overwritten with defaultWindowWidth if -1
79+
int windowHeight = -1; // ^^^ same
8080
int initWindowPosX = 20;
8181
int initWindowPosY = 20;
8282
bool windowResizable = true;

include/polyscope/view.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ extern float& flightTargetFov;
6969
extern float& flightInitialFov;
7070

7171
// Default values
72+
extern const int defaultWindowWidth;
73+
extern const int defaultWindowHeight;
7274
extern const double defaultNearClipRatio;
7375
extern const double defaultFarClipRatio;
7476
extern const double defaultFov;

src/polyscope.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ void readPrefsFile() {
6666

6767
// Set values
6868
// Do some basic validation on the sizes first to work around bugs with bogus values getting written to init file
69-
if (prefsJSON.count("windowWidth") > 0) {
69+
if (view::windowWidth == -1 && prefsJSON.count("windowWidth") > 0) { // only load if not already set
7070
int val = prefsJSON["windowWidth"];
7171
if (val >= 64 && val < 10000) view::windowWidth = val;
7272
}
73-
if (prefsJSON.count("windowHeight") > 0) {
73+
if (view::windowHeight == -1 && prefsJSON.count("windowHeight") > 0) { // only load if not already set
7474
int val = prefsJSON["windowHeight"];
7575
if (val >= 64 && val < 10000) view::windowHeight = val;
7676
}
@@ -148,6 +148,8 @@ void init(std::string backend) {
148148
if (options::usePrefsFile) {
149149
readPrefsFile();
150150
}
151+
if (view::windowWidth == -1) view::windowWidth = view::defaultWindowWidth;
152+
if (view::windowHeight == -1) view::windowHeight = view::defaultWindowHeight;
151153

152154
// Initialize the rendering engine
153155
render::initializeRenderEngine(backend);

src/view.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ float& flightInitialFov = state::globalContext.flightInitialFov;
4444

4545

4646
// Default values
47+
const int defaultWindowWidth = 1280;
48+
const int defaultWindowHeight = 720;
4749
const double defaultNearClipRatio = 0.005;
4850
const double defaultFarClipRatio = 20.0;
4951
const double defaultFov = 45.;

0 commit comments

Comments
 (0)