Skip to content

Commit

Permalink
Use a buffer applied to the bounding box based on the font size
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji authored and hjanetzek committed Dec 14, 2015
1 parent aebe3c4 commit e4a5442
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion core/resources/scene.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ layers:
polygons:
order: 0
color: '#f0ebeb'

landuse:
data: { source: osm }
filter:
Expand Down
3 changes: 2 additions & 1 deletion core/resources/shaders/sdf.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void main(void) {
#pragma tangram: filter

gl_FragColor = color;
gl_FragColor += vec4(0.0, 0.0, 1.0, 0.5);
gl_FragColor.r *= 0.5;
gl_FragColor.a = 0.5;
}

1 change: 0 additions & 1 deletion core/src/labels/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ void Label::resetState() {
m_updateMeshVisibility = true;
m_dirty = true;
m_proxy = false;
m_skipTransitions = false;
enterState(State::wait_occ, 0.0);
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/labels/label.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Label {
Transition selectTransition;
Transition hideTransition;
Transition showTransition;
float buffer = 0.f;

// the label hash based on its styling parameters
size_t paramHash;
Expand Down Expand Up @@ -159,8 +160,6 @@ class Label {
bool m_occlusionSolved;
// whether or not we need to update the mesh visibilit (alpha channel)
bool m_updateMeshVisibility;
// label options
Options m_options;
// whether this label should skip transitions to move to first visible state
bool m_skipTransitions;

Expand All @@ -185,6 +184,8 @@ class Label {
LabelMesh& m_mesh;
// first vertex and count in m_mesh vertices
Range m_vertexRange;
// label options
Options m_options;
};

}
Expand All @@ -209,4 +210,3 @@ namespace std {
}
};
}

9 changes: 5 additions & 4 deletions core/src/labels/textLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void TextLabel::updateBBoxes(float _zoomFract) {
obbCenter += m_perpAxis * m_quadLocalOrigin.y + m_perpAxis * m_dim.y;
obbCenter += t * m_quadLocalOrigin.x;

m_obb = OBB(obbCenter.x, obbCenter.y, m_transform.state.rotation, m_dim.x, m_dim.y);
m_obb = OBB(obbCenter.x, obbCenter.y, m_transform.state.rotation, m_dim.x + m_options.buffer, m_dim.y + m_options.buffer);
m_aabb = m_obb.getExtent();
}

Expand All @@ -57,8 +57,9 @@ void TextLabel::align(glm::vec2& _screenPosition, const glm::vec2& _ap1, const g
case Type::debug:
case Type::point:
// modify position set by updateScreenTransform()
_screenPosition.x -= m_dim.x * 0.5f;
_screenPosition.x -= m_dim.x * 0.5f + m_quadLocalOrigin.x;
_screenPosition.y -= m_metrics.descender;

if (m_nLines > 1) {
_screenPosition.y -= m_dim.y * 0.5f;
_screenPosition.y += m_metrics.lineHeight;
Expand All @@ -68,11 +69,11 @@ void TextLabel::align(glm::vec2& _screenPosition, const glm::vec2& _ap1, const g
case Type::line: {
// anchor at line center
_screenPosition = (_ap1 + _ap2) * 0.5f;

// move back by half the length (so that text will be drawn centered)
glm::vec2 direction = glm::normalize(_ap1 - _ap2);
_screenPosition += direction * m_dim.x * 0.5f;

_screenPosition += m_perpAxis * (m_dim.y * 0.5f + m_metrics.descender);
_screenPosition += m_perpAxis * (m_dim.y * 0.5f + 2.f * m_metrics.descender);
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/style/textStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ auto TextStyle::applyRule(const DrawRule& _rule, const Properties& _props) const
float emSize = p.fontSize / 16.f;
p.blurSpread = m_sdf ? emSize * 5.0f : 0.0f;

float boundingBoxBuffer = -p.fontSize / 2.f;
p.labelOptions.buffer = boundingBoxBuffer;

std::hash<Parameters> hash;
p.labelOptions.paramHash = hash(p);

Expand Down
1 change: 0 additions & 1 deletion core/src/text/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ bool TextBuffer::addLabel(const TextStyle::Parameters& _params, Label::Transform
}

bbox.x -= xMin;
LOG("%f %f", quads[0].x0, quads[0].y0);
glm::vec2 quadsLocalOrigin(xMin, quads[0].y0);

_fontContext.unlock();
Expand Down

0 comments on commit e4a5442

Please sign in to comment.