Mac: Fixed SDL_SetWindowSize to set the size of the content area of the window, rather than the total size including decorations.
authorAlex Szpakowski <slime73@gmail.com>
Wed, 09 Sep 2015 13:55:11 -0300
changeset 9860858a9b80e18a
parent 9859 2ec928ff921c
child 9861 2117766ff8d2
Mac: Fixed SDL_SetWindowSize to set the size of the content area of the window, rather than the total size including decorations.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Sep 07 13:25:36 2015 -0400
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Wed Sep 09 13:55:11 2015 -0300
     1.3 @@ -1288,13 +1288,23 @@
     1.4  {
     1.5      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
     1.6      NSWindow *nswindow = windata->nswindow;
     1.7 +    NSRect rect;
     1.8 +    Uint32 moveHack;
     1.9  
    1.10 -    NSRect frame = [nswindow frame];
    1.11 -    frame.origin.y = (frame.origin.y + frame.size.height) - ((float) window->h);
    1.12 -    frame.size.width = window->w;
    1.13 -    frame.size.height = window->h;
    1.14 +    /* Cocoa will resize the window from the bottom-left rather than the
    1.15 +     * top-left when -[nswindow setContentSize:] is used, so we must set the
    1.16 +     * entire frame based on the new size, in order to preserve the position.
    1.17 +     */
    1.18 +    rect.origin.x = window->x;
    1.19 +    rect.origin.y = window->y;
    1.20 +    rect.size.width = window->w;
    1.21 +    rect.size.height = window->h;
    1.22 +    ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
    1.23  
    1.24 -    [nswindow setFrame:frame display:YES];
    1.25 +    moveHack = s_moveHack;
    1.26 +    s_moveHack = 0;
    1.27 +    [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
    1.28 +    s_moveHack = moveHack;
    1.29  
    1.30      ScheduleContextUpdates(windata);
    1.31  }}