Exemple #1
0
        /// <inheritdoc/>
        XContainer IProjectFactory.GetTemplate(XProject project, string name)
        {
            var template = XContainer.CreateTemplate(name);

            template.Background = ArgbColor.Create(0xFF, 0xFF, 0xFF, 0xFF);
            return(template);
        }
Exemple #2
0
 /// <summary>
 /// Converts a value.
 /// </summary>
 /// <param name="value">The value that is produced by the binding target.</param>
 /// <param name="targetType">The type to convert to.</param>
 /// <param name="parameter">The converter parameter to use.</param>
 /// <param name="culture">The culture to use in the converter.</param>
 /// <returns>A converted value.</returns>
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is SolidColorBrush brush && value != DependencyProperty.UnsetValue)
     {
         return(ArgbColor.Create(
                    brush.Color.A,
                    brush.Color.R,
                    brush.Color.G,
                    brush.Color.B));
     }
     return(DependencyProperty.UnsetValue);
 }
        public void Template_Not_Null_Background_Returns_Template_Background()
        {
            var target = new Class1()
            {
                Background = ArgbColor.Create(),
                Template   = new Class1()
                {
                    Background = ArgbColor.Create()
                }
            };

            Assert.Equal(target.Template.Background, target.Background);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var brush = value as SolidColorBrush;

            if (brush != null)
            {
                return(ArgbColor.Create(
                           brush.Color.A,
                           brush.Color.R,
                           brush.Color.G,
                           brush.Color.B));
            }
            return(null);
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArrowStyle"/> class.
 /// </summary>
 /// <param name="source">The source style.</param>
 public ArrowStyle(BaseStyle source) : this()
 {
     Stroke = ArgbColor.Create
                  (source.Stroke.A,
                  source.Stroke.R,
                  source.Stroke.G,
                  source.Stroke.B);
     Fill = ArgbColor.Create
                (source.Fill.A,
                source.Fill.R,
                source.Fill.G,
                source.Fill.B);
     Thickness  = source.Thickness;
     LineCap    = source.LineCap;
     Dashes     = source.Dashes != null ? source.Dashes : default(string);
     DashOffset = source.DashOffset;
 }
Exemple #6
0
        /// <summary>
        /// Creates a new <see cref="ShapeStyle"/> instance.
        /// </summary>
        /// <param name="name">The shape style name.</param>
        /// <param name="sa">The stroke color alpha channel.</param>
        /// <param name="sr">The stroke color red channel.</param>
        /// <param name="sg">The stroke color green channel.</param>
        /// <param name="sb">The stroke color blue channel.</param>
        /// <param name="fa">The fill color alpha channel.</param>
        /// <param name="fr">The fill color red channel.</param>
        /// <param name="fg">The fill color green channel.</param>
        /// <param name="fb">The fill color blue channel.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="textStyle">The text style.</param>
        /// <param name="lineStyle">The line style.</param>
        /// <param name="startArrowStyle">The start arrow style.</param>
        /// <param name="endArrowStyle">The end arrow style.</param>
        /// <param name="lineCap">The line cap.</param>
        /// <param name="dashes">The line dashes.</param>
        /// <param name="dashOffset">The line dash offset.</param>
        /// <returns>The new instance of the <see cref="ShapeStyle"/> class.</returns>
        public static ShapeStyle Create(string name = "", byte sa = 0xFF, byte sr = 0x00, byte sg = 0x00, byte sb = 0x00, byte fa = 0xFF, byte fr = 0x00, byte fg = 0x00, byte fb = 0x00, double thickness = 2.0, TextStyle textStyle = null, LineStyle lineStyle = null, ArrowStyle startArrowStyle = null, ArrowStyle endArrowStyle = null, LineCap lineCap = LineCap.Round, string dashes = default(string), double dashOffset = 0.0)
        {
            var style = new ShapeStyle()
            {
                Name       = name,
                Stroke     = ArgbColor.Create(sa, sr, sg, sb),
                Fill       = ArgbColor.Create(fa, fr, fg, fb),
                Thickness  = thickness,
                LineCap    = lineCap,
                Dashes     = dashes,
                DashOffset = dashOffset,
                LineStyle  = lineStyle ?? LineStyle.Create("Line"),
                TextStyle  = textStyle ?? TextStyle.Create("Text")
            };

            style.StartArrowStyle = startArrowStyle ?? ArrowStyle.Create("Start", style);
            style.EndArrowStyle   = endArrowStyle ?? ArrowStyle.Create("End", style);

            return(style);
        }
Exemple #7
0
        /// <summary>
        /// Creates a new <see cref="XContainer"/> template instance.
        /// </summary>
        /// <param name="name">The template name.</param>
        /// <param name="width">The template width.</param>
        /// <param name="height">The template height.</param>
        /// <returns>The new instance of the <see cref="XContainer"/>.</returns>
        public static XContainer CreateTemplate(string name = "Template", double width = 840, double height = 600)
        {
            var template = new XContainer()
            {
                Name = name
            };

            template.Background = ArgbColor.Create(0x00, 0xFF, 0xFF, 0xFF);
            template.Width      = width;
            template.Height     = height;

            var builder = template.Layers.ToBuilder();

            builder.Add(XLayer.Create("TemplateLayer1", template));
            builder.Add(XLayer.Create("TemplateLayer2", template));
            builder.Add(XLayer.Create("TemplateLayer3", template));
            template.Layers = builder.ToImmutable();

            template.CurrentLayer = template.Layers.FirstOrDefault();
            template.WorkingLayer = XLayer.Create("TemplateWorking", template);
            template.HelperLayer  = XLayer.Create("TemplateHelper", template);

            return(template);
        }
Exemple #8
0
        public void ToHtml_Should_Return_Color_String_Statring_With_Hash()
        {
            var target = ArgbColor.Create(0xFF, 0x7F, 0x5A, 0x45);

            Assert.Equal("#FF7F5A45", ArgbColor.ToHtml(target));
        }
        /// <summary>
        /// Initializes static designer context.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        public static void InitializeContext(IServiceProvider serviceProvider)
        {
            // Editor

            Editor = serviceProvider.GetService <ProjectEditor>();

            // Recent Projects

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

            // New Project

            Editor.OnNewProject();

            // Transform

            Transform = MatrixObject.Identity;

            // Data

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

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

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

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

            // Project

            IProjectFactory factory = new ProjectFactory();

            Project = factory.GetProject();

            Template = PageContainer.CreateTemplate();

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

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

            Document = DocumentContainer.Create();
            Layer    = LayerContainer.Create();
            Options  = Options.Create();

            // State

            State = ShapeState.Create();

            // Style

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

            // Shapes

            Arc             = ArcShape.Create(0, 0, Style, null);
            CubicBezier     = CubicBezierShape.Create(0, 0, Style, null);
            Ellipse         = EllipseShape.Create(0, 0, Style, null);
            Group           = GroupShape.Create(Constants.DefaulGroupName);
            Image           = ImageShape.Create(0, 0, Style, null, "key");
            Line            = LineShape.Create(0, 0, Style, null);
            Path            = PathShape.Create(Style, null);
            Point           = PointShape.Create();
            QuadraticBezier = QuadraticBezierShape.Create(0, 0, Style, null);
            Rectangle       = RectangleShape.Create(0, 0, Style, null);
            Text            = TextShape.Create(0, 0, Style, null, "Text");

            // Path

            ArcSegment                 = ArcSegment.Create(PointShape.Create(), PathSize.Create(), 180, true, SweepDirection.Clockwise, true, true);
            CubicBezierSegment         = CubicBezierSegment.Create(PointShape.Create(), PointShape.Create(), PointShape.Create(), true, true);
            LineSegment                = LineSegment.Create(PointShape.Create(), true, true);
            PathFigure                 = PathFigure.Create(PointShape.Create(), false, true);
            PathGeometry               = PathGeometry.Create(ImmutableArray.Create <PathFigure>(), FillRule.EvenOdd);
            PathSize                   = PathSize.Create();
            PolyCubicBezierSegment     = PolyCubicBezierSegment.Create(ImmutableArray.Create <PointShape>(), true, true);
            PolyLineSegment            = PolyLineSegment.Create(ImmutableArray.Create <PointShape>(), true, true);
            PolyQuadraticBezierSegment = PolyQuadraticBezierSegment.Create(ImmutableArray.Create <PointShape>(), true, true);
            QuadraticBezierSegment     = QuadraticBezierSegment.Create(PointShape.Create(), PointShape.Create(), true, true);
        }
Exemple #10
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);
        }