public static void ReloadBackgroundImage(this IStyleHelper helper, IStyleSheet styleSheet, IBound bound, Control control)
 {
     IBackgroundImage image;
     if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
     {
         var imageCache = styleSheet.GetCache<ImageCache>();
         using (BitmapDrawable background = imageCache.GetImage(image.Path, bound.Width, bound.Height))
             control.SetBackground(background);
     }
 }
Beispiel #2
0
        public static void ReloadBackgroundImage(this IStyleHelper helper, IStyleSheet styleSheet, IBound bound, Control control)
        {
            IBackgroundImage image;

            if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
            {
                var imageCache = styleSheet.GetCache <ImageCache>();
                using (BitmapDrawable background = imageCache.GetImage(image.Path, bound.Width, bound.Height))
                    control.SetBackground(background);
            }
        }
Beispiel #3
0
        public static bool BackgroundChanged(this IStyleHelper helper
                                             , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false)
        {
            if (!whithoutImage)
            {
                IBackgroundImage image;
                if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
                {
                    background = styleSheet.GetCache <ImageCache>().GetImage(image.Path, bound.Width, bound.Height);
                    return(true);
                }

                // if control has background image, we have to ignore background color
                if (!string.IsNullOrWhiteSpace(image.Path))
                {
                    background = null;
                    return(false);
                }
            }

            IBackgroundColor backgroundColor;
            IBorderStyle     borderStyle;
            IBorderWidth     borderWidth;
            IBorderColor     borderColor;
            IBorderRadius    borderRadius;

            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    var   shape = new GradientDrawable();
                    var   width = (int)Math.Round(borderWidth.Value);
                    Color color = borderColor.ToColorOrTransparent();

                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(backgroundColor.ToColorOrTransparent());
                    shape.SetCornerRadius(borderRadius.Radius);
                    shape.SetStroke(width, color);
                    background = shape;
                }
                else
                {
                    background = new ColorDrawable(backgroundColor.ToColorOrTransparent());
                }
                return(true);
            }

            background = null;
            return(false);
        }
        public static bool BackgroundChanged(this IStyleHelper helper
            , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false)
        {
            if (!whithoutImage)
            {
                IBackgroundImage image;
                if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
                {
                    background = styleSheet.GetCache<ImageCache>().GetImage(image.Path, bound.Width, bound.Height);
                    return true;
                }

                // if control has background image, we have to ignore background color
                if (!string.IsNullOrWhiteSpace(image.Path))
                {
                    background = null;
                    return false;
                }
            }

            IBackgroundColor backgroundColor;
            IBorderStyle borderStyle;
            IBorderWidth borderWidth;
            IBorderColor borderColor;
            IBorderRadius borderRadius;
            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    var shape = new GradientDrawable();
                    var width = (int)Math.Round(borderWidth.Value);
                    Color color = borderColor.ToColorOrTransparent();

                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(backgroundColor.ToColorOrTransparent());
                    shape.SetCornerRadius(borderRadius.Radius);
                    shape.SetStroke(width, color);
                    background = shape;
                }
                else
                    background = new ColorDrawable(backgroundColor.ToColorOrTransparent());
                return true;
            }

            background = null;
            return false;
        }
Beispiel #5
0
        public static Drawable Background(this IStyleSheet styleSheet, IStyledObject control, IBound bound, bool whithoutImage = false)
        {
            Drawable background = null;

            if (!whithoutImage)
            {
                string path = styleSheet.Helper.BackgroundImage(control);
                if (path != null)
                {
                    background = styleSheet.GetCache <ImageCache>().GetImage(path, bound.Width, bound.Height);
                }
            }

            return(background ??
                   ColorWithBorders(styleSheet, control, ToColorOrTransparent(styleSheet.Helper.BackgroundColor(control))));
        }