Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Also fixed Cocoa implementation so that it affects client area, not the whole window area.
This commit is contained in:
parent
ce28a79602
commit
1a92f18381
11 changed files with 148 additions and 4 deletions
|
@ -65,6 +65,10 @@ typedef struct
|
||||||
int window_y;
|
int window_y;
|
||||||
int window_w;
|
int window_w;
|
||||||
int window_h;
|
int window_h;
|
||||||
|
int window_minW;
|
||||||
|
int window_minH;
|
||||||
|
int window_maxW;
|
||||||
|
int window_maxH;
|
||||||
int depth;
|
int depth;
|
||||||
int refresh_rate;
|
int refresh_rate;
|
||||||
int num_windows;
|
int num_windows;
|
||||||
|
|
|
@ -535,6 +535,7 @@ extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
|
||||||
* automatically matches the size of the display mode.
|
* automatically matches the size of the display mode.
|
||||||
*
|
*
|
||||||
* \sa SDL_GetWindowMinimumSize()
|
* \sa SDL_GetWindowMinimumSize()
|
||||||
|
* \sa SDL_SetWindowMaximumSize()
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
|
extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
|
||||||
int min_w, int min_h);
|
int min_w, int min_h);
|
||||||
|
@ -542,11 +543,33 @@ extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
|
||||||
/**
|
/**
|
||||||
* \brief Get the minimum size of a window's client area.
|
* \brief Get the minimum size of a window's client area.
|
||||||
*
|
*
|
||||||
|
* \sa SDL_GetWindowMaximumSize()
|
||||||
* \sa SDL_SetWindowMinimumSize()
|
* \sa SDL_SetWindowMinimumSize()
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
|
extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
|
||||||
int *w, int *h);
|
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.
|
* \brief Set the border state of a window.
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define VIDEO_USAGE \
|
#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 \
|
#define AUDIO_USAGE \
|
||||||
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
|
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
|
||||||
|
@ -266,6 +266,44 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
|
||||||
state->window_h = SDL_atoi(h);
|
state->window_h = SDL_atoi(h);
|
||||||
return 2;
|
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) {
|
if (SDL_strcasecmp(argv[index], "--depth") == 0) {
|
||||||
++index;
|
++index;
|
||||||
if (!argv[index]) {
|
if (!argv[index]) {
|
||||||
|
@ -751,6 +789,12 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
return SDL_FALSE;
|
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);
|
SDL_GetWindowSize(state->windows[i], &w, &h);
|
||||||
if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
|
if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
|
||||||
(w != state->window_w || h != state->window_h)) {
|
(w != state->window_w || h != state->window_h)) {
|
||||||
|
|
|
@ -75,6 +75,7 @@ struct SDL_Window
|
||||||
int x, y;
|
int x, y;
|
||||||
int w, h;
|
int w, h;
|
||||||
int min_w, min_h;
|
int min_w, min_h;
|
||||||
|
int max_w, max_h;
|
||||||
Uint32 flags;
|
Uint32 flags;
|
||||||
|
|
||||||
/* Stored position and size for windowed mode */
|
/* Stored position and size for windowed mode */
|
||||||
|
@ -184,6 +185,7 @@ struct SDL_VideoDevice
|
||||||
void (*SetWindowPosition) (_THIS, SDL_Window * window);
|
void (*SetWindowPosition) (_THIS, SDL_Window * window);
|
||||||
void (*SetWindowSize) (_THIS, SDL_Window * window);
|
void (*SetWindowSize) (_THIS, SDL_Window * window);
|
||||||
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
|
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
|
||||||
|
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
|
||||||
void (*ShowWindow) (_THIS, SDL_Window * window);
|
void (*ShowWindow) (_THIS, SDL_Window * window);
|
||||||
void (*HideWindow) (_THIS, SDL_Window * window);
|
void (*HideWindow) (_THIS, SDL_Window * window);
|
||||||
void (*RaiseWindow) (_THIS, SDL_Window * window);
|
void (*RaiseWindow) (_THIS, SDL_Window * window);
|
||||||
|
|
|
@ -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
|
void
|
||||||
SDL_ShowWindow(SDL_Window * window)
|
SDL_ShowWindow(SDL_Window * window)
|
||||||
{
|
{
|
||||||
|
|
|
@ -220,7 +220,7 @@ Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static const char *
|
||||||
Cocoa_GetDisplayName(CGDirectDisplayID displayID)
|
Cocoa_GetDisplayName(CGDirectDisplayID displayID)
|
||||||
{
|
{
|
||||||
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
|
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
|
||||||
|
@ -299,7 +299,7 @@ Cocoa_InitModes(_THIS)
|
||||||
displaydata->display = displays[i];
|
displaydata->display = displays[i];
|
||||||
|
|
||||||
SDL_zero(display);
|
SDL_zero(display);
|
||||||
display.name = Cocoa_GetDisplayName(displays[i]);
|
display.name = (char *)Cocoa_GetDisplayName(displays[i]);
|
||||||
if (!GetDisplayMode (_this, moderef, &mode)) {
|
if (!GetDisplayMode (_this, moderef, &mode)) {
|
||||||
Cocoa_ReleaseDisplayMode(_this, moderef);
|
Cocoa_ReleaseDisplayMode(_this, moderef);
|
||||||
SDL_free(displaydata);
|
SDL_free(displaydata);
|
||||||
|
|
|
@ -96,6 +96,7 @@ Cocoa_CreateDevice(int devindex)
|
||||||
device->SetWindowPosition = Cocoa_SetWindowPosition;
|
device->SetWindowPosition = Cocoa_SetWindowPosition;
|
||||||
device->SetWindowSize = Cocoa_SetWindowSize;
|
device->SetWindowSize = Cocoa_SetWindowSize;
|
||||||
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
|
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
|
||||||
|
device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
|
||||||
device->ShowWindow = Cocoa_ShowWindow;
|
device->ShowWindow = Cocoa_ShowWindow;
|
||||||
device->HideWindow = Cocoa_HideWindow;
|
device->HideWindow = Cocoa_HideWindow;
|
||||||
device->RaiseWindow = Cocoa_RaiseWindow;
|
device->RaiseWindow = Cocoa_RaiseWindow;
|
||||||
|
|
|
@ -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_SetWindowPosition(_THIS, SDL_Window * window);
|
||||||
extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
|
extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
|
||||||
extern void Cocoa_SetWindowMinimumSize(_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_ShowWindow(_THIS, SDL_Window * window);
|
||||||
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
|
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
|
||||||
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
|
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
|
||||||
|
|
|
@ -740,7 +740,22 @@ Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
||||||
minSize.width = window->min_w;
|
minSize.width = window->min_w;
|
||||||
minSize.height = window->min_h;
|
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];
|
[pool release];
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,6 +447,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
int x, y;
|
int x, y;
|
||||||
int w, h;
|
int w, h;
|
||||||
int min_w, min_h;
|
int min_w, min_h;
|
||||||
|
int max_w, max_h;
|
||||||
int style;
|
int style;
|
||||||
BOOL menu;
|
BOOL menu;
|
||||||
|
|
||||||
|
@ -462,11 +463,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
/* Calculate current size of our window */
|
/* Calculate current size of our window */
|
||||||
SDL_GetWindowSize(data->window, &w, &h);
|
SDL_GetWindowSize(data->window, &w, &h);
|
||||||
SDL_GetWindowMinimumSize(data->window, &min_w, &min_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
|
/* Store in min_w and min_h difference between current size and minimal
|
||||||
size so we don't need to call AdjustWindowRectEx twice */
|
size so we don't need to call AdjustWindowRectEx twice */
|
||||||
min_w -= w;
|
min_w -= w;
|
||||||
min_h -= h;
|
min_h -= h;
|
||||||
|
max_w -= w;
|
||||||
|
max_h -= h;
|
||||||
|
|
||||||
size.top = 0;
|
size.top = 0;
|
||||||
size.left = 0;
|
size.left = 0;
|
||||||
|
@ -489,6 +493,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
|
if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
|
||||||
info->ptMinTrackSize.x = w + min_w;
|
info->ptMinTrackSize.x = w + min_w;
|
||||||
info->ptMinTrackSize.y = h + min_h;
|
info->ptMinTrackSize.y = h + min_h;
|
||||||
|
info->ptMaxTrackSize.x = w + max_w;
|
||||||
|
info->ptMaxTrackSize.y = h + max_h;
|
||||||
} else {
|
} else {
|
||||||
info->ptMaxSize.x = w;
|
info->ptMaxSize.x = w;
|
||||||
info->ptMaxSize.y = h;
|
info->ptMaxSize.y = h;
|
||||||
|
|
|
@ -80,6 +80,15 @@ main(int argc, char *argv[])
|
||||||
SDLTest_CommonEvent(state, &event, &done);
|
SDLTest_CommonEvent(state, &event, &done);
|
||||||
|
|
||||||
if (event.type == SDL_WINDOWEVENT) {
|
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) {
|
if (event.window.event == SDL_WINDOWEVENT_MOVED) {
|
||||||
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
|
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
|
||||||
if (window) {
|
if (window) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue