Implemented fullscreen on OS X.

This commit is contained in:
Pietro Gagliardi 2016-06-16 09:29:28 -04:00
parent 69cafde7f3
commit fd9af04123
2 changed files with 40 additions and 1 deletions

View File

@ -15,6 +15,7 @@ struct uiWindow {
void (*onContentSizeChanged)(uiWindow *, void *);
void *onContentSizeChangedData;
BOOL suppressSizeChanged;
int fullscreen;
};
@interface windowDelegateClass : NSObject<NSWindowDelegate> {
@ -23,6 +24,8 @@ struct uiWindow {
- (BOOL)windowShouldClose:(id)sender;
- (void)windowDidMove:(NSNotification *)note;
- (void)windowDidResize:(NSNotification *)note;
- (void)windowDidEnterFullScreen:(NSNotification *)note;
- (void)windowDidExitFullScreen:(NSNotification *)note;
- (void)registerWindow:(uiWindow *)w;
- (void)unregisterWindow:(uiWindow *)w;
- (uiWindow *)lookupWindow:(NSWindow *)w;
@ -74,6 +77,24 @@ struct uiWindow {
(*(w->onContentSizeChanged))(w, w->onContentSizeChangedData);
}
- (void)windowDidEnterFullScreen:(NSNotification *)note
{
uiWindow *w;
w = [self lookupWindow:((NSWindow *) [note object])];
if (!w->suppressSizeChanged)
w->fullscreen = 1;
}
- (void)windowDidExitFullScreen:(NSNotification *)note
{
uiWindow *w;
w = [self lookupWindow:((NSWindow *) [note object])];
if (!w->suppressSizeChanged)
w->fullscreen = 0;
}
- (void)registerWindow:(uiWindow *)w
{
mapSet(self->windows, w->window, w);
@ -290,6 +311,23 @@ void uiWindowSetContentSize(uiWindow *w, int width, int height)
w->suppressSizeChanged = NO;
}
int uiWindowFullscreen(uiWindow *w)
{
return w->fullscreen;
}
void uiWindowSetFullscreen(uiWindow *w, int fullscreen)
{
if (w->fullscreen && fullscreen)
return;
if (!w->fullscreen && !fullscreen)
return;
w->fullscreen = fullscreen;
w->suppressSizeChanged = YES;
[w->window toggleFullScreen:w->window];
w->suppressSizeChanged = NO;
}
void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data)
{
w->onContentSizeChanged = f;

View File

@ -75,6 +75,7 @@ static void updatesize(uiWindow *w)
uiWindowContentSize(w, &xp, &yp);
uiSpinboxSetValue(width, xp);
uiSpinboxSetValue(height, yp);
// TODO on OS X this is updated AFTER sending the size change, not before
uiCheckboxSetChecked(fullscreen, uiWindowFullscreen(w));
}
@ -88,7 +89,7 @@ void setFullscreen(uiCheckbox *cb, void *data)
{
uiWindow *w = uiWindow(data);
uiWindowSetFullscreen(w, uiCheckboxChecked(tb));
uiWindowSetFullscreen(w, uiCheckboxChecked(fullscreen));
updatesize(w);
}