looper/backends/ui/imgui/RendererBackendOSX.mm
Zachary Hall 51d4ed39ab
Some checks failed
Build / build-gentoo (push) Failing after 14s
Build / download-system-deps (push) Successful in 3m28s
Build / get-source-code (push) Successful in 9m18s
Build / build-deb (push) Failing after 3m41s
Build / build-appimage (push) Successful in 4m12s
Build / build-android (push) Failing after 2m47s
Build / build-windows (push) Failing after 7m10s
Add support for macOS
- Remove unused OpenMP from playback backend
  - Fix update_assets on macOS
  - Add support for Objective C++ on macOS
  - Add macOS-specific code into the Dear ImGui backend
  - Add macOS .app packaging
  - Add support for global menus, and include support for macOS global menu into the Dear ImGui backend
2025-02-09 10:13:46 -08:00

63 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]];
}
}