Skip to content

Commit

Permalink
Implement label scaling.
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksymenko committed Apr 26, 2022
1 parent e70807b commit fdbed02
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
7 changes: 4 additions & 3 deletions worldwind/src/main/java/gov/nasa/worldwind/shape/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ protected void makeDrawable(RenderContext rc) {
// origin at the text's bottom-left corner and axes that extend up and to the right from the origin point.
int w = texture.getWidth();
int h = texture.getHeight();
double s = this.activeAttributes.scale;
this.activeAttributes.textOffset.offsetForSize(w, h, renderData.offset);
renderData.unitSquareTransform.setTranslation(
renderData.screenPlacePoint.x - renderData.offset.x,
renderData.screenPlacePoint.y - renderData.offset.y,
renderData.screenPlacePoint.x - renderData.offset.x * s,
renderData.screenPlacePoint.y - renderData.offset.y * s,
renderData.screenPlacePoint.z);

// Apply the label's rotation according to its rotation value and orientation mode. The rotation is applied
Expand All @@ -462,7 +463,7 @@ protected void makeDrawable(RenderContext rc) {
}

// Apply the label's translation and scale according to its text size.
renderData.unitSquareTransform.multiplyByScale(w, h, 1);
renderData.unitSquareTransform.multiplyByScale(w * s, h * s, 1);

WWMath.boundingRectForUnitSquare(renderData.unitSquareTransform, renderData.screenBounds);
if (!rc.frustum.intersectsViewport(renderData.screenBounds)) {
Expand Down
12 changes: 9 additions & 3 deletions worldwind/src/main/java/gov/nasa/worldwind/shape/Placemark.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,16 +840,22 @@ protected void doRender(RenderContext rc) {
}

if (this.labelTexture != null) {
// Compute an camera-position proximity scaling factor, so that distant placemarks can be scaled smaller than
// nearer placemarks.
visibilityScale = this.isEyeDistanceScaling() ?
Math.max(this.activeAttributes.minimumImageScale, Math.min(1, this.getEyeDistanceScalingLabelThreshold() / this.cameraDistance)) : 1;

int w = this.labelTexture.getWidth();
int h = this.labelTexture.getHeight();
double s = this.activeAttributes.labelAttributes.scale * visibilityScale;
this.activeAttributes.labelAttributes.textOffset.offsetForSize(w, h, offset);

labelTransform.setTranslation(
screenPlacePoint.x - offset.x,
screenPlacePoint.y - offset.y,
screenPlacePoint.x - offset.x * s,
screenPlacePoint.y - offset.y * s,
screenPlacePoint.z);

labelTransform.setScale(w, h, 1);
labelTransform.setScale(w * s, h * s, 1);

WWMath.boundingRectForUnitSquare(labelTransform, labelBounds);
if (rc.frustum.intersectsViewport(labelBounds)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class TextAttributes {

protected float outlineWidth;

protected double scale;

public TextAttributes() {
this.textColor = new Color(1, 1, 1, 1);
this.textOffset = Offset.bottomCenter();
Expand All @@ -41,6 +43,7 @@ public TextAttributes() {
this.outlineColor = new Color(0, 0, 0, 1);
this.enableDepthTest = true;
this.outlineWidth = 3;
this.scale = 1;
}

public TextAttributes(TextAttributes attributes) {
Expand All @@ -57,6 +60,7 @@ public TextAttributes(TextAttributes attributes) {
this.enableOutline = attributes.enableOutline;
this.enableDepthTest = attributes.enableDepthTest;
this.outlineWidth = attributes.outlineWidth;
this.scale = attributes.scale;
}

public TextAttributes set(TextAttributes attributes) {
Expand All @@ -73,6 +77,7 @@ public TextAttributes set(TextAttributes attributes) {
this.outlineColor.set(attributes.outlineColor);
this.enableDepthTest = attributes.enableDepthTest;
this.outlineWidth = attributes.outlineWidth;
this.scale = attributes.scale;

return this;
}
Expand All @@ -94,7 +99,8 @@ public boolean equals(Object o) {
&& this.enableOutline == that.enableOutline
&& this.outlineColor.equals(that.outlineColor)
&& this.enableDepthTest == that.enableDepthTest
&& this.outlineWidth == that.outlineWidth;
&& this.outlineWidth == that.outlineWidth
&& this.scale == that.scale;
}

@Override
Expand All @@ -107,6 +113,8 @@ public int hashCode() {
result = 31 * result + this.outlineColor.hashCode();
result = 31 * result + (this.enableDepthTest ? 1 : 0);
result = 31 * result + (this.outlineWidth != +0.0f ? Float.floatToIntBits(this.outlineWidth) : 0);
long temp = Double.doubleToLongBits(this.scale);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}

Expand Down Expand Up @@ -196,4 +204,13 @@ public TextAttributes setOutlineWidth(float lineWidth) {
this.outlineWidth = lineWidth;
return this;
}

public double getScale() {
return this.scale;
}

public TextAttributes setScale(double scale) {
this.scale = scale;
return this;
}
}

0 comments on commit fdbed02

Please sign in to comment.