Made glfwGetWindowSize immediate.

Conflicts:
	src/internal.h
This commit is contained in:
Camilla Berglund 2012-11-25 14:53:33 +01:00
parent 075e37d29e
commit c17a7dd464
6 changed files with 82 additions and 46 deletions

View File

@ -690,8 +690,11 @@ static GLboolean createWindow(_GLFWwindow* window,
styleMask |= NSResizableWindowMask; styleMask |= NSResizableWindowMask;
} }
NSRect contentRect = NSMakeRect(wndconfig->positionX, wndconfig->positionY,
wndconfig->width, wndconfig->height);
window->ns.object = [[NSWindow alloc] window->ns.object = [[NSWindow alloc]
initWithContentRect:NSMakeRect(wndconfig->positionX, wndconfig->positionY, window->width, window->height) initWithContentRect:contentRect
styleMask:styleMask styleMask:styleMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
@ -773,7 +776,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{ {
int bpp = colorBits + fbconfig->alphaBits; int bpp = colorBits + fbconfig->alphaBits;
if (!_glfwSetVideoMode(window->monitor, &window->width, &window->height, &bpp)) if (!_glfwSetVideoMode(window->monitor, &window->videoMode.width, &window->videoMode.height, &bpp))
return GL_FALSE; return GL_FALSE;
_glfwPlatformShowWindow(window); _glfwPlatformShowWindow(window);
@ -819,6 +822,17 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
[window->ns.object setTitle:[NSString stringWithUTF8String:title]]; [window->ns.object setTitle:[NSString stringWithUTF8String:title]];
} }
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
NSRect contentRect =
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
if (width)
*width = contentRect.size.width;
if (height)
*height = contentRect.size.height;
}
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{ {
[window->ns.object setContentSize:NSMakeSize(width, height)]; [window->ns.object setContentSize:NSMakeSize(width, height)];

View File

@ -37,7 +37,7 @@
static void setCursorMode(_GLFWwindow* window, int newMode) static void setCursorMode(_GLFWwindow* window, int newMode)
{ {
int oldMode, centerPosX, centerPosY; int width, height, oldMode, centerPosX, centerPosY;
if (newMode != GLFW_CURSOR_NORMAL && if (newMode != GLFW_CURSOR_NORMAL &&
newMode != GLFW_CURSOR_HIDDEN && newMode != GLFW_CURSOR_HIDDEN &&
@ -51,8 +51,10 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
if (oldMode == newMode) if (oldMode == newMode)
return; return;
centerPosX = window->width / 2; _glfwPlatformGetWindowSize(window, &width, &height);
centerPosY = window->height / 2;
centerPosX = width / 2;
centerPosY = height / 2;
if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED) if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetCursorPos(window, centerPosX, centerPosY); _glfwPlatformSetCursorPos(window, centerPosX, centerPosY);

View File

@ -157,6 +157,8 @@ struct _GLFWhints
*/ */
struct _GLFWwndconfig struct _GLFWwndconfig
{ {
int width;
int height;
const char* title; const char* title;
GLboolean resizable; GLboolean resizable;
GLboolean visible; GLboolean visible;
@ -205,7 +207,6 @@ struct _GLFWwindow
struct _GLFWwindow* next; struct _GLFWwindow* next;
// Window settings and state // Window settings and state
int width, height;
int positionX, positionY; int positionX, positionY;
GLboolean iconified; GLboolean iconified;
GLboolean resizable; GLboolean resizable;
@ -460,6 +461,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window);
*/ */
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title); void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
/*! @ingroup platform
*/
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
/*! @ingroup platform /*! @ingroup platform
*/ */
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);

View File

@ -738,7 +738,9 @@ static int createWindow(_GLFWwindow* window,
} }
// Adjust window size for frame and title bar // Adjust window size for frame and title bar
getFullWindowSize(window, window->width, window->height, &fullWidth, &fullHeight); getFullWindowSize(window,
wndconfig->width, wndconfig->height,
&fullWidth, &fullHeight);
if (window->monitor) if (window->monitor)
{ {
@ -915,13 +917,27 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
free(wideTitle); free(wideTitle);
} }
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
RECT area;
GetClientRect(window->win32.handle, &area);
if (width)
*width = area.right;
if (height)
*height = area.bottom;
}
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{ {
GLboolean sizeChanged = GL_FALSE; GLboolean sizeChanged = GL_FALSE;
if (window->monitor) if (window->monitor)
{ {
if (width > window->width || height > window->height) GLFWvidmode mode;
_glfwPlatformGetVideoMode(window->monitor, &mode);
if (width > mode.width || height > mode.height)
{ {
// The new video mode is larger than the current one, so we resize // The new video mode is larger than the current one, so we resize
// the window before switch modes to avoid exposing whatever is // the window before switch modes to avoid exposing whatever is
@ -980,9 +996,11 @@ void _glfwPlatformPollEvents(void)
window = _glfw.focusedWindow; window = _glfw.focusedWindow;
if (window) if (window)
{ {
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
window->win32.cursorCentered = GL_FALSE; window->win32.cursorCentered = GL_FALSE;
window->win32.oldCursorX = window->width / 2; window->win32.oldCursorX = width / 2;
window->win32.oldCursorY = window->height / 2; window->win32.oldCursorY = height / 2;
} }
else else
{ {
@ -1038,9 +1056,9 @@ void _glfwPlatformPollEvents(void)
if (window->cursorMode == GLFW_CURSOR_CAPTURED && if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
!window->win32.cursorCentered) !window->win32.cursorCentered)
{ {
_glfwPlatformSetCursorPos(window, int width, height;
window->width / 2, _glfwPlatformGetWindowSize(window, &width, &height);
window->height / 2); _glfwPlatformSetCursorPos(window, width / 2, height / 2);
window->win32.cursorCentered = GL_TRUE; window->win32.cursorCentered = GL_TRUE;
} }
} }

View File

@ -122,12 +122,6 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height) void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
{ {
if (window->width == width && window->height == height)
return;
window->width = width;
window->height = height;
if (window->callbacks.size) if (window->callbacks.size)
window->callbacks.size((GLFWwindow*) window, width, height); window->callbacks.size((GLFWwindow*) window, width, height);
} }
@ -206,6 +200,8 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
fbconfig.sRGB = _glfw.hints.sRGB ? GL_TRUE : GL_FALSE; fbconfig.sRGB = _glfw.hints.sRGB ? GL_TRUE : GL_FALSE;
// Set up desired window config // Set up desired window config
wndconfig.width = width;
wndconfig.height = height;
wndconfig.title = title; wndconfig.title = title;
wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE; wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE; wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE;
@ -247,8 +243,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
window->videoMode.blueBits = fbconfig.blueBits; window->videoMode.blueBits = fbconfig.blueBits;
} }
window->width = width;
window->height = height;
window->monitor = wndconfig.monitor; window->monitor = wndconfig.monitor;
window->resizable = wndconfig.resizable; window->resizable = wndconfig.resizable;
window->cursorMode = GLFW_CURSOR_NORMAL; window->cursorMode = GLFW_CURSOR_NORMAL;
@ -487,11 +481,7 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
return; return;
} }
if (width != NULL) _glfwPlatformGetWindowSize(window, width, height);
*width = window->width;
if (height != NULL)
*height = window->height;
} }
GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
@ -510,10 +500,6 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
return; return;
} }
// Don't do anything if the window size did not change
if (width == window->width && height == window->height)
return;
if (window->monitor) if (window->monitor)
{ {
window->videoMode.width = width; window->videoMode.width = width;

View File

@ -121,7 +121,7 @@ static GLboolean createWindow(_GLFWwindow* window,
window->x11.handle = XCreateWindow(_glfw.x11.display, window->x11.handle = XCreateWindow(_glfw.x11.display,
_glfw.x11.root, _glfw.x11.root,
wndconfig->positionX, wndconfig->positionY, wndconfig->positionX, wndconfig->positionY,
window->width, window->height, wndconfig->width, wndconfig->height,
0, // Border width 0, // Border width
visual->depth, // Color depth visual->depth, // Color depth
InputOutput, InputOutput,
@ -227,8 +227,8 @@ static GLboolean createWindow(_GLFWwindow* window,
if (!wndconfig->resizable) if (!wndconfig->resizable)
{ {
hints->flags |= (PMinSize | PMaxSize); hints->flags |= (PMinSize | PMaxSize);
hints->min_width = hints->max_width = window->width; hints->min_width = hints->max_width = wndconfig->width;
hints->min_height = hints->max_height = window->height; hints->min_height = hints->max_height = wndconfig->height;
} }
XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints); XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
@ -392,12 +392,15 @@ static void enterFullscreenMode(_GLFWwindow* window)
// In override-redirect mode we have divorced ourselves from the // In override-redirect mode we have divorced ourselves from the
// window manager, so we need to do everything manually // window manager, so we need to do everything manually
GLFWvidmode mode;
_glfwPlatformGetVideoMode(window->monitor, &mode);
XRaiseWindow(_glfw.x11.display, window->x11.handle); XRaiseWindow(_glfw.x11.display, window->x11.handle);
XSetInputFocus(_glfw.x11.display, window->x11.handle, XSetInputFocus(_glfw.x11.display, window->x11.handle,
RevertToParent, CurrentTime); RevertToParent, CurrentTime);
XMoveWindow(_glfw.x11.display, window->x11.handle, 0, 0); XMoveWindow(_glfw.x11.display, window->x11.handle, 0, 0);
XResizeWindow(_glfw.x11.display, window->x11.handle, XResizeWindow(_glfw.x11.display, window->x11.handle,
window->width, window->height); mode.width, mode.height);
} }
} }
@ -893,10 +896,19 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
} }
} }
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
XWindowAttributes attribs;
XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &attribs);
if (width)
*width = attribs.width;
if (height)
*height = attribs.height;
}
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{ {
GLboolean sizeChanged = GL_FALSE;
if (!window->resizable) if (!window->resizable)
{ {
// Update window size restrictions to match new window size // Update window size restrictions to match new window size
@ -913,18 +925,17 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
if (window->monitor) if (window->monitor)
{ {
// Change window size before changing fullscreen mode? if (window->x11.overrideRedirect)
if (width > window->width)
{ {
XResizeWindow(_glfw.x11.display, window->x11.handle, width, height); GLFWvidmode mode;
sizeChanged = GL_TRUE; _glfwPlatformGetVideoMode(window->monitor, &mode);
XResizeWindow(_glfw.x11.display, window->x11.handle,
window->videoMode.width, window->videoMode.height);
} }
_glfwSetVideoMode(window->monitor, &window->videoMode); _glfwSetVideoMode(window->monitor, &window->videoMode);
} }
else
// Set window size (if not already changed)
if (!sizeChanged)
XResizeWindow(_glfw.x11.display, window->x11.handle, width, height); XResizeWindow(_glfw.x11.display, window->x11.handle, width, height);
} }
@ -993,9 +1004,9 @@ void _glfwPlatformPollEvents(void)
if (window->cursorMode == GLFW_CURSOR_CAPTURED && if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
!window->x11.cursorCentered) !window->x11.cursorCentered)
{ {
_glfwPlatformSetCursorPos(window, int width, height;
window->width / 2, _glfwPlatformGetWindowSize(window, &width, &height);
window->height / 2); _glfwPlatformSetCursorPos(window, width / 2, height / 2);
window->x11.cursorCentered = GL_TRUE; window->x11.cursorCentered = GL_TRUE;
// NOTE: This is a temporary fix. It works as long as you use // NOTE: This is a temporary fix. It works as long as you use