diff --git a/.gitignore b/.gitignore index 390e353..cc91ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ SDL2-2.0.12/sdl2.pc SDL2-2.0.12/sdl2-config install_manifest.txt +## macOS +.DS_Store ## Xcode projects AerofoilMac/xcuserdata/ diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index 0416bf5..df9ab65 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -7,8 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 4A04C5AC269AD58E009F5CA3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */; }; + 4A04C5AF269AD600009F5CA3 /* AerofoilAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */; }; + 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */; }; + 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B0269AE243009F5CA3 /* MacInit.mm */; }; + 4A2818FE26BBDD35005A36C0 /* CompositeRenderedFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */; }; + 4A2818FF26BBDD35005A36C0 /* CompositeRenderedFont.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */; }; + 4AA1EB5C26BF9556001D8CC6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */; }; 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D09F2629B42400AB55E0 /* Assets.xcassets */; }; - 5C54D0A32629B42400AB55E0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D0A12629B42400AB55E0 /* Main.storyboard */; }; 5C54D0BE2629B72000AB55E0 /* stb_image_write.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C54D0BC2629B72000AB55E0 /* stb_image_write.h */; }; 5C54D0BF2629B72000AB55E0 /* stb_image_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D0BD2629B72000AB55E0 /* stb_image_write.c */; }; 5C54D26D2629B86700AB55E0 /* adler32.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D25E2629B86600AB55E0 /* adler32.c */; }; @@ -589,9 +595,18 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 4A04C59E269AD58E009F5CA3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 4A04C5AD269AD600009F5CA3 /* AerofoilAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AerofoilAppDelegate.h; sourceTree = ""; }; + 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AerofoilAppDelegate.mm; sourceTree = ""; usesTabs = 1; }; + 4A04C5B0269AE243009F5CA3 /* MacInit.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MacInit.mm; sourceTree = ""; }; + 4A04C5B2269AE368009F5CA3 /* MacInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MacInit.h; sourceTree = ""; }; + 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AerofoilApplication.h; sourceTree = ""; }; + 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompositeRenderedFont.cpp; path = CompositeRenderedFont.cpp; sourceTree = ""; }; + 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CompositeRenderedFont.h; path = CompositeRenderedFont.h; sourceTree = ""; }; + 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AerofoilApplication.mm; sourceTree = ""; }; + 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 5C54D0962629B42100AB55E0 /* Aerofoil.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aerofoil.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5C54D09F2629B42400AB55E0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 5C54D0A22629B42400AB55E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 5C54D0A42629B42400AB55E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5C54D0A72629B42400AB55E0 /* AerofoilMac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AerofoilMac.entitlements; sourceTree = ""; }; 5C54D0B32629B5C600AB55E0 /* libAerofoilShared.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAerofoilShared.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1019,6 +1034,7 @@ files = ( 5C54D636262D7E4800AB55E0 /* SDL2.framework in Frameworks */, 5C54D635262D7E4100AB55E0 /* libAerofoilShared.a in Frameworks */, + 4AA1EB5C26BF9556001D8CC6 /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1042,6 +1058,7 @@ 5C54D687262D8AC400AB55E0 /* Resources */, ); sourceTree = ""; + usesTabs = 1; }; 5C54D0972629B42100AB55E0 /* Products */ = { isa = PBXGroup; @@ -1064,10 +1081,16 @@ 5C54D656262D84A800AB55E0 /* GpLogDriver_X.cpp */, 5C54D659262D84A900AB55E0 /* GpLogDriver_X.h */, 5C54D654262D84A800AB55E0 /* GpMain_SDL_X.cpp */, + 4A04C5B0269AE243009F5CA3 /* MacInit.mm */, + 4A04C5B2269AE368009F5CA3 /* MacInit.h */, 5C54D655262D84A800AB55E0 /* GpSystemServices_X.cpp */, 5C54D658262D84A900AB55E0 /* GpSystemServices_X.h */, 5C54D0A42629B42400AB55E0 /* Info.plist */, - 5C54D0A12629B42400AB55E0 /* Main.storyboard */, + 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */, + 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */, + 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */, + 4A04C5AD269AD600009F5CA3 /* AerofoilAppDelegate.h */, + 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */, ); path = AerofoilMac; sourceTree = ""; @@ -1150,6 +1173,8 @@ 5C54D2B12629BC6800AB55E0 /* CFileStream.cpp */, 5C54D2AE2629BC6800AB55E0 /* CFileStream.h */, 5C54D2B52629BC6800AB55E0 /* CombinedTimestamp.h */, + 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */, + 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */, 5C54D2FC2629BC6800AB55E0 /* DataTypes.h */, 5C54D2D62629BC6800AB55E0 /* DeflateCodec.cpp */, 5C54D2EB2629BC6800AB55E0 /* DeflateCodec.h */, @@ -1490,6 +1515,7 @@ 5C54D5D5262D746E00AB55E0 /* Frameworks */ = { isa = PBXGroup; children = ( + 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */, 5C54D5D6262D759500AB55E0 /* SDL.xcodeproj */, ); name = Frameworks; @@ -1614,6 +1640,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 4A2818FF26BBDD35005A36C0 /* CompositeRenderedFont.h in Headers */, 5C54D44B2629BC6D00AB55E0 /* FontFamilyID.h in Headers */, 5CB787212639D1D800D8FDB6 /* GpAllocator_C.h in Headers */, 5C54D38C2629BC6A00AB55E0 /* EllipsePlotter.h in Headers */, @@ -1980,7 +2007,7 @@ buildActionMask = 2147483647; files = ( 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */, - 5C54D0A32629B42400AB55E0 /* Main.storyboard in Resources */, + 4A04C5AC269AD58E009F5CA3 /* MainMenu.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1996,8 +2023,10 @@ 5C54D67A262D889D00AB55E0 /* DrawQuad32P.cpp in Sources */, 5C54D67B262D889D00AB55E0 /* CopyQuadP.cpp in Sources */, 5C54D669262D886900AB55E0 /* GpThreadEvent_Cpp11.cpp in Sources */, + 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.mm in Sources */, 5C54D65B262D84A900AB55E0 /* GpMain_SDL_X.cpp in Sources */, 5C54D67C262D889E00AB55E0 /* DrawQuadPaletteP.cpp in Sources */, + 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */, 5C54D679262D889D00AB55E0 /* GpDisplayDriver_SDL_GL2.cpp in Sources */, 5C54D67F262D889E00AB55E0 /* GpAudioDriver_SDL2.cpp in Sources */, 5C54D668262D886900AB55E0 /* GpSystemServices_POSIX.cpp in Sources */, @@ -2005,6 +2034,7 @@ 5C54D65C262D84A900AB55E0 /* GpSystemServices_X.cpp in Sources */, 5C54D67D262D889E00AB55E0 /* ScaleQuadP.cpp in Sources */, 5C54D678262D889D00AB55E0 /* GpInputDriver_SDL_Gamepad.cpp in Sources */, + 4A04C5AF269AD600009F5CA3 /* AerofoilAppDelegate.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2183,6 +2213,7 @@ 5C54D4282629BC6C00AB55E0 /* RandomNumberGenerator.cpp in Sources */, 5C54D550262B3C2E00AB55E0 /* DynamicMaps.cpp in Sources */, 5C54D4502629BC6D00AB55E0 /* PLButtonWidget.cpp in Sources */, + 4A2818FE26BBDD35005A36C0 /* CompositeRenderedFont.cpp in Sources */, 5C54D568262B3C2E00AB55E0 /* Scoreboard.cpp in Sources */, 5C54D596262B3C2F00AB55E0 /* Link.cpp in Sources */, ); @@ -2199,12 +2230,12 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ - 5C54D0A12629B42400AB55E0 /* Main.storyboard */ = { + 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( - 5C54D0A22629B42400AB55E0 /* Base */, + 4A04C59E269AD58E009F5CA3 /* Base */, ); - name = Main.storyboard; + name = MainMenu.xib; sourceTree = ""; }; /* End PBXVariantGroup section */ @@ -2348,7 +2379,6 @@ "@executable_path/../Frameworks", ); MARKETING_VERSION = 1.1.0; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.madthijs.AerofoilMac; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -2382,7 +2412,6 @@ "@executable_path/../Frameworks", ); MARKETING_VERSION = 1.1.0; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.madthijs.AerofoilMac; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.h b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.h new file mode 100644 index 0000000..48808e4 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.h @@ -0,0 +1,9 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface AerofoilAppDelegate : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm new file mode 100644 index 0000000..6ddf4f8 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm @@ -0,0 +1,43 @@ +#import "AerofoilAppDelegate.h" +#import "AerofoilApplication.h" +#include "WindowManager.h" +#include "GliderDefines.h" // kPlayMode + +extern short theMode; + +@interface AerofoilAppDelegate () + +@property (weak) IBOutlet NSMenuItem *aboutAerofoilMenuItem; +@property (weak) IBOutlet NSMenuItem *aboutGliderPROMenuItem; +@property (weak) IBOutlet NSMenuItem *preferencesMenuItem; + +@end + +@implementation AerofoilAppDelegate + +- (IBAction)showAboutAerofoil:(id)sender { + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutAerofoil]; +} +- (IBAction)showAboutGliderPRO:(id)sender { + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutGliderPRO]; +} +- (IBAction)showPreferences:(id)sender { + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kPreferences]; +} + +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { + if (menuItem == _aboutAerofoilMenuItem || menuItem == _aboutGliderPROMenuItem) { + return ![self menuItemsDisabled]; + } else if (menuItem == _preferencesMenuItem) { + return ![self menuItemsDisabled]; + } else { + return NO; + } +} + +- (BOOL)menuItemsDisabled { + PortabilityLayer::WindowManager* wm = PortabilityLayer::WindowManager::GetInstance(); + return theMode == kPlayMode || wm->IsExclusiveWindowVisible(); +} + +@end diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.h b/AerofoilMac/AerofoilMac/AerofoilApplication.h new file mode 100644 index 0000000..79e4cd5 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.h @@ -0,0 +1,12 @@ +#import +#include "GpVOSEvent.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface AerofoilApplication : NSApplication + +- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.mm b/AerofoilMac/AerofoilMac/AerofoilApplication.mm new file mode 100644 index 0000000..616b3c4 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.mm @@ -0,0 +1,28 @@ +#import "AerofoilApplication.h" +#include "IGpVOSEventQueue.h" +#include "GpAppInterface.h" +#include "SDL.h" + +@implementation AerofoilApplication + +- (void)terminate:(id)sender { + SDL_Event event; + event.quit.type = SDL_QUIT; + event.quit.timestamp = SDL_GetTicks(); + SDL_PushEvent(&event); +} + +- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent { + GpVOSEvent event; + event.m_eventType = GpVOSEventTypes::kMenuItemSelected; + event.m_event.m_menuItemSelectionEvent = itemEvent; + [self sendVOSEvent:event]; +} + +- (void)sendVOSEvent:(GpVOSEvent)event { + IGpVOSEventQueue* queue = GpAppInterface_Get()->PL_GetDriverCollection()->GetDriver(); + if (GpVOSEvent *evt = queue->QueueEvent()) + *evt = event; +} + +@end diff --git a/AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard b/AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard deleted file mode 100644 index bffcdff..0000000 --- a/AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard +++ /dev/null @@ -1,717 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib b/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib new file mode 100644 index 0000000..9eaf59c --- /dev/null +++ b/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AerofoilMac/AerofoilMac/Info.plist b/AerofoilMac/AerofoilMac/Info.plist index af98330..cb3c356 100644 --- a/AerofoilMac/AerofoilMac/Info.plist +++ b/AerofoilMac/AerofoilMac/Info.plist @@ -24,8 +24,8 @@ public.app-category.arcade-games LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) - NSMainStoryboardFile - Main + NSMainNibFile + MainMenu NSPrincipalClass NSApplication diff --git a/AerofoilMac/AerofoilMac/MacInit.h b/AerofoilMac/AerofoilMac/MacInit.h new file mode 100644 index 0000000..de81670 --- /dev/null +++ b/AerofoilMac/AerofoilMac/MacInit.h @@ -0,0 +1,3 @@ +#pragma once + +int MacInit(void); diff --git a/AerofoilMac/AerofoilMac/MacInit.mm b/AerofoilMac/AerofoilMac/MacInit.mm new file mode 100644 index 0000000..d77408f --- /dev/null +++ b/AerofoilMac/AerofoilMac/MacInit.mm @@ -0,0 +1,22 @@ +#import +#import "AerofoilApplication.h" +#import "AerofoilAppDelegate.h" +#import "MacInit.h" +#include "SDL.h" + +int MacInit(void) { + // Instantiate NSApp and its delegate first, so SDL chooses those over its own implementation. + [AerofoilApplication sharedApplication]; + [[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp topLevelObjects:nil]; + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) + return -1; + + // Gracefully activate app. + // + // (SDL forcefully does this via [NSApp activateIgnoringOtherApps:YES], + // which isn't consistent with normal Mac apps). + [NSApp finishLaunching]; + + return 0; +} diff --git a/AerofoilX/GpMain_SDL_X.cpp b/AerofoilX/GpMain_SDL_X.cpp index f5d5880..74c9bcb 100644 --- a/AerofoilX/GpMain_SDL_X.cpp +++ b/AerofoilX/GpMain_SDL_X.cpp @@ -20,6 +20,7 @@ #include "IGpVOSEventQueue.h" #include +#include "MacInit.h" GpXGlobals g_gpXGlobals; @@ -40,7 +41,11 @@ SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]) enableLogging = true; } +#ifndef __MACOS__ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) +#else + if (MacInit()) +#endif return -1; GpFileSystem_X::GetInstance()->Init(); diff --git a/AerofoilX/GpSystemServices_X.cpp b/AerofoilX/GpSystemServices_X.cpp index d8439dd..32e0f8f 100644 --- a/AerofoilX/GpSystemServices_X.cpp +++ b/AerofoilX/GpSystemServices_X.cpp @@ -107,7 +107,11 @@ bool GpSystemServices_X::HasNativeFileManager() const GpOperatingSystem_t GpSystemServices_X::GetOperatingSystem() const { +#ifdef __MACOS__ + return GpOperatingSystems::kMacOS; +#else return GpOperatingSystems::kLinux; +#endif } GpOperatingSystemFlavor_t GpSystemServices_X::GetOperatingSystemFlavor() const diff --git a/GpApp/About.h b/GpApp/About.h index a90709e..03387d1 100644 --- a/GpApp/About.h +++ b/GpApp/About.h @@ -6,5 +6,5 @@ void DoAbout (void); - +void DoAboutFramework (void); diff --git a/GpApp/Events.cpp b/GpApp/Events.cpp index 657f1a8..0f83b74 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -28,7 +28,7 @@ void HandleOSEvent (EventRecord *); void HandleHighLevelEvent (EventRecord *); void HandleIdleTask (void); void IncrementMode (void); - +void DoEndGame (void); long lastUp, incrementModeTime; @@ -398,6 +398,17 @@ void HandleIdleTask (void) HandleSplashResolutionChange(); } } + +#ifndef COMPILEDEMO + if (quitting) { + if (theMode == kEditMode) { + if (!QuerySaveChanges()) { + quitting = false; + } + } + } +#endif + TickMainMenuUI(); } @@ -455,6 +466,21 @@ void HandleEvent (void) break; } } + else if (theEvent.m_vosEvent.m_eventType == GpVOSEventType_t::kMenuItemSelected) + { + switch (theEvent.m_vosEvent.m_event.m_menuItemSelectionEvent) + { + case GpMenuItemSelectionEvents::kAboutGliderPRO: + DoAbout(); + break; + case GpMenuItemSelectionEvents::kAboutAerofoil: + DoAboutFramework(); + break; + case GpMenuItemSelectionEvents::kPreferences: + DoSettingsMain(); + break; + } + } } else HandleIdleTask(); diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index 4d93dc0..775d4f3 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -3257,7 +3257,11 @@ static ExportHouseResult_t TryExportIcon(GpVector &resData, const THand for (uint8_t i = 0; i < 16; i++) { uint32_t error = 0; - const int16_t deltas[3] = { palette[i].r - color.r, palette[i].g - color.g, palette[i].b - color.b }; + const int16_t deltas[3] = { + static_cast(palette[i].r - color.r), + static_cast(palette[i].g - color.g), + static_cast(palette[i].b - color.b) + }; for (int ch = 0; ch < 3; ch++) error += static_cast(deltas[ch] * deltas[ch]); diff --git a/GpApp/Input.cpp b/GpApp/Input.cpp index 3e0c8d2..dca9837 100644 --- a/GpApp/Input.cpp +++ b/GpApp/Input.cpp @@ -42,6 +42,7 @@ void DoPause (void); void DoTouchScreenMenu (void); void DoBatteryEngaged (gliderPtr); void DoHeliumEngaged (gliderPtr); +void DoEndGame (void); void QuerySaveGame (Boolean &save, Boolean &cancel); @@ -72,27 +73,10 @@ void LogDemoKey (char keyIs) void DoCommandKey (void) { const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); - + if (theKeys->IsSet(PL_KEY_ASCII('Q'))) { - Boolean wantCancel = false; - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) - { - Boolean wantSave = false; - QuerySaveGame(wantSave, wantCancel); - - if (wantSave) - { - // New save game. - if (!SaveGame2()) - wantCancel = true; - } - } - - if (wantCancel) - playing = true; + DoEndGame(); } else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame)) { @@ -337,24 +321,7 @@ void DoTouchScreenMenu(void) switch (highlightedItem) { case TouchScreenMenuItems::kQuit: - { - Boolean wantCancel = false; - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) - { - Boolean wantSave = false; - QuerySaveGame(wantSave, wantCancel); - if (wantSave) - { - if (!SaveGame2()) // New save game. - wantCancel = true; - } - } - - if (wantCancel) - playing = true; - } + DoEndGame(); break; case TouchScreenMenuItems::kSave: assert(!twoPlayerGame); @@ -813,6 +780,28 @@ void GetInput (gliderPtr thisGlider) } } +void DoEndGame() { + Boolean wantCancel = false; + playing = false; + paused = false; + quitting = false; + if ((!twoPlayerGame) && (!demoGoing)) + { + Boolean wantSave = false; + QuerySaveGame(wantSave, wantCancel); + if (wantSave) + { + if (!SaveGame2()) // New save game. + wantCancel = true; + } + } + + if (wantCancel) + { + playing = true; + } +} + //-------------------------------------------------------------- QuerySaveGame void QuerySaveGame (Boolean &save, Boolean &cancel) diff --git a/GpApp/Play.cpp b/GpApp/Play.cpp index 1715dc0..9e2923f 100644 --- a/GpApp/Play.cpp +++ b/GpApp/Play.cpp @@ -46,7 +46,7 @@ void HandleRoomVisitation (void); void SetObjectsToDefaults (void); void InitTelephone (void); void HandleTelephone (void); - +void DoEndGame (void); phoneType thePhone, theChimes; Rect glidSrcRect, justRoomsRect; @@ -717,7 +717,11 @@ void PlayGame (void) HandleDynamicScoreboard(); } } - + + if (quitting) { + DoEndGame(); + } + if (gameOver) { countDown--; diff --git a/GpCommon/GpVOSEvent.h b/GpCommon/GpVOSEvent.h index 80f30a5..cca994c 100644 --- a/GpCommon/GpVOSEvent.h +++ b/GpCommon/GpVOSEvent.h @@ -270,6 +270,17 @@ struct GpVideoResolutionChangedEvent uint32_t m_newHeight; }; +namespace GpMenuItemSelectionEvents +{ + enum GpMenuItemSelectionEvent { + kAboutGliderPRO, + kAboutAerofoil, + kPreferences + }; +} + +typedef GpMenuItemSelectionEvents::GpMenuItemSelectionEvent GpMenuItemSelectionEvent_t; + namespace GpVOSEventTypes { enum GpVOSEventType @@ -279,6 +290,7 @@ namespace GpVOSEventTypes kTouchInput, kGamepadInput, kVideoResolutionChanged, + kMenuItemSelected, kQuit }; } @@ -294,6 +306,7 @@ struct GpVOSEvent GpTouchInputEvent m_touchInputEvent; GpGamepadInputEvent m_gamepadInputEvent; GpVideoResolutionChangedEvent m_resolutionChangedEvent; + GpMenuItemSelectionEvent_t m_menuItemSelectionEvent; }; EventUnion m_event; diff --git a/PortabilityLayer/PLSysCalls.cpp b/PortabilityLayer/PLSysCalls.cpp index 536ea34..e79454c 100644 --- a/PortabilityLayer/PLSysCalls.cpp +++ b/PortabilityLayer/PLSysCalls.cpp @@ -169,6 +169,10 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po appHandler->OnQuit(); break; + case GpVOSEventTypes::kMenuItemSelected: + if (TimeTaggedVOSEvent *evt = queue->Enqueue()) + *evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp); + break; } } diff --git a/PortabilityLayer/RenderedFont.h b/PortabilityLayer/RenderedFont.h index 3eca5c1..3aadd9d 100644 --- a/PortabilityLayer/RenderedFont.h +++ b/PortabilityLayer/RenderedFont.h @@ -1,6 +1,7 @@ #pragma once #include +#include class PLPasStr; struct GpRenderedFontMetrics; diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index 31d26a5..40f9c39 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -186,6 +186,7 @@ namespace PortabilityLayer void SetWindowTitle(Window *window, const PLPasStr &title) override; Rect2i GetWindowFullRect(Window *window) const override; bool GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const override; + bool IsExclusiveWindowVisible() override; void SwapExclusiveWindow(Window *& windowRef) override; void FlickerWindowIn(Window *window, int32_t velocity) GP_ASYNCIFY_PARANOID_OVERRIDE; @@ -1322,6 +1323,10 @@ namespace PortabilityLayer return static_cast(window)->GetChromeInteractionZone(point, outRegion); } + bool WindowManagerImpl::IsExclusiveWindowVisible() { + return m_exclusiveWindow != nullptr; + } + void WindowManagerImpl::SwapExclusiveWindow(Window *& windowRef) { const bool hadExclusiveWindow = (m_exclusiveWindow != nullptr); diff --git a/PortabilityLayer/WindowManager.h b/PortabilityLayer/WindowManager.h index a17483e..613350a 100644 --- a/PortabilityLayer/WindowManager.h +++ b/PortabilityLayer/WindowManager.h @@ -38,6 +38,7 @@ namespace PortabilityLayer virtual void SetWindowTitle(Window *window, const PLPasStr &title) = 0; virtual Rect2i GetWindowFullRect(Window *window) const = 0; virtual bool GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const = 0; + virtual bool IsExclusiveWindowVisible() = 0; virtual void SwapExclusiveWindow(Window *& windowRef) = 0; GP_ASYNCIFY_PARANOID_VIRTUAL void FlickerWindowIn(Window *window, int32_t velocity) GP_ASYNCIFY_PARANOID_PURE;