Skip to content
Permalink
Browse files

Improved support for round rect border in CSS. Previously CSS would u…

…se 9-piece borders for if the it couldn't reproduce it with a round rect border in normal, top-only, or bottom-only mode. E.g. if only the top left and bottom right corners have a radius defined, then it would fall back to a 9-piece border. This change allows roundrectborder to be used for any combination of corners being rounded. It still doesn't allow you to have different non-zero radiuses in different corners. All of the corners need to either have the same radius, or zero. If one corner has, for examle, a radius of 3mm and another has 2mm, then it will fall back to a 9-piece border still. #2350
  • Loading branch information...
shannah committed Feb 11, 2019
1 parent ab7e226 commit 52172ba9297ccfefaeb9497fae39b3360edeea5d
@@ -1622,6 +1622,25 @@ private Object createBorder(DataInputStream input, int type) throws IOException
bezierCorners(input.readBoolean()).
topOnlyMode(input.readBoolean()).
bottomOnlyMode(input.readBoolean());
// round rect border with top-left, top-right, bottom-right, bottom-left corners
// specified independently
case 0xff15:
return RoundRectBorder.create().
stroke(input.readFloat(), input.readBoolean()).
strokeColor(input.readInt()).
strokeOpacity(input.readInt()).
shadowBlur(input.readFloat()).
shadowOpacity(input.readInt()).
shadowSpread(input.readFloat()).
shadowX(input.readFloat()).
shadowY(input.readFloat()).
cornerRadius(input.readFloat()).
bezierCorners(input.readBoolean()).
topLeftMode(input.readBoolean()).
topRightMode(input.readBoolean()).
bottomRightMode(input.readBoolean()).
bottomLeftMode(input.readBoolean());

}
return null;
}
@@ -1400,6 +1400,9 @@ public boolean isModified(String id) {
}

public void updateResources() {
// TODO: We need to remove stale theme entries
// https://github.com/codenameone/CodenameOne/issues/2698

for (String id : elements.keySet()) {
if (!isModified(id)) {
continue;
@@ -1415,7 +1418,6 @@ public void updateResources() {
String unselId = id;
String pressedId = id+".press";
String disabledId = id+".dis";

res.setThemeProperty(themeName, unselId+".padding", el.getThemePadding(unselectedStyles));
res.setThemeProperty(themeName, unselId+".padUnit", el.getThemePaddingUnit(unselectedStyles));
res.setThemeProperty(themeName, selId+"#padding", el.getThemePadding(selectedStyles));
@@ -2386,18 +2388,10 @@ public boolean canBeAchievedWithUnderlineBorder(Map<String,LexicalUnit> styles)
}

public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles) {
//System.out.println("Checking if we can achieve with background image generation "+styles);
if (hasUnequalBorders() || this.hasGradient() || !isBorderLineOrNone() || !isNone(backgroundImageUrl) || hasBoxShadow()) {
//System.out.println("Failed test 1");
//System.out.println("unequalBorders? "+hasUnequalBorders());
//System.out.println("Has gradient? "+hasGradient());
//System.out.println("BorderLineOrNone? "+isBorderLineOrNone());
//System.out.println("Background Image URL: "+backgroundImageUrl);
return false;
}



String prefix = "cn1-border";
String[] corners = new String[]{"top-left", "top-right", "bottom-left", "bottom-right"};
String[] xy = new String[]{"x", "y"};
@@ -2411,25 +2405,9 @@ public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles)
}

ScaledUnit val = null;
boolean topLeft=false;
boolean topRight = false;
boolean bottomLeft = false;
boolean bottomRight = false;
for (String cornerStyle : radiusAtts) {
ScaledUnit u = (ScaledUnit)styles.get(cornerStyle);
if (u != null && u.getPixelValue() != 0) {
if (cornerStyle.indexOf("top-left") != -1) {
topLeft = true;
}
if (cornerStyle.indexOf("top-right") != -1) {
topRight = true;
}
if (cornerStyle.indexOf("bottom-left") != -1) {
bottomLeft = true;
}
if (cornerStyle.indexOf("bottom-right") != -1) {
bottomRight = true;
}
if (val != null && val.getPixelValue() != u.getPixelValue()) {
// We have more than one non-zero corner radius
//System.out.println("Failed corner test");
@@ -2440,13 +2418,6 @@ public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles)
}
}


if (topLeft != topRight || bottomLeft != bottomRight) {
// Resource files don't currently support topLeftMode, topRightMode, bottomLeftMode, and bottomRightMode
// so we need to fall back to image borders if the left and right have different radii
return false;
}

// All corners are the same, so we can proceed to the next step.

prefix = "border";
@@ -4484,11 +4455,15 @@ private ScaledUnit getBorderRadius(Map<String,LexicalUnit> styles) {
ScaledUnit bottomRightRadius = getBorderRadius(styles, "bottom-right");
//System.out.println("TopLeftRadius is : "+topLeftRadius+" isZero? "+isZero(topLeftRadius));
//System.out.println("BottomRight Radius is : "+bottomRightRadius+" isZero? "+isZero(bottomRightRadius));
if (!isZero(bottomLeftRadius) && !isZero(bottomRightRadius) && isZero(topLeftRadius) && isZero(topRightRadius)) {
out.bottomOnlyMode(true);
} else if (isZero(bottomLeftRadius) && isZero(bottomRightRadius) && !isZero(topLeftRadius) && !isZero(topRightRadius)) {
out.topOnlyMode(true);
}
//if (!isZero(bottomLeftRadius) && !isZero(bottomRightRadius) && isZero(topLeftRadius) && isZero(topRightRadius)) {
// out.bottomOnlyMode(true);
//} else if (isZero(bottomLeftRadius) && isZero(bottomRightRadius) && !isZero(topLeftRadius) && !isZero(topRightRadius)) {
// out.topOnlyMode(true);
//}
out.topLeftMode(!isZero(topLeftRadius));
out.topRightMode(!isZero(topRightRadius));
out.bottomRightMode(!isZero(bottomRightRadius));
out.bottomLeftMode(!isZero(bottomLeftRadius));



@@ -110,7 +110,7 @@
* @author Shai Almog
*/
public class EditableResources extends Resources implements TreeModel {
private static final short MINOR_VERSION = 9;
private static final short MINOR_VERSION = 10;
private static final short MAJOR_VERSION = 1;

private boolean modified;
@@ -2082,8 +2082,10 @@ private void writeBorder(DataOutputStream output, Border border, boolean newVers
return;
}
if(border instanceof RoundRectBorder) {
output.writeShort(0xff13);


RoundRectBorder rb = (RoundRectBorder)border;
output.writeShort(0xff15);
output.writeFloat(rb.getStrokeThickness());
output.writeBoolean(rb.isStrokeMM());
output.writeInt(rb.getStrokeColor());
@@ -2095,8 +2097,10 @@ private void writeBorder(DataOutputStream output, Border border, boolean newVers
output.writeFloat(rb.getShadowY());
output.writeFloat(rb.getCornerRadius());
output.writeBoolean(rb.isBezierCorners());
output.writeBoolean(rb.isTopOnlyMode());
output.writeBoolean(rb.isBottomOnlyMode());
output.writeBoolean(rb.isTopLeft());
output.writeBoolean(rb.isTopRight());
output.writeBoolean(rb.isBottomRight());
output.writeBoolean(rb.isBottomLeft());
return;
}
int type = Accessor.getType(border);

0 comments on commit 52172ba

Please sign in to comment.
You can’t perform that action at this time.