Exemplo n.º 1
0
        public void Invalidate_Should_Invalidate_All_Layers()
        {
            var target = new Class1();

            var layer1 = XLayer.Create("Layer1", target);
            var layer2 = XLayer.Create("Layer2", target);

            target.Layers = target.Layers.Add(layer1);
            target.Layers = target.Layers.Add(layer2);

            var workingLayer = XLayer.Create("WorkingLayer", target);
            var helperLayer  = XLayer.Create("HelperLayer", target);

            target.WorkingLayer = workingLayer;
            target.HelperLayer  = helperLayer;

            int count = 0;

            layer1.InvalidateLayer       += (sender, e) => count++;
            layer2.InvalidateLayer       += (sender, e) => count++;
            workingLayer.InvalidateLayer += (sender, e) => count++;
            helperLayer.InvalidateLayer  += (sender, e) => count++;

            target.Invalidate();

            Assert.Equal(4, count);
        }
Exemplo n.º 2
0
        public void SetSelected_Container()
        {
            var target = new XProject();

            var document = XDocument.Create();

            target.Documents = target.Documents.Add(document);

            var page = XContainer.CreatePage();

            document.Pages = document.Pages.Add(page);

            var layer = XLayer.Create("Layer1", page);

            page.Layers = page.Layers.Add(layer);

            bool raised = false;

            layer.InvalidateLayer += (sender, e) =>
            {
                raised = true;
            };

            target.SetSelected(page);

            Assert.Equal(document, target.CurrentDocument);
            Assert.Equal(page, target.CurrentContainer);
            Assert.True(raised);
        }
Exemplo n.º 3
0
        public void SetSelected_Layer()
        {
            var target = new XProject();

            var page  = new XContainer();
            var layer = XLayer.Create("Layer1", page);

            target.SetSelected(layer);

            Assert.Equal(layer, page.CurrentLayer);
        }
Exemplo n.º 4
0
        public void SetCurrentLayer_Sets_CurrentLayer()
        {
            var target = new Class1();

            var layer = XLayer.Create("Layer1", target);

            target.Layers = target.Layers.Add(layer);

            target.SetCurrentLayer(layer);

            Assert.Equal(layer, target.CurrentLayer);
        }
Exemplo n.º 5
0
        public void Invalidate_Raises_InvalidateLayer_Event()
        {
            var target = XLayer.Create("Layer1");

            bool raised = false;

            target.InvalidateLayer += (sender, e) =>
            {
                raised = true;
            };

            target.Invalidate();

            Assert.True(raised);
        }
Exemplo n.º 6
0
        public void Setting_IsVisible_Should_Invalidate_Layer()
        {
            var target = XLayer.Create("Layer1");

            bool raised = false;

            target.InvalidateLayer += (sender, e) =>
            {
                raised = true;
            };

            target.IsVisible = false;

            Assert.True(raised);
        }
Exemplo n.º 7
0
        public void Invalidate_Sets_EventArgs()
        {
            var target = XLayer.Create("Layer1");

            InvalidateLayerEventArgs args = null;

            target.InvalidateLayer += (sender, e) =>
            {
                args = e;
            };

            target.Invalidate();

            Assert.NotNull(args);
            Assert.True(args is InvalidateLayerEventArgs);
        }
Exemplo n.º 8
0
        public void Invalidate_Should_Invalidate_Template()
        {
            var target = new XContainer()
            {
                Template = new XContainer()
            };

            var layer = XLayer.Create("Layer1", target);

            target.Template.Layers = target.Template.Layers.Add(layer);

            bool raised = false;

            layer.InvalidateLayer += (sender, e) =>
            {
                raised = true;
            };

            target.Invalidate();

            Assert.True(raised);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes static designer context.
        /// </summary>
        /// <param name="renderer">The design time renderer instance.</param>
        /// <param name="clipboard">The design time clipboard instance.</param>
        /// <param name="jsonSerializer">The design time Json serializer instance.</param>
        /// <param name="xamlSerializer">The design time Xaml serializer instance.</param>
        /// <returns>The new instance of the <see cref="DesignerContext"/> class.</returns>
        public static void InitializeContext(ShapeRenderer renderer, ITextClipboard clipboard, ITextSerializer jsonSerializer, ITextSerializer xamlSerializer)
        {
            // Editor

            Editor = new ProjectEditor()
            {
                CurrentTool     = Tool.Selection,
                CurrentPathTool = PathTool.Line,
                CommandManager  = new DesignerCommandManager(),
                Renderers       = new ShapeRenderer[] { renderer },
                ProjectFactory  = new ProjectFactory(),
                TextClipboard   = clipboard,
                JsonSerializer  = jsonSerializer,
                XamlSerializer  = xamlSerializer
            }.Defaults();

            // Recent Projects
            Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test1", "Test1.project"));
            Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test2", "Test2.project"));

            // Commands

            Editor.InitializeCommands();
            InitializeCommands(Editor);
            Editor.CommandManager.RegisterCommands();

            // New Project

            Editor.OnNew(null);

            // Data

            var db      = XDatabase.Create("Db");
            var fields  = new string[] { "Column0", "Column1" };
            var columns = ImmutableArray.CreateRange(fields.Select(c => XColumn.Create(db, c)));

            db.Columns = columns;
            var values = Enumerable.Repeat("<empty>", db.Columns.Length).Select(c => XValue.Create(c));
            var record = XRecord.Create(
                db,
                db.Columns,
                ImmutableArray.CreateRange(values));

            db.Records       = db.Records.Add(record);
            db.CurrentRecord = record;

            Database = db;
            Data     = XContext.Create(record);
            Record   = record;

            // Project

            IProjectFactory factory = new ProjectFactory();

            Project = factory.GetProject();

            Template = XContainer.CreateTemplate();

            Page = XContainer.CreatePage();
            var layer = Page.Layers.FirstOrDefault();

            layer.Shapes      = layer.Shapes.Add(XLine.Create(0, 0, null, null));
            Page.CurrentLayer = layer;
            Page.CurrentShape = layer.Shapes.FirstOrDefault();
            Page.Template     = Template;

            Document = XDocument.Create();
            Layer    = XLayer.Create();
            Options  = XOptions.Create();

            // State

            State = ShapeState.Create();

            // Style

            ArgbColor       = ArgbColor.Create();
            ArrowStyle      = ArrowStyle.Create();
            FontStyle       = FontStyle.Create();
            LineFixedLength = LineFixedLength.Create();
            LineStyle       = LineStyle.Create();
            Style           = ShapeStyle.Create("Default");
            TextStyle       = TextStyle.Create();

            // Shapes

            Arc             = XArc.Create(0, 0, Style, null);
            CubicBezier     = XCubicBezier.Create(0, 0, Style, null);
            Ellipse         = XEllipse.Create(0, 0, Style, null);
            Group           = XGroup.Create(Constants.DefaulGroupName);
            Image           = XImage.Create(0, 0, Style, null, "key");
            Line            = XLine.Create(0, 0, Style, null);
            Path            = XPath.Create("Path", Style, null);
            Point           = XPoint.Create();
            QuadraticBezier = XQuadraticBezier.Create(0, 0, Style, null);
            Rectangle       = XRectangle.Create(0, 0, Style, null);
            Text            = XText.Create(0, 0, Style, null, "Text");

            // Path

            ArcSegment                 = XArcSegment.Create(XPoint.Create(), XPathSize.Create(), 180, true, XSweepDirection.Clockwise, true, true);
            CubicBezierSegment         = XCubicBezierSegment.Create(XPoint.Create(), XPoint.Create(), XPoint.Create(), true, true);
            LineSegment                = XLineSegment.Create(XPoint.Create(), true, true);
            PathFigure                 = XPathFigure.Create(XPoint.Create(), false, true);
            PathGeometry               = XPathGeometry.Create(ImmutableArray.Create <XPathFigure>(), XFillRule.EvenOdd);
            PathSize                   = XPathSize.Create();
            PolyCubicBezierSegment     = XPolyCubicBezierSegment.Create(ImmutableArray.Create <XPoint>(), true, true);
            PolyLineSegment            = XPolyLineSegment.Create(ImmutableArray.Create <XPoint>(), true, true);
            PolyQuadraticBezierSegment = XPolyQuadraticBezierSegment.Create(ImmutableArray.Create <XPoint>(), true, true);
            QuadraticBezierSegment     = XQuadraticBezierSegment.Create(XPoint.Create(), XPoint.Create(), true, true);
        }