Exemplo n.º 1
0
        private RegistrationPointFlags FindRegistrationPoint()
        {
            if (!this.IsRenderTransform || this.objectSet.ViewModel == null)
            {
                return(RegistrationPointFlags.None);
            }
            RegistrationPointFlags registrationPointFlags = RegistrationPointFlags.None;
            bool flag = false;

            foreach (SceneNode sceneNode in this.objectSet.Objects)
            {
                BaseFrameworkElement element = sceneNode as BaseFrameworkElement;
                if (element != null)
                {
                    RegistrationPointFlags registrationPointForElement = this.FindRegistrationPointForElement(element);
                    if (!flag)
                    {
                        registrationPointFlags = registrationPointForElement;
                        flag = true;
                    }
                    if (registrationPointForElement != registrationPointFlags)
                    {
                        return(RegistrationPointFlags.None);
                    }
                }
            }
            return(registrationPointFlags);
        }
Exemplo n.º 2
0
        private Point CenterFromRegistrationPoint(RegistrationPointFlags registrationPoint)
        {
            if (registrationPoint == RegistrationPointFlags.None)
            {
                return(new Point(double.NaN, double.NaN));
            }
            double x = 0.5;
            double y = 0.5;

            if ((registrationPoint & RegistrationPointFlags.Right) != RegistrationPointFlags.Center)
            {
                x = 1.0;
            }
            if ((registrationPoint & RegistrationPointFlags.Left) != RegistrationPointFlags.Center)
            {
                x = 0.0;
            }
            if ((registrationPoint & RegistrationPointFlags.Bottom) != RegistrationPointFlags.Center)
            {
                y = 1.0;
            }
            if ((registrationPoint & RegistrationPointFlags.Top) != RegistrationPointFlags.Center)
            {
                y = 0.0;
            }
            return(new Point(x, y));
        }
 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs args)
 {
     if (this.IsEnabled)
     {
         Point position = args.MouseDevice.GetPosition((IInputElement)this);
         RegistrationPointFlags registrationPointFlags = RegistrationPointFlags.Center;
         double actualWidth  = this.ActualWidth;
         double actualHeight = this.ActualHeight;
         if (position.X < actualWidth / 3.0)
         {
             registrationPointFlags |= RegistrationPointFlags.Left;
         }
         if (position.X > actualWidth * (2.0 / 3.0))
         {
             registrationPointFlags |= RegistrationPointFlags.Right;
         }
         if (position.Y < actualHeight / 3.0)
         {
             registrationPointFlags |= RegistrationPointFlags.Top;
         }
         if (position.Y > actualHeight * (2.0 / 3.0))
         {
             registrationPointFlags |= RegistrationPointFlags.Bottom;
         }
         if (registrationPointFlags != this.RegistrationPoint)
         {
             this.RegistrationPoint = registrationPointFlags;
         }
     }
     args.Handled = true;
     base.OnMouseLeftButtonDown(args);
 }
Exemplo n.º 4
0
        private void ChangeRegistrationPoint(RegistrationPointFlags registrationPoint)
        {
            if (this.objectSet.ViewModel == null)
            {
                return;
            }
            bool flag1 = false;

            using (SceneEditTransaction editTransaction = this.objectSet.ViewModel.CreateEditTransaction(StringTable.UndoUnitTransformPaneCenterPoint))
            {
                Point point1 = this.CenterFromRegistrationPoint(registrationPoint);
                foreach (SceneElement sceneElement in this.objectSet.Objects)
                {
                    BaseFrameworkElement frameworkElement = sceneElement as BaseFrameworkElement;
                    if (frameworkElement != null)
                    {
                        flag1 = true;
                        CanonicalTransform canonicalTransform1 = new CanonicalTransform((Transform)frameworkElement.GetComputedValueAsWpf(this.PropertyReference));
                        CanonicalTransform canonicalTransform2 = new CanonicalTransform(canonicalTransform1);
                        if (this.IsRenderTransform)
                        {
                            Point point2 = (Point)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
                            Rect  computedTightBounds = frameworkElement.GetComputedTightBounds();
                            Point oldOrigin           = new Point(point2.X * computedTightBounds.Width + computedTightBounds.Left, point2.Y * computedTightBounds.Height + computedTightBounds.Top);
                            Point newOrigin           = new Point(point1.X * computedTightBounds.Width + computedTightBounds.Left, point1.Y * computedTightBounds.Height + computedTightBounds.Top);
                            canonicalTransform2.UpdateForNewOrigin(oldOrigin, newOrigin);
                            bool flag2 = false;
                            if (!double.IsNaN(point1.X) && !object.Equals((object)point1.X, (object)point2.X))
                            {
                                point2.X = point1.X;
                                flag2    = true;
                            }
                            if (!double.IsNaN(point1.Y) && !object.Equals((object)point1.Y, (object)point2.Y))
                            {
                                point2.Y = point1.Y;
                                flag2    = true;
                            }
                            if (flag2)
                            {
                                frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point2);
                            }
                        }
                        double num1 = RoundingHelper.RoundToDoublePrecision(canonicalTransform2.TranslationX, 6);
                        double num2 = RoundingHelper.RoundToDoublePrecision(canonicalTransform2.TranslationY, 6);
                        if (canonicalTransform1.TranslationX != num1)
                        {
                            frameworkElement.SetValue(this.TranslationXPropertyReference, (object)num1);
                        }
                        if (canonicalTransform1.TranslationY != num2)
                        {
                            frameworkElement.SetValue(this.TranslationYPropertyReference, (object)num2);
                        }
                    }
                }
                if (flag1)
                {
                    editTransaction.Commit();
                }
                else
                {
                    editTransaction.Cancel();
                }
            }
        }