Пример #1
0
        protected void ClearSelection()
        {
            if (TSFrame != null)
            {
                if (TSFrame.Parent is Canvas)
                {
                    (TSFrame.Parent as Canvas).Children.Remove(TSFrame);
                    TSFrame = null;
                }
                DraggingPoint = null;
                if (FrameChanged != null)
                {
                    FrameChanged(null);
                }
            }

            if (SelectionRect != null)
            {
                if (SelectionRect.Parent is Canvas)
                {
                    (SelectionRect.Parent as Canvas).Children.Remove(SelectionRect);
                    SelectionRect = null;
                }
            }
        }
Пример #2
0
        public void SelectObjects(Canvas drawingCanvas, params DDObject[] targets)
        {
            if (drawingCanvas == null)
            {
                return;
            }

            ClearSelection();

            if ((targets != null) && (targets.Length > 0) && (targets[0] != null))
            {
                TSFrame = new DDTranslateAndScaleFrame(targets);
                drawingCanvas.Children.Add(TSFrame);
                if (FrameChanged != null)
                {
                    FrameChanged(TSFrame);
                }
            }
        }
Пример #3
0
        private void xamlButton2_Click(object sender, RoutedEventArgs e)
        {
            xamlCanvas.Children.Clear();

            Random rand   = new Random();
            int    pCount = rand.Next(30) + 10;

            DDPolygon[] polygons = new DDPolygon[pCount];
            for (int i = 0; i < pCount; i++)
            {
                polygons[i] = new DDPolygon();

                int   nCount = rand.Next(10) + 5;
                Point pos    = new Point(rand.Next(800), rand.Next(800));
                Size  size   = new Size(rand.Next(600) + 50, rand.Next(600) + 50);
                for (int j = 0; j < nCount; j++)
                {
                    DDNodeWithHandles node = new DDNodeWithHandles(xamlCanvas)
                    {
                        Point = new Point(
                            pos.X + rand.Next((int)size.Width),
                            pos.Y + rand.Next((int)size.Height))
                    };
                    polygons[i].Nodes.Add(node);
                }

                polygons[i].Stroke = new SolidColorBrush(Color.FromArgb((byte)(200 + rand.Next(56)),
                                                                        (byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256)));
                polygons[i].Fill = new SolidColorBrush(Color.FromArgb((byte)(200 + rand.Next(56)),
                                                                      (byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256)));
                polygons[i].StrokeThickness = rand.Next(6);
                xamlCanvas.Children.Add(polygons[i]);
            }

            DDTranslateAndScaleFrame manipulationFrame = new DDTranslateAndScaleFrame(polygons);

            xamlCanvas.Children.Add(manipulationFrame);
        }
Пример #4
0
        private void xamlButton3_Click(object sender, RoutedEventArgs e)
        {
            List <DDObject> objects = new List <DDObject>();

            foreach (UIElement el in xamlCanvas.Children)
            {
                if (el is DDObject)
                {
                    objects.Add(el as DDObject);
                }
            }

            if (manipulationFrame == null)
            {
                manipulationFrame = new DDTranslateAndScaleFrame(objects.ToArray());
                xamlCanvas.Children.Add(manipulationFrame);
            }
            else
            {
                xamlCanvas.Children.Remove(manipulationFrame);
                manipulationFrame = null;
            }
        }
Пример #5
0
        protected void TSFrameChangedHandler(DDTranslateAndScaleFrame refFrame)
        {
            if (refFrame == null)
            {
                xamlExpanderSelectionLayout.Visibility = Visibility.Collapsed;
                BindingOperations.ClearAllBindings(xamlLayoutX);
                BindingOperations.ClearAllBindings(xamlLayoutY);
                BindingOperations.ClearAllBindings(xamlLayoutWidth);
                BindingOperations.ClearAllBindings(xamlLayoutHeight);
            }
            else
            {
                xamlExpanderSelectionLayout.Visibility = Visibility.Visible;
                xamlLayoutX.SetBinding(DDNumericUpDown.ValueProperty, new Binding("X")
                {
                    Source = refFrame, Mode = BindingMode.TwoWay
                });
                xamlLayoutY.SetBinding(DDNumericUpDown.ValueProperty, new Binding("Y")
                {
                    Source = refFrame, Mode = BindingMode.TwoWay
                });
                xamlLayoutWidth.SetBinding(DDNumericUpDown.ValueProperty, new Binding("Width")
                {
                    Source = refFrame, Mode = BindingMode.TwoWay
                });
                xamlLayoutHeight.SetBinding(DDNumericUpDown.ValueProperty, new Binding("Height")
                {
                    Source = refFrame, Mode = BindingMode.TwoWay
                });
            }

            if ((refFrame != null) && (refFrame.Targets.Count == 1))
            {
                if (!(refFrame.Targets[0] is DDPolyline))
                {
                    xamlExpanderFill.Visibility = Visibility.Visible;
                }
                xamlExpanderStroke.Visibility = Visibility.Visible;
                if (refFrame.Targets[0] is DDRectangle)
                {
                    xamlExpanderRectangle.Visibility = Visibility.Visible;
                }
                if (refFrame.Targets[0] is DDPolygon)
                {
                    _convertTarget = refFrame.Targets[0] as DDNodeObject;
                    xamlExpanderPolygon.Visibility = Visibility.Visible;
                }
                if (refFrame.Targets[0] is DDPolyline)
                {
                    _convertTarget = refFrame.Targets[0] as DDNodeObject;
                    xamlExpanderPolyline.Visibility = Visibility.Visible;
                }
                BindFillAndStrokeObject(refFrame.Targets[0]);
            }
            else
            {
                _convertTarget = null;
                xamlExpanderFill.Visibility      = Visibility.Collapsed;
                xamlExpanderStroke.Visibility    = Visibility.Collapsed;
                xamlExpanderRectangle.Visibility = Visibility.Collapsed;
                xamlExpanderPolygon.Visibility   = Visibility.Collapsed;
                xamlExpanderPolyline.Visibility  = Visibility.Collapsed;
                BindFillAndStrokeObject(null);
            }

            _activeTSFrame = refFrame;
            TryAddUndoStep();
        }