Skip to content

Commit

Permalink
Line texture improvements, #1005 (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 authored Jan 11, 2023
1 parent c36d62e commit fd092aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
20 changes: 9 additions & 11 deletions vtm-web/src/org/oscim/gdx/emu/org/oscim/theme/XmlThemeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ else if ("fix".equals(name))
b.fixed = parseBoolean(value);

else if ("stipple".equals(name))
b.stipple = Math.round(parseInt(value) * mScale * mStrokeScale);
b.stipple = (int) (parseInt(value) * mScale * mStrokeScale);

else if ("stipple-stroke".equals(name))
b.stippleColor(value);
Expand Down Expand Up @@ -615,12 +615,16 @@ else if ("repeat-gap".equals(name))
if (b.dashArray.length == 1) {
b.randomOffset = false;
b.stipple = b.dashArray[0] < 1 ? 1 : (int) b.dashArray[0];
if (mTheme.isMapsforgeTheme())
b.stipple *= Parameters.MAPSFORGE_DASH_FACTOR;
b.stippleWidth = 1;
b.stippleColor = Color.TRANSPARENT;
b.dashArray = null;
} else {
// Min dash is 1
float factor = 1;
for (float f : b.dashArray) {
if (0 < f && f < 1)
factor = Math.max(factor, 1 / f);
}
// Odd number of entries is duplicated
if (b.dashArray.length % 2 != 0) {
float[] newDashArray = new float[b.dashArray.length * 2];
Expand All @@ -631,10 +635,7 @@ else if ("repeat-gap".equals(name))
int width = 0;
int height = b.strokeWidth < 1 ? 1 : (int) b.strokeWidth;
for (float f : b.dashArray) {
if (f < 1)
f = 1;
if (mTheme.isMapsforgeTheme())
f *= Parameters.MAPSFORGE_DASH_FACTOR;
f *= factor;
width += f;
}
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
Expand All @@ -643,10 +644,7 @@ else if ("repeat-gap".equals(name))
int x = 0;
boolean transparent = false;
for (float f : b.dashArray) {
if (f < 1)
f = 1;
if (mTheme.isMapsforgeTheme())
f *= Parameters.MAPSFORGE_DASH_FACTOR;
f *= factor;
canvas.fillRectangle(x, 0, f, height, transparent ? Color.TRANSPARENT : Color.WHITE);
x += f;
transparent = !transparent;
Expand Down
16 changes: 2 additions & 14 deletions vtm/src/org/oscim/renderer/bucket/LineTexBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,8 @@ else if (line.texture != null)
GLUtils.setColor(shader.uColor, line.stippleColor, 1);
GLUtils.setColor(shader.uBgColor, line.color, 1);

float pScale;
if (s >= 1) {
pScale = line.stipple * s;
float cnt = pScale / line.stipple;
pScale = line.stipple / (cnt + 1);
} else {
pScale = line.stipple / s;
float cnt = pScale / line.stipple;
pScale = line.stipple * cnt;
}

//log.debug("pScale {} {}", pScale, s);

gl.uniform1f(shader.uPatternScale, COORD_SCALE * pScale);
/* keep line stipple fixed */
gl.uniform1f(shader.uPatternScale, (lb.scale * line.stipple) / (s + 1) * COORD_SCALE);

gl.uniform1f(shader.uPatternWidth, line.stippleWidth);

Expand Down
20 changes: 9 additions & 11 deletions vtm/src/org/oscim/theme/XmlThemeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ else if ("fix".equals(name))
b.fixed = Boolean.parseBoolean(value);

else if ("stipple".equals(name))
b.stipple = Math.round(Integer.parseInt(value) * mScale * mStrokeScale);
b.stipple = (int) (Integer.parseInt(value) * mScale * mStrokeScale);

else if ("stipple-stroke".equals(name))
b.stippleColor(value);
Expand Down Expand Up @@ -635,12 +635,16 @@ else if ("repeat-gap".equals(name))
if (b.dashArray.length == 1) {
b.randomOffset = false;
b.stipple = b.dashArray[0] < 1 ? 1 : (int) b.dashArray[0];
if (mTheme.isMapsforgeTheme())
b.stipple *= Parameters.MAPSFORGE_DASH_FACTOR;
b.stippleWidth = 1;
b.stippleColor = Color.TRANSPARENT;
b.dashArray = null;
} else {
// Min dash is 1
float factor = 1;
for (float f : b.dashArray) {
if (0 < f && f < 1)
factor = Math.max(factor, 1 / f);
}
// Odd number of entries is duplicated
if (b.dashArray.length % 2 != 0) {
float[] newDashArray = new float[b.dashArray.length * 2];
Expand All @@ -651,10 +655,7 @@ else if ("repeat-gap".equals(name))
int width = 0;
int height = b.strokeWidth < 1 ? 1 : (int) b.strokeWidth;
for (float f : b.dashArray) {
if (f < 1)
f = 1;
if (mTheme.isMapsforgeTheme())
f *= Parameters.MAPSFORGE_DASH_FACTOR;
f *= factor;
width += f;
}
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
Expand All @@ -663,10 +664,7 @@ else if ("repeat-gap".equals(name))
int x = 0;
boolean transparent = false;
for (float f : b.dashArray) {
if (f < 1)
f = 1;
if (mTheme.isMapsforgeTheme())
f *= Parameters.MAPSFORGE_DASH_FACTOR;
f *= factor;
canvas.fillRectangle(x, 0, f, height, transparent ? Color.TRANSPARENT : Color.WHITE);
x += f;
transparent = !transparent;
Expand Down
5 changes: 0 additions & 5 deletions vtm/src/org/oscim/utils/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public enum SymbolScaling {ALL, POI}
*/
public static boolean MAP_EVENT_LAYER2 = false;

/**
* Dash factor for Mapsforge themes.
*/
public static float MAPSFORGE_DASH_FACTOR = 1;

/**
* If true the markers are sorted in y-axis.
*/
Expand Down

0 comments on commit fd092aa

Please sign in to comment.