mirror of
https://github.com/AxioDL/boo.git
synced 2025-06-09 16:13:33 +00:00
Reformat Objective-C code with new style
This commit is contained in:
parent
9658d1372d
commit
2135f4e4dc
File diff suppressed because it is too large
Load Diff
@ -19,22 +19,19 @@
|
|||||||
#define COCOA_TERMINATE 1
|
#define COCOA_TERMINATE 1
|
||||||
|
|
||||||
namespace boo { class ApplicationCocoa; }
|
namespace boo { class ApplicationCocoa; }
|
||||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
@interface AppDelegate : NSObject <NSApplicationDelegate> {
|
||||||
{
|
|
||||||
boo::ApplicationCocoa* m_app;
|
boo::ApplicationCocoa* m_app;
|
||||||
@public
|
@public
|
||||||
}
|
}
|
||||||
- (id)initWithApp:(boo::ApplicationCocoa*)app;
|
- (id)initWithApp:(boo::ApplicationCocoa*)app;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
namespace boo
|
namespace boo {
|
||||||
{
|
|
||||||
static logvisor::Module Log("boo::ApplicationCocoa");
|
static logvisor::Module Log("boo::ApplicationCocoa");
|
||||||
|
|
||||||
std::shared_ptr<IWindow> _WindowCocoaNew(SystemStringView title, MetalContext* metalCtx);
|
std::shared_ptr<IWindow> _WindowCocoaNew(SystemStringView title, MetalContext* metalCtx);
|
||||||
|
|
||||||
class ApplicationCocoa : public IApplication
|
class ApplicationCocoa : public IApplication {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
IApplicationCallback& m_callback;
|
IApplicationCallback& m_callback;
|
||||||
AppDelegate* m_appDelegate;
|
AppDelegate* m_appDelegate;
|
||||||
@ -54,8 +51,7 @@ private:
|
|||||||
GLContext m_glCtx;
|
GLContext m_glCtx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void _deletedWindow(IWindow* window)
|
void _deletedWindow(IWindow* window) {
|
||||||
{
|
|
||||||
m_windows.erase(window->getPlatformHandle());
|
m_windows.erase(window->getPlatformHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,8 +69,7 @@ public:
|
|||||||
m_uniqueName(uniqueName),
|
m_uniqueName(uniqueName),
|
||||||
m_friendlyName(friendlyName),
|
m_friendlyName(friendlyName),
|
||||||
m_pname(pname),
|
m_pname(pname),
|
||||||
m_args(args)
|
m_args(args) {
|
||||||
{
|
|
||||||
m_metalCtx.m_sampleCount = samples;
|
m_metalCtx.m_sampleCount = samples;
|
||||||
m_metalCtx.m_anisotropy = anisotropy;
|
m_metalCtx.m_anisotropy = anisotropy;
|
||||||
m_metalCtx.m_pixelFormat = deepColor ? MTLPixelFormatRGBA16Float : MTLPixelFormatBGRA8Unorm;
|
m_metalCtx.m_pixelFormat = deepColor ? MTLPixelFormatRGBA16Float : MTLPixelFormatBGRA8Unorm;
|
||||||
@ -115,19 +110,17 @@ public:
|
|||||||
Log.report(logvisor::Info, "using Metal renderer");
|
Log.report(logvisor::Info, "using Metal renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
EPlatformType getPlatformType() const
|
EPlatformType getPlatformType() const {
|
||||||
{
|
|
||||||
return EPlatformType::Cocoa;
|
return EPlatformType::Cocoa;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::thread m_clientThread;
|
std::thread m_clientThread;
|
||||||
int m_clientReturn = 0;
|
int m_clientReturn = 0;
|
||||||
bool m_terminateNow = false;
|
bool m_terminateNow = false;
|
||||||
int run()
|
|
||||||
{
|
int run() {
|
||||||
/* Spawn client thread */
|
/* Spawn client thread */
|
||||||
m_clientThread = std::thread([&]()
|
m_clientThread = std::thread([&]() {
|
||||||
{
|
|
||||||
std::string thrName = std::string(getFriendlyName()) + " Client Thread";
|
std::string thrName = std::string(getFriendlyName()) + " Client Thread";
|
||||||
logvisor::RegisterThreadName(thrName.c_str());
|
logvisor::RegisterThreadName(thrName.c_str());
|
||||||
|
|
||||||
@ -164,33 +157,27 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit()
|
void quit() {
|
||||||
{
|
|
||||||
[NSApp terminate:nil];
|
[NSApp terminate:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemStringView getUniqueName() const
|
SystemStringView getUniqueName() const {
|
||||||
{
|
|
||||||
return m_uniqueName;
|
return m_uniqueName;
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemStringView getFriendlyName() const
|
SystemStringView getFriendlyName() const {
|
||||||
{
|
|
||||||
return m_friendlyName;
|
return m_friendlyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemStringView getProcessName() const
|
SystemStringView getProcessName() const {
|
||||||
{
|
|
||||||
return m_pname;
|
return m_pname;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<SystemString>& getArgs() const
|
const std::vector<SystemString>& getArgs() const {
|
||||||
{
|
|
||||||
return m_args;
|
return m_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IWindow> newWindow(std::string_view title)
|
std::shared_ptr<IWindow> newWindow(std::string_view title) {
|
||||||
{
|
|
||||||
auto newWindow = _WindowCocoaNew(title, &m_metalCtx);
|
auto newWindow = _WindowCocoaNew(title, &m_metalCtx);
|
||||||
m_windows[newWindow->getPlatformHandle()] = newWindow;
|
m_windows[newWindow->getPlatformHandle()] = newWindow;
|
||||||
return newWindow;
|
return newWindow;
|
||||||
@ -210,6 +197,7 @@ void _CocoaUpdateLastGLCtx(NSOpenGLContext* lastGLCtx)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
IApplication* APP = nullptr;
|
IApplication* APP = nullptr;
|
||||||
|
|
||||||
int ApplicationRun(IApplication::EPlatformType platform,
|
int ApplicationRun(IApplication::EPlatformType platform,
|
||||||
IApplicationCallback& cb,
|
IApplicationCallback& cb,
|
||||||
SystemStringView uniqueName,
|
SystemStringView uniqueName,
|
||||||
@ -220,14 +208,11 @@ int ApplicationRun(IApplication::EPlatformType platform,
|
|||||||
uint32_t samples,
|
uint32_t samples,
|
||||||
uint32_t anisotropy,
|
uint32_t anisotropy,
|
||||||
bool deepColor,
|
bool deepColor,
|
||||||
bool singleInstance)
|
bool singleInstance) {
|
||||||
{
|
|
||||||
std::string thrName = std::string(friendlyName) + " Main Thread";
|
std::string thrName = std::string(friendlyName) + " Main Thread";
|
||||||
logvisor::RegisterThreadName(thrName.c_str());
|
logvisor::RegisterThreadName(thrName.c_str());
|
||||||
@autoreleasepool
|
@autoreleasepool {
|
||||||
{
|
if (!APP) {
|
||||||
if (!APP)
|
|
||||||
{
|
|
||||||
if (platform != IApplication::EPlatformType::Cocoa &&
|
if (platform != IApplication::EPlatformType::Cocoa &&
|
||||||
platform != IApplication::EPlatformType::Auto)
|
platform != IApplication::EPlatformType::Auto)
|
||||||
return 1;
|
return 1;
|
||||||
@ -250,26 +235,27 @@ int ApplicationRun(IApplication::EPlatformType platform,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
- (id)initWithApp:(boo::ApplicationCocoa*)app
|
- (id)initWithApp:(boo::ApplicationCocoa*)app {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
m_app = app;
|
m_app = app;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification*)notification
|
|
||||||
{
|
- (void)applicationDidFinishLaunching:(NSNotification*)notification {
|
||||||
(void) notification;
|
(void) notification;
|
||||||
m_app->run();
|
m_app->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if COCOA_TERMINATE
|
#if COCOA_TERMINATE
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app
|
|
||||||
{
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app {
|
||||||
(void) app;
|
(void) app;
|
||||||
if (m_app->m_terminateNow)
|
if (m_app->m_terminateNow)
|
||||||
return NSTerminateNow;
|
return NSTerminateNow;
|
||||||
m_app->m_callback.appQuitting(m_app);
|
m_app->m_callback.appQuitting(m_app);
|
||||||
return NSTerminateLater;
|
return NSTerminateLater;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app
|
||||||
{
|
{
|
||||||
@ -278,33 +264,33 @@ int ApplicationRun(IApplication::EPlatformType platform,
|
|||||||
return NSTerminateCancel;
|
return NSTerminateCancel;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename
|
|
||||||
{
|
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename {
|
||||||
std::vector<boo::SystemString> strVec;
|
std::vector<boo::SystemString> strVec;
|
||||||
strVec.push_back(boo::SystemString([filename UTF8String]));
|
strVec.push_back(boo::SystemString([filename UTF8String]));
|
||||||
m_app->m_callback.appFilesOpen(boo::APP, strVec);
|
m_app->m_callback.appFilesOpen(boo::APP, strVec);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames
|
|
||||||
{
|
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames {
|
||||||
std::vector<boo::SystemString> strVec;
|
std::vector<boo::SystemString> strVec;
|
||||||
strVec.reserve([filenames count]);
|
strVec.reserve([filenames count]);
|
||||||
for (NSString* str in filenames)
|
for (NSString* str in filenames)
|
||||||
strVec.push_back(boo::SystemString([str UTF8String]));
|
strVec.push_back(boo::SystemString([str UTF8String]));
|
||||||
m_app->m_callback.appFilesOpen(boo::APP, strVec);
|
m_app->m_callback.appFilesOpen(boo::APP, strVec);
|
||||||
}
|
}
|
||||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender
|
|
||||||
{
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
|
||||||
(void) sender;
|
(void) sender;
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
- (IBAction)toggleFs:(id)sender
|
|
||||||
{
|
- (IBAction)toggleFs:(id)sender {
|
||||||
(void) sender;
|
(void) sender;
|
||||||
[[NSApp keyWindow] toggleFullScreen:nil];
|
[[NSApp keyWindow] toggleFullScreen:nil];
|
||||||
}
|
}
|
||||||
- (IBAction)quitApp:(id)sender
|
|
||||||
{
|
- (IBAction)quitApp:(id)sender {
|
||||||
(void) sender;
|
(void) sender;
|
||||||
[NSApp terminate:nil];
|
[NSApp terminate:nil];
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user