private void OnTouchDrawing() { var inkPresenter = InkCanvas.GetInkCanvasView().InkPresenter; bool isTouch = false; if (inkPresenter.InputDeviceTypes.HasFlag(XCoreInputDeviceTypes.Touch)) { inkPresenter.InputDeviceTypes = XCoreInputDeviceTypes.Pen; TouchDrawingButton.BackgroundColor = Color.Transparent; } else { inkPresenter.InputDeviceTypes = XCoreInputDeviceTypes.Pen | XCoreInputDeviceTypes.Touch | XCoreInputDeviceTypes.Mouse; TouchDrawingButton.BackgroundColor = Color.LightGray; isTouch = true; } var properties = new Dictionary <string, string> { ["Enabled"] = isTouch.ToString(CultureInfo.InvariantCulture) }; Analytics.TrackEvent("Touch drawing", properties); }
private void OnShowPalette(object sender, EventArgs e) { FullPaletteView.IsVisible = true; var attributes = InkCanvas.GetInkCanvasView().InkPresenter.CopyDefaultDrawingAttributes(); FullPaletteView.PenSize = attributes.Size; FullPaletteView.PenColor = attributes.Color; }
private void OnPaletteChanged(object sender, PaletteChangedEventArgs e) { var attributes = InkCanvas.GetInkCanvasView().InkPresenter.CopyDefaultDrawingAttributes(); attributes.Size = e.PenWidth; attributes.Color = e.PenColor; InkCanvas.GetInkCanvasView().InkPresenter.UpdateDefaultDrawingAttributes(attributes); }
/// <summary> /// detach the events when disappering /// </summary> protected override void OnDisappearing() { base.OnDisappearing(); var inkCanvasView = InkCanvas.GetInkCanvasView(); inkCanvasView.InkPresenter.StrokesCollected -= OnStrokesCollected; inkCanvasView.InkPresenter.StrokesErased -= InkStrokeContainer_StrokesErased; DualScreenInfo.Current.PropertyChanged -= FormsWindow_PropertyChanged; _dualScreenInfo.PropertyChanged -= OnDualScreenInfoPropertyChanged; }
private async void UndoManagerUpdated(object sender, EventArgs e) { InkCanvas.GetInkCanvasView().InkPresenter.StrokeContainer.SetRange(App.GetSketchData().InkStrokes); InkCanvas.GetInkCanvasView().InvalidateCanvas(false, true); await SaveSketchAsync().ConfigureAwait(false); await UpdateWebViewAsync().ConfigureAwait(false); }
private async void InkStrokeContainer_StrokesErased(object sender, Xamarin.Forms.Inking.XInkStrokesErasedEventArgs e) { var undoItem = App.Container.Resolve <IAddStrokesUndoItem>(); undoItem.Container = App.GetSketchData(); undoItem.Strokes = e.Strokes.ToList(); undoItem.IsErase = true; _viewModel.UndoManager.Add(undoItem); App.GetSketchData().InkStrokes = InkCanvas.GetInkCanvasView().InkPresenter.StrokeContainer.GetStrokes(); await UpdateWebViewAsync().ConfigureAwait(false); }
public SplitPage(ISplitPageViewModel splitPageViewModel) { _viewModel = splitPageViewModel ?? throw new ArgumentNullException(nameof(splitPageViewModel)); _viewModel.ActivateModeCommand = new Command <string>(ActivateMode); _viewModel.TouchDrawingCommand = new Command(OnTouchDrawing); _viewModel.UndoManager.Updated += UndoManagerUpdated; InitializeComponent(); _viewModel.InkCanvasView = InkCanvas.GetInkCanvasView(); MenuView.NewSketchCommand = new Command(OnNewSketch); MenuView.Page = this; BindingContext = _viewModel; _dualScreenInfo = new DualScreenInfo(ControlPanel); ActivateMode(Mode.Drawing); }
/// <summary> /// Update the sketch data /// </summary> /// <param name="sketchData">the sketch data</param> public async void SketchDataUpdated(ISketchData sketchData) { _ = sketchData ?? throw new ArgumentNullException(nameof(sketchData)); // Title = sketchData.Name; var inkCanvasView = InkCanvas.GetInkCanvasView(); Dispatcher.BeginInvokeOnMainThread(delegate { inkCanvasView.BackgroundColor = sketchData.BackgroundColor; InkCanvas.CanvasSize = new Size(sketchData.Width, sketchData.Height); InkCanvas.GetInkCanvasView().InkPresenter.StrokeContainer.Clear(); InkCanvas.GetInkCanvasView().InkPresenter.StrokeContainer.Add(sketchData.InkStrokes); inkCanvasView.InvalidateCanvas(false, true); }); _viewModel.UndoManager.Reset(); await UpdateWebViewAsync().ConfigureAwait(false); }
private void OnZoomSliderValueChanged(object sender, ValueChangedEventArgs e) { InkCanvas.GetInkCanvasView().ZoomFactor = e.NewValue; }
/// <summary> /// Attach events and initialize the sketch data when appearing /// </summary> protected override async void OnAppearing() { Analytics.TrackEvent("Split page"); base.OnAppearing(); MenuContainerPane1.InputTransparent = true; MenuViewRootLayout.InputTransparent = true; if (Xamarin.Essentials.Preferences.Get(SettingsPage.LandscapeDrawingRight, false)) { WideModePreference = TwoPaneViewWideModeConfiguration.RightLeft; } else { WideModePreference = TwoPaneViewWideModeConfiguration.LeftRight; } if (Xamarin.Essentials.Preferences.Get(SettingsPage.PortraitDrawingBottom, false)) { TallModePreference = TwoPaneViewTallModeConfiguration.BottomTop; } else { TallModePreference = TwoPaneViewTallModeConfiguration.TopBottom; } UpdateSize(); DualScreenInfo.Current.PropertyChanged += FormsWindow_PropertyChanged; _dualScreenInfo.PropertyChanged += OnDualScreenInfoPropertyChanged; var sketchData = App.GetSketchData(); if (sketchData != null) { Title = sketchData.Name; } var inkCanvasView = InkCanvas.GetInkCanvasView(); if (sketchData != null) { inkCanvasView.BackgroundColor = sketchData.BackgroundColor; inkCanvasView.InkPresenter.StrokeContainer.Clear(); inkCanvasView.InkPresenter.StrokeContainer.Add(sketchData.InkStrokes); } inkCanvasView.InkPresenter.StrokesCollected += OnStrokesCollected; inkCanvasView.InkPresenter.StrokesErased += InkStrokeContainer_StrokesErased; UpdateTwoPaneView(); await UpdateWebViewAsync().ConfigureAwait(false); if (InkCanvas.GetInkCanvasView().InkPresenter.InputDeviceTypes.HasFlag(XCoreInputDeviceTypes.Touch)) { TouchDrawingButton.BackgroundColor = Color.LightGray; } else { TouchDrawingButton.BackgroundColor = Color.Transparent; } }