2015-05-04 23:37:28 +00:00
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
#include "windowsys/IWindow.hpp"
|
|
|
|
#include "windowsys/IGraphicsContext.hpp"
|
|
|
|
|
2015-05-05 07:16:06 +00:00
|
|
|
namespace boo {class CWindowCocoa;}
|
2015-05-04 23:37:28 +00:00
|
|
|
@interface CWindowCocoaInternal : NSWindow
|
2015-05-05 07:16:06 +00:00
|
|
|
{
|
|
|
|
boo::CWindowCocoa* booWindow;
|
|
|
|
}
|
|
|
|
- (id)initWithBooWindow:(boo::CWindowCocoa*)bw;
|
2015-05-04 23:37:28 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
|
|
|
class CWindowCocoa final : public IWindow
|
|
|
|
{
|
|
|
|
|
|
|
|
CWindowCocoaInternal* m_nsWindow;
|
|
|
|
IGraphicsContext* m_gfxCtx;
|
2015-05-05 07:16:06 +00:00
|
|
|
|
2015-05-04 23:37:28 +00:00
|
|
|
public:
|
2015-05-05 07:16:06 +00:00
|
|
|
|
2015-05-04 23:37:28 +00:00
|
|
|
CWindowCocoa()
|
|
|
|
{
|
2015-05-05 07:16:06 +00:00
|
|
|
m_nsWindow = [[CWindowCocoaInternal alloc] initWithBooWindow:this];
|
2015-05-04 23:37:28 +00:00
|
|
|
m_gfxCtx = IGraphicsContextNew(IGraphicsContext::API_OPENGL_3_3);
|
2015-05-05 07:16:06 +00:00
|
|
|
m_gfxCtx->_setPlatformWindowHandle(m_nsWindow);
|
2015-05-04 23:37:28 +00:00
|
|
|
m_gfxCtx->initializeContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
~CWindowCocoa()
|
|
|
|
{
|
|
|
|
[m_nsWindow orderOut:nil];
|
|
|
|
[m_nsWindow release];
|
|
|
|
delete m_gfxCtx;
|
|
|
|
}
|
|
|
|
|
2015-05-05 07:16:06 +00:00
|
|
|
void setCallback(IWindowCallback* cb)
|
|
|
|
{
|
|
|
|
m_gfxCtx->_setCallback(cb);
|
|
|
|
}
|
|
|
|
|
2015-05-04 23:37:28 +00:00
|
|
|
void showWindow()
|
|
|
|
{
|
|
|
|
[m_nsWindow makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
void hideWindow()
|
|
|
|
{
|
|
|
|
[m_nsWindow orderOut:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getTitle()
|
|
|
|
{
|
|
|
|
return [[m_nsWindow title] UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTitle(const std::string& title)
|
|
|
|
{
|
|
|
|
[m_nsWindow setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowFrameDefault()
|
|
|
|
{
|
|
|
|
NSScreen* mainScreen = [NSScreen mainScreen];
|
|
|
|
NSRect scrFrame = mainScreen.frame;
|
|
|
|
float x_off = scrFrame.size.width / 3.0;
|
|
|
|
float y_off = scrFrame.size.height / 3.0;
|
|
|
|
[m_nsWindow setFrame:NSMakeRect(x_off, y_off, x_off * 2.0, y_off * 2.0) display:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
|
|
|
|
{
|
|
|
|
NSRect wFrame = m_nsWindow.frame;
|
|
|
|
xOut = wFrame.origin.x;
|
|
|
|
yOut = wFrame.origin.y;
|
|
|
|
wOut = wFrame.size.width;
|
|
|
|
hOut = wFrame.size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowFrame(float x, float y, float w, float h)
|
|
|
|
{
|
|
|
|
NSRect wFrame = NSMakeRect(x, y, w, h);
|
|
|
|
[m_nsWindow setFrame:wFrame display:NO];
|
|
|
|
}
|
|
|
|
|
2015-05-05 07:16:06 +00:00
|
|
|
float getVirtualPixelFactor() const
|
|
|
|
{
|
|
|
|
return [m_nsWindow backingScaleFactor];
|
|
|
|
}
|
|
|
|
|
2015-05-04 23:37:28 +00:00
|
|
|
bool isFullscreen() const
|
|
|
|
{
|
|
|
|
return ([m_nsWindow styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFullscreen(bool fs)
|
|
|
|
{
|
|
|
|
if ((fs && !isFullscreen()) || (!fs && isFullscreen()))
|
|
|
|
[m_nsWindow toggleFullScreen:nil];
|
|
|
|
}
|
|
|
|
|
2015-05-05 07:16:06 +00:00
|
|
|
ETouchType getTouchType() const
|
|
|
|
{
|
|
|
|
return TOUCH_TRACKPAD;
|
|
|
|
}
|
|
|
|
|
2015-05-04 23:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
IWindow* IWindowNew()
|
|
|
|
{
|
|
|
|
return new CWindowCocoa;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation CWindowCocoaInternal
|
2015-05-05 07:16:06 +00:00
|
|
|
- (id)initWithBooWindow:(boo::CWindowCocoa *)bw
|
2015-05-04 23:37:28 +00:00
|
|
|
{
|
2015-05-05 07:16:06 +00:00
|
|
|
self = [self initWithContentRect:NSMakeRect(0, 0, 100, 100)
|
|
|
|
styleMask:NSTitledWindowMask|
|
|
|
|
NSClosableWindowMask|
|
|
|
|
NSMiniaturizableWindowMask|
|
|
|
|
NSResizableWindowMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES];
|
|
|
|
booWindow = bw;
|
|
|
|
return self;
|
2015-05-04 23:37:28 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|