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

Commit

Permalink
SetMinimumWindowSize for OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
stopiccot committed Nov 18, 2012
1 parent 0213022 commit 4b5e221
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .hgignore
Expand Up @@ -23,6 +23,10 @@ build
*.pbxuser
(^|/)build($|/)
.DS_Store
Xcode/SDL/SDL.xcodeproj/xcuserdata
Xcode/SDL/SDL.xcodeproj/project.xcworkspace/xcuserdata
Xcode/SDL/SDLTest.xcodeproj/xcuserdata
Xcode/SDL/SDLTest.xcodeproj/project.xcworkspace/xcuserdata

# for Visual C++
Debug
Expand Down
19 changes: 19 additions & 0 deletions include/SDL_video.h
Expand Up @@ -517,6 +517,25 @@ extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w,
*/
extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
int *h);

/**
* \brief Set the minimum size of a window's client area.
*
* \note You can't change the minimum size of a fullscreen window, it
* automatically matches the size of the display mode.
*
* \sa SDL_GetWindowMinimumSize()
*/
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_SetWindowMinimumSize()
*/
extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
int *w, int *h);

/**
* \brief Set the border state of a window.
Expand Down
2 changes: 2 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -74,6 +74,7 @@ struct SDL_Window
char *title;
int x, y;
int w, h;
int min_w, min_h;
Uint32 flags;

/* Stored position and size for windowed mode */
Expand Down Expand Up @@ -181,6 +182,7 @@ struct SDL_VideoDevice
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
void (*SetWindowPosition) (_THIS, SDL_Window * window);
void (*SetWindowSize) (_THIS, SDL_Window * window);
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
void (*ShowWindow) (_THIS, SDL_Window * window);
void (*HideWindow) (_THIS, SDL_Window * window);
void (*RaiseWindow) (_THIS, SDL_Window * window);
Expand Down
52 changes: 40 additions & 12 deletions src/video/SDL_video.c
Expand Up @@ -1563,19 +1563,47 @@ SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
CHECK_WINDOW_MAGIC(window, );

if (_this && window && window->magic == &_this->window_magic) {
if (w) {
*w = window->w;
}
if (h) {
*h = window->h;
}
} else {
if (w) {
*w = 0;
}
if (h) {
*h = 0;
*w = window->w;
*h = window->h;
}
}

void
SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
{
CHECK_WINDOW_MAGIC(window, );

if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
window->min_w = min_w;
window->min_h = min_h;
if (_this->SetWindowMinimumSize) {
_this->SetWindowMinimumSize(_this, window);
}
/* Ensure that window is not smaller than minimal size */
SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
}
}

void
SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
{
int dummy;

if (!min_w) {
min_w = &dummy;
}
if (!min_h) {
min_h = &dummy;
}

*min_w = 0;
*min_h = 0;

CHECK_WINDOW_MAGIC(window, );

if (_this && window && window->magic == &_this->window_magic) {
*min_w = window->min_w;
*min_h = window->min_h;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -95,6 +95,7 @@
device->SetWindowIcon = Cocoa_SetWindowIcon;
device->SetWindowPosition = Cocoa_SetWindowPosition;
device->SetWindowSize = Cocoa_SetWindowSize;
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
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 @@ -94,6 +94,7 @@ extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
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_ShowWindow(_THIS, SDL_Window * window);
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
Expand Down
15 changes: 15 additions & 0 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -730,6 +730,21 @@ - (void)rightMouseDown:(NSEvent *)theEvent
[pool release];
}

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

NSSize minSize;
minSize.width = window->min_w;
minSize.height = window->min_h;

[windata->nswindow setMinSize:minSize];

[pool release];
}

void
Cocoa_ShowWindow(_THIS, SDL_Window * window)
{
Expand Down

0 comments on commit 4b5e221

Please sign in to comment.