summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-08-26 22:05:48 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-08-26 22:27:55 -0700
commitf4be8260baa1e90e24ea066d0d3b28896cd138ad (patch)
tree8aaf5902637c45e0f49c0e0f7638dbe6129a5624 /platform
parent35a1c01166f997deaa386bf30247e7cb1ed33e07 (diff)
downloadqtlocation-mapboxgl-f4be8260baa1e90e24ea066d0d3b28896cd138ad.tar.gz
[ios, macos] Specialize color properties by platform
Duplicate each color-typed property once per platform using conditional compilation macros. Let’s just hope we never have to throw CGColor into the mix.
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/scripts/generate-style-code.js31
-rw-r--r--platform/darwin/src/MGLBackgroundStyleLayer.h13
-rw-r--r--platform/darwin/src/MGLCircleStyleLayer.h11
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.h13
-rw-r--r--platform/darwin/src/MGLLineStyleLayer.h13
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h52
6 files changed, 119 insertions, 14 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index cd4ab94e36..29040d3c54 100644
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -150,15 +150,15 @@ global.describeValue = function (value, property, layerType) {
throw new Error(`unrecognized color format in default value of ${property.name}`);
}
if (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 0) {
- return '`NSColor.clearColor` or `UIColor.clearColor`';
+ return '`MGLColor.clearColor`';
}
if (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 1) {
- return '`NSColor.blackColor` or `UIColor.blackColor`';
+ return '`MGLColor.blackColor`';
}
if (color.r === 1 && color.g === 1 && color.b === 1 && color.a === 1) {
- return '`NSColor.whiteColor` or `UIColor.whiteColor`';
+ return '`MGLColor.whiteColor`';
}
- return 'an `NSColor` or `UIColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
+ return 'an `MGLColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
case 'array':
let units = property.units || '';
if (units) {
@@ -310,8 +310,27 @@ const layers = spec.layer.type.values.map((type) => {
};
});
-for (const layer of layers) {
- fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, layerH(layer));
+function duplicatePlatformDecls(src) {
+ // Look for a documentation comment that contains “MGLColor” and the
+ // subsequent function, method, or property declaration. Try not to match
+ // greedily.
+ return src.replace(/(\/\*\*(?:\*[^\/]|[^*])*?\bMGLColor\b[\s\S]*?\*\/)(\s*.+?;)/g,
+ (match, comment, decl) => {
+ let iosComment = comment.replace(/\bMGLColor\b/g, 'UIColor')
+ // Use the correct indefinite article.
+ .replace(/\b(a)n(\s+`?UIColor)\b/gi, '$1$2');
+ let macosComment = comment.replace(/\bMGLColor\b/g, 'NSColor');
+ return `\
+#if TARGET_OS_IPHONE
+${iosComment}${decl}
+#else
+${macosComment}${decl}
+#endif`;
+ });
+}
+
+for (var layer of layers) {
+ fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer)));
fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer));
fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer));
}
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h
index 577767814c..0d99b38b6a 100644
--- a/platform/darwin/src/MGLBackgroundStyleLayer.h
+++ b/platform/darwin/src/MGLBackgroundStyleLayer.h
@@ -10,14 +10,25 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Accessing the Paint Attributes
+#if TARGET_OS_IPHONE
/**
The color with which the background will be drawn.
- The default value of this property is `NSColor.blackColor` or `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `backgroundPattern` is set to `nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> backgroundColor;
+#else
+/**
+ The color with which the background will be drawn.
+
+ The default value of this property is `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `backgroundPattern` is set to `nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> backgroundColor;
+#endif
/**
Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512).
diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h
index e489bd4e53..7d2ef05848 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.h
+++ b/platform/darwin/src/MGLCircleStyleLayer.h
@@ -29,12 +29,21 @@ typedef NS_ENUM(NSUInteger, MGLCircleStyleLayerCirclePitchScale) {
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleRadius;
+#if TARGET_OS_IPHONE
/**
The color of the circle.
- The default value of this property is `NSColor.blackColor` or `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleColor;
+#else
+/**
+ The color of the circle.
+
+ The default value of this property is `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleColor;
+#endif
/**
Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h
index bbf284833b..c03e8ecae1 100644
--- a/platform/darwin/src/MGLFillStyleLayer.h
+++ b/platform/darwin/src/MGLFillStyleLayer.h
@@ -29,14 +29,25 @@ typedef NS_ENUM(NSUInteger, MGLFillStyleLayerFillTranslateAnchor) {
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> fillOpacity;
+#if TARGET_OS_IPHONE
/**
The color of the filled part of this layer. This color can be specified as rgba with an alpha component and the color's opacity will not affect the opacity of the 1pt stroke, if it is used.
- The default value of this property is `NSColor.blackColor` or `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `fillPattern` is set to `nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> fillColor;
+#else
+/**
+ The color of the filled part of this layer. This color can be specified as rgba with an alpha component and the color's opacity will not affect the opacity of the 1pt stroke, if it is used.
+
+ The default value of this property is `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `fillPattern` is set to `nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> fillColor;
+#endif
/**
The outline color of the fill. Matches the value of `fillColor` if unspecified.
diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h
index a52664c532..435829c502 100644
--- a/platform/darwin/src/MGLLineStyleLayer.h
+++ b/platform/darwin/src/MGLLineStyleLayer.h
@@ -68,14 +68,25 @@ typedef NS_ENUM(NSUInteger, MGLLineStyleLayerLineTranslateAnchor) {
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> lineOpacity;
+#if TARGET_OS_IPHONE
/**
The color with which the line will be drawn.
- The default value of this property is `NSColor.blackColor` or `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `linePattern` is set to `nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> lineColor;
+#else
+/**
+ The color with which the line will be drawn.
+
+ The default value of this property is `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `linePattern` is set to `nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> lineColor;
+#endif
/**
The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively.
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index c8a7aff601..ef88ff996e 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -400,23 +400,45 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) {
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> iconOpacity;
+#if TARGET_OS_IPHONE
/**
The color of the icon. This can only be used with sdf icons.
- The default value of this property is `NSColor.blackColor` or `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> iconColor;
+#else
+/**
+ The color of the icon. This can only be used with sdf icons.
+
+ The default value of this property is `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> iconColor;
+#endif
+#if TARGET_OS_IPHONE
+/**
+ The color of the icon's halo. Icon halos can only be used with sdf icons.
+
+ The default value of this property is `UIColor.clearColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> iconHaloColor;
+#else
/**
The color of the icon's halo. Icon halos can only be used with sdf icons.
- The default value of this property is `NSColor.clearColor` or `UIColor.clearColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `NSColor.clearColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> iconHaloColor;
+#endif
/**
Distance of halo to the icon outline.
@@ -469,23 +491,45 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) {
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> textOpacity;
+#if TARGET_OS_IPHONE
/**
The color with which the text will be drawn.
- The default value of this property is `NSColor.blackColor` or `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> textColor;
+#else
+/**
+ The color with which the text will be drawn.
+
+ The default value of this property is `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> textColor;
+#endif
+#if TARGET_OS_IPHONE
+/**
+ The color of the text's halo, which helps it stand out from backgrounds.
+
+ The default value of this property is `UIColor.clearColor`. Set this property to `nil` to reset it to the default value.
+
+ This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored.
+ */
+@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> textHaloColor;
+#else
/**
The color of the text's halo, which helps it stand out from backgrounds.
- The default value of this property is `NSColor.clearColor` or `UIColor.clearColor`. Set this property to `nil` to reset it to the default value.
+ The default value of this property is `NSColor.clearColor`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> textHaloColor;
+#endif
/**
Distance of halo to the font outline. Max text halo width is 1/4 of the font-size.