make text layers respect the translate-anchor
you can now specify "translate-anchor": "viewport" to have the text translated in screen coordinates rather than relative to the tile. The default value remains "translate-anchor": "map" refs #189
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <llmr/util/mat4.hpp>
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/renderer/frame_history.hpp>
|
||||
#include <llmr/style/properties.hpp>
|
||||
|
||||
#include <llmr/shader/plain_shader.hpp>
|
||||
#include <llmr/shader/outline_shader.hpp>
|
||||
@@ -88,7 +89,8 @@ public:
|
||||
bool needsAnimation() const;
|
||||
private:
|
||||
void setupShaders();
|
||||
void translateLayer(std::array<float, 2> translation, const Tile::ID &id, bool reverse = false);
|
||||
void translateLayer(const std::array<float, 2> &translation, const Tile::ID &id, bool reverse = false);
|
||||
mat4 translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor = TranslateAnchor::Map);
|
||||
|
||||
void prepareTile(const Tile& tile);
|
||||
void useProgram(uint32_t program);
|
||||
|
||||
@@ -171,7 +171,7 @@ void Painter::renderTileLayer(const Tile& tile, const LayerDescription &layer_de
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::translateLayer(const std::array<float, 2> translation, const Tile::ID &id, bool reverse) {
|
||||
void Painter::translateLayer(const std::array<float, 2> &translation, const Tile::ID &id, bool reverse) {
|
||||
if (translation[0] || translation[1]) {
|
||||
const int direction = reverse ? -1 : 1;
|
||||
// TODO: Get rid of the 8 (scaling from 4096 to tile size)
|
||||
@@ -181,6 +181,32 @@ void Painter::translateLayer(const std::array<float, 2> translation, const Tile:
|
||||
}
|
||||
}
|
||||
|
||||
mat4 Painter::translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor) {
|
||||
if (translation[0] == 0 && translation[1] == 0) {
|
||||
return matrix;
|
||||
} else {
|
||||
// TODO: Get rid of the 8 (scaling from 4096 to tile size)
|
||||
const double factor = ((double)(1 << id.z)) / map.getState().getScale() /
|
||||
map.getState().getPixelRatio() * (4096.0 / util::tileSize);
|
||||
|
||||
mat4 result;
|
||||
if (anchor == TranslateAnchor::Viewport) {
|
||||
const double sin_a = sin(-map.getState().getAngle());
|
||||
const double cos_a = cos(-map.getState().getAngle());
|
||||
matrix::translate(result, matrix,
|
||||
factor * (translation[0] * cos_a - translation[1] * sin_a),
|
||||
factor * (translation[0] * sin_a + translation[1] * cos_a),
|
||||
0);
|
||||
} else {
|
||||
matrix::translate(result, matrix,
|
||||
factor * translation[0],
|
||||
factor * translation[1],
|
||||
0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::renderMatte() {
|
||||
gl::group group("matte");
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -16,8 +16,6 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
|
||||
const TextProperties& properties = text_properties_it->second;
|
||||
if (!properties.enabled) return;
|
||||
|
||||
translateLayer(properties.translate, id);
|
||||
|
||||
mat4 exMatrix;
|
||||
matrix::copy(exMatrix, projMatrix);
|
||||
if (bucket.geom_desc.path == TextPathType::Curve) {
|
||||
@@ -33,8 +31,10 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
|
||||
float fontSize = fmin(properties.size, bucket.geom_desc.font_size);
|
||||
matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f);
|
||||
|
||||
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
|
||||
useProgram(textShader->program);
|
||||
textShader->setMatrix(matrix);
|
||||
textShader->setMatrix(vtxMatrix);
|
||||
textShader->setExtrudeMatrix(exMatrix);
|
||||
|
||||
map.getGlyphAtlas().bind();
|
||||
@@ -109,6 +109,4 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
|
||||
textShader->setBuffer((256.0f - 64.0f) / 256.0f);
|
||||
glDepthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
|
||||
translateLayer(properties.translate, id, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user