Skip to content

Commit cbd1a83

Browse files
BryceBryce
Bryce
authored and
Bryce
committed
Reorganize directory structure and partially fix Mac build issues.
1 parent 5810317 commit cbd1a83

19 files changed

+154
-20
lines changed

src/Mac/AppDelegate.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010

1111
@class Downloader;
1212
@class MainWindowController;
13+
@class MapView;
1314

1415
@interface AppDelegate : NSObject <NSApplicationDelegate>
1516
{
1617
}
1718

18-
@property (strong,nonatomic) MainWindowController * mainWindowController;
19+
@property (strong,nonatomic) MainWindowController * mainWindowController;
20+
@property (assign,nonatomic) MapView * mapView;
1921

2022
@property (strong,nonatomic) NSString * userName;
2123
@property (strong,nonatomic) NSString * userPassword;
2224

25+
+(AppDelegate *)getAppDelegate;
26+
2327
-(NSString *)appName;
2428
-(NSString *)appVersion;
2529

src/Mac/AppDelegate.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
#import "AppDelegate.h"
1010
#import "EditorMapLayer.h"
1111
#import "MainWindowController.h"
12-
#import "TagInfo.h"
1312

1413

1514
@implementation AppDelegate
1615

16+
+(AppDelegate *)getAppDelegate
17+
{
18+
return (AppDelegate *)[[NSApplication sharedApplication] delegate];
19+
}
20+
1721
- (NSString *)appName
1822
{
1923
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
@@ -24,6 +28,7 @@ - (NSString *)appVersion
2428
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
2529
}
2630

31+
#if 0
2732
- (NSArray *)tagCompletionsForKey:(NSString *)key
2833
{
2934
NSSet * set = [[TagInfoDatabase sharedTagInfoDatabase] allTagValuesForKey:key];
@@ -32,11 +37,10 @@ - (NSArray *)tagCompletionsForKey:(NSString *)key
3237
if ( [key isEqualToString:@"wifi"] ) {
3338
values addObjectsFromArray:
3439
}
35-
xxx
3640
NSArray * list = [values allObjects];
3741
return list;
3842
}
39-
43+
#endif
4044

4145
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
4246
{
@@ -46,8 +50,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
4650
self.mainWindowController = [[MainWindowController alloc] init];
4751
[self.mainWindowController showWindow:self];
4852

53+
#if 0
4954
BOOL enableMapCss = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableMapCss"];
5055
self.mainWindowController.mapView.editorLayer.enableMapCss = enableMapCss;
56+
#endif
5157
}
5258

5359
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
@@ -57,8 +63,10 @@ - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
5763

5864
- (void)applicationWillTerminate:(NSNotification *)notification
5965
{
66+
#if 0
6067
BOOL enableMapCss = self.mainWindowController.mapView.editorLayer.enableMapCss;
6168
[[NSUserDefaults standardUserDefaults] setBool:enableMapCss forKey:@"enableMapCss"];
69+
#endif
6270
}
6371

6472
@end

src/Mac/ChangesWindowController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ -(IBAction)upload:(id)sender
5959
[_progressIndicator startAnimation:self];
6060
[_uploadButton setEnabled:NO];
6161
[_cancelButton setEnabled:NO];
62-
[_mapData uploadChangeset:comment completion:^(NSString * error){
62+
63+
[_mapData uploadChangesetWithComment:comment imagery:nil completion:^(NSString *error) {
6364
[_progressIndicator stopAnimation:nil];
6465
[_uploadButton setEnabled:YES];
6566
[_cancelButton setEnabled:YES];

src/Mac/MainWindowController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@class UsersWindowController;
1717

1818

19-
@interface MainWindowController : NSWindowController <MapViewDelegate>
19+
@interface MainWindowController : NSWindowController
2020
{
2121
TagEditorWindowController * _tagEditorWindowController;
2222
UsersWindowController * _usersWindowController;

src/Shared/AerialList.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright (c) 2014 Bryce Cogswell. All rights reserved.
77
//
88

9+
#import "iosapi.h"
910
#import "AerialList.h"
1011
#import <CommonCrypto/CommonDigest.h>
1112

@@ -226,7 +227,19 @@ -(void)scaleAttributionIconToHeight:(CGFloat)height
226227
{
227228
if ( _attributionIcon && fabs(_attributionIcon.size.height - height) > 0.1 ) {
228229
CGFloat scale = _attributionIcon.size.height / height;
230+
#if TARGET_OS_IPHONE
229231
_attributionIcon = [[UIImage alloc] initWithCGImage:_attributionIcon.CGImage scale:scale orientation:_attributionIcon.imageOrientation];
232+
#else
233+
NSSize size = { _attributionIcon.size.width * scale, _attributionIcon.size.height * scale };
234+
NSImage * result = [[NSImage alloc] initWithSize:size];
235+
[result lockFocus];
236+
NSAffineTransform * transform = [NSAffineTransform transform];
237+
[transform scaleBy:scale];
238+
[transform concat];
239+
[_attributionIcon drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0];
240+
[result unlockFocus];
241+
_attributionIcon = result;
242+
#endif
230243
}
231244
}
232245

@@ -237,7 +250,7 @@ -(void)loadIconFromWeb:(NSString *)url
237250
timeoutInterval:60];
238251
NSURLSessionDataTask * task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) {
239252
if ( data ) {
240-
UIImage * image = [UIImage imageWithData:data];
253+
UIImage * image = [[NSImage alloc] initWithData:data];
241254
_attributionIcon = image;
242255
}
243256
}];
@@ -457,7 +470,7 @@ -(NSArray *)processOsmLabAerialsList:(NSArray *)featureArray isGeoJSON:(BOOL)isG
457470
if ( [attribIconString hasPrefix:prefix] ) {
458471
attribIconString = [attribIconString substringFromIndex:prefix.length];
459472
NSData * decodedData = [[NSData alloc] initWithBase64EncodedString:attribIconString options:0];
460-
attribIcon = [UIImage imageWithData:decodedData];
473+
attribIcon = [[UIImage alloc] initWithData:decodedData];
461474
if ( attribIcon == nil ) {
462475
NSLog(@"bad icon decode: %@\n",attribIconString);
463476
}

src/Shared/CommonTagList.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
// Copyright (c) 2014 Bryce Cogswell. All rights reserved.
77
//
88

9+
#if TARGET_OS_IPHONE
910
#import <UIKit/UIKit.h>
11+
#else
12+
#import <Cocoa/Cocoa.h>
13+
typedef int UIKeyboardType;
14+
typedef int UITextAutocapitalizationType;
15+
#endif
1016

1117

1218
#define GEOMETRY_AREA @"area"

src/Shared/CurvedTextLayer.m

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import <CoreText/CoreText.h>
1010
#import <QuartzCore/QuartzCore.h>
1111

12+
#import "iosapi.h"
1213
#import "CurvedTextLayer.h"
1314
#import "PathUtil.h"
1415

@@ -31,7 +32,9 @@ -(instancetype)init
3132
_textSizeCache.countLimit = 100;
3233
#endif
3334

35+
#if TARGET_OS_IPHONE
3436
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fontSizeDidChange:) name:UIContentSizeCategoryDidChangeNotification object:nil];
37+
#endif
3538
}
3639
return self;
3740
}
@@ -65,7 +68,11 @@ -(CALayer *)layerWithString:(NSString *)string whiteOnBlock:(BOOL)whiteOnBlack
6568
// Don't cache these here because they are cached by the objects they are attached to
6669
CATextLayer * layer = [CATextLayer new];
6770

71+
#if TARGET_OS_IPHONE
6872
UIFont * font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
73+
#else
74+
NSFont * font = [NSFont labelFontOfSize:12];
75+
#endif
6976
UIColor * textColor = whiteOnBlack ? UIColor.whiteColor : UIColor.blackColor;
7077
UIColor * shadowColor = whiteOnBlack ? UIColor.blackColor : UIColor.whiteColor;
7178
NSAttributedString * attrString = [[NSAttributedString alloc] initWithString:string
@@ -201,13 +208,22 @@ -(CGSize)sizeOfText:(NSAttributedString *)string
201208
{
202209
NSValue * size = [_textSizeCache objectForKey:string];
203210
if ( size ) {
211+
#if TARGET_OS_IPHONE
204212
return size.CGSizeValue;
213+
#else
214+
return size.sizeValue;
215+
#endif
205216
}
206217

207218
CTFramesetterRef framesetter = [self framesetterForString:string];
208219
CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, CGSizeMake(70, CGFLOAT_MAX), NULL);
209220
CFRelease( framesetter );
210-
[_textSizeCache setObject:[NSValue valueWithCGSize:suggestedSize] forKey:string];
221+
#if TARGET_OS_IPHONE
222+
NSValue * value = [NSValue valueWithCGSize:suggestedSize];
223+
#else
224+
NSValue * value = [NSValue valueWithSize:suggestedSize];
225+
#endif
226+
[_textSizeCache setObject:value forKey:string];
211227
return suggestedSize;
212228
}
213229

@@ -223,7 +239,11 @@ -(id)getCachedLayerForString:(NSString *)string whiteOnBlack:(BOOL)whiteOnBlack
223239

224240
-(NSArray *)layersWithString:(NSString *)string alongPath:(CGPathRef)path whiteOnBlock:(BOOL)whiteOnBlack
225241
{
242+
#if TARGET_OS_IPHONE
226243
UIFont * uiFont = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
244+
#else
245+
NSFont * uiFont = [NSFont labelFontOfSize:12];
246+
#endif
227247

228248
UIColor * textColor = whiteOnBlack ? UIColor.whiteColor : UIColor.blackColor;
229249
NSAttributedString * attrString = [[NSAttributedString alloc] initWithString:string
@@ -270,7 +290,11 @@ -(NSArray *)layersWithString:(NSString *)string alongPath:(CGPathRef)path whiteO
270290

271291
NSMutableArray * layers = [NSMutableArray new];
272292

293+
#if TARGET_OS_IPHONE
273294
double lineHeight = uiFont.lineHeight;
295+
#else
296+
double lineHeight = uiFont.ascender + uiFont.descender + 2.0;
297+
#endif
274298
CFIndex currentCharacter = 0;
275299
double currentPixelOffset = offset;
276300
while ( currentCharacter < charCount ) {
@@ -318,8 +342,9 @@ -(NSArray *)layersWithString:(NSString *)string alongPath:(CGPathRef)path whiteO
318342
layer.alignmentMode = kCAAlignmentCenter;
319343

320344
layer.shouldRasterize = YES;
345+
#if TARGET_OS_IPHONE
321346
layer.contentsScale = [[UIScreen mainScreen] scale];
322-
347+
#endif
323348
CGPathRef shadowPath = CGPathCreateWithRect(bounds, NULL);
324349
layer.shadowColor = whiteOnBlack ? UIColor.blackColor.CGColor : UIColor.whiteColor.CGColor;
325350
layer.shadowRadius = 0.0;

src/Shared/DisplayLink.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
@interface DisplayLink : NSObject
1212
{
13+
#if TARGET_OS_IPHONE
1314
CADisplayLink * _displayLink;
15+
#else
16+
CVDisplayLinkRef _displayLink;
17+
#endif
1418
NSMutableDictionary * _blockDict;
1519
}
1620
+(instancetype)shared;

src/Shared/DisplayLink.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
#import "DisplayLink.h"
1010

11+
#if !TARGET_OS_IPHONE
12+
#define CADisplayLink void
13+
#endif
14+
15+
1116
@implementation DisplayLink
1217

1318
+(instancetype)shared
@@ -26,9 +31,15 @@ -(instancetype)init
2631
self = [super init];
2732
if ( self ) {
2833
_blockDict = [NSMutableDictionary new];
34+
#if TARGET_OS_IPHONE
2935
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update:)];
3036
_displayLink.paused = YES;
3137
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
38+
#else
39+
CGDirectDisplayID displayID = CGMainDisplayID();
40+
CVDisplayLinkCreateWithCGDisplay(displayID, &_displayLink);
41+
CVDisplayLinkSetOutputCallback(_displayLink, displayLinkCallback, (__bridge void *)self);
42+
#endif
3243
}
3344
return self;
3445
}
@@ -40,19 +51,45 @@ -(void)update:(CADisplayLink *)displayLink
4051
}];
4152
}
4253

54+
#if TARGET_OS_IPHONE
55+
#else
56+
CVReturn displayLinkCallback( CVDisplayLinkRef CV_NONNULL displayLink,
57+
const CVTimeStamp * CV_NONNULL inNow,
58+
const CVTimeStamp * CV_NONNULL inOutputTime,
59+
CVOptionFlags flagsIn,
60+
CVOptionFlags * CV_NONNULL flagsOut,
61+
void * CV_NULLABLE displayLinkContext )
62+
{
63+
DisplayLink * myself = (__bridge DisplayLink *)displayLinkContext;
64+
[myself update:nil];
65+
}
66+
#endif
67+
4368
-(double)duration
4469
{
70+
#if TARGET_OS_IPHONE
4571
return _displayLink.duration;
72+
#else
73+
return CVDisplayLinkGetActualOutputVideoRefreshPeriod(_displayLink);
74+
#endif
4675
}
4776
-(CFTimeInterval)timestamp
4877
{
78+
#if TARGET_OS_IPHONE
4979
return _displayLink.timestamp;
80+
#else
81+
return CACurrentMediaTime();
82+
#endif
5083
}
5184

5285
-(void)addName:(NSString *)name block:(void(^)(void))block;
5386
{
5487
[_blockDict setObject:block forKey:name];
88+
#if TARGET_OS_IPHONE
5589
_displayLink.paused = NO;
90+
#else
91+
CVDisplayLinkStart(_displayLink);
92+
#endif
5693
}
5794

5895
-(BOOL)hasName:(NSString *)name
@@ -65,12 +102,20 @@ -(void)removeName:(NSString *)name;
65102
[_blockDict removeObjectForKey:name];
66103

67104
if ( _blockDict.count == 0 ) {
105+
#if TARGET_OS_IPHONE
68106
_displayLink.paused = YES;
107+
#else
108+
CVDisplayLinkStop(_displayLink);
109+
#endif
69110
}
70111
}
71112

72113
-(void)dealloc
73114
{
115+
#if TARGET_OS_IPHONE
74116
[_displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
117+
#else
118+
CVDisplayLinkRelease(_displayLink);
119+
#endif
75120
}
76121
@end

src/Shared/EditorMapLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static const CGFloat DragConnectHitTestRadius = DefaultHitTestRadius * 0.6; // h
3030

3131
extern const double MinIconSizeInPixels;
3232

33-
@interface EditorMapLayer : CALayer<UIActionSheetDelegate,NSCoding>
33+
@interface EditorMapLayer : CALayer<NSCoding>
3434
{
3535
CGSize _iconSize;
3636
double _highwayScale;

src/Shared/ExternalGPS.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ -(void)processNMEA:(NSMutableData *)data
182182
if ( [EW isEqualToString:@"W"] )
183183
dLon = -dLon;
184184

185+
#if TARGET_OS_IPHONE
185186
CLLocation * loc = [[CLLocation alloc] initWithLatitude:dLat longitude:dLon];
186187
DLog(@"lat/lon = %@", loc);
187188
AppDelegate * appDelegate = [AppDelegate getAppDelegate];
188189
[appDelegate.mapView locationUpdatedTo:loc];
190+
#endif
189191
} else if ( [line hasPrefix:@"PGSV"] ) {
190192
// satelite info, one line per satelite
191193
} else if ( [line hasPrefix:@"PGSA"] ) {

0 commit comments

Comments
 (0)