From ab5b310a9eb7c88935cc457da1af81349fbe8d41 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Thu, 25 May 2017 14:36:05 -0700 Subject: [iOS][macOS] Add ImageSource bindings --- .../macos/app/Assets.xcassets/Radar/Contents.json | 6 ++ .../Radar/southeast_0.imageset/Contents.json | 21 ++++++ .../southeast_0.imageset/southeast_radar_0.png | Bin 0 -> 172489 bytes .../Radar/southeast_1.imageset/Contents.json | 21 ++++++ .../southeast_1.imageset/southeast_radar_1.png | Bin 0 -> 177163 bytes .../Radar/southeast_2.imageset/Contents.json | 21 ++++++ .../southeast_2.imageset/southeast_radar_2.png | Bin 0 -> 179236 bytes .../Radar/southeast_3.imageset/Contents.json | 21 ++++++ .../southeast_3.imageset/southeast_radar_3.png | Bin 0 -> 177074 bytes platform/macos/app/Base.lproj/MainMenu.xib | 6 ++ platform/macos/app/MapDocument.m | 78 +++++++++++++++++---- platform/macos/macos.xcodeproj/project.pbxproj | 14 ++++ platform/macos/src/Mapbox.h | 1 + platform/macos/src/NSImage+MGLAdditions.h | 2 + platform/macos/src/NSImage+MGLAdditions.mm | 15 ++-- 15 files changed, 186 insertions(+), 20 deletions(-) create mode 100644 platform/macos/app/Assets.xcassets/Radar/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/southeast_radar_0.png create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/southeast_radar_1.png create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/southeast_radar_2.png create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/southeast_radar_3.png (limited to 'platform/macos') diff --git a/platform/macos/app/Assets.xcassets/Radar/Contents.json b/platform/macos/app/Assets.xcassets/Radar/Contents.json new file mode 100644 index 0000000000..da4a164c91 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Radar/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/Contents.json new file mode 100644 index 0000000000..ea096b04b8 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "southeast_radar_0.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/southeast_radar_0.png b/platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/southeast_radar_0.png new file mode 100644 index 0000000000..c304b619c4 Binary files /dev/null and b/platform/macos/app/Assets.xcassets/Radar/southeast_0.imageset/southeast_radar_0.png differ diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/Contents.json new file mode 100644 index 0000000000..a6a031ae2b --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "southeast_radar_1.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/southeast_radar_1.png b/platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/southeast_radar_1.png new file mode 100644 index 0000000000..ed09fffbe1 Binary files /dev/null and b/platform/macos/app/Assets.xcassets/Radar/southeast_1.imageset/southeast_radar_1.png differ diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/Contents.json new file mode 100644 index 0000000000..d607dda298 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "southeast_radar_2.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/southeast_radar_2.png b/platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/southeast_radar_2.png new file mode 100644 index 0000000000..fee630f863 Binary files /dev/null and b/platform/macos/app/Assets.xcassets/Radar/southeast_2.imageset/southeast_radar_2.png differ diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/Contents.json new file mode 100644 index 0000000000..9a110068a1 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "southeast_radar_3.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/southeast_radar_3.png b/platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/southeast_radar_3.png new file mode 100644 index 0000000000..c4c7146afa Binary files /dev/null and b/platform/macos/app/Assets.xcassets/Radar/southeast_3.imageset/southeast_radar_3.png differ diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 20a4f65b3f..9a8cf05c16 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -554,6 +554,12 @@ + + + + + + diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 59844d363e..281497ac92 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -617,6 +617,34 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id valueWithInterpolationMode:MGLInterpolationModeExponential cameraStops:@{ @0.0: [MGLStyleValue valueWithRawValue:[NSColor redColor]], @10.0: [MGLStyleValue valueWithRawValue:[NSColor yellowColor]], @20.0: [MGLStyleValue valueWithRawValue:[NSColor blackColor]], } options:nil]; - fillStyleLayer.fillColor = colorFunction; + + if ([waterLayer respondsToSelector:@selector(fillColor)]) { + [waterLayer setValue:colorFunction forKey:@"fillColor"]; + } else if ([waterLayer respondsToSelector:@selector(lineColor)]) { + [waterLayer setValue:colorFunction forKey:@"lineColor"]; + } NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *geoJSONURL = [NSURL fileURLWithPath:filePath]; @@ -714,21 +746,34 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id )mgl_styleImageWithIdentifier:(NSString *)identifier; +- (mbgl::PremultipliedImage) mgl_PremultipliedImage; + @end NS_ASSUME_NONNULL_END diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm index ecd8aabe15..e4ef38eea5 100644 --- a/platform/macos/src/NSImage+MGLAdditions.mm +++ b/platform/macos/src/NSImage+MGLAdditions.mm @@ -33,6 +33,15 @@ } - (std::unique_ptr)mgl_styleImageWithIdentifier:(NSString *)identifier { + mbgl::PremultipliedImage cPremultipliedImage = self.mgl_PremultipliedImage; + auto imageWidth = cPremultipliedImage.size.width; + return std::make_unique([identifier UTF8String], + std::move(cPremultipliedImage), + (float)(imageWidth / self.size.width), + [self isTemplate]); +} + +- (mbgl::PremultipliedImage)mgl_PremultipliedImage { // Create a bitmap image representation from the image, respecting backing // scale factor and any resizing done on the image at runtime. // http://www.cocoabuilder.com/archive/cocoa/82430-nsimage-getting-raw-bitmap-data.html#82431 @@ -42,10 +51,6 @@ mbgl::PremultipliedImage cPremultipliedImage({ static_cast(rep.pixelsWide), static_cast(rep.pixelsHigh) }); std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.bytes(), cPremultipliedImage.data.get()); - return std::make_unique([identifier UTF8String], - std::move(cPremultipliedImage), - (float)(rep.pixelsWide / self.size.width), - [self isTemplate]); + return cPremultipliedImage; } - @end -- cgit v1.2.1