aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2014-09-28 22:00:30 +0200
committerDavid Robillard <d@drobilla.net>2014-12-16 18:31:22 -0500
commit2e07e028c1080051846b1b200493e528a8f9a5e6 (patch)
tree61db9c5aba47555204d1b054662ac1954008d256 /pugl
parent3fa6c2c10f7d4ca06fd30e2442dcd25f492cc351 (diff)
downloadpugl-2e07e028c1080051846b1b200493e528a8f9a5e6.tar.gz
pugl-2e07e028c1080051846b1b200493e528a8f9a5e6.tar.bz2
pugl-2e07e028c1080051846b1b200493e528a8f9a5e6.zip
Support minimum window size.
Conflicts: pugl/pugl_win.cpp
Diffstat (limited to 'pugl')
-rw-r--r--pugl/pugl.h6
-rw-r--r--pugl/pugl_internal.h9
-rw-r--r--pugl/pugl_osx.m3
-rw-r--r--pugl/pugl_win.cpp17
-rw-r--r--pugl/pugl_x11.c5
5 files changed, 38 insertions, 2 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 68ecc19..54b4c78 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -165,6 +165,12 @@ PUGL_API void
puglInitWindowSize(PuglView* view, int width, int height);
/**
+ Set the minimum window size before creating a window.
+*/
+PUGL_API void
+puglInitWindowMinSize(PuglView* view, int width, int height);
+
+/**
Enable or disable resizing before creating a window.
*/
PUGL_API void
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index 32d31bf..8a193d6 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -52,6 +52,8 @@ struct PuglViewImpl {
int width;
int height;
+ int min_width;
+ int min_height;
int mods;
bool mouse_in_view;
bool ignoreKeyRepeat;
@@ -90,6 +92,13 @@ puglInitWindowSize(PuglView* view, int width, int height)
}
void
+puglInitWindowMinSize(PuglView* view, int width, int height)
+{
+ view->min_width = width;
+ view->min_height = height;
+}
+
+void
puglInitWindowParent(PuglView* view, PuglNativeWindow parent)
{
view->parent = parent;
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index 464a8a2..3b62fae 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -459,6 +459,9 @@ puglCreateWindow(PuglView* view, const char* title)
[window setPuglview:view];
[window setTitle:titleString];
+ if (view->min_width || view->min_height) {
+ [window setContentMinSize:NSMakeSize(view->min_width, view->min_height)];
+ }
impl->glview = [PuglOpenGLView new];
impl->window = window;
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index ead0236..2040b98 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -128,9 +128,16 @@ puglCreateWindow(PuglView* view, const char* title)
int winFlags = WS_POPUPWINDOW | WS_CAPTION;
if (view->resizable) {
winFlags |= WS_SIZEBOX;
+ if (view->min_width || view->min_height) {
+ // Adjust the minimum window size to accomodate requested view size
+ RECT mr = { 0, 0, view->min_width, view->min_height };
+ AdjustWindowRectEx(&mr, winFlags, FALSE, WS_EX_TOPMOST);
+ view->min_width = mr.right - mr.left;
+ view->min_height = wr.bottom - mr.top;
+ }
}
- // Adjust the overall window size to accomodate our requested client size
+ // Adjust the window size to accomodate requested view size
RECT wr = { 0, 0, view->width, view->height };
AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST);
@@ -305,18 +312,24 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
PuglKey key;
+ RECT rect;
+ MINMAXINFO* mmi;
setModifiers(view);
switch (message) {
case WM_CREATE:
case WM_SHOWWINDOW:
case WM_SIZE:
- RECT rect;
GetClientRect(view->impl->hwnd, &rect);
puglReshape(view, rect.right, rect.bottom);
view->width = rect.right;
view->height = rect.bottom;
break;
+ case WM_GETMINMAXINFO:
+ mmi = (MINMAXINFO*)lParam;
+ mmi->ptMinTrackSize.x = view->min_width;
+ mmi->ptMinTrackSize.y = view->min_height;
+ break;
case WM_PAINT:
BeginPaint(view->impl->hwnd, &ps);
puglDisplay(view);
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index e0852be..e3325cd 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -210,6 +210,11 @@ puglCreateWindow(PuglView* view, const char* title)
sizeHints.max_width = view->width;
sizeHints.max_height = view->height;
XSetNormalHints(impl->display, impl->win, &sizeHints);
+ } else if (view->min_width || view->min_height) {
+ sizeHints.flags = PMinSize;
+ sizeHints.min_width = view->min_width;
+ sizeHints.min_height = view->min_height;
+ XSetNormalHints(impl->display, impl->win, &sizeHints);
}
if (title) {