Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Browse files Browse the repository at this point in the history
Also fixed Cocoa implementation so that it affects client area, not the whole window area.
  • Loading branch information
slouken committed Dec 31, 2012
1 parent d38c22c commit 0ae1fc0
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 4 deletions.
4 changes: 4 additions & 0 deletions include/SDL_test_common.h
Expand Up @@ -65,6 +65,10 @@ typedef struct
int window_y;
int window_w;
int window_h;
int window_minW;
int window_minH;
int window_maxW;
int window_maxH;
int depth;
int refresh_rate;
int num_windows;
Expand Down
23 changes: 23 additions & 0 deletions include/SDL_video.h
Expand Up @@ -535,18 +535,41 @@ extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
* automatically matches the size of the display mode.
*
* \sa SDL_GetWindowMinimumSize()
* \sa SDL_SetWindowMaximumSize()
*/
extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
int min_w, int min_h);

/**
* \brief Get the minimum size of a window's client area.
*
* \sa SDL_GetWindowMaximumSize()
* \sa SDL_SetWindowMinimumSize()
*/
extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
int *w, int *h);

/**
* \brief Set the maximum size of a window's client area.
*
* \note You can't change the maximum size of a fullscreen window, it
* automatically matches the size of the display mode.
*
* \sa SDL_GetWindowMaximumSize()
* \sa SDL_SetWindowMinimumSize()
*/
extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window,
int max_w, int max_h);

/**
* \brief Get the maximum size of a window's client area.
*
* \sa SDL_GetWindowMinimumSize()
* \sa SDL_SetWindowMaximumSize()
*/
extern DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window * window,
int *w, int *h);

/**
* \brief Set the border state of a window.
*
Expand Down
46 changes: 45 additions & 1 deletion src/test/SDL_test_common.c
Expand Up @@ -27,7 +27,7 @@
#include <stdio.h>

#define VIDEO_USAGE \
"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"

#define AUDIO_USAGE \
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
Expand Down Expand Up @@ -266,6 +266,44 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
state->window_h = SDL_atoi(h);
return 2;
}
if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
char *w, *h;
++index;
if (!argv[index]) {
return -1;
}
w = argv[index];
h = argv[index];
while (*h && *h != 'x') {
++h;
}
if (!*h) {
return -1;
}
*h++ = '\0';
state->window_minW = SDL_atoi(w);
state->window_minH = SDL_atoi(h);
return 2;
}
if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
char *w, *h;
++index;
if (!argv[index]) {
return -1;
}
w = argv[index];
h = argv[index];
while (*h && *h != 'x') {
++h;
}
if (!*h) {
return -1;
}
*h++ = '\0';
state->window_maxW = SDL_atoi(w);
state->window_maxH = SDL_atoi(h);
return 2;
}
if (SDL_strcasecmp(argv[index], "--depth") == 0) {
++index;
if (!argv[index]) {
Expand Down Expand Up @@ -751,6 +789,12 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
SDL_GetError());
return SDL_FALSE;
}
if (state->window_minW || state->window_minH) {
SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
}
if (state->window_maxW || state->window_maxH) {
SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
}
SDL_GetWindowSize(state->windows[i], &w, &h);
if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
(w != state->window_w || h != state->window_h)) {
Expand Down
2 changes: 2 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -75,6 +75,7 @@ struct SDL_Window
int x, y;
int w, h;
int min_w, min_h;
int max_w, max_h;
Uint32 flags;

/* Stored position and size for windowed mode */
Expand Down Expand Up @@ -184,6 +185,7 @@ struct SDL_VideoDevice
void (*SetWindowPosition) (_THIS, SDL_Window * window);
void (*SetWindowSize) (_THIS, SDL_Window * window);
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
void (*ShowWindow) (_THIS, SDL_Window * window);
void (*HideWindow) (_THIS, SDL_Window * window);
void (*RaiseWindow) (_THIS, SDL_Window * window);
Expand Down
39 changes: 39 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -1640,6 +1640,45 @@ SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
}
}

void
SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
{
CHECK_WINDOW_MAGIC(window, );

if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
window->max_w = max_w;
window->max_h = max_h;
if (_this->SetWindowMaximumSize) {
_this->SetWindowMaximumSize(_this, window);
}
/* Ensure that window is not larger than maximal size */
SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h));
}
}

void
SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
{
int dummy;

if (!max_w) {
max_w = &dummy;
}
if (!max_h) {
max_h = &dummy;
}

*max_w = 0;
*max_h = 0;

CHECK_WINDOW_MAGIC(window, );

if (_this && window && window->magic == &_this->window_magic) {
*max_w = window->max_w;
*max_h = window->max_h;
}
}

void
SDL_ShowWindow(SDL_Window * window)
{
Expand Down
4 changes: 2 additions & 2 deletions src/video/cocoa/SDL_cocoamodes.m
Expand Up @@ -220,7 +220,7 @@ - (void) setFrame:(NSRect)frame;
#endif
}

static char *
static const char *
Cocoa_GetDisplayName(CGDirectDisplayID displayID)
{
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
Expand Down Expand Up @@ -299,7 +299,7 @@ - (void) setFrame:(NSRect)frame;
displaydata->display = displays[i];

SDL_zero(display);
display.name = Cocoa_GetDisplayName(displays[i]);
display.name = (char *)Cocoa_GetDisplayName(displays[i]);
if (!GetDisplayMode (_this, moderef, &mode)) {
Cocoa_ReleaseDisplayMode(_this, moderef);
SDL_free(displaydata);
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -96,6 +96,7 @@
device->SetWindowPosition = Cocoa_SetWindowPosition;
device->SetWindowSize = Cocoa_SetWindowSize;
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
device->ShowWindow = Cocoa_ShowWindow;
device->HideWindow = Cocoa_HideWindow;
device->RaiseWindow = Cocoa_RaiseWindow;
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoawindow.h
Expand Up @@ -95,6 +95,7 @@ extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
Expand Down
17 changes: 16 additions & 1 deletion src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -740,7 +740,22 @@ - (void)rightMouseDown:(NSEvent *)theEvent
minSize.width = window->min_w;
minSize.height = window->min_h;

[windata->nswindow setMinSize:minSize];
[windata->nswindow setContentMinSize:minSize];

[pool release];
}

void
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;

NSSize maxSize;
maxSize.width = window->max_w;
maxSize.height = window->max_h;

[windata->nswindow setContentMaxSize:maxSize];

[pool release];
}
Expand Down
6 changes: 6 additions & 0 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -447,6 +447,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int x, y;
int w, h;
int min_w, min_h;
int max_w, max_h;
int style;
BOOL menu;

Expand All @@ -462,11 +463,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* Calculate current size of our window */
SDL_GetWindowSize(data->window, &w, &h);
SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);

/* Store in min_w and min_h difference between current size and minimal
size so we don't need to call AdjustWindowRectEx twice */
min_w -= w;
min_h -= h;
max_w -= w;
max_h -= h;

size.top = 0;
size.left = 0;
Expand All @@ -489,6 +493,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
info->ptMinTrackSize.x = w + min_w;
info->ptMinTrackSize.y = h + min_h;
info->ptMaxTrackSize.x = w + max_w;
info->ptMaxTrackSize.y = h + max_h;
} else {
info->ptMaxSize.x = w;
info->ptMaxSize.y = h;
Expand Down
9 changes: 9 additions & 0 deletions test/testwm2.c
Expand Up @@ -80,6 +80,15 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);

if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
printf("Window %d resized to %dx%d\n",
event.window.windowID,
event.window.data1,
event.window.data2);
}
}
if (event.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
Expand Down

0 comments on commit 0ae1fc0

Please sign in to comment.