Skip to content

Commit fdbed02

Browse files
committed
Implement label scaling.
1 parent e70807b commit fdbed02

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

worldwind/src/main/java/gov/nasa/worldwind/shape/Label.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,11 @@ protected void makeDrawable(RenderContext rc) {
445445
// origin at the text's bottom-left corner and axes that extend up and to the right from the origin point.
446446
int w = texture.getWidth();
447447
int h = texture.getHeight();
448+
double s = this.activeAttributes.scale;
448449
this.activeAttributes.textOffset.offsetForSize(w, h, renderData.offset);
449450
renderData.unitSquareTransform.setTranslation(
450-
renderData.screenPlacePoint.x - renderData.offset.x,
451-
renderData.screenPlacePoint.y - renderData.offset.y,
451+
renderData.screenPlacePoint.x - renderData.offset.x * s,
452+
renderData.screenPlacePoint.y - renderData.offset.y * s,
452453
renderData.screenPlacePoint.z);
453454

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

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

467468
WWMath.boundingRectForUnitSquare(renderData.unitSquareTransform, renderData.screenBounds);
468469
if (!rc.frustum.intersectsViewport(renderData.screenBounds)) {

worldwind/src/main/java/gov/nasa/worldwind/shape/Placemark.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,16 +840,22 @@ protected void doRender(RenderContext rc) {
840840
}
841841

842842
if (this.labelTexture != null) {
843+
// Compute an camera-position proximity scaling factor, so that distant placemarks can be scaled smaller than
844+
// nearer placemarks.
845+
visibilityScale = this.isEyeDistanceScaling() ?
846+
Math.max(this.activeAttributes.minimumImageScale, Math.min(1, this.getEyeDistanceScalingLabelThreshold() / this.cameraDistance)) : 1;
847+
843848
int w = this.labelTexture.getWidth();
844849
int h = this.labelTexture.getHeight();
850+
double s = this.activeAttributes.labelAttributes.scale * visibilityScale;
845851
this.activeAttributes.labelAttributes.textOffset.offsetForSize(w, h, offset);
846852

847853
labelTransform.setTranslation(
848-
screenPlacePoint.x - offset.x,
849-
screenPlacePoint.y - offset.y,
854+
screenPlacePoint.x - offset.x * s,
855+
screenPlacePoint.y - offset.y * s,
850856
screenPlacePoint.z);
851857

852-
labelTransform.setScale(w, h, 1);
858+
labelTransform.setScale(w * s, h * s, 1);
853859

854860
WWMath.boundingRectForUnitSquare(labelTransform, labelBounds);
855861
if (rc.frustum.intersectsViewport(labelBounds)) {

worldwind/src/main/java/gov/nasa/worldwind/shape/TextAttributes.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class TextAttributes {
3232

3333
protected float outlineWidth;
3434

35+
protected double scale;
36+
3537
public TextAttributes() {
3638
this.textColor = new Color(1, 1, 1, 1);
3739
this.textOffset = Offset.bottomCenter();
@@ -41,6 +43,7 @@ public TextAttributes() {
4143
this.outlineColor = new Color(0, 0, 0, 1);
4244
this.enableDepthTest = true;
4345
this.outlineWidth = 3;
46+
this.scale = 1;
4447
}
4548

4649
public TextAttributes(TextAttributes attributes) {
@@ -57,6 +60,7 @@ public TextAttributes(TextAttributes attributes) {
5760
this.enableOutline = attributes.enableOutline;
5861
this.enableDepthTest = attributes.enableDepthTest;
5962
this.outlineWidth = attributes.outlineWidth;
63+
this.scale = attributes.scale;
6064
}
6165

6266
public TextAttributes set(TextAttributes attributes) {
@@ -73,6 +77,7 @@ public TextAttributes set(TextAttributes attributes) {
7377
this.outlineColor.set(attributes.outlineColor);
7478
this.enableDepthTest = attributes.enableDepthTest;
7579
this.outlineWidth = attributes.outlineWidth;
80+
this.scale = attributes.scale;
7681

7782
return this;
7883
}
@@ -94,7 +99,8 @@ public boolean equals(Object o) {
9499
&& this.enableOutline == that.enableOutline
95100
&& this.outlineColor.equals(that.outlineColor)
96101
&& this.enableDepthTest == that.enableDepthTest
97-
&& this.outlineWidth == that.outlineWidth;
102+
&& this.outlineWidth == that.outlineWidth
103+
&& this.scale == that.scale;
98104
}
99105

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

@@ -196,4 +204,13 @@ public TextAttributes setOutlineWidth(float lineWidth) {
196204
this.outlineWidth = lineWidth;
197205
return this;
198206
}
207+
208+
public double getScale() {
209+
return this.scale;
210+
}
211+
212+
public TextAttributes setScale(double scale) {
213+
this.scale = scale;
214+
return this;
215+
}
199216
}

0 commit comments

Comments
 (0)