Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

SetMinimumWindowSize for OS X

  • Loading branch information
stopiccot committed Nov 18, 2012
1 parent 0213022 commit 4b5e2214a79aa53131004176ce57294daab842ce
@@ -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
@@ -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.
@@ -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 */
@@ -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);
@@ -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;
}
}

@@ -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;
@@ -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);
@@ -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)
{

0 comments on commit 4b5e221

Please sign in to comment.