diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm index cb115d3..6ddf4f8 100644 --- a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm @@ -1,10 +1,9 @@ #import "AerofoilAppDelegate.h" -#import "About.h" +#import "AerofoilApplication.h" #include "WindowManager.h" #include "GliderDefines.h" // kPlayMode extern short theMode; -void DoSettingsMain(void); @interface AerofoilAppDelegate () @@ -17,19 +16,13 @@ void DoSettingsMain(void); @implementation AerofoilAppDelegate - (IBAction)showAboutAerofoil:(id)sender { - [self performAsynchronously:DoAboutFramework]; + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutAerofoil]; } - (IBAction)showAboutGliderPRO:(id)sender { - [self performAsynchronously:DoAbout]; + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutGliderPRO]; } - (IBAction)showPreferences:(id)sender { - [self performAsynchronously:DoSettingsMain]; -} - -- (void)performAsynchronously:(void(*)())function { - dispatch_async(dispatch_get_main_queue(), ^{ - function(); - }); + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kPreferences]; } - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.h b/AerofoilMac/AerofoilMac/AerofoilApplication.h index 537b2ec..79e4cd5 100644 --- a/AerofoilMac/AerofoilMac/AerofoilApplication.h +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.h @@ -1,9 +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 index 7ec1389..616b3c4 100644 --- a/AerofoilMac/AerofoilMac/AerofoilApplication.mm +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.mm @@ -1,4 +1,6 @@ #import "AerofoilApplication.h" +#include "IGpVOSEventQueue.h" +#include "GpAppInterface.h" #include "SDL.h" @implementation AerofoilApplication @@ -10,4 +12,17 @@ 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/GpApp/Events.cpp b/GpApp/Events.cpp index 67199bc..0f83b74 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -466,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/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; } }