add prefix to drawable inner names for borders and box shadows

This commit is contained in:
gazer 2017-10-13 08:31:25 +03:00 committed by dayllenger
parent bb4c7b0a02
commit fe0e86d58b
1 changed files with 26 additions and 17 deletions

View File

@ -491,33 +491,40 @@ static if (BACKEND_CONSOLE) {
/// decode solid color / gradient / border drawable from string like #AARRGGBB, e.g. #5599AA /// decode solid color / gradient / border drawable from string like #AARRGGBB, e.g. #5599AA
/// ///
/// SolidFillDrawable: #AARRGGBB - e.g. #8090A0 or #80ffffff /// SolidFillDrawable: #AARRGGBB - e.g. #8090A0 or #80ffffff
/// GradientDrawable: #linear,Ndeg,#firstColor,#secondColor /// GradientDrawable: #linear,Ndeg,firstColor,secondColor
/// BorderDrawable: #borderColor,borderWidth[,#middleColor] /// BorderDrawable: #border,borderColor,borderWidth[,middleColor]
/// or #borderColor,leftBorderWidth,topBorderWidth,rightBorderWidth,bottomBorderWidth[,#middleColor] /// or #border,borderColor,leftBorderWidth,topBorderWidth,rightBorderWidth,bottomBorderWidth[,middleColor]
/// e.g. #000000,2,#C0FFFFFF - black border of width 2 with 75% transparent white middle /// e.g. #border,#000000,2,#C0FFFFFF - black border of width 2 with 75% transparent white middle
/// e.g. #0000FF,2,3,4,5,#FFFFFF - blue border with left,top,right,bottom borders of width 2,3,4,5 and white inner area /// e.g. #border,#0000FF,2,3,4,5,#FFFFFF - blue border with left,top,right,bottom borders of width 2,3,4,5 and white inner area
static Drawable createColorDrawable(string s) { static Drawable createColorDrawable(string s) {
Log.d("creating color drawable ", s); Log.d("creating color drawable ", s);
enum DrawableType { SolidColor, LinearGradient, Border } enum DrawableType { SolidColor, LinearGradient, Border, BoxShadow }
auto type = DrawableType.SolidColor; auto type = DrawableType.SolidColor;
string[] items = s.split(','); string[] items = s.split(',');
uint[] values; uint[] values;
foreach (i, item; items) { if (items.length != 0) {
if (item == "#linear") if (items[0] == "#linear")
type = DrawableType.LinearGradient; type = DrawableType.LinearGradient;
else if (item.startsWith("#")) else if (items[0] == "#border")
type = DrawableType.Border;
else if (items[0] == "#box-shadow")
type = DrawableType.BoxShadow;
else if (items[0].startsWith("#"))
values ~= decodeHexColor(items[0]);
foreach (i, item; items[1 .. $]) {
if (item.startsWith("#"))
values ~= decodeHexColor(item); values ~= decodeHexColor(item);
else if (item.endsWith("deg")) else if (item.endsWith("deg"))
values ~= decodeAngle(item); values ~= decodeAngle(item);
else { else
values ~= decodeDimension(item); values ~= decodeDimension(item);
type = DrawableType.Border;
}
if (i >= 6) if (i >= 6)
break; break;
} }
}
if (type == DrawableType.SolidColor && values.length == 1) // only color #AARRGGBB if (type == DrawableType.SolidColor && values.length == 1) // only color #AARRGGBB
return new SolidFillDrawable(values[0]); return new SolidFillDrawable(values[0]);
@ -1133,16 +1140,18 @@ class StateDrawable : Drawable {
/// Drawable which allows to combine together background image, gradient, borders, box shadows, etc. /// Drawable which allows to combine together background image, gradient, borders, box shadows, etc.
class CombinedDrawable : Drawable { class CombinedDrawable : Drawable {
DrawableRef boxShadow;
DrawableRef background; DrawableRef background;
DrawableRef border; DrawableRef border;
this(uint backgroundColor, string backgroundImageId, string borderDescription, string boxShadowDescription) { this(uint backgroundColor, string backgroundImageId, string borderDescription, string boxShadowDescription) {
boxShadow = boxShadowDescription !is null ? drawableCache.get("#box-shadow," ~ boxShadowDescription) : new EmptyDrawable;
background = background =
(backgroundImageId !is null) ? drawableCache.get(backgroundImageId) : (backgroundImageId !is null) ? drawableCache.get(backgroundImageId) :
(!backgroundColor.isFullyTransparentColor) ? new SolidFillDrawable(backgroundColor) : null; (!backgroundColor.isFullyTransparentColor) ? new SolidFillDrawable(backgroundColor) : null;
if (background is null) if (background is null)
background = new EmptyDrawable; background = new EmptyDrawable;
border = borderDescription !is null ? drawableCache.get(borderDescription) : new EmptyDrawable; border = borderDescription !is null ? drawableCache.get("#border," ~ borderDescription) : new EmptyDrawable;
} }
override void drawTo(DrawBuf buf, Rect rc, uint state = 0, int tilex0 = 0, int tiley0 = 0) { override void drawTo(DrawBuf buf, Rect rc, uint state = 0, int tilex0 = 0, int tiley0 = 0) {