Пример #1
0
        internal static XDrawingShape CreateFromXml(XDrawing drawing, Path path, XElement xGeometry)
        {
            var nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            var tmpDoc = XDocument.Parse((xGeometry.Parent.FirstNode as XComment).Value);

            path.Data = null;
            var txt = new XDrawingText(drawing, path);

            var props = tmpDoc.Root.Attribute("TopLeft").Value.Split(',', ' ');

            txt.TopLeft = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi));

            props           = tmpDoc.Root.Attribute("BottomRight").Value.Split(',', ' ');
            txt.BottomRight = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi));

            txt.Text       = tmpDoc.Root.Attribute("Text").Value;
            txt.FontFamily = new FontFamily(tmpDoc.Root.Attribute("FontFamily").Value);
            txt.FontStyle  = tmpDoc.Root.Attribute("FontStyle").Value == "Italic" ? FontStyles.Italic : FontStyles.Normal;
            txt.FontWeight = tmpDoc.Root.Attribute("FontWeight").Value == "Bold" ? FontWeights.Bold : FontWeights.Normal;
            txt.TextSize   = Double.Parse(tmpDoc.Root.Attribute("TextSize").Value, nfi);
            txt.Alignment  = (TextAlignment)Enum.Parse(typeof(TextAlignment), tmpDoc.Root.Attribute("Alignment").Value);
            txt.Trimming   = (TextTrimming)Enum.Parse(typeof(TextTrimming), tmpDoc.Root.Attribute("Trimming").Value);

            return(txt);
        }
Пример #2
0
        public static HitTestInfo CreateNewByDrag(XDrawing drawing, Point startPt, out XDrawingModes newMode)
        {
            var path = new Path();

            path.Fill            = new SolidColorBrush(Colors.Black);
            path.StrokeThickness = 1.0;
            var shape = new XDrawingText(drawing, path);

            shape.TopLeft     = startPt;
            shape.BottomRight = startPt;
            ControlPoint cp;

            shape.CreateControlPoints(false, out cp);
            //newMode = XDrawingModes.Select;
            newMode = XDrawingModes.Edit;
            var hti = new HitTestInfo();

            hti.Shape        = shape;
            hti.Offset       = new Vector(0.0, 0.0);
            hti.ControlPoint = cp;
            return(hti);
        }
Пример #3
0
        void Canvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var pt = e.GetPosition(Canvas);

            Canvas.Focus();
            Keyboard.Focus(Canvas);


            if (e.ChangedButton == MouseButton.Left)
            {
                switch (Mode)
                {
                //case XDrawingModes.Select:
                case XDrawingModes.Edit:
                    m_DragInfo = HitTest(pt);
                    if (!m_DragInfo.HasValue)
                    {
                        SelectedShape = null;
                    }
                    else
                    {
                        if (m_DragInfo.Value.Shape != SelectedShape)
                        {
                            SelectedShape = m_DragInfo.Value.Shape;
                        }
                        if (m_DragInfo.Value.ControlPoint != SelectedControlPoint)
                        {
                            if (m_DragInfo.Value.ControlPoint == null || m_DragInfo.Value.ControlPoint.IsSelectable)
                            {
                                SelectedControlPoint = m_DragInfo.Value.ControlPoint;
                            }
                        }
                        m_DragInfo.Value.DragObject.StartDrag();
                    }
                    break;

                case XDrawingModes.NewLine:
                case XDrawingModes.NewRect:
                case XDrawingModes.NewEllipse:
                case XDrawingModes.NewPath:
                case XDrawingModes.NewText:
                    SelectedShape = null;
                    XDrawingModes newMode = Mode;
                    switch (Mode)
                    {
                    case XDrawingModes.NewLine:
                        m_DragInfo = XDrawingLine.CreateNewByDrag(this, SnapToGrid(pt), out newMode);
                        break;

                    case XDrawingModes.NewRect:
                        m_DragInfo = XDrawingRectangle.CreateNewByDrag(this, SnapToGrid(pt), out newMode);
                        break;

                    case XDrawingModes.NewEllipse:
                        m_DragInfo = XDrawingEllipse.CreateNewByDrag(this, SnapToGrid(pt), out newMode);
                        break;

                    case XDrawingModes.NewPath:
                        m_DragInfo = XDrawingPath.CreateNewByDrag(this, SnapToGrid(pt), out newMode);
                        break;

                    case XDrawingModes.NewText:
                        m_DragInfo = XDrawingText.CreateNewByDrag(this, SnapToGrid(pt), out newMode);
                        break;
                    }
                    if (m_DragInfo.HasValue)
                    {
                        Mode = newMode;
                        SetValue(SelectedShapeProperty, m_DragInfo.Value.Shape);
                        m_Shapes.Add(m_DragInfo.Value.Shape);
                        Canvas.Children.Insert(Canvas.Children.IndexOf(m_ControlPointPath), m_DragInfo.Value.Shape.Path);
                        m_DragInfo.Value.DragObject.StartDrag();
                    }
                    break;
                }
                Canvas.CaptureMouse();
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                var hti = HitTest(pt);
                if (!hti.HasValue)
                {
                    SelectedShape = null;
                }
                else
                {
                    if (hti.Value.Shape != SelectedShape)
                    {
                        SelectedShape = hti.Value.Shape;
                    }
                    if (hti.Value.ControlPoint != SelectedControlPoint)
                    {
                        if (hti.Value.ControlPoint == null || hti.Value.ControlPoint.IsSelectable)
                        {
                            SelectedControlPoint = hti.Value.ControlPoint;
                        }
                    }
                }
            }
            e.Handled = true;
        }