add translate-anchor for fills
This commit is contained in:
@@ -105,6 +105,7 @@ struct LineProperties {
|
||||
struct FillClass {
|
||||
FunctionProperty enabled = true;
|
||||
std::array<FunctionProperty, 2> translate = {{ 0, 0 }};
|
||||
TranslateAnchor translateAnchor = TranslateAnchor::Map;
|
||||
Winding winding = Winding::NonZero;
|
||||
FunctionProperty antialias = true;
|
||||
Color fill_color = {{ 0, 0, 0, 1 }};
|
||||
@@ -116,6 +117,7 @@ struct FillClass {
|
||||
struct FillProperties {
|
||||
bool enabled = true;
|
||||
std::array<float, 2> translate = {{ 0, 0 }};
|
||||
TranslateAnchor translateAnchor = TranslateAnchor::Map;
|
||||
Winding winding = Winding::NonZero;
|
||||
bool antialias = true;
|
||||
Color fill_color = {{ 0, 0, 0, 1 }};
|
||||
|
||||
@@ -35,13 +35,13 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
|
||||
stroke_color = fill_color;
|
||||
}
|
||||
|
||||
translateLayer(properties.translate, id);
|
||||
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
|
||||
// Because we're drawing top-to-bottom, and we update the stencil mask
|
||||
// below, we have to draw the outline first (!)
|
||||
if (outline && pass == Translucent) {
|
||||
useProgram(outlineShader->program);
|
||||
outlineShader->setMatrix(matrix);
|
||||
outlineShader->setMatrix(vtxMatrix);
|
||||
lineWidth(2.0f); // This is always fixed and does not depend on the pixelRatio!
|
||||
|
||||
outlineShader->setColor(stroke_color);
|
||||
@@ -93,7 +93,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
|
||||
};
|
||||
|
||||
useProgram(patternShader->program);
|
||||
patternShader->setMatrix(matrix);
|
||||
patternShader->setMatrix(vtxMatrix);
|
||||
patternShader->setOffset(offset);
|
||||
patternShader->setPatternSize(imageSize);
|
||||
patternShader->setPatternTopLeft({{ imagePos.tl.x, imagePos.tl.y }});
|
||||
@@ -111,7 +111,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
|
||||
// fragments
|
||||
// Draw filling rectangle.
|
||||
useProgram(plainShader->program);
|
||||
plainShader->setMatrix(matrix);
|
||||
plainShader->setMatrix(vtxMatrix);
|
||||
plainShader->setColor(fill_color);
|
||||
|
||||
// Draw the actual triangles into the color & stencil buffer.
|
||||
@@ -124,7 +124,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
|
||||
// below, we have to draw the outline first (!)
|
||||
if (fringeline && pass == Translucent) {
|
||||
useProgram(outlineShader->program);
|
||||
outlineShader->setMatrix(matrix);
|
||||
outlineShader->setMatrix(vtxMatrix);
|
||||
lineWidth(2.0f); // This is always fixed and does not depend on the pixelRatio!
|
||||
|
||||
outlineShader->setColor(fill_color);
|
||||
@@ -138,6 +138,4 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
|
||||
glDepthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawVertices(*outlineShader);
|
||||
}
|
||||
|
||||
translateLayer(properties.translate, id, true);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ void Style::cascade(float z) {
|
||||
fill.enabled = layer.enabled.evaluate<bool>(z);
|
||||
fill.translate = {{ layer.translate[0].evaluate<float>(z),
|
||||
layer.translate[1].evaluate<float>(z) }};
|
||||
fill.translateAnchor = layer.translateAnchor;
|
||||
fill.winding = layer.winding;
|
||||
fill.antialias = layer.antialias.evaluate<bool>(z);
|
||||
fill.fill_color = layer.fill_color;
|
||||
|
||||
@@ -194,6 +194,19 @@ void StyleParser::parseConstants(JSVal value) {
|
||||
}
|
||||
}
|
||||
|
||||
TranslateAnchor parseTranslateAnchor(JSVal anchor) {
|
||||
if (anchor.IsString()) {
|
||||
std::string a { anchor.GetString(), anchor.GetStringLength() };
|
||||
if (a == "viewport") {
|
||||
return TranslateAnchor::Viewport;
|
||||
} else {
|
||||
return TranslateAnchor::Map;
|
||||
}
|
||||
} else {
|
||||
throw Style::exception("translate anchor must be a string");
|
||||
}
|
||||
}
|
||||
|
||||
void StyleParser::parseClasses(JSVal value, std::map<std::string, ClassDescription>& classes, std::map<std::string, BucketDescription>& buckets, std::vector<LayerDescription>& layers) {
|
||||
if (value.IsArray()) {
|
||||
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
|
||||
@@ -434,6 +447,10 @@ FillClass StyleParser::parseFillClass(JSVal value) {
|
||||
klass.translate = std::array<FunctionProperty, 2> {{ values[0], values[1] }};
|
||||
}
|
||||
|
||||
if (value.HasMember("translate-anchor")) {
|
||||
klass.translateAnchor = parseTranslateAnchor(value["translate-anchor"]);
|
||||
}
|
||||
|
||||
if (value.HasMember("color")) {
|
||||
klass.fill_color = parseColor(value["color"]);
|
||||
}
|
||||
@@ -530,19 +547,6 @@ PointClass StyleParser::parsePointClass(JSVal value) {
|
||||
return klass;
|
||||
}
|
||||
|
||||
TranslateAnchor parseTranslateAnchor(JSVal anchor) {
|
||||
if (anchor.IsString()) {
|
||||
std::string a { anchor.GetString(), anchor.GetStringLength() };
|
||||
if (a == "viewport") {
|
||||
return TranslateAnchor::Viewport;
|
||||
} else {
|
||||
return TranslateAnchor::Map;
|
||||
}
|
||||
} else {
|
||||
throw Style::exception("translate anchor must be a string");
|
||||
}
|
||||
}
|
||||
|
||||
TextClass StyleParser::parseTextClass(JSVal value) {
|
||||
TextClass klass;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user