예제 #1
0
        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);
        }
예제 #2
0
        private void OnShowPalette(object sender, EventArgs e)
        {
            FullPaletteView.IsVisible = true;
            var attributes = InkCanvas.GetInkCanvasView().InkPresenter.CopyDefaultDrawingAttributes();

            FullPaletteView.PenSize  = attributes.Size;
            FullPaletteView.PenColor = attributes.Color;
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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;
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
 private void OnZoomSliderValueChanged(object sender, ValueChangedEventArgs e)
 {
     InkCanvas.GetInkCanvasView().ZoomFactor = e.NewValue;
 }
예제 #10
0
        /// <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;
            }
        }