aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-04 19:28:22 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:34:39 +0200
commite7ccbec8f5f0097ca54b8d7ea27e0815b069b57c (patch)
tree9b8cfba48e3078a15b5c68f70a1e8a442b84025e
parentf98e804c5f844f2dd78e94f7a1c9db15b7332fbb (diff)
Replace size and aspect ratio init functions with dynamic ones
-rw-r--r--pugl/detail/implementation.c20
-rw-r--r--pugl/detail/mac.m34
-rw-r--r--pugl/detail/win.c22
-rw-r--r--pugl/detail/x11.c38
-rw-r--r--pugl/pugl.h73
-rw-r--r--test/pugl_cairo_test.c2
-rw-r--r--test/pugl_test.c4
7 files changed, 147 insertions, 46 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index d6e4b86..f971284 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -128,26 +128,6 @@ puglInitWindowHint(PuglView* view, PuglWindowHint hint, int value)
}
void
-puglInitWindowMinSize(PuglView* view, int width, int height)
-{
- view->minWidth = width;
- view->minHeight = height;
-}
-
-void
-puglInitWindowAspectRatio(PuglView* view,
- int minX,
- int minY,
- int maxX,
- int maxY)
-{
- view->minAspectX = minX;
- view->minAspectY = minY;
- view->maxAspectX = maxX;
- view->maxAspectY = maxY;
-}
-
-void
puglInitWindowClass(PuglView* view, const char* name)
{
const size_t len = strlen(name);
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index ea55c0f..6d156c6 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -966,3 +966,37 @@ puglSetFrame(PuglView* view, const PuglRect frame)
return PUGL_SUCCESS;
}
+
+PuglStatus
+puglSetMinSize(PuglView* const view, const int width, const int height)
+{
+ view->minWidth = width;
+ view->minHeight = height;
+
+ if (view->impl->window && (view->minWidth || view->minHeight)) {
+ [view->impl->window
+ setContentMinSize:NSMakeSize(view->minWidth, view->minHeight)];
+ }
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglSetAspectRatio(PuglView* const view,
+ const int minX,
+ const int minY,
+ const int maxX,
+ const int maxY)
+{
+ view->minAspectX = minX;
+ view->minAspectY = minY;
+ view->maxAspectX = maxX;
+ view->maxAspectY = maxY;
+
+ if (view->impl->window && view->minAspectX && view->minAspectY) {
+ [view->impl->window setContentAspectRatio:NSMakeSize(view->minAspectX,
+ view->minAspectY)];
+ }
+
+ return PUGL_SUCCESS;
+}
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 2c4074c..96642cc 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -804,3 +804,25 @@ puglSetFrame(PuglView* view, const PuglRect frame)
return PUGL_SUCCESS;
}
+
+PuglStatus
+puglSetMinSize(PuglView* const view, const int width, const int height)
+{
+ view->minWidth = width;
+ view->minHeight = height;
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglSetAspectRatio(PuglView* const view,
+ const int minX,
+ const int minY,
+ const int maxX,
+ const int maxY)
+{
+ view->minAspectX = minX;
+ view->minAspectY = minY;
+ view->maxAspectX = maxX;
+ view->maxAspectY = maxY;
+ return PUGL_SUCCESS;
+}
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index 1e1f96f..d7b7677 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -723,3 +723,41 @@ puglSetFrame(PuglView* view, const PuglRect frame)
return PUGL_SUCCESS;
}
+
+PuglStatus
+puglSetMinSize(PuglView* const view, const int width, const int height)
+{
+ Display* display = view->world->impl->display;
+
+ view->minWidth = width;
+ view->minHeight = height;
+
+ if (view->impl->win) {
+ XSizeHints sizeHints = getSizeHints(view);
+ XSetNormalHints(display, view->impl->win, &sizeHints);
+ }
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglSetAspectRatio(PuglView* const view,
+ const int minX,
+ const int minY,
+ const int maxX,
+ const int maxY)
+{
+ Display* display = view->world->impl->display;
+
+ view->minAspectX = minX;
+ view->minAspectY = minY;
+ view->maxAspectX = maxX;
+ view->maxAspectY = maxY;
+
+ if (view->impl->win) {
+ XSizeHints sizeHints = getSizeHints(view);
+ XSetNormalHints(display, view->impl->win, &sizeHints);
+ }
+
+ return PUGL_SUCCESS;
+}
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 6d2d8b1..26593f2 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -535,29 +535,6 @@ PUGL_API void
puglInitWindowParent(PuglView* view, PuglNativeWindow parent);
/**
- Set the minimum window size before creating a window.
-*/
-PUGL_API void
-puglInitWindowMinSize(PuglView* view, int width, int height);
-
-/**
- Set the window aspect ratio range before creating a window.
-
- The x and y values here represent a ratio of width to height. To set a
- fixed aspect ratio, set the minimum and maximum values to the same ratio.
-
- Note that setting different minimum and maximum constraints does not
- currenty work on MacOS (the minimum is used), so only setting a fixed aspect
- ratio works properly across all platforms.
-*/
-PUGL_API void
-puglInitWindowAspectRatio(PuglView* view,
- int minX,
- int minY,
- int maxX,
- int maxY);
-
-/**
Set transient parent before creating a window.
On X11, parent must be a Window.
@@ -648,6 +625,27 @@ PUGL_API PuglStatus
puglSetFrame(PuglView* view, PuglRect frame);
/**
+ Set the minimum size of the view.
+
+ To avoid stutter, this should be called before creating the window.
+*/
+PUGL_API PuglStatus
+puglSetMinSize(PuglView* view, int width, int height);
+
+/**
+ Set the window aspect ratio range.
+
+ The x and y values here represent a ratio of width to height. To set a
+ fixed aspect ratio, set the minimum and maximum values to the same ratio.
+
+ Note that setting different minimum and maximum constraints does not
+ currenty work on MacOS (the minimum is used), so only setting a fixed aspect
+ ratio works properly across all platforms.
+*/
+PUGL_API PuglStatus
+puglSetAspectRatio(PuglView* view, int minX, int minY, int maxX, int maxY);
+
+/**
@name Context
Functions for accessing the drawing context.
@{
@@ -815,6 +813,35 @@ puglInitWindowSize(PuglView* view, int width, int height)
}
/**
+ Set the minimum window size before creating a window.
+*/
+static inline PUGL_DEPRECATED_BY("puglSetMinSize") void
+puglInitWindowMinSize(PuglView* view, int width, int height)
+{
+ puglSetMinSize(view, width, height);
+}
+
+/**
+ Set the window aspect ratio range before creating a window.
+
+ The x and y values here represent a ratio of width to height. To set a
+ fixed aspect ratio, set the minimum and maximum values to the same ratio.
+
+ Note that setting different minimum and maximum constraints does not
+ currenty work on MacOS (the minimum is used), so only setting a fixed aspect
+ ratio works properly across all platforms.
+*/
+static inline PUGL_DEPRECATED_BY("puglSetAspectRatio") void
+puglInitWindowAspectRatio(PuglView* view,
+ int minX,
+ int minY,
+ int maxX,
+ int maxY)
+{
+ puglSetAspectRatio(view, minX, minY, maxX, maxY);
+}
+
+/**
Enable or disable resizing before creating a window.
@deprecated Use puglInitWindowHint() with @ref PUGL_RESIZABLE.
diff --git a/test/pugl_cairo_test.c b/test/pugl_cairo_test.c
index f339abd..c396dad 100644
--- a/test/pugl_cairo_test.c
+++ b/test/pugl_cairo_test.c
@@ -211,7 +211,7 @@ main(int argc, char** argv)
PuglView* view = puglNewView(world);
puglInitWindowClass(view, "PuglCairoTest");
puglSetFrame(view, frame);
- puglInitWindowMinSize(view, 256, 256);
+ puglSetMinSize(view, 256, 256);
puglInitWindowHint(view, PUGL_RESIZABLE, resizable);
puglInitBackend(view, puglCairoBackend());
diff --git a/test/pugl_test.c b/test/pugl_test.c
index 7ee04b8..285c5d9 100644
--- a/test/pugl_test.c
+++ b/test/pugl_test.c
@@ -317,8 +317,8 @@ main(int argc, char** argv)
const PuglRect parentFrame = { 0, 0, 512, 512 };
puglInitWindowClass(app.parent, "PuglTest");
puglSetFrame(app.parent, parentFrame);
- puglInitWindowMinSize(app.parent, 256, 256);
- puglInitWindowAspectRatio(app.parent, 1, 1, 16, 9);
+ puglSetMinSize(app.parent, borderWidth * 3, borderWidth * 3);
+ puglSetAspectRatio(app.parent, 1, 1, 16, 9);
puglInitBackend(app.parent, puglGlBackend());
puglInitWindowHint(app.parent, PUGL_RESIZABLE, resizable);