Esempio n. 1
0
        void AttachedPropertiesSnippets()
        {
            //<Snippet27>
            InkCanvas.SetTop(button1, 100);
            //</Snippet27>

            //<Snippet28>
            InkCanvas.SetBottom(button1, 100);
            //</Snippet28>

            //<Snippet29>
            InkCanvas.SetLeft(button1, 100);
            //</Snippet29>

            //<Snippet30>
            InkCanvas.SetRight(button1, 100);
            //</Snippet30>

            //<Snippet31>
            double buttonLeft = InkCanvas.GetLeft(button1);
            //</Snippet31>

            //<Snippet32>
            double buttonRight = InkCanvas.GetRight(button1);
            //</Snippet32>

            //<Snippet33>
            double buttonTop = InkCanvas.GetTop(button1);
            //</Snippet33>

            //<Snippet34>
            double buttonBottom = InkCanvas.GetBottom(button1);
            //</Snippet34>
        }
Esempio n. 2
0
        /// <summary>
        /// Canvas computes a position for each of its children taking into account their margin and
        /// attached Canvas properties: Top, Left.
        ///
        /// Canvas will also arrange each of its children.
        /// This code is same as the Canvas'.
        /// </summary>
        /// <param name="arrangeSize">Size that Canvas will assume to position children.</param>
        protected override Size ArrangeOverride(Size arrangeSize)
        {
            //Canvas arranges children at their DesiredSize.
            //This means that Margin on children is actually respected and added
            //to the size of layout partition for a child.
            //Therefore, is Margin is 10 and Left is 20, the child's ink will start at 30.

            foreach (UIElement child in InternalChildren)
            {
                if (child == null)
                {
                    continue;
                }

                double x = 0;
                double y = 0;


                //Compute offset of the child:
                //If Left is specified, then Right is ignored
                //If Left is not specified, then Right is used
                //If both are not there, then 0
                double left = (double)InkCanvas.GetLeft(child);
                if (!DoubleUtil.IsNaN(left))
                {
                    x = left;
                }
                else
                {
                    double right = (double)InkCanvas.GetRight(child);

                    if (!DoubleUtil.IsNaN(right))
                    {
                        x = arrangeSize.Width - child.DesiredSize.Width - right;
                    }
                }

                double top = (double)InkCanvas.GetTop(child);
                if (!DoubleUtil.IsNaN(top))
                {
                    y = top;
                }
                else
                {
                    double bottom = (double)InkCanvas.GetBottom(child);

                    if (!DoubleUtil.IsNaN(bottom))
                    {
                        y = arrangeSize.Height - child.DesiredSize.Height - bottom;
                    }
                }

                child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
            }

            return(arrangeSize);
        }
Esempio n. 3
0
 // Token: 0x060077AF RID: 30639 RVA: 0x00222714 File Offset: 0x00220914
 protected override Size ArrangeOverride(Size arrangeSize)
 {
     foreach (object obj in base.InternalChildren)
     {
         UIElement uielement = (UIElement)obj;
         if (uielement != null)
         {
             double x   = 0.0;
             double y   = 0.0;
             double num = InkCanvas.GetLeft(uielement);
             if (!DoubleUtil.IsNaN(num))
             {
                 x = num;
             }
             else
             {
                 double num2 = InkCanvas.GetRight(uielement);
                 if (!DoubleUtil.IsNaN(num2))
                 {
                     x = arrangeSize.Width - uielement.DesiredSize.Width - num2;
                 }
             }
             double num3 = InkCanvas.GetTop(uielement);
             if (!DoubleUtil.IsNaN(num3))
             {
                 y = num3;
             }
             else
             {
                 double num4 = InkCanvas.GetBottom(uielement);
                 if (!DoubleUtil.IsNaN(num4))
                 {
                     y = arrangeSize.Height - uielement.DesiredSize.Height - num4;
                 }
             }
             uielement.Arrange(new Rect(new Point(x, y), uielement.DesiredSize));
         }
     }
     return(arrangeSize);
 }
Esempio n. 4
0
        /// <summary>
        /// UpdateElementBounds:
        ///     Called by   InkCanvasSelection.UpdateElementBounds
        ///                 ClipboardProcessor.CopySelectionInXAML
        /// </summary>
        /// <param name="originalElement"></param>
        /// <param name="updatedElement"></param>
        /// <param name="transform"></param>
        internal void UpdateElementBounds(UIElement originalElement, UIElement updatedElement, Matrix transform)
        {
            if (originalElement.DependencyObjectType.Id == updatedElement.DependencyObjectType.Id)
            {
                // Get the transform from element to Canvas
                GeneralTransform elementToCanvas = originalElement.TransformToAncestor(_inkCanvas.InnerCanvas);

                //cast to a FrameworkElement, nothing inherits from UIElement besides it right now
                FrameworkElement frameworkElement = originalElement as FrameworkElement;
                Size             size;
                Thickness        thickness = new Thickness();
                if (frameworkElement == null)
                {
                    // Get the element's render size.
                    size = originalElement.RenderSize;
                }
                else
                {
                    size      = new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight);
                    thickness = frameworkElement.Margin;
                }

                Rect elementBounds = new Rect(0, 0, size.Width, size.Height);   // Rect in element space
                elementBounds = elementToCanvas.TransformBounds(elementBounds); // Rect in Canvas space

                // Now apply the matrix to the element bounds
                Rect newBounds = Rect.Transform(elementBounds, transform);

                if (!DoubleUtil.AreClose(elementBounds.Width, newBounds.Width))
                {
                    if (frameworkElement == null)
                    {
                        Size newSize = originalElement.RenderSize;
                        newSize.Width             = newBounds.Width;
                        updatedElement.RenderSize = newSize;
                    }
                    else
                    {
                        ((FrameworkElement)updatedElement).Width = newBounds.Width;
                    }
                }

                if (!DoubleUtil.AreClose(elementBounds.Height, newBounds.Height))
                {
                    if (frameworkElement == null)
                    {
                        Size newSize = originalElement.RenderSize;
                        newSize.Height            = newBounds.Height;
                        updatedElement.RenderSize = newSize;
                    }
                    else
                    {
                        ((FrameworkElement)updatedElement).Height = newBounds.Height;
                    }
                }

                double left   = InkCanvas.GetLeft(originalElement);
                double top    = InkCanvas.GetTop(originalElement);
                double right  = InkCanvas.GetRight(originalElement);
                double bottom = InkCanvas.GetBottom(originalElement);

                Point originalPosition = new Point(); // Default as (0, 0)
                if (!double.IsNaN(left))
                {
                    originalPosition.X = left;
                }
                else if (!double.IsNaN(right))
                {
                    originalPosition.X = right;
                }

                if (!double.IsNaN(top))
                {
                    originalPosition.Y = top;
                }
                else if (!double.IsNaN(bottom))
                {
                    originalPosition.Y = bottom;
                }

                Point newPosition = originalPosition * transform;

                if (!double.IsNaN(left))
                {
                    InkCanvas.SetLeft(updatedElement, newPosition.X - thickness.Left);           // Left wasn't auto
                }
                else if (!double.IsNaN(right))
                {
                    // NOTICE-2005/05/05-WAYNEZEN
                    // Canvas.RightProperty means the distance between element right side and its parent Canvas
                    // right side. The same definition is applied to Canvas.BottomProperty
                    InkCanvas.SetRight(updatedElement, (right - (newPosition.X - originalPosition.X)));     // Right wasn't not auto
                }
                else
                {
                    InkCanvas.SetLeft(updatedElement, newPosition.X - thickness.Left);           // Both Left and Right were aut. Modify Left by default.
                }

                if (!double.IsNaN(top))
                {
                    InkCanvas.SetTop(updatedElement, newPosition.Y - thickness.Top);           // Top wasn't auto
                }
                else if (!double.IsNaN(bottom))
                {
                    InkCanvas.SetBottom(updatedElement, (bottom - (newPosition.Y - originalPosition.Y)));          // Bottom wasn't not auto
                }
                else
                {
                    InkCanvas.SetTop(updatedElement, newPosition.Y - thickness.Top);           // Both Top and Bottom were aut. Modify Left by default.
                }
            }
            else
            {
                Debug.Assert(false, "The updatedElement has to be the same type as the originalElement.");
            }
        }
        private void buttonTouchSelection(System.Windows.Input.StylusEventArgs e)
        {
            Point pos = e.GetPosition(inkCanvas);

            moveX = pos.X;
            moveY = pos.Y;

            UIElement currentStylusOver = findShape(moveX, moveY);

            // If we are still in the same element, then don't need to do anything
            if (currentStylusOver == null)
            {
                lastStylusOver = null;
                firstHover     = true;
                return;
            }

            bool ignore = false;

            if (currentStylusOver.GetType().ToString().Equals("System.Windows.Shapes.Rectangle"))
            {
                if (((Rectangle)currentStylusOver).DesiredSize.Width == 4 || ((Rectangle)currentStylusOver).Fill == Brushes.Transparent)
                {
                    ignore = true;
                }
            }

            if (firstHover == true)
            {
                if (ignore)
                {
                    return;
                }
                double left   = InkCanvas.GetLeft(currentStylusOver);
                double width  = InkCanvas.GetRight(currentStylusOver) - left;
                double middle = left + (width / 2);
                if (left < moveX && moveX < middle)
                {
                    left_side = true;
                }
                else
                {
                    left_side = false;
                }
                firstHover  = false;
                leftCurrent = currentStylusOver;
            }

            if (ignore)
            {
                return;
            }

            // if the stylus has moved to a different shape, then no way we are going to select.
            // just reset everything and return
            if (leftCurrent.Equals(currentStylusOver) == false)
            {
                firstHover = true;
                return;
            }

            // If we are crossing over a button or an item control, then don't do anything
            if (currentStylusOver.GetType().ToString().Equals("System.Windows.Controls.ItemsControl"))
            {
                return;
            }
            if (currentStylusOver.GetType().ToString().Equals("System.Windows.Controls.Button"))
            {
                return;
            }

            if (buttonTouchSelect && allowSelection)  // shouldSelect is for timing issues
            // allowSelection is for disabling selection while menu is on
            {
                if (left_side)
                {
                    double left   = InkCanvas.GetLeft(currentStylusOver);
                    double width  = InkCanvas.GetRight(currentStylusOver) - left;
                    double middle = left + (width / 2);
                    if (left < moveX && moveX < middle)
                    {
                        return;
                    }
                    else
                    {
                        left_side = false;
                    }
                }
                else
                {
                    double left   = InkCanvas.GetLeft(currentStylusOver);
                    double width  = InkCanvas.GetRight(currentStylusOver) - left;
                    double middle = left + (width / 2);
                    if (left < moveX && moveX < middle)
                    {
                        left_side = true;
                    }
                    else
                    {
                        return;
                    }
                }
                if (currentSelection.Contains(currentStylusOver))
                {
                    currentSelection.Remove(currentStylusOver);
                }
                else
                {
                    currentSelection.Add(currentStylusOver);
                }

                lastStylusOver = currentStylusOver;
                updateSelection();
            }
        }
Esempio n. 6
0
 // Token: 0x06006D82 RID: 28034 RVA: 0x001F7060 File Offset: 0x001F5260
 internal void UpdateElementBounds(UIElement originalElement, UIElement updatedElement, Matrix transform)
 {
     if (originalElement.DependencyObjectType.Id == updatedElement.DependencyObjectType.Id)
     {
         GeneralTransform generalTransform = originalElement.TransformToAncestor(this._inkCanvas.InnerCanvas);
         FrameworkElement frameworkElement = originalElement as FrameworkElement;
         Thickness        thickness        = default(Thickness);
         Size             renderSize;
         if (frameworkElement == null)
         {
             renderSize = originalElement.RenderSize;
         }
         else
         {
             renderSize = new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight);
             thickness  = frameworkElement.Margin;
         }
         Rect rect = new Rect(0.0, 0.0, renderSize.Width, renderSize.Height);
         rect = generalTransform.TransformBounds(rect);
         Rect rect2 = Rect.Transform(rect, transform);
         if (!DoubleUtil.AreClose(rect.Width, rect2.Width))
         {
             if (frameworkElement == null)
             {
                 Size renderSize2 = originalElement.RenderSize;
                 renderSize2.Width         = rect2.Width;
                 updatedElement.RenderSize = renderSize2;
             }
             else
             {
                 ((FrameworkElement)updatedElement).Width = rect2.Width;
             }
         }
         if (!DoubleUtil.AreClose(rect.Height, rect2.Height))
         {
             if (frameworkElement == null)
             {
                 Size renderSize3 = originalElement.RenderSize;
                 renderSize3.Height        = rect2.Height;
                 updatedElement.RenderSize = renderSize3;
             }
             else
             {
                 ((FrameworkElement)updatedElement).Height = rect2.Height;
             }
         }
         double left   = InkCanvas.GetLeft(originalElement);
         double top    = InkCanvas.GetTop(originalElement);
         double right  = InkCanvas.GetRight(originalElement);
         double bottom = InkCanvas.GetBottom(originalElement);
         Point  point  = default(Point);
         if (!double.IsNaN(left))
         {
             point.X = left;
         }
         else if (!double.IsNaN(right))
         {
             point.X = right;
         }
         if (!double.IsNaN(top))
         {
             point.Y = top;
         }
         else if (!double.IsNaN(bottom))
         {
             point.Y = bottom;
         }
         Point point2 = point * transform;
         if (!double.IsNaN(left))
         {
             InkCanvas.SetLeft(updatedElement, point2.X - thickness.Left);
         }
         else if (!double.IsNaN(right))
         {
             InkCanvas.SetRight(updatedElement, right - (point2.X - point.X));
         }
         else
         {
             InkCanvas.SetLeft(updatedElement, point2.X - thickness.Left);
         }
         if (!double.IsNaN(top))
         {
             InkCanvas.SetTop(updatedElement, point2.Y - thickness.Top);
             return;
         }
         if (!double.IsNaN(bottom))
         {
             InkCanvas.SetBottom(updatedElement, bottom - (point2.Y - point.Y));
             return;
         }
         InkCanvas.SetTop(updatedElement, point2.Y - thickness.Top);
     }
 }