Reformat Objective-C code with new style

This commit is contained in:
Jack Andersen 2019-02-03 14:00:12 -10:00
parent 9658d1372d
commit 2135f4e4dc
3 changed files with 2645 additions and 2887 deletions

File diff suppressed because it is too large Load Diff

View File

@ -19,22 +19,19 @@
#define COCOA_TERMINATE 1
namespace boo { class ApplicationCocoa; }
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
@interface AppDelegate : NSObject <NSApplicationDelegate> {
boo::ApplicationCocoa* m_app;
@public
}
- (id)initWithApp:(boo::ApplicationCocoa*)app;
@end
namespace boo
{
namespace boo {
static logvisor::Module Log("boo::ApplicationCocoa");
std::shared_ptr<IWindow> _WindowCocoaNew(SystemStringView title, MetalContext* metalCtx);
class ApplicationCocoa : public IApplication
{
class ApplicationCocoa : public IApplication {
public:
IApplicationCallback& m_callback;
AppDelegate* m_appDelegate;
@ -54,8 +51,7 @@ private:
GLContext m_glCtx;
#endif
void _deletedWindow(IWindow* window)
{
void _deletedWindow(IWindow* window) {
m_windows.erase(window->getPlatformHandle());
}
@ -73,8 +69,7 @@ public:
m_uniqueName(uniqueName),
m_friendlyName(friendlyName),
m_pname(pname),
m_args(args)
{
m_args(args) {
m_metalCtx.m_sampleCount = samples;
m_metalCtx.m_anisotropy = anisotropy;
m_metalCtx.m_pixelFormat = deepColor ? MTLPixelFormatRGBA16Float : MTLPixelFormatBGRA8Unorm;
@ -115,19 +110,17 @@ public:
Log.report(logvisor::Info, "using Metal renderer");
}
EPlatformType getPlatformType() const
{
EPlatformType getPlatformType() const {
return EPlatformType::Cocoa;
}
std::thread m_clientThread;
int m_clientReturn = 0;
bool m_terminateNow = false;
int run()
{
int run() {
/* Spawn client thread */
m_clientThread = std::thread([&]()
{
m_clientThread = std::thread([&]() {
std::string thrName = std::string(getFriendlyName()) + " Client Thread";
logvisor::RegisterThreadName(thrName.c_str());
@ -164,33 +157,27 @@ public:
return 0;
}
void quit()
{
void quit() {
[NSApp terminate:nil];
}
SystemStringView getUniqueName() const
{
SystemStringView getUniqueName() const {
return m_uniqueName;
}
SystemStringView getFriendlyName() const
{
SystemStringView getFriendlyName() const {
return m_friendlyName;
}
SystemStringView getProcessName() const
{
SystemStringView getProcessName() const {
return m_pname;
}
const std::vector<SystemString>& getArgs() const
{
const std::vector<SystemString>& getArgs() const {
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);
m_windows[newWindow->getPlatformHandle()] = newWindow;
return newWindow;
@ -210,6 +197,7 @@ void _CocoaUpdateLastGLCtx(NSOpenGLContext* lastGLCtx)
#endif
IApplication* APP = nullptr;
int ApplicationRun(IApplication::EPlatformType platform,
IApplicationCallback& cb,
SystemStringView uniqueName,
@ -220,14 +208,11 @@ int ApplicationRun(IApplication::EPlatformType platform,
uint32_t samples,
uint32_t anisotropy,
bool deepColor,
bool singleInstance)
{
bool singleInstance) {
std::string thrName = std::string(friendlyName) + " Main Thread";
logvisor::RegisterThreadName(thrName.c_str());
@autoreleasepool
{
if (!APP)
{
@autoreleasepool {
if (!APP) {
if (platform != IApplication::EPlatformType::Cocoa &&
platform != IApplication::EPlatformType::Auto)
return 1;
@ -250,26 +235,27 @@ int ApplicationRun(IApplication::EPlatformType platform,
}
@implementation AppDelegate
- (id)initWithApp:(boo::ApplicationCocoa*)app
{
- (id)initWithApp:(boo::ApplicationCocoa*)app {
self = [super init];
m_app = app;
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
- (void)applicationDidFinishLaunching:(NSNotification*)notification {
(void) notification;
m_app->run();
}
#if COCOA_TERMINATE
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app
{
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app {
(void) app;
if (m_app->m_terminateNow)
return NSTerminateNow;
m_app->m_callback.appQuitting(m_app);
return NSTerminateLater;
}
#else
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app
{
@ -278,33 +264,33 @@ int ApplicationRun(IApplication::EPlatformType platform,
return NSTerminateCancel;
}
#endif
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename
{
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename {
std::vector<boo::SystemString> strVec;
strVec.push_back(boo::SystemString([filename UTF8String]));
m_app->m_callback.appFilesOpen(boo::APP, strVec);
return true;
}
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames
{
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames {
std::vector<boo::SystemString> strVec;
strVec.reserve([filenames count]);
for (NSString* str in filenames)
strVec.push_back(boo::SystemString([str UTF8String]));
m_app->m_callback.appFilesOpen(boo::APP, strVec);
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender
{
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
(void) sender;
return YES;
}
- (IBAction)toggleFs:(id)sender
{
- (IBAction)toggleFs:(id)sender {
(void) sender;
[[NSApp keyWindow] toggleFullScreen:nil];
}
- (IBAction)quitApp:(id)sender
{
- (IBAction)quitApp:(id)sender {
(void) sender;
[NSApp terminate:nil];
}

File diff suppressed because it is too large Load Diff