Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Expand changes to entire API
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Oct 12, 2016
1 parent acb0859 commit bd25c25
Show file tree
Hide file tree
Showing 55 changed files with 1,059 additions and 1,804 deletions.
141 changes: 63 additions & 78 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ global.testGetterImplementation = function (property, layerType, isFunction) {
if (isFunction) {
return `XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`;
}
return `XCTAssert([(NSValue *)gLayer.${objCName(property)} isEqualToValue:${value}], @"%@ is not equal to %@", gLayer.${objCName(property)}, ${value});`;
return `XCTAssert([gLayer.${objCName(property)} isKindOfClass:[MGLStyleConstantValue class]]);
XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`;
}
return `XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`;
}
Expand Down Expand Up @@ -129,7 +130,7 @@ global.propertyReqs = function (property, layoutPropertiesByName, type) {
return '`' + camelizeWithLeadingLowercase(req['!']) + '` is set to `nil`';
} else {
let name = Object.keys(req)[0];
return '`' + camelizeWithLeadingLowercase(name) + '` is set to ' + describeValue(req[name], layoutPropertiesByName[name], type);
return '`' + camelizeWithLeadingLowercase(name) + '` is set to an `MGLStyleValue` object containing ' + describeValue(req[name], layoutPropertiesByName[name], type);
}
}).join(', and ') + '. Otherwise, it is ignored.';
};
Expand Down Expand Up @@ -204,109 +205,93 @@ global.describeValue = function (value, property, layerType) {
};

global.propertyDefault = function (property, layerType) {
return describeValue(property.default, property, layerType);
return 'an `MGLStyleValue` object containing ' + describeValue(property.default, property, layerType);
};

global.propertyType = function (property, _private) {
return _private ? `id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>` : `id <MGLStyleAttributeValue>`;
};

global.initLayer = function (layerType) {
if (layerType == "background") {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String);`
} else {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String, source.identifier.UTF8String);`
}
}

global.setSourceLayer = function() {
return `_layer->setSourceLayer(sourceLayer.UTF8String);`
}

global.setterImplementation = function(property, layerType) {
let implementation = '';
global.propertyType = function (property) {
switch (property.type) {
case 'boolean':
implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_boolPropertyValue);`;
break;
return 'NSNumber *';
case 'number':
implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_floatPropertyValue);`;
break;
return 'NSNumber *';
case 'string':
implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_stringPropertyValue);`;
break;
return 'NSString *';
case 'enum':
let objCType = global.objCType(layerType, property.name);
implementation = `MGLSetEnumProperty(${objCName(property)}, ${camelize(property.name)}, ${mbglType(property)}, ${objCType});`;
break;
return 'NSValue *';
case 'color':
implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_colorPropertyValue);`;
break;
return 'MGLColor *';
case 'array':
implementation = arraySetterImplementation(property);
break;
default: throw new Error(`unknown type for ${property.name}`)
}
return implementation;
}

global.mbglType = function(property) {
let mbglType = camelize(property.name) + 'Type';
if (/-translate-anchor$/.test(property.name)) {
mbglType = 'TranslateAnchorType';
}
if (/-(rotation|pitch)-alignment$/.test(property.name)) {
mbglType = 'AlignmentType';
switch (arrayType(property)) {
case 'dasharray':
return 'NSArray<NSNumber *> *';
case 'font':
return 'NSArray<NSString *> *';
case 'padding':
return 'NSValue *';
case 'offset':
case 'translate':
return 'NSValue *';
default:
throw new Error(`unknown array type for ${property.name}`);
}
default:
throw new Error(`unknown type for ${property.name}`);
}
return mbglType;
}

global.arraySetterImplementation = function(property) {
return `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_${convertedType(property)}PropertyValue);`;
}
};

global.styleAttributeFactory = function (property, layerType) {
global.valueTransformerArguments = function (property) {
let objCType = propertyType(property);
switch (property.type) {
case 'boolean':
return 'mbgl_boolWithPropertyValueBool';
return ['bool', objCType];
case 'number':
return 'mbgl_numberWithPropertyValueNumber';
return ['float', objCType];
case 'string':
return 'mbgl_stringWithPropertyValueString';
return ['std::string', objCType];
case 'enum':
throw new Error('Use MGLGetEnumProperty() for enums.');
return [`mbgl::style::${mbglType(property)}`, objCType];
case 'color':
return 'mbgl_colorWithPropertyValueColor';
return ['mbgl::Color', objCType];
case 'array':
return `mbgl_${convertedType(property)}WithPropertyValue${camelize(convertedType(property))}`;
switch (arrayType(property)) {
case 'dasharray':
return ['std::vector<float>', objCType, 'float'];
case 'font':
return ['std::vector<std::string>', objCType, 'std::string'];
case 'padding':
return ['std::array<float, 4>', objCType];
case 'offset':
case 'translate':
return ['std::array<float, 2>', objCType];
default:
throw new Error(`unknown array type for ${property.name}`);
}
default:
throw new Error(`unknown type for ${property.name}`);
}
};

global.getterImplementation = function(property, layerType) {
if (property.type === 'enum') {
let objCType = global.objCType(layerType, property.name);
return `MGLGetEnumProperty(${camelize(property.name)}, ${mbglType(property)}, ${objCType});`;
global.initLayer = function (layerType) {
if (layerType == "background") {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String);`
} else {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String, source.identifier.UTF8String);`
}
let rawValue = `self.layer->get${camelize(property.name)}() ?: self.layer->getDefault${camelize(property.name)}()`;
return `return [MGLStyleAttribute ${styleAttributeFactory(property, layerType)}:${rawValue}];`;
}

global.convertedType = function(property) {
switch (arrayType(property)) {
case 'dasharray':
return 'numberArray';
case 'font':
return 'stringArray';
case 'padding':
return 'padding';
case 'offset':
case 'translate':
return 'offset';
default:
throw new Error(`unknown array type for ${property.name}`);
global.setSourceLayer = function() {
return `_layer->setSourceLayer(sourceLayer.UTF8String);`
}

global.mbglType = function(property) {
let mbglType = camelize(property.name) + 'Type';
if (/-translate-anchor$/.test(property.name)) {
mbglType = 'TranslateAnchorType';
}
if (/-(rotation|pitch)-alignment$/.test(property.name)) {
mbglType = 'AlignmentType';
}
return mbglType;
}

const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true });
Expand Down
16 changes: 8 additions & 8 deletions platform/darwin/src/MGLBackgroundStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLStyleAttributeValue.h"
#import "MGLStyleValue.h"
#import "MGLStyleLayer.h"

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -22,33 +22,33 @@ NS_ASSUME_NONNULL_BEGIN
/**
The color with which the background will be drawn.
The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing `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;
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *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.
The default value of this property is an `MGLStyleValue` object containing `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;
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *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).
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> backgroundPattern;
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *backgroundPattern;

/**
The opacity at which the background will be drawn.
The default value of this property is an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> backgroundOpacity;
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *backgroundOpacity;

@end

Expand Down
32 changes: 19 additions & 13 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
#import "MGLStyleValue_Private.h"
#import "MGLBackgroundStyleLayer.h"

#include <mbgl/style/layers/background_layer.hpp>
Expand All @@ -27,28 +27,34 @@ - (instancetype)initWithIdentifier:(NSString *)identifier

#pragma mark - Accessing the Paint Attributes

- (void)setBackgroundColor:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)backgroundColor {
self.layer->setBackgroundColor(backgroundColor.mbgl_colorPropertyValue);
- (void)setBackgroundColor:(MGLStyleValue<MGLColor *> *)backgroundColor {
auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(backgroundColor);
self.layer->setBackgroundColor(mbglValue);
}

- (id <MGLStyleAttributeValue>)backgroundColor {
return [MGLStyleAttribute mbgl_colorWithPropertyValueColor:self.layer->getBackgroundColor() ?: self.layer->getDefaultBackgroundColor()];
- (MGLStyleValue<MGLColor *> *)backgroundColor {
auto propertyValue = self.layer->getBackgroundColor() ?: self.layer->getDefaultBackgroundColor();
return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue);
}

- (void)setBackgroundPattern:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)backgroundPattern {
self.layer->setBackgroundPattern(backgroundPattern.mbgl_stringPropertyValue);
- (void)setBackgroundPattern:(MGLStyleValue<NSString *> *)backgroundPattern {
auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(backgroundPattern);
self.layer->setBackgroundPattern(mbglValue);
}

- (id <MGLStyleAttributeValue>)backgroundPattern {
return [MGLStyleAttribute mbgl_stringWithPropertyValueString:self.layer->getBackgroundPattern() ?: self.layer->getDefaultBackgroundPattern()];
- (MGLStyleValue<NSString *> *)backgroundPattern {
auto propertyValue = self.layer->getBackgroundPattern() ?: self.layer->getDefaultBackgroundPattern();
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue);
}

- (void)setBackgroundOpacity:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)backgroundOpacity {
self.layer->setBackgroundOpacity(backgroundOpacity.mbgl_floatPropertyValue);
- (void)setBackgroundOpacity:(MGLStyleValue<NSNumber *> *)backgroundOpacity {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(backgroundOpacity);
self.layer->setBackgroundOpacity(mbglValue);
}

- (id <MGLStyleAttributeValue>)backgroundOpacity {
return [MGLStyleAttribute mbgl_numberWithPropertyValueNumber:self.layer->getBackgroundOpacity() ?: self.layer->getDefaultBackgroundOpacity()];
- (MGLStyleValue<NSNumber *> *)backgroundOpacity {
auto propertyValue = self.layer->getBackgroundOpacity() ?: self.layer->getDefaultBackgroundOpacity();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

@end
34 changes: 17 additions & 17 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLStyleAttributeValue.h"
#import "MGLStyleValue.h"
#import "MGLVectorStyleLayer.h"

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -53,64 +53,64 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) {
This property is measured in points.
The default value of this property is an `NSNumber` object containing the float `5`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `5`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleRadius;
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleRadius;

#if TARGET_OS_IPHONE
/**
The fill color of the circle.
The default value of this property is `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing `UIColor.blackColor`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleColor;
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *circleColor;
#else
/**
The fill 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.
The default value of this property is an `MGLStyleValue` object containing `NSColor.blackColor`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleColor;
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *circleColor;
#endif

/**
Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
The default value of this property is an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleBlur;
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleBlur;

/**
The opacity at which the circle will be drawn.
The default value of this property is an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleOpacity;
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleOpacity;

/**
The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively.
This property is measured in points.
The default value of this property is an `NSValue` object containing a `CGVector` struct set to 0 points from the left and 0 points from the top. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing a `CGVector` struct set to 0 points from the left and 0 points from the top. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleTranslate;
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslate;

/**
Controls the translation reference point.
The default value of this property is an `NSValue` object containing `MGLCircleTranslateAnchorMap`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLCircleTranslateAnchorMap`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `circleTranslate` is non-`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circleTranslateAnchor;
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslateAnchor;

/**
Controls the scaling behavior of the circle when the map is pitched.
The default value of this property is an `NSValue` object containing `MGLCirclePitchScaleMap`. Set this property to `nil` to reset it to the default value.
The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLCirclePitchScaleMap`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) id <MGLStyleAttributeValue> circlePitchScale;
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circlePitchScale;

@end

Expand Down
Loading

0 comments on commit bd25c25

Please sign in to comment.