Пример #1
0
 public ExampleViewModel()
 {
     this.ScaleXCommand = new DelegateCommand(new Action<object>(this.OnScaleXCommandExecuted));
     this.ScaleYCommand = new DelegateCommand(new Action<object>(this.OnScaleYCommandExecuted));
     var transformCollection = new TransformCollection();
     transformCollection.Add(new RotateTransform());
     transformCollection.Add(new ScaleTransform());
     this.renderTransform = new TransformGroup() { Children = transformCollection };
 }
Пример #2
0
        public Shape Draw()
        {
            Shape s = Model.Draw();
            TransformCollection tc = ((TransformGroup)s.RenderTransform).Children;

            tc.Add(new ScaleTransform(Scale, Scale));
            tc.Add(new RotateTransform(Angle));
            tc.Add(new TranslateTransform(X, Y));
            return(s);
        }
        public ExampleViewModel()
        {
            this.ScaleXCommand = new DelegateCommand(new Action <object>(this.OnScaleXCommandExecuted));
            this.ScaleYCommand = new DelegateCommand(new Action <object>(this.OnScaleYCommandExecuted));
            var transformCollection = new TransformCollection();

            transformCollection.Add(new RotateTransform());
            transformCollection.Add(new ScaleTransform());
            this.renderTransform = new TransformGroup()
            {
                Children = transformCollection
            };
        }
Пример #4
0
        /// <inheritdoc />
        public void Add(Node node)
        {
            if (node is IInternalTransform)
            {
                _transforms.Add(node);
            }
            else
            {
                _components.Add(node);
                SetInheritedBindingContext(node, BindingContext);

                Forms.mainThread.Send(state =>
                {
                    if (_sleeping != null)
                    {
                        node.AddToInMainThread(_sleeping.gameObject);
                    }
                    else if (Body != null)
                    {
                        node.AddToInMainThread(Body.gameObject);
                        node.AwakeInMainThread();
                    }
                }, null);
            }
        }
        protected override void OnAttached()
        {
            FrameworkElement associatedObject = AssociatedObject;

            _scale     = new ScaleTransform();
            _rotate    = new RotateTransform();
            _translate = new TranslateTransform();
            TransformGroup      transform = new TransformGroup();
            TransformCollection children  = transform.Children;

            children.Add(_scale);
            children.Add(_rotate);
            children.Add(_translate);
            associatedObject.RenderTransform       = transform;
            associatedObject.RenderTransformOrigin = new Point(0.5f, 0.5f);

            associatedObject.IsManipulationEnabled        = true;
            associatedObject.ManipulationStarting        += OnManipulationStarting;
            associatedObject.ManipulationInertiaStarting += OnManipulationInertia;
            associatedObject.ManipulationDelta           += OnManipulationDelta;
            associatedObject.MouseLeftButtonDown         += OnMouseDown;
            associatedObject.MouseLeftButtonUp           += OnMouseUp;
        }
Пример #6
0
        protected static Transform RemoveScaleFromCanonicalTransform(CanonicalTransform canonicalTransform)
        {
            TransformCollection children            = canonicalTransform.TransformGroup.Children;
            TransformCollection transformCollection = new TransformCollection();

            foreach (Transform transform in children)
            {
                if (!typeof(ScaleTransform).IsAssignableFrom(transform.GetType()))
                {
                    transformCollection.Add(transform);
                }
            }
            return((Transform) new TransformGroup()
            {
                Children = transformCollection
            });
        }
Пример #7
0
        private void Redraw()
        {
            TranslateTransform tt = new TranslateTransform(-canvasPos.Left, -canvasPos.Top);
            ScaleTransform     st = new ScaleTransform(canvasSize.Y * zoom, canvasSize.Y * zoom);
            TransformGroup     tg = new TransformGroup()
            {
                Children = new TransformCollection()
                {
                    tt, st
                }
            };
            List <Shape>     shapes     = new List <Shape>();
            List <Polyline>  selections = new List <Polyline>();
            HashSet <string> addedNodes = new HashSet <string>();

            canvas.Children.Clear();

            foreach (KeyValuePair <string, Node> kvp in nodes)
            {
                Node node = kvp.Value;
                Rect aabb = node.AABB;

                if (!aabb.IntersectsWith(canvasPos))
                {
                    continue;
                }

                Shape s = node.Draw();
                TransformCollection tc = ((TransformGroup)s.RenderTransform).Children;
                tc.Add(tt);
                tc.Add(st);
                shapes.Add(s);
                addedNodes.Add(kvp.Key);

                if (node.Selected)
                {
                    Polyline p = new Polyline()
                    {
                        Stroke = Brushes.Red, StrokeThickness = 2, Points = new PointCollection()
                        {
                            tg.Transform(aabb.TopLeft), tg.Transform(aabb.TopRight), tg.Transform(aabb.BottomRight), tg.Transform(aabb.BottomLeft), tg.Transform(aabb.TopLeft)
                        }
                    };
                    selections.Add(p);
                }

                if (!showRefs[node.Instance.Class])
                {
                    continue;
                }

                Point p1 = tg.Transform(new Point(node.X, node.Y));

                foreach (string target in node.OutReferences)
                {
                    Node targetNode;

                    if (addedNodes.Contains(target) || !nodes.TryGetValue(target, out targetNode) || !showRefs[targetNode.Instance.Class])
                    {
                        continue;
                    }

                    Point p2 = tg.Transform(new Point(targetNode.X, targetNode.Y));

                    Line line = new Line()
                    {
                        Stroke = Brushes.Black, StrokeThickness = 2, X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y
                    };
                    canvas.Children.Add(line);
                }

                foreach (string target in node.InReferences)
                {
                    Node targetNode;

                    if (addedNodes.Contains(target) || !nodes.TryGetValue(target, out targetNode) || !showRefs[targetNode.Instance.Class])
                    {
                        continue;
                    }

                    Point p2 = tg.Transform(new Point(targetNode.X, targetNode.Y));

                    Line line = new Line()
                    {
                        Stroke = Brushes.Black, StrokeThickness = 2, X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y
                    };
                    canvas.Children.Add(line);
                }
            }

            foreach (Shape shape in shapes)
            {
                canvas.Children.Add(shape);
            }

            foreach (Polyline p in selections)
            {
                canvas.Children.Add(p);
            }
        }
Пример #8
0
        /// <summary> 
        /// NOTE: THIS METHOD IS ONLY FOR INTERNAL SPECIFIC USE. It does not support some features of FrameworkElement,
        /// for example RenderTarnsfromOrigin and LayoutTransform. 
        /// 
        /// This is the method layout parent uses to set a location of the child
        /// relative to parent's visual as a result of layout. Typically, this is called 
        /// by the parent inside of its ArrangeOverride implementation. The transform passed into
        /// this method does not get combined with offset that is set by SetLayoutOffset, but rahter resets
        /// LayoutOffset to (0,0). Typically, layout parents use offset most of the time and only need to use this method instead if they need to introduce
        /// a non-trivial transform (including rotation or scale) between them and a layout child. 
        /// DO NOT name this SetLayoutTransform()!  The Xaml Compile may be fooled into thinking LayoutTransform is an attached property.
        /// </summary> 
        /// <param name="element">The element on which to set a transform.</param> 
        /// <param name="layoutTransform">The final transform of this element relative to its parent's visual.</param>
        internal static void InternalSetLayoutTransform(UIElement element, Transform layoutTransform) 
        {
            FrameworkElement fe = element as FrameworkElement;
            element.InternalSetOffsetWorkaround(new Vector());
 
            Transform additionalTransform = (fe == null ? null : fe.GetFlowDirectionTransform()); //rtl
 
            Transform renderTransform = element.RenderTransform; 
            if(renderTransform == Transform.Identity)
                renderTransform = null; 

            // Create a TransformCollection and make sure it does not participate
            // in the InheritanceContext treeness because it is internal operation only.
            TransformCollection ts = new TransformCollection(); 
            ts.CanBeInheritanceContext = false;
 
            if(additionalTransform != null) 
                ts.Add(additionalTransform);
 
            if(renderTransform != null)
                ts.Add(renderTransform);

            ts.Add(layoutTransform); 

            TransformGroup group = new TransformGroup(); 
            group.Children = ts; 

            element.InternalSetTransformWorkaround(group); 
        }
Пример #9
0
 internal static void InternalSetLayoutTransform(UIElement element, Transform layoutTransform)
 {
     FrameworkElement frameworkElement = element as FrameworkElement;
       element.InternalSetOffsetWorkaround(new Vector());
       Transform transform1 = frameworkElement == null ? (Transform) null : frameworkElement.GetFlowDirectionTransform();
       Transform transform2 = element.RenderTransform;
       if (transform2 == Transform.Identity)
     transform2 = (Transform) null;
       TransformCollection transformCollection = new TransformCollection();
       transformCollection.CanBeInheritanceContext = false;
       if (transform1 != null)
     transformCollection.Add(transform1);
       if (transform2 != null)
     transformCollection.Add(transform2);
       transformCollection.Add(layoutTransform);
       element.InternalSetTransformWorkaround((Transform) new TransformGroup()
       {
     Children = transformCollection
       });
 }
Пример #10
0
 private static void AddToTransformCollection(TransformCollection transformCollection, GeneralTransform transform)
 {
     var transformGroup = transform as TransformGroup;
     if (transformGroup == null)
     {
         transformCollection.Add((Transform) transform);
     }
     else
     {
         foreach (var child in transformGroup.Children)
         {
             transformCollection.Add(child);
         }
     }
 }
Пример #11
0
 private void Image_SetTransform()
 {
     TransformCollection tc = new TransformCollection();
     tc.Add(scaletrans);
     tc.Add(trans);
     TransformGroup tg = new TransformGroup();
     tg.Children = tc;
     Image.RenderTransform = tg;
 }