Example #1
0
        private void AddButtons(CustomStroke stroke, CustomInkCanvas canvas)
        {
            visualChildren = new VisualCollection(this);

            editButton            = new EditionButton(stroke, canvas);
            editButton.Cursor     = Cursors.Hand;
            editButton.Width      = 20;
            editButton.Height     = 20;
            editButton.Background = Brushes.White;

            BitmapImage img = new BitmapImage();

            img.BeginInit();
            img.UriSource = new Uri("../../Resources/pencil.png", UriKind.Relative);
            img.EndInit();

            System.Windows.Controls.Image image = new System.Windows.Controls.Image();
            image.Source = img;

            editButton.Content = image;

            visualChildren.Add(editButton);

            deleteButton = new DeleteButton(new StrokeCollection {
                stroke
            }, canvas);
            deleteButton.Cursor     = Cursors.Hand;
            deleteButton.Width      = 20;
            deleteButton.Height     = 20;
            deleteButton.Background = Brushes.White;

            BitmapImage img2 = new BitmapImage();

            img2.BeginInit();
            img2.UriSource = new Uri("../../Resources/trash.png", UriKind.Relative);
            img2.EndInit();

            System.Windows.Controls.Image image2 = new System.Windows.Controls.Image();
            image2.Source        = img2;
            deleteButton.Content = image2;

            visualChildren.Add(deleteButton);
        }
        public SelectionMultipleAdorner(UIElement adornedElement, StrokeCollection strokes, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            adornedStroke = null;

            visualChildren  = new VisualCollection(this);
            strokesSelected = strokes;

            foreach (CustomStroke stroke in strokesSelected)
            {
                if (stroke is ShapeStroke)
                {
                    RotateTransform rotation = new RotateTransform((stroke as ShapeStroke).shapeStyle.rotation, stroke.GetCenter().X, stroke.GetCenter().Y);
                    Path            path     = new Path();
                    path.Data            = new RectangleGeometry(stroke.GetCustomBound(), 0, 0, rotation);
                    path.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF809dce"));
                    path.StrokeThickness = 2;
                    shapeBorders.Add(path);

                    visualChildren.Add(path);
                }
                if (stroke is LinkStroke)
                {
                    Path path = new Path();
                    path.Data            = stroke.GetGeometry();
                    path.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF809dce"));
                    path.StrokeThickness = (stroke as LinkStroke).getThickness();
                    shapeBorders.Add(path);

                    visualChildren.Add(path);
                }
            }

            double maxX = -9999999;
            double minX = 9999999;
            double maxY = -9999999;
            double minY = 9999999;

            foreach (CustomStroke stroke in strokesSelected)
            {
                if (stroke.GetEditingBounds().X < minX)
                {
                    minX = stroke.GetEditingBounds().X;
                }
                if (stroke.GetEditingBounds().X + stroke.GetEditingBounds().Width > maxX)
                {
                    maxX = stroke.GetEditingBounds().X + stroke.GetEditingBounds().Width;
                }
                if (stroke.GetEditingBounds().Y < minY)
                {
                    minY = stroke.GetEditingBounds().Y;
                }
                if (stroke.GetEditingBounds().Y + stroke.GetEditingBounds().Height > maxY)
                {
                    maxY = stroke.GetEditingBounds().Y + stroke.GetEditingBounds().Height;
                }
            }

            strokeBounds = new Rect(new Point(minX, minY), new Point(maxX, maxY));

            moveThumb                = new Thumb();
            moveThumb.Cursor         = Cursors.SizeAll;
            moveThumb.Height         = strokeBounds.Height;
            moveThumb.Width          = strokeBounds.Width;
            moveThumb.Background     = Brushes.Transparent;
            moveThumb.DragDelta     += new DragDeltaEventHandler(Move_DragDelta);
            moveThumb.DragCompleted += new DragCompletedEventHandler(Move_DragCompleted);
            moveThumb.DragStarted   += new DragStartedEventHandler(All_DragStarted);

            visualChildren.Add(moveThumb);

            resizePreview                 = new Path();
            resizePreview.Stroke          = Brushes.Gray;
            resizePreview.StrokeDashArray = new DoubleCollection {
                5, 2
            };
            resizePreview.StrokeThickness = 1;
            visualChildren.Add(resizePreview);

            canvas = actualCanvas;

            outerBoundPath                 = new Path();
            outerBoundPath.Stroke          = Brushes.Black;
            outerBoundPath.StrokeDashArray = new DoubleCollection {
                5, 2
            };
            outerBoundPath.StrokeThickness = 1;
            outerBoundPath.Data            = new RectangleGeometry(strokeBounds);
            visualChildren.Add(outerBoundPath);

            deleteButton            = new DeleteButton(strokes, canvas);
            deleteButton.Cursor     = Cursors.Hand;
            deleteButton.Width      = 20;
            deleteButton.Height     = 20;
            deleteButton.Background = Brushes.White;

            BitmapImage img2 = new BitmapImage();

            img2.BeginInit();
            img2.UriSource = new Uri("../../Resources/trash.png", UriKind.Relative);
            img2.EndInit();

            System.Windows.Controls.Image image2 = new System.Windows.Controls.Image();
            image2.Source        = img2;
            deleteButton.Content = image2;

            visualChildren.Add(deleteButton);

            centerAlignButton            = new CenterAlignButton(strokes, canvas);
            centerAlignButton.Cursor     = Cursors.Hand;
            centerAlignButton.Width      = 20;
            centerAlignButton.Height     = 20;
            centerAlignButton.Background = Brushes.White;

            BitmapImage img3 = new BitmapImage();

            img3.BeginInit();
            img3.UriSource = new Uri("../../Resources/NewLook/horizontal-align-center.png", UriKind.Relative);
            img3.EndInit();

            System.Windows.Controls.Image image3 = new System.Windows.Controls.Image();
            image3.Source             = img3;
            centerAlignButton.Content = image3;

            visualChildren.Add(centerAlignButton);

            leftAlignButton            = new LeftAlignButton(strokes, canvas);
            leftAlignButton.Cursor     = Cursors.Hand;
            leftAlignButton.Width      = 20;
            leftAlignButton.Height     = 20;
            leftAlignButton.Background = Brushes.White;

            BitmapImage img4 = new BitmapImage();

            img4.BeginInit();
            img4.UriSource = new Uri("../../Resources/NewLook/left-align.png", UriKind.Relative);
            img4.EndInit();

            System.Windows.Controls.Image image4 = new System.Windows.Controls.Image();
            image4.Source           = img4;
            leftAlignButton.Content = image4;

            visualChildren.Add(leftAlignButton);

            rectangleCenter    = new Rect(strokeBounds.X + strokeBounds.Width / 2 - 10, strokeBounds.Y - 20, 20, 20);
            rectangleLeftAlign = new Rect(strokeBounds.X, strokeBounds.Y - 20, 20, 20);
            rectangleDelete    = new Rect(strokeBounds.TopRight.X - 20, strokeBounds.TopRight.Y - 20, 20, 20);
        }