improved stretching of tiles
@@ -1,5 +1,5 @@
|
|||||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||||
<rect x="0" y="35" width="100" height="30" />
|
<rect x="0" y="35" width="%width%" height="30" />
|
||||||
<rect class="block" x="10" y="10" width="80" height="80" />
|
<rect class="block" x="20" y="10" width="%width%-40" height="80" />
|
||||||
<text x="10" y="65" fill="red">I love SVG!</text>
|
<text x="25" y="65" fill="red">%text%</text>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 225 B |
5
resources/svg/BlockV.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||||
|
<rect x="35" y="0" width="30" height="%height%" />
|
||||||
|
<rect class="block" x="10" y="20" width="80" height="%height%-40" />
|
||||||
|
<text x="25" y="65" fill="red" transform="translate(100, 0) rotate(90)">%text%</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 268 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
<svg width="%width%" height="100" viewbox="0 0 %width% 100">
|
||||||
<rect x="0" y="35" width="100" height="30" />
|
<rect x="0" y="35" width="%width%" height="30" />
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 106 B After Width: | Height: | Size: 118 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
<svg width="100" height="" viewbox="0 0 100 100">
|
||||||
<rect x="35" y="0" width="30" height="100" />
|
<rect x="35" y="0" width="30" height="%height%" />
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 109 B |
@@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.tiles.BlockH;
|
import de.srsoftware.web4rail.tiles.BlockH;
|
||||||
|
import de.srsoftware.web4rail.tiles.BlockV;
|
||||||
import de.srsoftware.web4rail.tiles.CrossH;
|
import de.srsoftware.web4rail.tiles.CrossH;
|
||||||
import de.srsoftware.web4rail.tiles.CrossV;
|
import de.srsoftware.web4rail.tiles.CrossV;
|
||||||
import de.srsoftware.web4rail.tiles.DiagES;
|
import de.srsoftware.web4rail.tiles.DiagES;
|
||||||
@@ -299,6 +300,7 @@ public class Plan {
|
|||||||
tiles.append(new CrossV().tag());
|
tiles.append(new CrossV().tag());
|
||||||
tiles.append(new Eraser().tag());
|
tiles.append(new Eraser().tag());
|
||||||
tiles.append(new BlockH().tag());
|
tiles.append(new BlockH().tag());
|
||||||
|
tiles.append(new BlockV().tag());
|
||||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,9 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
|
||||||
|
|
||||||
public class StraightH extends StretchableTile{
|
public class StraightH extends StretchableTile{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int len() {
|
public int len() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag tag() throws IOException {
|
|
||||||
Tag tag = super.tag();
|
|
||||||
if (length>1) {
|
|
||||||
String style = tag.get("style");
|
|
||||||
tag.style(style.trim()+" width: "+(30*length)+"px;");
|
|
||||||
tag.attr("preserveAspectRatio","none");
|
|
||||||
}
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,9 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
|
||||||
|
|
||||||
public class StraightV extends StretchableTile{
|
public class StraightV extends StretchableTile{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int height() {
|
public int height() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag tag() throws IOException {
|
|
||||||
Tag tag = super.tag();
|
|
||||||
if (length>1) {
|
|
||||||
LOG.debug("{}.tag: length = {}",getClass().getSimpleName(),length);
|
|
||||||
String style = tag.get("style");
|
|
||||||
tag.style(style.trim()+" height: "+(30*length)+"px;");
|
|
||||||
tag.attr("preserveAspectRatio","none");
|
|
||||||
}
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,14 +52,19 @@ public abstract class Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tag tag() throws IOException {
|
public Tag tag() throws IOException {
|
||||||
|
int width = 100*len();
|
||||||
|
int height = 100*height();
|
||||||
|
String style = "";
|
||||||
Tag svg = new Tag("svg")
|
Tag svg = new Tag("svg")
|
||||||
.id((x!=-1 && y!=-1)?("tile-"+x+"-"+y):(getClass().getSimpleName()))
|
.id((x!=-1 && y!=-1)?("tile-"+x+"-"+y):(getClass().getSimpleName()))
|
||||||
.clazz(classes)
|
.clazz(classes)
|
||||||
.size(100,100)
|
.size(100,100)
|
||||||
.attr("name", getClass().getSimpleName())
|
.attr("name", getClass().getSimpleName())
|
||||||
.attr("viewbox", "0 0 100 100");
|
.attr("viewbox", "0 0 "+width+" "+height);
|
||||||
if (x>-1) svg.style("left: "+(30*x)+"px; top: "+(30*y)+"px;");
|
if (x>-1) style="left: "+(30*x)+"px; top: "+(30*y)+"px;";
|
||||||
|
if (len()>1) style+=" width: "+(30*len())+"px;";
|
||||||
|
if (height()>1) style+=" height: "+(30*height())+"px;";
|
||||||
|
if (!style.isEmpty()) svg.style(style);
|
||||||
|
|
||||||
File file = new File(System.getProperty("user.dir")+"/resources/svg/"+getClass().getSimpleName()+".svg");
|
File file = new File(System.getProperty("user.dir")+"/resources/svg/"+getClass().getSimpleName()+".svg");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@@ -68,6 +73,8 @@ public abstract class Tile {
|
|||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
if (line.startsWith("<svg") || line.endsWith("svg>")) continue;
|
if (line.startsWith("<svg") || line.endsWith("svg>")) continue;
|
||||||
|
line = replace(line,"%width%",width);
|
||||||
|
line = replace(line,"%height%",height);
|
||||||
sb.append(line+"\n");
|
sb.append(line+"\n");
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
@@ -83,6 +90,18 @@ public abstract class Tile {
|
|||||||
return svg;
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String replace(String line, String key, int val) {
|
||||||
|
int start = line.indexOf(key);
|
||||||
|
int len = key.length();
|
||||||
|
while (start>0) {
|
||||||
|
String tag = line.substring(start, line.indexOf("\"",start));
|
||||||
|
int summand = (tag.length()>len) ? Integer.parseInt(tag.substring(len)) : 0;
|
||||||
|
line = line.replace(tag, ""+(val+summand));
|
||||||
|
start = line.indexOf(key);
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
protected static String t(String txt, Object...fills) {
|
protected static String t(String txt, Object...fills) {
|
||||||
return Translation.get(Application.class, txt, fills);
|
return Translation.get(Application.class, txt, fills);
|
||||||
}
|
}
|
||||||
|
|||||||