diff options
Diffstat (limited to 'platform/darwin/src/MGLStyleAttributeFunction_Private.h')
-rw-r--r-- | platform/darwin/src/MGLStyleAttributeFunction_Private.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLStyleAttributeFunction_Private.h b/platform/darwin/src/MGLStyleAttributeFunction_Private.h new file mode 100644 index 0000000000..a75e17483d --- /dev/null +++ b/platform/darwin/src/MGLStyleAttributeFunction_Private.h @@ -0,0 +1,61 @@ +#import "MGLStyleAttributeFunction.h" + +#include <mbgl/util/color.hpp> +#include <mbgl/style/function.hpp> +#include <mbgl/style/property_value.hpp> + +#define MGLSetEnumProperty(name, Name, MBGLType, ObjCType) \ + if (name.isFunction) { \ + NSAssert([name isKindOfClass:[MGLStyleAttributeFunction class]], @"" #name @" should be a function"); \ + \ + __block std::vector<std::pair<float, mbgl::style::MBGLType>> stops; \ + [[(MGLStyleAttributeFunction *)name stops] enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, NSValue * _Nonnull obj, BOOL * _Nonnull stop) { \ + NSAssert([obj isKindOfClass:[NSValue class]], @"Stops in " #name @" should be NSValues"); \ + ObjCType value; \ + [obj getValue:&value]; \ + stops.emplace_back(key.floatValue, static_cast<mbgl::style::MBGLType>(value)); \ + }]; \ + auto function = mbgl::style::Function<mbgl::style::MBGLType> { \ + stops, \ + [(MGLStyleAttributeFunction *)name base].floatValue, \ + }; \ + self.layer->set##Name(function); \ + } else { \ + NSAssert([name isKindOfClass:[NSValue class]], @"" #name @"should be an NSValue"); \ + ObjCType value; \ + [(NSValue *)name getValue:&value]; \ + self.layer->set##Name({ static_cast<mbgl::style::MBGLType>(value) }); \ + } + +#define MGLGetEnumProperty(Name, MBGLType, ObjCType) \ + const char *type = @encode(ObjCType); \ + mbgl::style::PropertyValue<mbgl::style::MBGLType> property = self.layer->get##Name(); \ + if (property.isConstant()) { \ + return [NSValue value:&property.asConstant() withObjCType:type]; \ + } else if (property.isFunction()) { \ + return nil; \ + } else { \ + return nil; \ + } + +@interface MGLStyleAttributeFunction(Private) + ++ (instancetype)functionWithColorPropertyValue:(mbgl::style::Function<mbgl::Color>)property; + ++ (instancetype)functionWithNumberPropertyValue:(mbgl::style::Function<float>)property; + ++ (instancetype)functionWithBoolPropertyValue:(mbgl::style::Function<bool>)property; + ++ (instancetype)functionWithStringPropertyValue:(mbgl::style::Function<std::string>)property; + ++ (instancetype)functionWithOffsetPropertyValue:(mbgl::style::Function<std::array<float, 2>>)property; + ++ (instancetype)functionWithPaddingPropertyValue:(mbgl::style::Function<std::array<float, 4>>)property; + ++ (instancetype)functionWithStringArrayPropertyValue:(mbgl::style::Function<std::vector<std::string>>)property; + ++ (instancetype)functionWithNumberArrayPropertyValue:(mbgl::style::Function<std::vector<float>>)property; + ++ (instancetype)functionWithEnumProperyValue:(mbgl::style::Function<bool>)property type:(const char *)type; + +@end; |