示例#1
0
        public void Build(Selection selection)
        {
            // check visibility
            Visible = selection.ForAll(f => FillDecorator.ContainsType(f.Style.FillStyle, typeof(TextureFill)));
            // show the editor only if all figures contain BorderStyle
            if (!Visible)
            {
                return;           // do not build anything
            }
            // remember editing object
            _selection = selection;

            // get list of objects
            var textureFillStyles = _selection.Select(f =>
                                                      (TextureFill)FillDecorator.GetDecorator(f.Style.FillStyle, typeof(TextureFill))).ToList();

            // copy properties of object to GUI
            _updating++;

            _image         = textureFillStyles.GetProperty(f => f.Image);
            lbWrap.Enabled = cbWrap.Enabled = lbScale.Enabled = nudScale.Enabled = _image != null;

            cbWrap.SelectedIndex = (int)textureFillStyles.GetProperty(f => f.WrapMode);
            nudScale.Value       = (decimal)textureFillStyles.GetProperty(f => f.Scale, 1);

            _updating--;
        }
示例#2
0
        public static bool ContainsAnyDecorator(Figure figure)
        {
            var result = false;

            result |= RendererDecorator.ContainsAnyDecorator(figure.Renderer);
            result |= FillDecorator.ContainsAnyDecorator(figure.Style.FillStyle);
            return(result);
        }
        private void DisplayRectangles()
        {
            decoratorContent.Children.Clear();

            randomNumber    = new Random();
            chartreuseBrush = new SolidColorBrush(Colors.Chartreuse);
            IBaseRectangle baseRect = new BaseRectangle();

            // The base component interface
            AddRectangleToStackPanel(
                baseRect,
                "The base component interface"
                );

            // The base component interface through the Stroke Decorator
            // with a Chartreuse stroke of random thickness
            AddRectangleToStackPanel(
                new StrokeDecorator(baseRect, chartreuseBrush, randomNumber.Next(10)),
                "Stroke Decorator adding a chartreuse stroke of random thickness"
                );

            // The base component interface through the Fill Decorator
            // with a random fill color
            AddRectangleToStackPanel(
                new FillDecorator(baseRect, RandomColorBrush()),
                "Fill Decorator adding a random fill color"
                );

            // The base component interface
            // through the Stroke Decorator with a random stroke of random thickness
            // through the Fill Decorator with a random fill color
            AddRectangleToStackPanel(
                new FillDecorator(new StrokeDecorator(baseRect, RandomColorBrush(), randomNumber.Next(10)), RandomColorBrush()),
                "Stroke Decorator with random color of random thickness, passed through Fill Decorator with random fill color"
                );

            // The base component
            // through the Fill Decorator with a random fill color
            // through the Stroke Decorator with a random stroke of random thickness
            FillDecorator fillDecorator = new FillDecorator(new BaseRectangle(), RandomColorBrush());

            AddRectangleToStackPanel(
                new StrokeDecorator(fillDecorator, RandomColorBrush(), randomNumber.Next(10)),
                "Explicitely initiated Fill Decorator with random fill color, passed through Stroke Decorator with random color and random thickness"
                );

            // The base component interface
            // through the Stroke Decorator
            // with a random stroke color and stroke thickness of 5
            AddRectangleToStackPanel(
                new StrokeDecorator(baseRect, RandomColorBrush(), 5),
                ""
                );
        }
示例#4
0
        private void UpdateObject()
        {
            if (_updating > 0)
            {
                return;                // we are in updating mode
            }
            // fire event
            StartChanging(this, new ChangingEventArgs("Texture Fill Style"));

            // get list of objects
            var textureFillStyles = _selection.Select(f =>
                                                      (TextureFill)FillDecorator.GetDecorator(f.Style.FillStyle, typeof(TextureFill))).ToList();

            // send values back from GUI to object
            textureFillStyles.SetProperty(f => f.Image    = (Bitmap)_image);
            textureFillStyles.SetProperty(f => f.WrapMode = (WrapMode)cbWrap.SelectedIndex);
            textureFillStyles.SetProperty(f => f.Scale    = (float)nudScale.Value);

            // fire event
            Changed(this, EventArgs.Empty);
        }
        private void UpdateObject()
        {
            if (_updating > 0)
            {
                return;                // we are in updating mode
            }
            // fire event
            StartChanging(this, new ChangingEventArgs("Hatch Fill Style"));

            // get list of objects
            var hatchStyles = _selection.Select(f =>
                                                (HatchFill)FillDecorator.GetDecorator(f.Style.FillStyle, typeof(HatchFill))).ToList();

            // send values back from GUI to object
            _hatchFill = (HatchStyle)cbHatch.SelectedIndex;
            hatchStyles.SetProperty(f => f.HatchStyle = _hatchFill);
            _color = lbHatchColor.BackColor;
            hatchStyles.SetProperty(f => f.HatchColor = _color);

            // fire event
            Changed(this, EventArgs.Empty);
        }
示例#6
0
 private static void AddDecorators(Figure fig, FigureTreeNode fignode)
 {
     if (Helper.ContainsAnyDecorator(fig))
     {
         if (FillDecorator.ContainsAnyDecorator(fig.Style.FillStyle))
         {
             var list = FillDecorator.GetDecorators(fig.Style.FillStyle);
             foreach (var item in list)
             {
                 fignode.Nodes.Add(string.Format("{0}FillStyleDecorator", item));
             }
         }
         if (RendererDecorator.ContainsAnyDecorator(fig.Renderer))
         {
             var list = RendererDecorator.GetDecorators(fig.Renderer);
             foreach (var item in list)
             {
                 fignode.Nodes.Add(string.Format("{0}RendererDecorator", item));
             }
         }
     }
 }
        public void Build(Selection selection)
        {
            // check visibility
            Visible = selection.ForAll(f => FillDecorator.ContainsType(f.Style.FillStyle, typeof(HatchFill)));
            // show the editor only if all figures contain BorderStyle
            if (!Visible)
            {
                return;           // do not build anything
            }
            // remember editing object
            _selection = selection;

            // get list of objects
            var hatchStyles = _selection.Select(f =>
                                                (HatchFill)FillDecorator.GetDecorator(f.Style.FillStyle, typeof(HatchFill))).ToList();

            // copy properties of object to GUI
            _updating++;

            cbHatch.SelectedIndex  = (int)hatchStyles.GetProperty(f => f.HatchStyle, _hatchFill);
            lbHatchColor.BackColor = hatchStyles.GetProperty(f => f.HatchColor, _color);

            _updating--;
        }
示例#8
0
        static void Main(string[] args)
        {
            Shape rect = ShapeFactory.GetInstance().GetShape(Shapes.Rectangle);

            rect.Render();

            GraphicDecorator border = new BorderDecorator(rect, "rosso", 2);

            border.Render();

            GraphicDecorator dec = new FillDecorator(border, "giallo", "nero", "destra");

            dec.Render();

            GraphicDecorator all = new BorderDecorator(
                new FillDecorator(
                    new ShadowDecorator(rect, "nero", 0.6),
                    "giallo", "verde", "destra"),
                "rosso", 2);

            all.Render();

            Console.ReadLine();
        }