Example #1
0
        private void buttonClear_Click(object sender, RoutedEventArgs e)
        {
            geos.Clear();             // REM 清除所有的笔划
            ptinfos.Clear();          // REM 清除一笔中所有点
            CreateNewBitmap();

            strokes.Clear();          // REM 清除所有的画笔
            tiwp.Clear();             // REM 清除控件中的选择
        }
        private void SetNewHost(string host, string nextAnswer, MessageType mt)
        {
            Application.Current.Dispatcher.InvokeAsync(() => Strokes.Clear());
            if (host == UserName)
            {
                IsHost = true;
            }
            else
            {
                IsHost = false;
            }

            if (IsHost && IsInGame)
            {
                CurrentAnswer = nextAnswer;
            }
            else
            {
                string blank = "";
                for (int i = 0; i < nextAnswer.Length; i++)
                {
                    blank += "□";
                }
                CurrentAnswer = blank;
            }
        }
        /// <summary>
        /// Redo image edits that were undone
        /// </summary>
        internal void Redo()
        {
            int index = redoActions.Count - 1;

            if (index < 0)
            {
                return;
            }
            if (redoActions[index] == InkCanvasEditingMode.Ink)
            {
                Strokes.Add(redoStrokes[index]);
            }
            else if (redoActions[index] == InkCanvasEditingMode.EraseByStroke)
            {
                Strokes.RemoveAt(Strokes.Count - 1);
            }
            else if (redoActions[index] == InkCanvasEditingMode.None)
            {
                Strokes.Clear();
            }
            undoActions.Add(redoActions[index]);
            undoStrokes.Add(redoStrokes[index]);
            redoActions.RemoveAt(index);
            redoStrokes.RemoveAt(index);
        }
Example #4
0
 private void ClearCanvas()
 {
     Application.Current.Dispatcher.Invoke(new Action(() =>
     {
         ABBManager.Instance.ShapesPending.Enqueue(new ObjectToDraw(EraseAll: true, Colour: Colors.White));
         Strokes.Clear();
     }));
 }
 internal void EraseAll()
 {
     Strokes.Clear();
     undoActions.Add(InkCanvasEditingMode.None);
     undoStrokes.Add(null);
     redoActions.Clear();
     redoStrokes.Clear();
 }
 internal void Clear()
 {
     Strokes.Clear();
     redoActions.Clear();
     redoStrokes.Clear();
     undoActions.Clear();
     undoStrokes.Clear();
 }
Example #7
0
 public void Clear()
 {
     Strokes.Clear();
     canvas.DrawColor(BackgroundColor != null ? new Color((byte)(BackgroundColor.R * 255.0), (byte)(BackgroundColor.G * 255.0), (byte)(BackgroundColor.B * 255.0), (byte)(BackgroundColor.A * 255.0)) : Color.Transparent, PorterDuff.Mode.Clear);
     if (backgroundBitmap != null)
     {
         DrawStrokes();
     }
     Invalidate();
 }
Example #8
0
        private void UpdateStrokes()
        {
            App.Current.Dispatcher.Invoke(() =>
            {
                // Do we need a lock here?
                IsRefreshingStrokes = true;
                var newStrokes      = new StrokeCollection(StrokeCollection.GetMergedStrokeMaps());

                Strokes.Clear();
                Strokes.Add(newStrokes);

                if (EditingMode == InkCanvasEditingMode.Select)
                {
                    SelectionChanged?.Invoke(SelectedStrokes);
                }
                IsRefreshingStrokes = false;
            });
        }
        /// <summary>
        /// Undo edit actions performed
        /// </summary>
        internal void Undo()
        {
            int index = undoActions.Count - 1;

            if (index < 0)
            {
                return;
            }
            if (undoActions[index] == InkCanvasEditingMode.Ink)
            {
                Strokes.RemoveAt(Strokes.Count - 1);
            }
            else if (undoActions[index] == InkCanvasEditingMode.EraseByStroke)
            {
                Strokes.Add(undoStrokes[index]);
            }
            else if (undoActions[index] == InkCanvasEditingMode.None)
            {
                for (int i = 0; i < index; i++)
                {
                    if (undoActions[i] == InkCanvasEditingMode.Ink)
                    {
                        Strokes.Add(undoStrokes[i]);
                    }
                    else if (undoActions[i] == InkCanvasEditingMode.EraseByStroke)
                    {
                        Strokes.Remove(undoStrokes[i]);
                    }
                    else if (undoActions[i] == InkCanvasEditingMode.None)
                    {
                        Strokes.Clear();
                    }
                }
            }
            redoActions.Add(undoActions[index]);
            redoStrokes.Add(undoStrokes[index]);
            undoActions.RemoveAt(index);
            undoStrokes.RemoveAt(index);
        }
Example #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <DrawingView> e)
        {
            base.OnElementChanged(e);
            if (Control == null && Element != null)
            {
                canvas = new InkCanvas
                {
                    Background = Element.BackgroundColor.ToBrush(),
                    DefaultDrawingAttributes = new()
                    {
                        Color  = Element.DefaultLineColor.ToMediaColor(),
                        Width  = Element.DefaultLineWidth,
                        Height = Element.DefaultLineWidth
                    }
                };
                Element.Lines.CollectionChanged += OnCollectionChanged;
                SetNativeControl(canvas);

                canvas.Strokes.StrokesChanged += OnStrokesChanged;
                Control !.PreviewMouseDown    += OnPreviewMouseDown;
            }

            if (e.OldElement != null)
            {
                canvas !.Strokes.StrokesChanged   -= OnStrokesChanged;
                Element !.Lines.CollectionChanged -= OnCollectionChanged;
                if (Control != null)
                {
                    Control.PreviewMouseDown -= OnPreviewMouseDown;
                }
            }
        }

        void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            canvas !.Strokes.StrokesChanged -= OnStrokesChanged;
            canvas.Strokes.Clear();
            LoadLines();
            canvas.Strokes.StrokesChanged += OnStrokesChanged;
        }

        void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) => Clear();

        void Clear(bool force = false)
        {
            if (!Element.MultiLineMode || force)
            {
                canvas !.Strokes.Clear();
                Element.Lines.Clear();
            }
        }

        void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
        {
            Element.Lines.CollectionChanged -= OnCollectionChanged;
            if (e.Added.Count > 0)
            {
                if (!Element.MultiLineMode)
                {
                    Element.Lines.Clear();
                }

                var lines = Element.MultiLineMode ? e.Added : new StrokeCollection()
                {
                    e.Added.First()
                };

                foreach (var line in lines)
                {
                    var points = line.StylusPoints.Select(point => new Point(point.X, point.Y)).ToList();
                    Element.Lines.Add(new Line()
                    {
                        Points    = new ObservableCollection <Point>(points),
                        LineColor = Color.FromRgba(line.DrawingAttributes.Color.R, line.DrawingAttributes.Color.G,
                                                   line.DrawingAttributes.Color.B, line.DrawingAttributes.Color.A),
                        LineWidth = (float)line.DrawingAttributes.Width
                    });
                }

                if (Element.Lines.Count > 0)
                {
                    var lastLine = Element.Lines.Last();
                    if (Element.DrawingLineCompletedCommand?.CanExecute(lastLine) ?? false)
                    {
                        Element.DrawingLineCompletedCommand.Execute(lastLine);
                    }
                }

                if (Element.ClearOnFinish)
                {
                    Element.Lines.CollectionChanged -= OnCollectionChanged;
                    Clear(true);
                    canvas !.Strokes.StrokesChanged += OnStrokesChanged;
                }
            }

            Element.Lines.CollectionChanged += OnCollectionChanged;
        }

        void LoadLines()
        {
            var lines = Element.MultiLineMode
                                ? Element.Lines
                                : Element.Lines.Any()
                                        ? new ObservableCollection <Line> {
                Element.Lines.LastOrDefault()
            }
                                        : new ObservableCollection <Line>();

            foreach (var line in lines)
            {
                var stylusPoints = line.Points.Select(point => new StylusPoint(point.X, point.Y)).ToList();
                if (stylusPoints is { Count: > 0 })
                {
                    var stroke = new Stroke(new StylusPointCollection(stylusPoints))
                    {
                        DrawingAttributes = new()
                        {
                            Color  = line.LineColor.ToMediaColor(),
                            Width  = line.LineWidth,
                            Height = line.LineWidth
                        }
                    };
                    canvas !.Strokes.Add(stroke);
                }
            }
        }
Example #11
0
 void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     canvas !.Strokes.Clear();
     Element.Points.Clear();
 }
Example #12
0
 public void Clear()
 {
     Strokes.Clear();
     CurrentPathView.Clear();
     drawPath();
 }
Example #13
0
 /// <summary>
 /// Clears all strokes added with <see cref="AddStroke(TouchStroke)"/>.
 /// </summary>
 public void ClearStrokes()
 {
     EnsureNotDisposed();
     _strokes.Clear();
 }
Example #14
0
		void TouchCanvas_Gesture(object sender, InkCanvasGestureEventArgs e)
		{
			GestureRecognitionResult recognitionResult = e.GetGestureRecognitionResults().FirstOrDefault();
			if (recognitionResult != null && recognitionResult.RecognitionConfidence == RecognitionConfidence.Strong && recognitionResult.ApplicationGesture == ApplicationGesture.ScratchOut)
				Strokes.Clear();
		}
Example #15
0
 public virtual void Clear()
 {
     Strokes.Clear();
     undo = 0;
 }
Example #16
0
 private void ClearCanvas(object param)
 {
     Strokes.Clear();
 }