Beispiel #1
0
        private static SketchLayer SketchLayer(
            Guid id                              = default(Guid),
            SketchLayer parent                   = null,
            SketchRect frame                     = null,
            string name                          = null,
            bool nameIsFixed                     = false,
            double rotation                      = 0,
            bool flippedVertically               = false,
            bool flippedHorizontally             = false,
            IReadOnlyList <SketchLayer> children = null)
        {
            var alignment = new SketchAlignment(
                new SketchAxisAlignment(false, false, false),
                new SketchAxisAlignment(false, false, false));                 //Can make parameter later if needed

            return(new SketchLayer(
                       id,
                       parent,
                       frame,
                       name,
                       nameIsFixed,
                       alignment,
                       rotation,
                       flippedVertically,
                       flippedHorizontally,
                       Optional.None(),
                       children ?? new List <SketchLayer>()));
        }
Beispiel #2
0
        private static bool HasMaskedChild(SketchLayer parent)
        {
            var hasMaskChild = parent.Layers
                               .Select(l => l as SketchShapeGroup)
                               .Where(l => l != null)
                               .Any(sg => sg.HasClippingMask);

            return(hasMaskChild);
        }
Beispiel #3
0
 public SketchShapePath(
     SketchLayer layer,
     SketchPath path,
     SketchBooleanOperation operation)
     : base(layer)
 {
     Path             = path;
     BooleanOperation = operation;
 }
Beispiel #4
0
        public static SketchSymbolMaster WithLayer(this SketchSymbolMaster symbol, SketchLayer layer)
        {
            var newLayers = new List <SketchLayer>(symbol.Layers)
            {
                layer
            };
            var newParent = new SketchLayer(symbol, newLayers);
            var newSymbol = new SketchSymbolMaster(newParent, symbol.SymbolId);

            layer.Parent = newSymbol;
            return(newSymbol);
        }
Beispiel #5
0
        //Public just for tests
        public UxNode BuildLayer(SketchLayer layer)
        {
            var node = BuildLayerInternal(layer);

            layer.Style.Do(style =>
                           style.Opacity.Where(opacity => opacity < 1).Do(opacity =>
                                                                          node.Attributes["Opacity"] = new UxFloat((float)opacity)));

            if (layer.Layers.Any())
            {
                var hasMaskedChild = HasMaskedChild(layer);
                if (hasMaskedChild)
                {
                    AddUnsupportedMaskingWarning(node, layer.Name);
                }

                // Skip processing children if we found a direct child that is a mask. 2017-12-12 anette
                // SketchShapeGroup is a SketchParentLayer but BuildShapeGroup handles it's own children.
                // This is inconsistent and should be cleaned up. 2017-12-06 anette
                if (!hasMaskedChild && !(layer is SketchShapeGroup))
                {
                    var children = layer.Layers
                                   .Select(BuildLayer)
                                   .ToList();

                    children.Reverse();

                    node.Children.AddRange(children);
                }
            }

            // Flip and rotate the panel. Order of transformations matter,
            // we first flip (done by rotating 180 around the X/Y-axis),
            // then the actual rotation (around the implicit Z-axis)
            if (layer.IsFlippedVertical)
            {
                node.Children.Add(new UxRotation(180, UxRotation.RotationAxis.X));
            }
            if (layer.IsFlippedHorizontal)
            {
                node.Children.Add(new UxRotation(180, UxRotation.RotationAxis.Y));
            }
            if (!layer.Rotation.Equals(0))
            {
                node.Children.Add(new UxRotation(layer.Rotation));
            }


            node.Children.Insert(0, new UxComment(layer.Name));

            return(node);
        }
Beispiel #6
0
        public UxNode BuildPage(SketchLayer parent)
        {
            var pageNode = new UxNode
            {
                ClassName       = "Panel",
                SketchLayerName = parent.Name,
                Attributes      = new Dictionary <string, IUxSerializeable> {
                    { "ClipToBounds", new UxString("true") }
                }
            };

            AddChildrenLayers(pageNode, parent);
            return(pageNode);
        }
Beispiel #7
0
        private void AddChildrenLayers(UxNode node, SketchLayer parent)
        {
            var hasMaskedChildLayer = HasMaskedChild(parent);

            if (hasMaskedChildLayer)
            {
                _log.Warning("Masked shapes are not supported " + parent.Name);
                node.Children.Add(new UxComment("Masked shape group is not supported in UX"));
            }
            else
            {
                node.Children = parent.Layers
                                .AsEnumerable()
                                .Reverse()
                                .Select(BuildLayer)
                                .Cast <IUxSerializeable>()
                                .ToList();
            }
        }
        SketchLayer ParseCommonLayerProperties(JObject layerJson)
        {
            var children = ParseChildLayers(layerJson).ToList();
            var parent   = new SketchLayer(
                ParseEntityId(layerJson),
                null,                 //Parent has to be set later, since it doesn't exist yet
                ParseFrame(layerJson),
                (string)layerJson["name"],
                (bool?)layerJson["nameIsFixed"] ?? false,
                ParseAlignment(layerJson),
                (double?)layerJson["rotation"] ?? 0,
                (bool?)layerJson["isFlippedVertical"] ?? false,
                (bool?)layerJson["isFlippedHorizontal"] ?? false,
                ParseStyle(layerJson),
                children
                );

            foreach (var child in children)
            {
                child.Parent = parent;                 //Parent doesn't exist until children are done parsing, so set it here
            }

            return(parent);
        }
Beispiel #9
0
 public SketchRectangle(SketchLayer layer, SketchPath path, SketchBooleanOperation operation)
     : base(layer, path, operation)
 {
 }
Beispiel #10
0
 public SketchArtboard(SketchLayer parentLayer) : base(parentLayer)
 {
 }
Beispiel #11
0
 UxNode BuildLayout(SketchLayer layer, UxNode targetNode)
 {
     return(new LayoutBuilder(layer).Build(targetNode));
 }
Beispiel #12
0
        UxNode BuildLayerInternal(SketchLayer layer)
        {
            var group = layer as SketchGroup;

            if (group != null)
            {
                return(BuildGroup(group));
            }

            var rectangle = layer as SketchRectangle;

            if (rectangle != null)
            {
                return(BuildRectangle(rectangle));
            }

            var shapeGroup = layer as SketchShapeGroup;

            if (shapeGroup != null)
            {
                return(BuildShapeGroup(shapeGroup));
            }

            var bitmap = layer as SketchBitmap;

            if (bitmap != null)
            {
                return(BuildBitmap(bitmap));
            }

            var text = layer as SketchText;

            if (text != null)
            {
                return(BuildText(text));
            }

            var symbolInstance = layer as SketchSymbolInstance;

            if (symbolInstance != null)
            {
                return(BuildSymbolInstance(symbolInstance));
            }

            var shapePath = layer as SketchShapePath;

            if (shapePath != null)
            {
                return(BuildShapePath(shapePath));
            }

            var warning = $"Unimplemented layer type: {layer.GetType().Name}";

            _log.Warning(warning);
            var groupNode = new UxNode
            {
                ClassName       = "Panel",
                SketchLayerName = layer.Name
            };

            groupNode.Children.Add(new UxComment(warning));
            return(groupNode);
        }
Beispiel #13
0
 public LayoutBuilder(SketchLayer layer)
 {
     _layer = layer;
 }
Beispiel #14
0
 public SketchGroup(SketchLayer parentLayer) : base(parentLayer)
 {
 }