64 lines
2.5 KiB
Text
64 lines
2.5 KiB
Text
|
#include <Foundation/Foundation.h>
|
||
|
#include <Cocoa/Cocoa.h>
|
||
|
#include <SDL.h>
|
||
|
#include <log.hpp>
|
||
|
NSWindow *window;
|
||
|
NSTitlebarAccessoryViewController *controller;
|
||
|
NSView *titlebarDummyView;
|
||
|
extern "C++" {
|
||
|
SDL_Window *CreateWindow() {
|
||
|
window = [[NSWindow alloc] init];
|
||
|
controller = [[NSTitlebarAccessoryViewController alloc] init];
|
||
|
titlebarDummyView = [[NSView alloc] init];
|
||
|
[controller setView:titlebarDummyView];
|
||
|
[controller setLayoutAttribute:NSLayoutAttributeLeft];
|
||
|
[window addTitlebarAccessoryViewController:controller];
|
||
|
return SDL_CreateWindowFrom((void*)[window contentView]);
|
||
|
}
|
||
|
void SetWindowProperties(bool enableBorderless) {
|
||
|
NSWindowStyleMask windowMask = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskTitled;
|
||
|
if (enableBorderless) {
|
||
|
windowMask |= NSWindowStyleMaskFullSizeContentView;
|
||
|
}
|
||
|
[window setTitleVisibility: enableBorderless ? NSWindowTitleHidden : NSWindowTitleVisible];
|
||
|
[window setStyleMask: windowMask];
|
||
|
[window setTitlebarAppearsTransparent: enableBorderless];
|
||
|
NSView *contentView = [window contentView];
|
||
|
NSView *frameView = [contentView superview];
|
||
|
for (NSTrackingArea *trackingArea : [frameView trackingAreas]) {
|
||
|
[contentView addTrackingArea:trackingArea];
|
||
|
DEBUG.writeln("Adding tracking area...");
|
||
|
}
|
||
|
}
|
||
|
float GetPostButtonPos() {
|
||
|
NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
|
||
|
NSButton *zoomButton = [window standardWindowButton:NSWindowZoomButton];
|
||
|
NSButton *miniatureButton = [window standardWindowButton:NSWindowMiniaturizeButton];
|
||
|
NSRect closeRect = closeButton.frame;
|
||
|
NSRect zoomRect = zoomButton.frame;
|
||
|
NSRect miniatureRect = miniatureButton.frame;
|
||
|
float closeX = NSMinX(closeRect);
|
||
|
float zoomX = NSMinX(zoomRect);
|
||
|
float miniatureX = NSMinX(miniatureRect);
|
||
|
float zoomEndX = NSMaxX(zoomRect);
|
||
|
return zoomEndX;
|
||
|
}
|
||
|
void SetMenubarWidth(float width) {
|
||
|
[titlebarDummyView setBounds:NSMakeRect(0, 0, width, 0)];
|
||
|
}
|
||
|
float GetTitlebarHeight() {
|
||
|
NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
|
||
|
NSRect closeRect = closeButton.frame;
|
||
|
float topY = NSMinY(closeRect);
|
||
|
float bottomY = NSMaxY(closeRect);
|
||
|
return bottomY;// + topY;
|
||
|
}
|
||
|
|
||
|
void SetSubtitle(const char *str) {
|
||
|
[window setSubtitle: [NSString stringWithUTF8String:str]];
|
||
|
}
|
||
|
void SetTitle(const char *str) {
|
||
|
[window setTitle: [NSString stringWithUTF8String:str]];
|
||
|
}
|
||
|
}
|