예제 #1
0
        internal static void InsertRectangle()
        {
            Rectangle req = new Rectangle();

            req.Height          = req.Width = 100;
            req.StrokeThickness = 0;
            req.Fill            = new SolidColorBrush(MWin.I.iCanv.DefaultDrawingAttributes.Color);
            MWin.I.iCanv.AddAnimationChild(req);
            InkCanvas.SetTop(req, 100);
            InkCanvas.SetLeft(req, 100);
        }
예제 #2
0
        private Rect centerDrawing()
        {
            removeGate();
            Rect bounds;

            if (gateChooser.SelectedItem == defaultChoice || (string)((ComboBoxItem)gateChooser.SelectedItem).Content == freehandString)
            {
                gate = null;
                return(new Rect());
            }

            gate = LogicDomain.getType((string)((ComboBoxItem)(gateChooser.SelectedItem)).Content);

            // Bounds are currently arbitrary, place shape template in the middle of canvas
            if (gate != LogicDomain.NOTBUBBLE)
            {
                bounds = new Rect(inkCanvas.Width / 2 - GATE_WIDTH / 2, inkCanvas.Height / 2 - GATE_HEIGHT / 2, GATE_WIDTH, GATE_HEIGHT);
            }
            else
            {
                bounds = new Rect(inkCanvas.Width / 2 - NOTBUBBLE_DIAMETER / 2, inkCanvas.Height / 2 - NOTBUBBLE_DIAMETER / 2, NOTBUBBLE_DIAMETER, NOTBUBBLE_DIAMETER);
            }


            // This is so NANDs look like ANDs with NOTBUBBLEs
            // Same goes for all gates in the OR family
            if (gate == LogicDomain.AND)
            {
                bounds.Width = bounds.Width - bounds.Width / 4;
            }
            else if (gate == LogicDomain.OR)
            {
                bounds.Width = bounds.Width - bounds.Width / 6 - bounds.Width / 4;
            }
            else if (gate == LogicDomain.NOR)
            {
                bounds.Width = bounds.Width - bounds.Width / 6;
            }
            else if (gate == LogicDomain.XOR)
            {
                bounds.Width = bounds.Width - bounds.Width / 4;
            }

            DrawingImage drawingImage = new DrawingImage(gateDrawer.DrawGate(gate, bounds, false, true));

            gateImage        = new Image();
            gateImage.Source = drawingImage;

            InkCanvas.SetLeft(gateImage, bounds.Left);
            InkCanvas.SetTop(gateImage, bounds.Top);

            inkCanvas.Children.Add(gateImage);
            return(bounds);
        }
예제 #3
0
 /// <summary>
 /// Ajoute la TextBox à l'InkCanvas en entrée
 /// </summary>
 /// <param name="window">Fenêtre du Whiteboard</param>
 /// <param name="ink">InkCanvas cible</param>
 public override void AddToCanvas(MainWindow window, InkCanvas ink)
 {
     BoxT        = new TextBox();
     BoxT.Text   = this.Text;
     BoxT.Width  = this.Width;
     BoxT.Height = this.Height;
     InkCanvas.SetTop(BoxT, this.Y);
     InkCanvas.SetLeft(BoxT, this.X);
     BoxT.LostFocus += new RoutedEventHandler(window.textBoxModified);
     ink.Children.Add(BoxT);
 }
예제 #4
0
        public override Shape FormatToShape(ConvertTarget Target)
        {
            Rectangle rect = new Rectangle();

            if (Format == "SVG")
            {
                foreach (XAttribute k in Target.Element.Attributes())
                {
                    if (k.Name == "x")
                    {
                        InkCanvas.SetLeft(rect, Target.Ratio.X * stringToDouble(k.Value)); continue;
                    }                                                                                                  // = 168.5
                    if (k.Name == "y")
                    {
                        InkCanvas.SetTop(rect, Target.Ratio.Y * stringToDouble(k.Value)); continue;
                    }                                                                                                 // = 143.990909090909
                    if (k.Name == "width")
                    {
                        rect.Width = Target.Ratio.X * stringToDouble(k.Value); continue;
                    }                                                                                          // = 62.5
                    if (k.Name == "height")
                    {
                        rect.Height = Target.Ratio.Y * stringToDouble(k.Value); continue;
                    }                                                                                            // = 68.5
                    if (k.Name == "fill")
                    {
                        rect.Fill = k.Value == "none" ? null : stringToBrush(k.Value); continue;
                    }                                                                                                 // = none
                    if (k.Name == "stroke")
                    {
                        rect.Stroke = stringToBrush(k.Value); continue;
                    }                                                                          // = #008000
                    if (k.Name == "stroke-width")
                    {
                        rect.StrokeThickness = stringToDouble(k.Value); continue;
                    }                                                                                          // = 1                                                                                           //Console.WriteLine(k.Name + " = " + k.Value);
                }
            }
            if (Format == "VGF")
            {
                if (Target.Array.Length != 8)
                {
                    rect = null;                          //Некорректное количество аргументов у Прямоугольника
                }
                InkCanvas.SetLeft(rect, Convert.ToDouble(Target.Array[1]));
                InkCanvas.SetTop(rect, Convert.ToDouble(Target.Array[2]));
                rect.Width           = Convert.ToDouble(Target.Array[3]);
                rect.Height          = Convert.ToDouble(Target.Array[4]);
                rect.Stroke          = (SolidColorBrush)(new BrushConverter().ConvertFrom(Target.Array[5]));
                rect.StrokeThickness = Convert.ToDouble(Target.Array[6]);
                rect.Fill            = Target.Array[7] == "noFill" ? null : (SolidColorBrush)(new BrushConverter().ConvertFrom(Target.Array[7]));
            }
            return(rect);
        }
예제 #5
0
        /// <summary>
        /// 鼠标移动时刷新图形
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public void Refresh(Point start, Point end)
        {
            this.Width  = Math.Abs(start.X - end.X);
            this.Height = Math.Abs(start.Y - end.Y);

            this.Position = new Point(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y));
            InkCanvas.SetLeft(this, Position.X);
            InkCanvas.SetTop(this, Position.Y);

            //Debug.WriteLine(this.Width + "*" + this.Height);
            //Debug.WriteLine(Position.X + "*" + Position.Y);
        }
예제 #6
0
        public void receiveTextBox(string[] textBoxString)
        {
            string text  = textBoxString[0];
            double X     = Convert.ToDouble(textBoxString[1]);
            double Y     = Convert.ToDouble(textBoxString[2]);
            Label  label = new Label();

            label.Content = text;
            inkCanvas.Children.Add(label);
            InkCanvas.SetLeft(label, X);
            InkCanvas.SetTop(label, Y);
        }
예제 #7
0
        /// <summary>
        /// Sets button properties and displays button
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        private System.Windows.Controls.Button setButtonProperties(int x, int y, string label)
        {
            Button newButton = new Button();

            newButton.Height = BUTTON_HEIGHT;
            newButton.Name   = label;

            newButton.StylusInAirMove += new StylusEventHandler(button_StylusOver);
            newButton.StylusLeave     += new StylusEventHandler(button_StylusAway);

            if (label != "Undo" && label != "Redo")
            {
                newButton.Width   = BUTTON_WIDTH;
                newButton.Content = label;
            }
            else if (label == "Undo")
            {
                newButton.Width = BUTTON_WIDTH / 2;
                if (commandManager.UndoValid)
                {
                    newButton.Content = undoImageGray;
                }
                else
                {
                    newButton.Content   = undoImage;
                    newButton.IsEnabled = false;
                }
            }
            else
            {
                newButton.Width = BUTTON_WIDTH / 2;
                if (commandManager.RedoValid)
                {
                    newButton.Content = redoImageGray;
                }
                else
                {
                    newButton.Content   = redoImage;
                    newButton.IsEnabled = false;
                }
            }

            newButton.FontSize = 9;

            InkCanvas.SetLeft(newButton, x);
            InkCanvas.SetTop(newButton, y - newButton.Height);
            newButton.BringIntoView();

            newButton.Visibility = System.Windows.Visibility.Visible;

            return(newButton);
        }
예제 #8
0
        /// <summary>
        /// Creates a label for given error message at drawPoint.
        ///
        /// Helper Function.
        /// </summary>
        private static System.Windows.Controls.Label createErrorLabel(string message, System.Drawing.Point drawPoint)
        {
            System.Windows.Controls.Label label = new System.Windows.Controls.Label();
            label.Content = message;
            InkCanvas.SetTop(label, drawPoint.Y);
            InkCanvas.SetLeft(label, drawPoint.X);
            label.ClipToBounds    = false;
            label.BorderThickness = new System.Windows.Thickness(1);
            label.IsEnabled       = true;
            label.Visibility      = System.Windows.Visibility.Visible;

            return(label);
        }
예제 #9
0
 /// <summary>
 /// Clears the canvas, draws everything in the supplied drawing group
 /// </summary>
 /// <param name="group"></param>
 private void Draw(DrawingGroup group)
 {
     this.Children.Clear();
     foreach (Drawing shape in group.Children)
     {
         DrawingImage di    = new DrawingImage(shape);
         Image        image = new Image();
         image.Source = di;
         InkCanvas.SetLeft(image, shape.Bounds.Left);
         InkCanvas.SetTop(image, shape.Bounds.Top);
         this.Children.Add(image);
     }
 }
예제 #10
0
        internal static void InsertLabel()
        {
            TextBlock blk = new TextBlock {
                Text       = "Текст",
                FontSize   = 20,
                Foreground = new SolidColorBrush(Colors.Blue),
                FontFamily = new FontFamily("Arial")
            };

            MWin.I.iCanv.AddAnimationChild(blk);
            InkCanvas.SetTop(blk, 100);
            InkCanvas.SetLeft(blk, 100);
        }
예제 #11
0
        // </Snippet21>

        void inkCanvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point firstPoint = e.GetPosition(inkCanvas1);

            Ellipse circle = new Ellipse();

            circle.Width  = 10;
            circle.Height = 10;
            circle.Fill   = Brushes.Red;
            InkCanvas.SetTop(circle, firstPoint.Y - 5);
            InkCanvas.SetLeft(circle, firstPoint.X - 5);
            inkCanvas1.Children.Add(circle);
        }
예제 #12
0
        //<Snippet13>
        void inkCanvas1_StylusDown(object sender, StylusDownEventArgs e)
        {
            StylusPointCollection points = e.GetStylusPoints(inkCanvas1);
            Point firstPoint             = (Point)points[0];

            Ellipse circle = new Ellipse();

            circle.Width  = 5;
            circle.Height = 5;
            circle.Fill   = Brushes.Red;
            InkCanvas.SetTop(circle, firstPoint.Y);
            InkCanvas.SetLeft(circle, firstPoint.X);
            inkCanvas1.Children.Add(circle);
        }
예제 #13
0
        private void Highlight(Point mouseDown, Point mouseUp)
        {
            double mdx = mouseDown.X;
            double mdy = mouseDown.Y;
            double mux = mouseUp.X;
            double muy = mouseUp.Y;

            double leftx;
            double rightx;
            double topy;
            double bottomy;

            if (mdx < mux)
            {
                leftx  = mdx;
                rightx = mux;
            }
            else
            {
                leftx  = mux;
                rightx = mdx;
            }

            if (mdy < muy)
            {
                bottomy = muy;
                topy    = mdy;
            }
            else
            {
                bottomy = mdy;
                topy    = muy;
            }


            Point     topleft = new Point(leftx, topy);
            Size      size    = new Size(Math.Abs(rightx - leftx), Math.Abs(topy - bottomy));
            Rectangle rect    = new Rectangle();

            InkCanvas.SetLeft(rect, topleft.X);
            InkCanvas.SetTop(rect, topleft.Y);
            rect.Width  = size.Width;
            rect.Height = size.Height;
            rect.Fill   = new SolidColorBrush()
            {
                Color = highlightColor, Opacity = opacity
            };
            addElement(rect);
        }
예제 #14
0
        //<Snippet20>
        public void GetBounds()
        {
            Rect bounds = inkCanvas1.Strokes.GetBounds();

            Rectangle boundsShape = new Rectangle();

            boundsShape.Width  = bounds.Width;
            boundsShape.Height = bounds.Height;
            boundsShape.Stroke = Brushes.Red;

            InkCanvas.SetTop(boundsShape, bounds.Top);
            InkCanvas.SetLeft(boundsShape, bounds.Left);

            inkCanvas1.Children.Add(boundsShape);
        }
예제 #15
0
        void AddTouchableImage(Point pt, BitmapImage image)
        {
            TouchableImage ti = new TouchableImage();

            ti.Source = image;
            ti.Width  = image.PixelWidth > 500 ? (double)(image.PixelWidth >> 1) : image.PixelWidth;
            ti.Height = image.PixelHeight > 500 ? (double)(image.PixelHeight >> 1) : image.PixelHeight;
            this.DrawingCanvas.Children.Add(ti);

            this.RefreshCurrentPreview();
            InkCanvas.SetLeft(ti, pt.X - ((int)ti.Width >> 2));
            InkCanvas.SetTop(ti, pt.Y - ((int)ti.Height >> 2));

            ti.IsManipulationEnabled = true;
        }
예제 #16
0
        protected static void iCanv_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Polyline lin = (Polyline)MWin.I.iCanv.Children[MWin.I.iCanv.Children.Count - 1];

            if (lin.Points.Count == 0)
            {
                Point p = e.GetPosition(MWin.I.iCanv);
                InkCanvas.SetTop(lin, p.Y);
                InkCanvas.SetLeft(lin, p.X);
                lin.Points.Add(new Point(0, 0));
            }
            else
            {
                lin.Points.Add(e.GetPosition(lin));
            }
        }
예제 #17
0
        void ShowTxt(Point pt)
        {
            if ("" == m_showTxt)
            {
                return;
            }

            TextBlock tb = new TextBlock();

            inkCanvasMeasure.Children.Add(tb);
            tb.Text         = m_showTxt;
            tb.Foreground   = brRed;
            tb.TextWrapping = TextWrapping.Wrap;
            InkCanvas.SetLeft(tb, pt.X);
            InkCanvas.SetTop(tb, pt.Y);
        }
예제 #18
0
        /// <summary>
        /// Скользящее рисование фигуры
        /// </summary>
        /// <param name="currentPoint">Текущая координата фигуры</param>
        public void DrawingShape(Point currentPoint)
        {
            switch (this._drawMode)
            {
            case BOADR_DRAW_SHAPE.POLYLINE:
                this._pointCnt++;
                if (this._pointCnt % 2 == 0)
                {
                    ((Polyline)this._currentShape).Points.Add(currentPoint);
                    this._pointCnt = 0;
                }
                break;

            case BOADR_DRAW_SHAPE.LINE:
                ((Line)this._currentShape).X2 = currentPoint.X;
                ((Line)this._currentShape).Y2 = currentPoint.Y;
                break;

            case BOADR_DRAW_SHAPE.RECTANGLE:
            case BOADR_DRAW_SHAPE.ROUND_RECTANGLE:
            case BOADR_DRAW_SHAPE.ELLIPSE:
                double width  = currentPoint.X - this._beginPoint.X;
                double height = currentPoint.Y - this._beginPoint.Y;

                //Нормализация фигуры

                if (width < 0 && height < 0)
                {
                    InkCanvas.SetLeft(this._currentShape, currentPoint.X);
                    InkCanvas.SetTop(this._currentShape, currentPoint.Y);
                }
                else if (width > 0 && height < 0)
                {
                    InkCanvas.SetTop(this._currentShape, currentPoint.Y);
                }
                else if (width < 0 && height > 0)
                {
                    InkCanvas.SetLeft(this._currentShape, currentPoint.X);
                }
                this._currentShape.Width  = Math.Abs(width);
                this._currentShape.Height = Math.Abs(height);
                break;

            default:
                throw new ApplicationException("Не известный тип фигуры");
            }
        }
예제 #19
0
        private void MainInkCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_drawerIsMove == true)
            {
                Point endP = e.GetPosition(MainInkCanvas);

                if (_drawerLastStroke != null && _mode != DrawMode.Ray && _mode != DrawMode.Text)
                {
                    StrokeCollection collection = new StrokeCollection();
                    collection.Add(_drawerLastStroke);
                    Push(_history, new StrokesHistoryNode(collection, StrokesHistoryNodeType.Added));
                }

                if (_drawerLastStroke != null && (_mode == DrawMode.Ray || _mode == DrawMode.Text))
                {
                    //us animation?

                    /*
                     * var ani = new DoubleAnimation(1, 1, Duration4);
                     * ani.Completed += (obj,arg)=> { MainInkCanvas.Strokes.Remove(_drawerLastStroke); };
                     * MainInkCanvas.BeginAnimation(OpacityProperty, ani);
                     */
                    MainInkCanvas.Strokes.Remove(_drawerLastStroke);
                }

                if (_mode == DrawMode.Text)
                {
                    //resize drawer text box
                    _drawerTextBox.Width  = Math.Abs(endP.X - _drawerIntPos.X);
                    _drawerTextBox.Height = Math.Abs(endP.Y - _drawerIntPos.Y);

                    if (_drawerTextBox.Width <= 100 || _drawerTextBox.Height <= 40)
                    {
                        _drawerTextBox.Width  = 100;
                        _drawerTextBox.Height = 40;
                    }

                    InkCanvas.SetLeft(_drawerTextBox, Math.Min(_drawerIntPos.X, endP.X));
                    InkCanvas.SetTop(_drawerTextBox, Math.Min(_drawerIntPos.Y, endP.Y));

                    _drawerTextBox.Focus();
                }

                _drawerIsMove        = false;
                _ignoreStrokesChange = false;
            }
        }
        private void cvs_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            Shape shapeToAdd = null;
            Brush b          = new SolidColorBrush(this.cvs.DefaultDrawingAttributes.Color);

            if (this.cvs != null)
            {
                if (rectShape.IsChecked == true)
                {
                    shapeToAdd = new Rectangle()
                    {
                        Fill = b, Height = 100, Width = 100, RadiusX = 0, RadiusY = 0
                    };
                }
                else if (circleShape.IsChecked == true)
                {
                    shapeToAdd = new Ellipse()
                    {
                        Fill = b, Height = 100, Width = 100
                    };
                }
                else if (lineShape.IsChecked == true)
                {
                    shapeToAdd = new Line()
                    {
                        Height          = 24, Width = 210,
                        StrokeThickness = 20, Stroke = b,
                        X1 = 5, X2 = 200, Y1 = 5, Y2 = 5,
                        StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round
                    };
                }
            }

            if (rectShape.IsChecked == true || circleShape.IsChecked == true)
            {
                InkCanvas.SetLeft(shapeToAdd, e.GetPosition(this.cvs).X - 50);
                InkCanvas.SetTop(shapeToAdd, e.GetPosition(this.cvs).Y - 50);
            }
            else
            {
                InkCanvas.SetLeft(shapeToAdd, e.GetPosition(this.cvs).X);
                InkCanvas.SetTop(shapeToAdd, e.GetPosition(this.cvs).Y - 12);
            }

            this.cvs.Children.Add(shapeToAdd);
        }
예제 #21
0
        void SetZoom(double zoom)
        {
            MainInkCanvas.Width = zoom * 1000;
            var scale = pdf.scale;

            double ver_offset = scrollViewer.VerticalOffset;
            double view_h     = scrollViewer.ViewportHeight;

            double ra = (ver_offset + view_h / 2) / scrollViewer.ExtentHeight;

            double top = 0;

            for (int i = 0; i < pdf.pages.Count; i++)
            {
                var img  = GetImageWithPage(i);
                var page = pdf.pages[i];
                img.Top.Width  = zoom * scale * page.width;
                img.Top.Height = zoom * scale * page.height / 2;
                page.Top       = top;
                InkCanvas.SetTop(img.Top, top);
                top += zoom * scale * page.height / 2;
                img.Bottom.Width  = zoom * scale * page.width;
                img.Bottom.Height = zoom * scale * page.height / 2;
                InkCanvas.SetTop(img.Bottom, top);
                top += zoom * scale * page.height / 2;

                if (Math.Abs(pdf.last_render_zoom - zoom) >= 0.4)
                {
                    pdf.dirt = true;
                }
            }
            var ver_offset_new = top * ra - view_h / 2;

            scrollViewer.ScrollToVerticalOffset(ver_offset_new);
            MainInkCanvas.Height = top;
            var ma = new System.Windows.Media.Matrix();

            ma.ScaleAt(1 / render_zoom, 1 / render_zoom, 0, 0);
            //ma.Translate(-render_zoom / 2 * 1000, 0);
            ma.ScaleAt(zoom, zoom, 0, 0);
            MainInkCanvas.Strokes.Transform(ma, false);

            render_zoom = zoom;
            CheckInView(ver_offset_new, view_h);
        }
예제 #22
0
        private void DrawStrokePoints(Stroke stk, InkCanvas outCanvas, Brush color)
        {
            for (int i = 0; i < stk.StylusPoints.Count; i++)
            {
                StylusPoint point  = stk.StylusPoints[i];
                Ellipse     circle = new Ellipse()
                {
                    Width           = 5,
                    Height          = 5,
                    Stroke          = color,
                    StrokeThickness = 1,
                };
                InkCanvas.SetLeft(circle, point.X - circle.Width / 2);
                InkCanvas.SetTop(circle, point.Y - circle.Height / 2);

                outCanvas.Children.Add(circle);
            }
        }
예제 #23
0
        private void MainCanvas_OnMouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            var element = e.OriginalSource as UIElement;
            var canvas  = sender as InkCanvas;

            if (element == null || canvas == null)
            {
                return;
            }
            var text = new TextBox();

            SetTextBoxStyle(text);
            SetTextBoxBehaviour(text);
            InkCanvas.SetTop(text, e.GetPosition(MainCanvas).Y);
            InkCanvas.SetLeft(text, e.GetPosition(MainCanvas).X);
            MainCanvas.Children.Add(text);
            MainCanvas.UpdateLayout();
            MainCanvas.CommandBindings.Clear();
        }
예제 #24
0
        public UIElement CreateUiElement()
        {
            switch (this.ChildType)
            {
            case ChildType.Image:
                Image image = new Image();
                image.Width  = this.Width;
                image.Height = this.Height;

                InkCanvas.SetLeft(image, this.Left);
                InkCanvas.SetTop(image, this.Top);

                image.Source = ByteImageConverter.ConvertByteArrayToBitmapImage(this.Data);
                return(image);

            default:
                throw new NotSupportedException("Child type " + this.ChildType + " not supported.");
            }
        }
예제 #25
0
        internal static void InsertEllipse()
        {
            Ellipse ell = new Ellipse();

            ell.Height          = ell.Width = 30;
            ell.StrokeThickness = 0;
            ell.Fill            = new SolidColorBrush(MWin.I.iCanv.DefaultDrawingAttributes.Color);
            BlurEffect blr = new BlurEffect {
                Radius = 40
            };

            //OuterGlowBitmapEffect myGlowEffect = new OuterGlowBitmapEffect();
            //myGlowEffect.GlowColor = MWin.I.iCanv.DefaultDrawingAttributes.Color;
            //myGlowEffect.GlowSize = 40;
            ell.Effect = blr;
            MWin.I.iCanv.AddAnimationChild(ell);
            InkCanvas.SetTop(ell, 100);
            InkCanvas.SetLeft(ell, 100);
        }
예제 #26
0
        /// <summary>
        /// Draws the area and open a dialog to pick up a name for the area
        /// </summary>
        /// <param name="p"></param>
        public override async void Draw(Point p)
        {
            _areaPoints.Push(p);

            //Count two point to create the rectangle area
            if (_areaPoints.Count == 2)
            {
                Point p2 = _areaPoints.Pop();
                Point p1 = _areaPoints.Pop();

                this._fillBrush = new SolidColorBrush(ImageUtil.RandomColor());

                // It the area type name is null, it come from the message box input
                if (_areaTypeName == "")
                {
                    _areaTypeName = await _receiver.ViewModel.ShowAreaDialog();
                }

                Area area = _receiver.ViewModel._plan.AddArea(p1, p2, _areaTypeName); // Add to the plan

                // Create the TextBlock object that contain the area name
                TextBlock textBlock = new TextBlock
                {
                    Text            = _areaTypeName,
                    Foreground      = Brushes.White,
                    Width           = 70,
                    Height          = 20,
                    TextAlignment   = TextAlignment.Center,
                    LayoutTransform = new ScaleTransform(1, -1)
                };

                //Add the textBlock to the canvas
                InkCanvas.SetLeft(textBlock, InkCanvas.GetLeft(_receiver.LastShape) + (_receiver.LastShape.Width / 2) - (textBlock.Width / 2));
                InkCanvas.SetTop(textBlock, InkCanvas.GetTop(_receiver.LastShape) + (_receiver.LastShape.Height / 2) - (textBlock.Height / 2));
                _receiver.ViewModel._mainWindow.canvas.Children.Add(textBlock);

                // Add to the history
                MainWindow.main.History = "Area";
                _receiver.ViewModel._stackHistory.Push(new Tuple <Object, Object, string>(textBlock, area, "Area"));

                _receiver.LastShape = null;
            }
        }
예제 #27
0
파일: WPFHelper.cs 프로젝트: satr/forquilt
 public static void CloneElementsTo(IList <UIElement> targetCollection, IEnumerator sourceCollection, InkCanvas inkCanvas, int offset)
 {
     while (sourceCollection.MoveNext())
     {
         if (!(sourceCollection.Current is UIElement))
         {
             return;
         }
         var element = (UIElement)sourceCollection.Current;
         var clone   = Clone(element, inkCanvas);
         if (clone == null)
         {
             continue;
         }
         targetCollection.Add(clone);
         InkCanvas.SetLeft(clone, InkCanvas.GetLeft(element) + offset);
         InkCanvas.SetTop(clone, InkCanvas.GetTop(element) + offset);
     }
 }
예제 #28
0
        private void canvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (canvas.Cursor == Cursors.IBeam && e.Source.GetType() != typeof(TextBox))  //Insert text
            {
                TextBox txt = new TextBox();
                txt.Text                     = "Add text here.";
                txt.TextWrapping             = TextWrapping.Wrap;
                txt.AcceptsReturn            = true;
                txt.FontFamily               = fontFamily;
                txt.FontSize                 = fontSize;
                txt.FontStyle                = fontStyle;
                txt.FontWeight               = fontWeight;
                txt.TextAlignment            = textAlignment;
                txt.Foreground               = foreground;
                txt.TextDecorations          = textDecorations;
                txt.VerticalContentAlignment = verticalContentAlignment;

                txt.Background  = Brushes.Transparent;
                txt.BorderBrush = Brushes.Transparent;
                txt.VerticalContentAlignment = VerticalAlignment.Top;

                InkCanvas.SetLeft(txt, e.GetPosition(canvas).X);
                InkCanvas.SetTop(txt, e.GetPosition(canvas).Y);

                canvas.Children.Add(txt);
                canvas.EditingMode = InkCanvasEditingMode.Select;
                canvas.Cursor      = Cursors.Arrow;

                selectedTextbox = txt;
                canvas.Select(canvas.Strokes, new UIElement[] { txt });
            }
            else if (e.Source.GetType() == typeof(TextBox))
            {
                selectedTextbox = e.Source as TextBox;
                canvas.Select(canvas.Strokes, new UIElement[] { e.Source as TextBox });
                UpdateSetUpTextBox(selectedTextbox);
            }
            else
            {
                canvas.Cursor = Cursors.Arrow;
            }
        }
예제 #29
0
        public void SetControl(String filePath4MapDescriptor)
        {
            _mapDatabase = Dal.GetMapDatabase(filePath4MapDescriptor);
            SelectCanvas(0);
            SetDataInControl4CurCanvas();

            InkCanvas.SetLeft(_counterTerroristStartPos, _mapDatabase.CounterTerroristStartPos.Center.X);
            InkCanvas.SetTop(_counterTerroristStartPos, _mapDatabase.CounterTerroristStartPos.Center.Y);

            InkCanvas.SetLeft(_terroristStartPos, _mapDatabase.TerroristStartPos.Center.X);
            InkCanvas.SetTop(_terroristStartPos, _mapDatabase.TerroristStartPos.Center.Y);

            _counterTerroristStartPos.Width  = _mapDatabase.CounterTerroristStartPos.Width;
            _counterTerroristStartPos.Height = _mapDatabase.CounterTerroristStartPos.Height;

            _terroristStartPos.Width  = _mapDatabase.TerroristStartPos.Width;
            _terroristStartPos.Height = _mapDatabase.TerroristStartPos.Height;

            SetMode(InkCanvasEditingMode.Select, EditorMode.Select);
        }
예제 #30
0
        /// <summary>
        /// Draw a rectangle on the canvas
        /// </summary>
        /// <param name="p1">Rectangle first point</param>
        /// <param name="p2">Rectangle second  point</param>
        /// <returns>Drawed rectangle</returns>
        protected Rectangle DrawRectangle(Point p1, Point p2)
        {
            Rectangle rectangle = new Rectangle
            {
                Fill   = _fillBrush,
                Width  = Math.Abs(p2.X - p1.X),
                Height = Math.Abs(p2.Y - p1.Y)
            };

            // Draw the recatngle to the canvas
            double leftMostX = p2.X > p1.X ? p1.X : p2.X;
            double topMostY  = p2.Y > p1.Y ? p1.Y : p2.Y;

            InkCanvas.SetLeft(rectangle, leftMostX);
            InkCanvas.SetTop(rectangle, topMostY);

            _receiver.ViewModel._mainWindow.canvas.Children.Add(rectangle);

            return(rectangle);
        }