diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 0685aca6cd..d3bb79281b 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -21,7 +21,7 @@ endif (APPLE) configure_file(InterfaceConfig.h.in ${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h) # grab the implementation and header files from src dir -file(GLOB INTERFACE_SRCS src/*.cpp src/*.h) +file(GLOB INTERFACE_SRCS src/*.mm src/*.cpp src/*.h) if (APPLE) # set how the icon shows up in the Info.plist file diff --git a/interface/src/InterfaceMacOSX.h b/interface/src/InterfaceMacOSX.h new file mode 100644 index 0000000000..2b36ff811f --- /dev/null +++ b/interface/src/InterfaceMacOSX.h @@ -0,0 +1,8 @@ +#ifndef __interface__InterfaceMacOSX +#define __interface__InterfaceMacOSX + +class Oscilloscope; + +void initMacOSXMenu(Oscilloscope *audioScope); + +#endif diff --git a/interface/src/InterfaceMacOSX.mm b/interface/src/InterfaceMacOSX.mm new file mode 100644 index 0000000000..466212207b --- /dev/null +++ b/interface/src/InterfaceMacOSX.mm @@ -0,0 +1,68 @@ +#include "Oscilloscope.h" + +#import +#import + +#import "InterfaceMacOSX.h" + +@class InterfaceMainMenuTarget; + +static InterfaceMainMenuTarget *sharedInterfaceMainMenuTarget = nil; +static Oscilloscope *sharedAudioScope; + + +@interface InterfaceMainMenuTarget : NSObject + +@property (strong, nonatomic) NSMenuItem *scopeAudioMenuItem; +@property (strong, nonatomic) NSMenuItem *scopeNoneMenuItem; + +@end + + +@implementation InterfaceMainMenuTarget + +- (void)scopeAudioAction { + sharedAudioScope->setState(true); + [self.scopeAudioMenuItem setState:NSOnState]; + [self.scopeNoneMenuItem setState:NSOffState]; +} + +- (void)scopeNoneAction { + sharedAudioScope->setState(false); + [self.scopeAudioMenuItem setState:NSOffState]; + [self.scopeNoneMenuItem setState:NSOnState]; +} + +@end + + +void initMacOSXMenu(Oscilloscope *audioScope) { + @autoreleasepool { + if (NSApp) { + if (!sharedInterfaceMainMenuTarget) { + sharedInterfaceMainMenuTarget = [[InterfaceMainMenuTarget alloc] init]; + } + sharedAudioScope = audioScope; + + NSMenu *mainMenu = [NSApp mainMenu]; + + NSMenuItem *scopeMenuItem = [mainMenu insertItemWithTitle:@"Scope" + action:nil + keyEquivalent:@"" + atIndex:3]; + + NSMenu *scopeMenu = [[[NSMenu alloc] init] initWithTitle:@"Scope"]; + [scopeMenuItem setSubmenu:scopeMenu]; + sharedInterfaceMainMenuTarget.scopeAudioMenuItem = [scopeMenu addItemWithTitle:@"Audio" + action:@selector(scopeAudioAction) + keyEquivalent:@""]; + [sharedInterfaceMainMenuTarget.scopeAudioMenuItem setTarget:sharedInterfaceMainMenuTarget]; + [sharedInterfaceMainMenuTarget.scopeAudioMenuItem setState:NSOnState]; + + sharedInterfaceMainMenuTarget.scopeNoneMenuItem = [scopeMenu addItemWithTitle:@"None" + action:@selector(scopeNoneAction) + keyEquivalent:@""]; + [sharedInterfaceMainMenuTarget.scopeNoneMenuItem setTarget:sharedInterfaceMainMenuTarget]; + } + } +} diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 52e602df6a..663e2628dc 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -44,6 +44,12 @@ #include "Oscilloscope.h" #include "UDPSocket.h" +#ifdef __APPLE__ + +#include "InterfaceMacOSX.h" + +#endif + using namespace std; int audio_on = 1; // Whether to turn on the audio support @@ -956,7 +962,11 @@ int main(int argc, char** argv) printf( "Init() complete.\n" ); glutTimerFunc(1000, Timer, 0); - + +#ifdef __APPLE__ + initMacOSXMenu(&audioScope); +#endif + glutMainLoop(); ::terminate();