コード例 #1
0
ファイル: EffectBrush.cs プロジェクト: XevianLight/Aurora
 public EffectBrush(EffectBrush otherBrush)
 {
     this.type           = otherBrush.type;
     this.wrap           = otherBrush.wrap;
     this.colorGradients = otherBrush.colorGradients;
     this.start          = otherBrush.start;
     this.end            = otherBrush.end;
     this.center         = otherBrush.center;
 }
コード例 #2
0
        public EffectBrush(System.Drawing.Brush brush)
        {
            if (brush is System.Drawing.SolidBrush)
            {
                type = BrushType.Solid;

                color_gradients.Add(0.0f, (brush as System.Drawing.SolidBrush).Color);
                color_gradients.Add(1.0f, (brush as System.Drawing.SolidBrush).Color);

                wrap = BrushWrap.Repeat;
            }
            else if (brush is System.Drawing.Drawing2D.LinearGradientBrush)
            {
                type = BrushType.Linear;

                System.Drawing.Drawing2D.LinearGradientBrush lgb = (brush as System.Drawing.Drawing2D.LinearGradientBrush);

                start = lgb.Rectangle.Location;
                end   = new System.Drawing.PointF(lgb.Rectangle.Width, lgb.Rectangle.Height);

                switch (lgb.WrapMode)
                {
                case (System.Drawing.Drawing2D.WrapMode.Clamp):
                    wrap = BrushWrap.None;
                    break;

                case (System.Drawing.Drawing2D.WrapMode.Tile):
                    wrap = BrushWrap.Repeat;
                    break;

                case (System.Drawing.Drawing2D.WrapMode.TileFlipXY):
                    wrap = BrushWrap.Reflect;
                    break;
                }

                try
                {
                    if (lgb.InterpolationColors != null && lgb.InterpolationColors.Colors.Length == lgb.InterpolationColors.Positions.Length)
                    {
                        for (int x = 0; x < lgb.InterpolationColors.Colors.Length; x++)
                        {
                            if (!color_gradients.ContainsKey(lgb.InterpolationColors.Positions[x]) && (lgb.InterpolationColors.Positions[x] >= 0.0f && lgb.InterpolationColors.Positions[x] <= 1.0f))
                            {
                                color_gradients.Add(
                                    lgb.InterpolationColors.Positions[x],
                                    lgb.InterpolationColors.Colors[x]
                                    );
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    color_gradients.Clear();

                    for (int x = 0; x < lgb.LinearColors.Length; x++)
                    {
                        float pos = x / (float)(lgb.LinearColors.Length - 1);

                        if (!color_gradients.ContainsKey(pos))
                        {
                            color_gradients.Add(
                                pos,
                                lgb.LinearColors[x]
                                );
                        }
                    }
                }
            }
            else if (brush is System.Drawing.Drawing2D.PathGradientBrush)
            {
                type = BrushType.Radial;

                System.Drawing.Drawing2D.PathGradientBrush pgb = (brush as System.Drawing.Drawing2D.PathGradientBrush);

                center = new System.Drawing.PointF(
                    pgb.CenterPoint.X,
                    pgb.CenterPoint.Y
                    );

                start = pgb.Rectangle.Location;
                end   = new System.Drawing.PointF(pgb.Rectangle.Width, pgb.Rectangle.Height);

                switch (pgb.WrapMode)
                {
                case (System.Drawing.Drawing2D.WrapMode.Clamp):
                    wrap = BrushWrap.None;
                    break;

                case (System.Drawing.Drawing2D.WrapMode.Tile):
                    wrap = BrushWrap.Repeat;
                    break;

                case (System.Drawing.Drawing2D.WrapMode.TileFlipXY):
                    wrap = BrushWrap.Reflect;
                    break;
                }

                try
                {
                    if (pgb.InterpolationColors != null && pgb.InterpolationColors.Colors.Length == pgb.InterpolationColors.Positions.Length)
                    {
                        for (int x = 0; x < pgb.InterpolationColors.Colors.Length; x++)
                        {
                            if (!color_gradients.ContainsKey(pgb.InterpolationColors.Positions[x]) && (pgb.InterpolationColors.Positions[x] >= 0.0f && pgb.InterpolationColors.Positions[x] <= 1.0f))
                            {
                                color_gradients.Add(
                                    pgb.InterpolationColors.Positions[x],
                                    pgb.InterpolationColors.Colors[x]
                                    );
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    color_gradients.Clear();

                    for (int x = 0; x < pgb.SurroundColors.Length; x++)
                    {
                        float pos = x / (float)(pgb.SurroundColors.Length - 1);

                        if (!color_gradients.ContainsKey(pos))
                        {
                            color_gradients.Add(
                                pos,
                                pgb.SurroundColors[x]
                                );
                        }
                    }
                }
            }
            else
            {
            }

            if (color_gradients.Count > 0)
            {
                bool firstFound = false;
                System.Drawing.Color first_color = new System.Drawing.Color();
                System.Drawing.Color last_color  = new System.Drawing.Color();

                foreach (var kvp in color_gradients)
                {
                    if (!firstFound)
                    {
                        first_color = kvp.Value;
                        firstFound  = true;
                    }

                    last_color = kvp.Value;
                }

                if (!color_gradients.ContainsKey(0.0f))
                {
                    color_gradients.Add(0.0f, first_color);
                }

                if (!color_gradients.ContainsKey(1.0f))
                {
                    color_gradients.Add(1.0f, last_color);
                }
            }
            else
            {
                if (!color_gradients.ContainsKey(0.0f))
                {
                    color_gradients.Add(0.0f, System.Drawing.Color.Transparent);
                }

                if (!color_gradients.ContainsKey(1.0f))
                {
                    color_gradients.Add(1.0f, System.Drawing.Color.Transparent);
                }
            }
        }
コード例 #3
0
        public EffectBrush(System.Windows.Media.Brush brush)
        {
            if (brush is System.Windows.Media.SolidColorBrush)
            {
                type = BrushType.Solid;

                wrap = BrushWrap.Repeat;

                color_gradients.Add(0.0f, Utils.ColorUtils.MediaColorToDrawingColor((brush as System.Windows.Media.SolidColorBrush).Color));
                color_gradients.Add(1.0f, Utils.ColorUtils.MediaColorToDrawingColor((brush as System.Windows.Media.SolidColorBrush).Color));
            }
            else if (brush is System.Windows.Media.LinearGradientBrush)
            {
                type = BrushType.Linear;

                System.Windows.Media.LinearGradientBrush lgb = (brush as System.Windows.Media.LinearGradientBrush);

                start = new System.Drawing.PointF((float)lgb.StartPoint.X, (float)lgb.StartPoint.Y);
                end   = new System.Drawing.PointF((float)lgb.EndPoint.X, (float)lgb.EndPoint.Y);

                switch (lgb.SpreadMethod)
                {
                case (System.Windows.Media.GradientSpreadMethod.Pad):
                    wrap = BrushWrap.None;
                    break;

                case (System.Windows.Media.GradientSpreadMethod.Repeat):
                    wrap = BrushWrap.Repeat;
                    break;

                case (System.Windows.Media.GradientSpreadMethod.Reflect):
                    wrap = BrushWrap.Reflect;
                    break;
                }

                foreach (var grad in lgb.GradientStops)
                {
                    if (!color_gradients.ContainsKey((float)grad.Offset) && ((float)grad.Offset >= 0.0f && (float)grad.Offset <= 1.0f))
                    {
                        color_gradients.Add(
                            (float)grad.Offset,
                            Utils.ColorUtils.MediaColorToDrawingColor(grad.Color)
                            );
                    }
                }
            }
            else if (brush is System.Windows.Media.RadialGradientBrush)
            {
                type = BrushType.Radial;

                System.Windows.Media.RadialGradientBrush rgb = (brush as System.Windows.Media.RadialGradientBrush);

                center = new System.Drawing.PointF(
                    (float)rgb.Center.X,
                    (float)rgb.Center.Y
                    );

                start = new System.Drawing.PointF(0, 0);
                end   = new System.Drawing.PointF((float)rgb.RadiusX * 2.0f, (float)rgb.RadiusY * 2.0f);

                switch (rgb.SpreadMethod)
                {
                case (System.Windows.Media.GradientSpreadMethod.Pad):
                    wrap = BrushWrap.None;
                    break;

                case (System.Windows.Media.GradientSpreadMethod.Repeat):
                    wrap = BrushWrap.Repeat;
                    break;

                case (System.Windows.Media.GradientSpreadMethod.Reflect):
                    wrap = BrushWrap.Reflect;
                    break;
                }

                foreach (var grad in rgb.GradientStops)
                {
                    if (!color_gradients.ContainsKey((float)grad.Offset) && ((float)grad.Offset >= 0.0f && (float)grad.Offset <= 1.0f))
                    {
                        color_gradients.Add(
                            (float)grad.Offset,
                            Utils.ColorUtils.MediaColorToDrawingColor(grad.Color)
                            );
                    }
                }
            }
            else
            {
            }

            if (color_gradients.Count > 0)
            {
                bool firstFound = false;
                System.Drawing.Color first_color = new System.Drawing.Color();
                System.Drawing.Color last_color  = new System.Drawing.Color();

                foreach (var kvp in color_gradients)
                {
                    if (!firstFound)
                    {
                        first_color = kvp.Value;
                        firstFound  = true;
                    }

                    last_color = kvp.Value;
                }

                if (!color_gradients.ContainsKey(0.0f))
                {
                    color_gradients.Add(0.0f, first_color);
                }

                if (!color_gradients.ContainsKey(1.0f))
                {
                    color_gradients.Add(1.0f, last_color);
                }
            }
            else
            {
                if (!color_gradients.ContainsKey(0.0f))
                {
                    color_gradients.Add(0.0f, System.Drawing.Color.Transparent);
                }

                if (!color_gradients.ContainsKey(1.0f))
                {
                    color_gradients.Add(1.0f, System.Drawing.Color.Transparent);
                }
            }
        }
コード例 #4
0
 public EffectBrush SetWrap(BrushWrap wrap)
 {
     this.wrap = wrap;
     return(this);
 }