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

Commit

Permalink
[core] Implement circle-stroke properties
Browse files Browse the repository at this point in the history
Also includes stubs for fill-extrusion layer, because most of the code was auto-generated.
  • Loading branch information
jfirebaugh committed Dec 8, 2016
1 parent aa9bf71 commit d747189
Show file tree
Hide file tree
Showing 21 changed files with 471 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/layers/background_layer.hpp
include/mbgl/style/layers/circle_layer.hpp
include/mbgl/style/layers/custom_layer.hpp
include/mbgl/style/layers/fill_extrusion_layer.hpp
include/mbgl/style/layers/fill_layer.hpp
include/mbgl/style/layers/line_layer.hpp
include/mbgl/style/layers/raster_layer.hpp
Expand All @@ -282,6 +283,11 @@ set(MBGL_CORE_FILES
src/mbgl/style/layers/custom_layer.cpp
src/mbgl/style/layers/custom_layer_impl.cpp
src/mbgl/style/layers/custom_layer_impl.hpp
src/mbgl/style/layers/fill_extrusion_layer.cpp
src/mbgl/style/layers/fill_extrusion_layer_impl.cpp
src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
src/mbgl/style/layers/fill_extrusion_layer_properties.cpp
src/mbgl/style/layers/fill_extrusion_layer_properties.hpp
src/mbgl/style/layers/fill_layer.cpp
src/mbgl/style/layers/fill_layer_impl.cpp
src/mbgl/style/layers/fill_layer_impl.hpp
Expand Down
13 changes: 13 additions & 0 deletions include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/background_layer.hpp>

Expand Down Expand Up @@ -67,6 +68,7 @@ auto makeLayoutPropertySetters() {




return result;
}

Expand Down Expand Up @@ -115,6 +117,17 @@ auto makePaintPropertySetters() {
result["circle-translate"] = makePropertySetter<V>(&CircleLayer::setCircleTranslate);
result["circle-translate-anchor"] = makePropertySetter<V>(&CircleLayer::setCircleTranslateAnchor);
result["circle-pitch-scale"] = makePropertySetter<V>(&CircleLayer::setCirclePitchScale);
result["circle-stroke-width"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeWidth);
result["circle-stroke-color"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeColor);
result["circle-stroke-opacity"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeOpacity);

result["fill-extrusion-opacity"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionOpacity);
result["fill-extrusion-color"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionColor);
result["fill-extrusion-translate"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionTranslate);
result["fill-extrusion-translate-anchor"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionTranslateAnchor);
result["fill-extrusion-pattern"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionPattern);
result["fill-extrusion-height"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionHeight);
result["fill-extrusion-base"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionBase);

result["raster-opacity"] = makePropertySetter<V>(&RasterLayer::setRasterOpacity);
result["raster-hue-rotate"] = makePropertySetter<V>(&RasterLayer::setRasterHueRotate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <mbgl/style/conversion/property_setter.hpp>

<% for (const layer of locals.layers) { -%>
#include <mbgl/style/layers/<%- layer.type %>_layer.hpp>
#include <mbgl/style/layers/<%- layer.type.replace('-', '_') %>_layer.hpp>
<% } -%>

#include <unordered_map>
Expand Down
4 changes: 4 additions & 0 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SymbolLayer;
class RasterLayer;
class BackgroundLayer;
class CustomLayer;
class FillExtrusionLayer;

/**
* The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style
Expand Down Expand Up @@ -42,6 +43,7 @@ class Layer : public mbgl::util::noncopyable {
Raster,
Background,
Custom,
FillExtrusion,
};

class Impl;
Expand Down Expand Up @@ -95,6 +97,8 @@ class Layer : public mbgl::util::noncopyable {
return visitor(*as<BackgroundLayer>());
case Type::Custom:
return visitor(*as<CustomLayer>());
case Type::FillExtrusion:
return visitor(*as<FillExtrusionLayer>());
}
}

Expand Down
12 changes: 12 additions & 0 deletions include/mbgl/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ class CircleLayer : public Layer {
PropertyValue<CirclePitchScaleType> getCirclePitchScale(const optional<std::string>& klass = {}) const;
void setCirclePitchScale(PropertyValue<CirclePitchScaleType>, const optional<std::string>& klass = {});

static PropertyValue<float> getDefaultCircleStrokeWidth();
PropertyValue<float> getCircleStrokeWidth(const optional<std::string>& klass = {}) const;
void setCircleStrokeWidth(PropertyValue<float>, const optional<std::string>& klass = {});

static PropertyValue<Color> getDefaultCircleStrokeColor();
PropertyValue<Color> getCircleStrokeColor(const optional<std::string>& klass = {}) const;
void setCircleStrokeColor(PropertyValue<Color>, const optional<std::string>& klass = {});

static PropertyValue<float> getDefaultCircleStrokeOpacity();
PropertyValue<float> getCircleStrokeOpacity(const optional<std::string>& klass = {}) const;
void setCircleStrokeOpacity(PropertyValue<float>, const optional<std::string>& klass = {});

// Private implementation

class Impl;
Expand Down
72 changes: 72 additions & 0 deletions include/mbgl/style/layers/fill_extrusion_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// This file is generated. Do not edit.

#pragma once

#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

namespace mbgl {
namespace style {

class FillExtrusionLayer : public Layer {
public:
FillExtrusionLayer(const std::string& layerID, const std::string& sourceID);
~FillExtrusionLayer() final;

// Source
const std::string& getSourceID() const;
const std::string& getSourceLayer() const;
void setSourceLayer(const std::string& sourceLayer);

void setFilter(const Filter&);
const Filter& getFilter() const;

// Paint properties

static PropertyValue<float> getDefaultFillExtrusionOpacity();
PropertyValue<float> getFillExtrusionOpacity(const optional<std::string>& klass = {}) const;
void setFillExtrusionOpacity(PropertyValue<float>, const optional<std::string>& klass = {});

static PropertyValue<Color> getDefaultFillExtrusionColor();
PropertyValue<Color> getFillExtrusionColor(const optional<std::string>& klass = {}) const;
void setFillExtrusionColor(PropertyValue<Color>, const optional<std::string>& klass = {});

static PropertyValue<std::array<float, 2>> getDefaultFillExtrusionTranslate();
PropertyValue<std::array<float, 2>> getFillExtrusionTranslate(const optional<std::string>& klass = {}) const;
void setFillExtrusionTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {});

static PropertyValue<TranslateAnchorType> getDefaultFillExtrusionTranslateAnchor();
PropertyValue<TranslateAnchorType> getFillExtrusionTranslateAnchor(const optional<std::string>& klass = {}) const;
void setFillExtrusionTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {});

static PropertyValue<std::string> getDefaultFillExtrusionPattern();
PropertyValue<std::string> getFillExtrusionPattern(const optional<std::string>& klass = {}) const;
void setFillExtrusionPattern(PropertyValue<std::string>, const optional<std::string>& klass = {});

static PropertyValue<float> getDefaultFillExtrusionHeight();
PropertyValue<float> getFillExtrusionHeight(const optional<std::string>& klass = {}) const;
void setFillExtrusionHeight(PropertyValue<float>, const optional<std::string>& klass = {});

static PropertyValue<float> getDefaultFillExtrusionBase();
PropertyValue<float> getFillExtrusionBase(const optional<std::string>& klass = {}) const;
void setFillExtrusionBase(PropertyValue<float>, const optional<std::string>& klass = {});

// Private implementation

class Impl;
Impl* const impl;

FillExtrusionLayer(const Impl&);
FillExtrusionLayer(const FillExtrusionLayer&) = delete;
};

template <>
inline bool Layer::is<FillExtrusionLayer>() const {
return type == Type::FillExtrusion;
}

} // namespace style
} // namespace mbgl
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"ejs": "^2.4.1",
"express": "^4.11.1",
"lodash": "^4.16.4",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#597115a1e1bd982944b068f8accde34eada74fc2",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#0c6f3e00193248474349cd730e232eb5ffcd9bf4",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#b51b85ffb8c512e228c36c5405293ce51d123519",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#deb30918f8637e7675a00731b799a5caec894b17",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#9252ffc5108131704b5acf52d78258ac05687871",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"request": "^2.72.0",
Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/style/layers/layer.cpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-%>
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`.

#include "<%- type %>_layer.hpp"
#include "<%- type.replace('-', '_') %>_layer.hpp"

#include <string>

Expand Down
20 changes: 11 additions & 9 deletions scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const fs = require('fs');
const ejs = require('ejs');
const spec = require('mapbox-gl-style-spec').latest;
var colorParser = require('csscolorparser');
const colorParser = require('csscolorparser');

require('./style-code');

function parseCSSColor(str) {
var color = colorParser.parseCSSColor(str);
const color = colorParser.parseCSSColor(str);
return [
color[0] / 255 * color[3], color[1] / 255 * color[3], color[2] / 255 * color[3], color[3]
];
Expand Down Expand Up @@ -40,7 +40,7 @@ global.propertyType = function (property) {
}
default: throw new Error(`unknown type for ${property.name}`)
}
}
};

global.defaultValue = function (property) {
// https://github.com/mapbox/mapbox-gl-native/issues/5258
Expand All @@ -64,7 +64,7 @@ global.defaultValue = function (property) {
return `${propertyType(property)}::${camelize(property.default)}`;
}
case 'color':
var color = parseCSSColor(property.default).join(', ');
const color = parseCSSColor(property.default).join(', ');
switch (color) {
case '0, 0, 0, 0':
return '{}';
Expand All @@ -85,7 +85,7 @@ global.defaultValue = function (property) {
default:
return property.default;
}
}
};

const layerHpp = ejs.compile(fs.readFileSync('include/mbgl/style/layers/layer.hpp.ejs', 'utf8'), {strict: true});
const layerCpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer.cpp.ejs', 'utf8'), {strict: true});
Expand Down Expand Up @@ -118,11 +118,13 @@ const layers = Object.keys(spec.layer.type.values).map((type) => {
});

for (const layer of layers) {
writeIfModified(`include/mbgl/style/layers/${layer.type}_layer.hpp`, layerHpp(layer));
writeIfModified(`src/mbgl/style/layers/${layer.type}_layer.cpp`, layerCpp(layer));
const layerFileName = layer.type.replace('-', '_');

writeIfModified(`include/mbgl/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer));
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer));

writeIfModified(`src/mbgl/style/layers/${layer.type}_layer_properties.hpp`, propertiesHpp(layer));
writeIfModified(`src/mbgl/style/layers/${layer.type}_layer_properties.cpp`, propertiesCpp(layer));
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.hpp`, propertiesHpp(layer));
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.cpp`, propertiesCpp(layer));
}

const propertySettersHpp = ejs.compile(fs.readFileSync('include/mbgl/style/conversion/make_property_setters.hpp.ejs', 'utf8'), {strict: true});
Expand Down
6 changes: 6 additions & 0 deletions src/mbgl/programs/circle_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace mbgl {

namespace uniforms {
MBGL_DEFINE_UNIFORM_SCALAR(float, u_radius);
MBGL_DEFINE_UNIFORM_SCALAR(Color, u_stroke_color);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_stroke_width);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_stroke_opacity);
MBGL_DEFINE_UNIFORM_SCALAR(bool, u_scale_with_map);
} // namespace uniforms

Expand All @@ -26,6 +29,9 @@ class CircleProgram : public Program<
uniforms::u_color,
uniforms::u_radius,
uniforms::u_blur,
uniforms::u_stroke_color,
uniforms::u_stroke_width,
uniforms::u_stroke_opacity,
uniforms::u_scale_with_map,
uniforms::u_extrude_scale>>
{
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/renderer/painter_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void Painter::renderCircle(PaintParameters& parameters,
uniforms::u_color::Value{ properties.get<CircleColor>() },
uniforms::u_radius::Value{ properties.get<CircleRadius>() },
uniforms::u_blur::Value{ properties.get<CircleBlur>() },
uniforms::u_stroke_color::Value{ properties.get<CircleStrokeColor>() },
uniforms::u_stroke_width::Value{ properties.get<CircleStrokeWidth>() },
uniforms::u_stroke_opacity::Value{ properties.get<CircleStrokeOpacity>() },
uniforms::u_scale_with_map::Value{ scaleWithMap },
uniforms::u_extrude_scale::Value{ scaleWithMap
? std::array<float, 2> {{
Expand Down
45 changes: 45 additions & 0 deletions src/mbgl/style/layers/circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,50 @@ void CircleLayer::setCirclePitchScale(PropertyValue<CirclePitchScaleType> value,
impl->observer->onLayerPaintPropertyChanged(*this);
}

PropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() {
return { 0 };
}

PropertyValue<float> CircleLayer::getCircleStrokeWidth(const optional<std::string>& klass) const {
return impl->paint.get<CircleStrokeWidth>(klass);
}

void CircleLayer::setCircleStrokeWidth(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleStrokeWidth(klass))
return;
impl->paint.set<CircleStrokeWidth>(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
}

PropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() {
return { Color::black() };
}

PropertyValue<Color> CircleLayer::getCircleStrokeColor(const optional<std::string>& klass) const {
return impl->paint.get<CircleStrokeColor>(klass);
}

void CircleLayer::setCircleStrokeColor(PropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getCircleStrokeColor(klass))
return;
impl->paint.set<CircleStrokeColor>(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
}

PropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() {
return { 1 };
}

PropertyValue<float> CircleLayer::getCircleStrokeOpacity(const optional<std::string>& klass) const {
return impl->paint.get<CircleStrokeOpacity>(klass);
}

void CircleLayer::setCircleStrokeOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleStrokeOpacity(klass))
return;
impl->paint.set<CircleStrokeOpacity>(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
}

} // namespace style
} // namespace mbgl
17 changes: 16 additions & 1 deletion src/mbgl/style/layers/circle_layer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,29 @@ struct CirclePitchScale : PaintProperty<CirclePitchScaleType> {
static CirclePitchScaleType defaultValue() { return CirclePitchScaleType::Map; }
};

struct CircleStrokeWidth : PaintProperty<float> {
static float defaultValue() { return 0; }
};

struct CircleStrokeColor : PaintProperty<Color> {
static Color defaultValue() { return Color::black(); }
};

struct CircleStrokeOpacity : PaintProperty<float> {
static float defaultValue() { return 1; }
};

class CirclePaintProperties : public PaintProperties<
CircleRadius,
CircleColor,
CircleBlur,
CircleOpacity,
CircleTranslate,
CircleTranslateAnchor,
CirclePitchScale
CirclePitchScale,
CircleStrokeWidth,
CircleStrokeColor,
CircleStrokeOpacity
> {};

} // namespace style
Expand Down
Loading

0 comments on commit d747189

Please sign in to comment.