Added support for refmarks (requires REFMARKS defined)

ver1_5_1
Da Woon Jung 2007-12-30 10:45:49 +00:00
parent 16f45d7b33
commit 0ff9a7e11f
6 changed files with 181 additions and 87 deletions

View File

@ -162,41 +162,59 @@
[appCore mouseButtonDown:location modifiers:[appCore toCelestiaModifiers: 0 buttons:CEL_LEFT_BUTTON]];
[appCore mouseButtonUp:location2 modifiers:[appCore toCelestiaModifiers: 0 buttons:CEL_LEFT_BUTTON]];
NSMenuItem *surfItem = nil;
NSMenuItem *satItem = nil;
int satMenuIndex = -1;
int surfMenuIndex = -1;
int auxItemIndex = -1;
int separatorIndex = -1;
BOOL insertedAuxItem = NO;
[[self menu] removePlanetarySystemItem];
[[self menu] removeAltSurfaceItem];
#if REFMARKS
[[self menu] removeRefMarkItems];
#endif
separatorIndex = [[self menu] numberOfItems] - 4;
if (separatorIndex < 0) separatorIndex = 0;
if ([[[self menu] itemAtIndex: separatorIndex] isSeparatorItem])
++separatorIndex;
if ([[[self menu] itemAtIndex: separatorIndex] isSeparatorItem])
[[self menu] removeItemAtIndex: separatorIndex];
selection = [[appCore simulation] selection];
satItem = [[self menu] addPlanetarySystemItemForSelection: selection
target: controller];
surfItem = [[self menu] addAltSurfaceItemForSelection: selection
target: controller];
if (surfItem)
surfMenuIndex = [[self menu] indexOfItem: surfItem];
if (satItem)
satMenuIndex = [[self menu] indexOfItem: satItem];
#if REFMARKS
auxItemIndex = [[self menu] numberOfItems] - 2;
if (auxItemIndex < 0) auxItemIndex = 0;
insertedAuxItem =
[[self menu] insertRefMarkItemsForSelection: selection
atIndex: auxItemIndex];
#endif
auxItemIndex = [[self menu] numberOfItems] - 2;
if (auxItemIndex < 0) auxItemIndex = 0;
insertedAuxItem =
[[self menu] insertPlanetarySystemItemForSelection: selection
target: controller
atIndex: auxItemIndex]
|| insertedAuxItem;
auxItemIndex = [[self menu] numberOfItems] - 2;
if (auxItemIndex < 0) auxItemIndex = 0;
insertedAuxItem =
[[self menu] insertAltSurfaceItemForSelection: selection
target: controller
atIndex: auxItemIndex]
|| insertedAuxItem;
separatorIndex = (surfMenuIndex > satMenuIndex) ?
surfMenuIndex + 1 :
satMenuIndex + 1;
if (separatorIndex > 0 && separatorIndex < [[self menu] numberOfItems])
if (insertedAuxItem)
{
[[self menu] insertItem: [NSMenuItem separatorItem]
atIndex: separatorIndex];
separatorIndex = [[self menu] numberOfItems] - 2;
if (separatorIndex > 0)
{
[[self menu] insertItem: [NSMenuItem separatorItem]
atIndex: separatorIndex];
}
}
if ([selection body])
{
selectionName = [[selection body] name];
#if REFMARKS
// TODO: Add support for reference marks
#endif
}
else if ([selection star])
{

View File

@ -8,7 +8,7 @@
@interface CelestiaSettings : NSObject {
@private
NSDictionary* tagDict;
NSMutableDictionary* tagDict;
NSArray* keyArray;
}

View File

@ -14,6 +14,7 @@
#include "celestia.h"
#include "render.h"
class MacOSXWatcher : public CelestiaWatcher
{
private:
@ -81,7 +82,7 @@ static NSMutableDictionary* tagMap;
appCore = (CelestiaCore*) [[CelestiaAppCore sharedAppCore] appCore];
tagDict = [[NSDictionary dictionaryWithObjectsAndKeys:
tagDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
// TAGDEF(101,@"time")
// TAGDEF(999,@"timeScale")
TAGDEF(300,@"fullScreenMode")
@ -173,9 +174,18 @@ static NSMutableDictionary* tagMap;
TAGDEF(904,@"galaxyBrightness")
// TAGDEF(999,@"saturationMagnitude")
nil ] retain];
nil];
keyArray = [[tagDict allValues] retain];
#if REFMARKS
NSDictionary *volatileTagDict = [NSDictionary dictionaryWithObjectsAndKeys:
TAGDEF(1000,@"showBodyAxes")
TAGDEF(1001,@"showFrameAxes")
TAGDEF(1002,@"showSunDirection")
TAGDEF(1003,@"showVelocityVector")
nil];
[tagDict addEntriesFromDictionary: volatileTagDict];
#endif
return self;
}
@ -245,21 +255,17 @@ static NSMutableDictionary* tagMap;
-(void) loadUserDefaults
{
id key;
// NSLog(@"loading user defaults");
NSDictionary* defaultsDictionary = [self findUserDefaults ];
if ( defaultsDictionary == nil ) return;
NSEnumerator* keys = [ defaultsDictionary keyEnumerator];
while ( nil != (key = [keys nextObject]) )
{
// NSLog([NSString stringWithFormat: @"loading default dict entry %@ %@", key, [defaultsDictionary objectForKey: key] ]);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
[self setValue: [defaultsDictionary objectForKey: key] forKey: key];
#else
[self takeValue: [defaultsDictionary objectForKey: key] forKey: key];
#endif
// NSLog([NSString stringWithFormat: @"loaded default dict entry %@ %@", key, [self valueForKey: key] ]);
}
// NSLog(@"loaded user defaults");
}
-(void) loadAppDefaults
@ -297,21 +303,19 @@ static NSMutableDictionary* tagMap;
-(id) valueForTag: (int) tag {
return [self valueForKey: [tagDict objectForKey: [NSNumber numberWithInt: tag] ] ];
}
}
-(void) takeValue: (id) value forTag: (int) tag
{
// NSLog([NSString stringWithFormat: @"take value for tag %@ %d", value, tag]);
id key = [tagDict objectForKey: [NSNumber numberWithInt: tag] ];
// NSLog([NSString stringWithFormat: @"take value for key %@ %@", value, key]);
if (key!= nil)
{
id key = [tagDict objectForKey: [NSNumber numberWithInt: tag] ];
if (key!= nil)
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
[self setValue: value forKey: key ];
[self setValue: value forKey: key ];
#else
[self takeValue: value forKey: key ];
[self takeValue: value forKey: key ];
#endif
}
}
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
@ -495,6 +499,17 @@ FEATUREMETHODS(Other)
-(float) minimumFeatureSize { return appCore->getRenderer()->getMinimumFeatureSize(); }
-(void) setMinimumFeatureSize: (float) value { appCore->getRenderer()->setMinimumFeatureSize(value); }
#if REFMARKS
// Refmark Settings
#define REFMARKMETHODS(flag) -(BOOL) show##flag { return (appCore->getSimulation()->getSelection().body()->getVisibleReferenceMarks()&Body::flag) != 0; } -(void) setShow##flag: (BOOL) value { appCore->getSimulation()->getSelection().body()->setVisibleReferenceMarks([self setValue: value forBit: Body::flag inSet: appCore->getSimulation()->getSelection().body()->getVisibleReferenceMarks()]); }
REFMARKMETHODS(BodyAxes)
REFMARKMETHODS(FrameAxes)
REFMARKMETHODS(SunDirection)
REFMARKMETHODS(VelocityVector)
#endif
// Lighting Settings
-(float) ambientLightLevel { return appCore->getRenderer()->getAmbientLightLevel(); }
@ -630,7 +645,7 @@ FEATUREMETHODS(Other)
if ( tag <= 128 ) { appCore->charEntered(tag); return; }
switch ( tag/100)
{
case 4: case 5: case 7: case 8: // 400, 500, 700, 800
case 4: case 5: case 7: case 8: case 10: // 400, 500, 700, 800, 1000
[self takeValue: [NSNumber numberWithInt: (1-[[self valueForTag: tag] intValue])] forTag: tag ];
break;
case 6: // 600
@ -688,27 +703,27 @@ FEATUREMETHODS(Other)
}
else
{
switch ( tag/100)
{
case 4: case 5: case 7: case 8:
// 400s, 500s, 700s, 800s (checkboxes)
[item setState: [[self valueForTag: tag] intValue] ? NSOnState : NSOffState ];
switch ( tag/100)
{
case 4: case 5: case 7: case 8: case 10:
// 400s, 500s, 700s, 800s, 1000s (checkboxes)
[item setState: [[self valueForTag: tag] intValue] ? NSOnState : NSOffState ];
break;
case 6:
// 600s (popups)
if ( tag >= 600 && tag < 610 ) // altSurface menu
{
int index = tag-600;
[item setState: ([self altSurface] == index ) ? NSOnState: NSOffState ];
}
else
[self validateButton: item atIndex: tag%10 withValue: [[self valueForTag: tag-(tag%10)] intValue] ];
if ( tag >= 600 && tag < 610 ) // altSurface menu
{
int index = tag-600;
[item setState: ([self altSurface] == index ) ? NSOnState: NSOffState ];
}
else
[self validateButton: item atIndex: tag%10 withValue: [[self valueForTag: tag-(tag%10)] intValue] ];
break;
case 9:
// 900s (floats)
[item setFloatValue: [[self valueForTag: tag] floatValue] ];
[item setFloatValue: [[self valueForTag: tag] floatValue] ];
break;
}
}
}
return YES;
}

View File

@ -13,10 +13,19 @@
@interface NSMenu (CelestiaMenu)
- (int) indexOfItemWithLocalizableTitle: (NSString *) aTitle;
- (NSMenuItem *) addPlanetarySystemItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget;
- (NSMenuItem *) addAltSurfaceItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget;
#if REFMARKS
- (BOOL) insertRefMarkItemsForSelection: (CelestiaSelection *) aSelection
atIndex: (int) aIndex;
#endif
- (BOOL) insertPlanetarySystemItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget
atIndex: (int) aIndex;
- (BOOL) insertAltSurfaceItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget
atIndex: (int) aIndex;
#if REFMARKS
- (void) removeRefMarkItems;
#endif
- (void) removePlanetarySystemItem;
- (void) removeAltSurfaceItem;
@end

View File

@ -9,6 +9,7 @@
#import "Menu_Extensions.h"
#import "CelestiaSelection.h"
#import "BrowserItem.h"
#import "CelestiaSettings.h"
@implementation NSMenu (CelestiaMenu)
@ -20,6 +21,21 @@
return index;
}
#if REFMARKS
- (void) removeRefMarkItems
{
int index;
index = [self indexOfItemWithTitle: NSLocalizedString(@"Show Body Axes",@"")];
if (index >= 0) [self removeItemAtIndex: index];
index = [self indexOfItemWithTitle: NSLocalizedString(@"Show Frame Axes",@"")];
if (index >= 0) [self removeItemAtIndex: index];
index = [self indexOfItemWithTitle: NSLocalizedString(@"Show Sun Direction",@"")];
if (index >= 0) [self removeItemAtIndex: index];
index = [self indexOfItemWithTitle: NSLocalizedString(@"Show Velocity Vector",@"")];
if (index >= 0) [self removeItemAtIndex: index];
}
#endif
- (void) removePlanetarySystemItem
{
int satMenuIndex = [self indexOfItemWithTitle:
@ -30,11 +46,7 @@
if (satMenuIndex < 0)
satMenuIndex = [self indexOfItemWithTitle: NSLocalizedStringFromTable(@"Planets",@"po",@"")];
if (satMenuIndex >= 0)
{
[self removeItemAtIndex: satMenuIndex];
if ([[self itemAtIndex: satMenuIndex] isSeparatorItem])
[self removeItemAtIndex: satMenuIndex];
}
}
- (void) removeAltSurfaceItem
@ -42,16 +54,60 @@
int surfMenuIndex = [self indexOfItemWithLocalizableTitle:
@"Show Alternate Surface" ];
if (surfMenuIndex >= 0)
{
[self removeItemAtIndex: surfMenuIndex];
if ([[self itemAtIndex: surfMenuIndex] isSeparatorItem])
[self removeItemAtIndex: surfMenuIndex];
}
}
- (NSMenuItem *) addPlanetarySystemItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget;
#if REFMARKS
- (BOOL) insertRefMarkItemsForSelection: (CelestiaSelection *) aSelection
atIndex: (int) aIndex
{
BOOL result = NO;
NSMenuItem *mi = nil;
id target = nil;
CelestiaSettings *settings = [CelestiaSettings shared];
if ([aSelection body])
{
target = [aSelection body];
mi = [[[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Show Velocity Vector",@"") action: nil keyEquivalent: @""] autorelease];
if (mi)
{
[mi setTag: 1003];
[self insertItem: mi atIndex: aIndex];
[settings scanForKeys: mi];
}
mi = [[[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Show Sun Direction",@"") action: nil keyEquivalent: @""] autorelease];
if (mi)
{
[mi setTag: 1002];
[self insertItem: mi atIndex: aIndex];
[settings scanForKeys: mi];
}
mi = [[[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Show Frame Axes",@"") action: nil keyEquivalent: @""] autorelease];
if (mi)
{
[mi setTag: 1001];
[self insertItem: mi atIndex: aIndex];
[settings scanForKeys: mi];
}
mi = [[[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Show Body Axes",@"") action: nil keyEquivalent: @""] autorelease];
if (mi)
{
[mi setTag: 1000];
[self insertItem: mi atIndex: aIndex];
[settings scanForKeys: mi];
}
result = YES;
}
return result;
}
#endif
- (BOOL) insertPlanetarySystemItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget
atIndex: (int) aIndex
{
BOOL result = NO;
NSMenuItem *mi = nil;
id browseItem;
if ([aSelection body])
@ -84,21 +140,17 @@
}
if (mi && [[mi submenu] numberOfItems] > 0)
{
int menuPos = [self numberOfItems] - 2;
if (menuPos < 0)
menuPos = 0;
[self insertItem: mi atIndex: menuPos];
[self insertItem: mi atIndex: aIndex];
result = YES;
}
else
{
mi = nil;
}
return mi;
return result;
}
- (NSMenuItem *) addAltSurfaceItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget;
- (BOOL) insertAltSurfaceItemForSelection: (CelestiaSelection *) aSelection
target: (id) aTarget
atIndex: (int) aIndex
{
BOOL result = NO;
NSMenuItem *mi = nil;
if ([aSelection body])
{
@ -113,18 +165,12 @@
action: @selector(activateMenuItem:)];
if (mi && [[mi submenu] numberOfItems] > 0)
{
int menuPos = [self numberOfItems] - 2;
if (menuPos < 0)
menuPos = 0;
[self insertItem: mi atIndex: menuPos];
}
else
{
mi = nil;
[self insertItem: mi atIndex: aIndex];
result = YES;
}
}
}
return mi;
return result;
}
@end

View File

@ -212,6 +212,7 @@
E5CC203709AA836E00CFFF2C /* POConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = E5CC203209AA834B00CFFF2C /* POConverter.m */; };
E5CC204709AA843300CFFF2C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = E5CC204509AA843300CFFF2C /* Localizable.strings */; };
E5D3196B096C91A6007FA87F /* vp_patch.sh in Resources */ = {isa = PBXBuildFile; fileRef = E5D3196A096C91A6007FA87F /* vp_patch.sh */; };
E5D3E6550D1EA18A00214838 /* axisarrow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5D3E6530D1EA18A00214838 /* axisarrow.cpp */; };
E5D446660777291700A1577D /* utf8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5D446640777291700A1577D /* utf8.cpp */; };
E5D4467607772B6C00A1577D /* CelestiaSettings.mm in Sources */ = {isa = PBXBuildFile; fileRef = E5D4467407772B6C00A1577D /* CelestiaSettings.mm */; };
E5D4467807772BA000A1577D /* CGLInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = F505BFFA02CA9DAE0100020A /* CGLInfo.m */; };
@ -627,6 +628,8 @@
E5CC204609AA843300CFFF2C /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/Localizable.strings; sourceTree = "<group>"; };
E5CC204809AA846600CFFF2C /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
E5D3196A096C91A6007FA87F /* vp_patch.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = vp_patch.sh; sourceTree = "<group>"; };
E5D3E6530D1EA18A00214838 /* axisarrow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = axisarrow.cpp; path = ../src/celengine/axisarrow.cpp; sourceTree = SOURCE_ROOT; };
E5D3E6540D1EA18A00214838 /* axisarrow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = axisarrow.h; path = ../src/celengine/axisarrow.h; sourceTree = SOURCE_ROOT; };
E5D446640777291700A1577D /* utf8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = utf8.cpp; path = ../src/celutil/utf8.cpp; sourceTree = SOURCE_ROOT; };
E5D446650777291700A1577D /* utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = utf8.h; path = ../src/celutil/utf8.h; sourceTree = SOURCE_ROOT; };
E5D4467307772B6C00A1577D /* CelestiaSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CelestiaSettings.h; sourceTree = "<group>"; };
@ -1365,6 +1368,8 @@
F51C6D52029596B4014901DC /* celengine */ = {
isa = PBXGroup;
children = (
E5D3E6530D1EA18A00214838 /* axisarrow.cpp */,
E5D3E6540D1EA18A00214838 /* axisarrow.h */,
E5A994710B1482FE009F40FA /* scriptrotation.cpp */,
E5A994700B1482FE009F40FA /* scriptrotation.h */,
E5A994730B1482FE009F40FA /* scriptobject.cpp */,
@ -1907,6 +1912,7 @@
E5E2BDD70C24F7E6000D6E83 /* TextWindowController.m in Sources */,
E512245A0CF9FC7D009092A2 /* BrowserItem.mm in Sources */,
E5D542770D0B87EA00E8C513 /* Menu_Extensions.m in Sources */,
E5D3E6550D1EA18A00214838 /* axisarrow.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};