private async void Cancel_Click(object sender, RoutedEventArgs e)
        {
            if (CropToolbar != null && CropToolbar.Visibility == Visibility.Visible)
            {
                // Reset Cropper
                await Cropper.SetSourceAsync(_media.File, _media.EditState.Rotation, _media.EditState.Flip, _media.EditState.Proportions, _media.EditState.Rectangle);

                _rotation      = _media.EditState.Rotation;
                _flip          = _media.EditState.Flip;
                Crop.IsChecked = IsCropped(Cropper.CropRectangle);
                ResetUiVisibility();
            }
            else if (DrawToolbar != null && DrawToolbar.Visibility == Visibility.Visible)
            {
                Canvas.RestoreState();

                ResetUiVisibility();
                SettingsService.Current.Pencil = DrawSlider.GetDefault();
            }
            else
            {
                if (_media is StorageMedia)
                {
                    _media.EditState = _originalMediaEditState; // Reset to state before starting editing
                }
                if (_media is StorageVideo video)
                {
                    video.IsMuted     = _originalVideoIsMuted;
                    video.Compression = _originalVideoCompression;
                }
                ResetUiVisibility();
                Hide(ContentDialogResult.Secondary);
            }
        }
        private void Accept_Click(object sender, RoutedEventArgs e)
        {
            if ((CropToolbar != null && CropToolbar.Visibility == Visibility.Visible) ||
                (!_hasMessageContext && _media.IsVideo))
            {
                var rect = Cropper.CropRectangle;

                TimeSpan trimStartTime;
                TimeSpan trimStopTime;

                if (TrimRange != null)
                {
                    trimStartTime = TimeSpan.FromMilliseconds(TrimRange.Minimum * TrimRange.OriginalDuration.TotalMilliseconds);
                    trimStopTime  = TimeSpan.FromMilliseconds(TrimRange.Maximum * TrimRange.OriginalDuration.TotalMilliseconds);
                }

                if (_media?.EditState is BitmapEditState es)
                {
                    es.Rectangle     = rect;
                    es.Proportions   = Cropper.Proportions;
                    es.Strokes       = Canvas.Strokes;
                    es.Flip          = _flip;
                    es.Rotation      = _rotation;
                    es.TrimStartTime = trimStartTime;
                    es.TrimStopTime  = trimStopTime;
                }
                Crop.IsChecked = IsCropped(rect);
                ResetUiVisibility();
                if (!_hasMessageContext && _media.IsVideo)
                {
                    Hide(ContentDialogResult.Primary);
                }
            }
            else if (DrawToolbar != null && DrawToolbar.Visibility == Visibility.Visible)
            {
                Canvas.SaveState();
                _media.EditState.Strokes = Canvas.Strokes;

                Draw.IsChecked = Canvas.Strokes?.Count > 0;
                ResetUiVisibility();

                SettingsService.Current.Pencil = DrawSlider.GetDefault();
            }
            else
            {
                if (_hasMessageContext)
                {
                    ResetUiVisibility();
                    _media.Caption = CaptionInput.GetFormattedText();
                }
                Hide(ContentDialogResult.Primary);
            }
        }
        private async void Accept_Click(object sender, RoutedEventArgs e)
        {
            if (Cropper.IsCropEnabled)
            {
                if (_media != null)
                {
                    var rect = Cropper.CropRectangle;
                    var w    = Cropper.PixelWidth;
                    var h    = Cropper.PixelHeight;

                    _media.EditState = new BitmapEditState
                    {
                        //Rectangle = new Rect(rect.X * w, rect.Y * h, rect.Width * w, rect.Height * h),
                        Rectangle   = rect,
                        Proportions = Cropper.Proportions,
                        Strokes     = Canvas.Strokes,
                        Flip        = _flip,
                        Rotation    = _rotation
                    };

                    Hide(ContentDialogResult.Primary);
                    return;
                }

                var cropped = await Cropper.CropAsync();

                var drawing = Canvas.Strokes;
                if (drawing != null && drawing.Count > 0)
                {
                    cropped = await ImageHelper.DrawStrokesAsync(cropped, drawing, Cropper.CropRectangle, _rotation, _flip);
                }

                Result = cropped;
                Hide(ContentDialogResult.Primary);
            }
            else
            {
                Canvas.SaveState();

                Cropper.IsCropEnabled = true;
                Canvas.IsEnabled      = false;

                BasicToolbar.Visibility = Visibility.Visible;
                DrawToolbar.Visibility  = Visibility.Collapsed;
                DrawSlider.Visibility   = Visibility.Collapsed;

                SettingsService.Current.Pencil = DrawSlider.GetDefault();
            }
        }
Beispiel #4
0
        private void Accept_Click(object sender, RoutedEventArgs e)
        {
            if (Cropper.IsCropEnabled)
            {
                var rect = Cropper.CropRectangle;
                var w    = Cropper.PixelWidth;
                var h    = Cropper.PixelHeight;

                TimeSpan trimStartTime;
                TimeSpan trimStopTime;

                if (TrimRange != null)
                {
                    trimStartTime = TimeSpan.FromMilliseconds(TrimRange.Minimum * TrimRange.OriginalDuration.TotalMilliseconds);
                    trimStopTime  = TimeSpan.FromMilliseconds(TrimRange.Maximum * TrimRange.OriginalDuration.TotalMilliseconds);
                }

                _media.EditState = new BitmapEditState
                {
                    //Rectangle = new Rect(rect.X * w, rect.Y * h, rect.Width * w, rect.Height * h),
                    Rectangle     = rect,
                    Proportions   = Cropper.Proportions,
                    Strokes       = Canvas.Strokes,
                    Flip          = _flip,
                    Rotation      = _rotation,
                    TrimStartTime = trimStartTime,
                    TrimStopTime  = trimStopTime,
                };

                Hide(ContentDialogResult.Primary);
            }
            else
            {
                Canvas.SaveState();

                Cropper.IsCropEnabled = true;
                Canvas.IsEnabled      = false;

                BasicToolbar.Visibility = Visibility.Visible;
                DrawToolbar.Visibility  = Visibility.Collapsed;
                DrawSlider.Visibility   = Visibility.Collapsed;

                SettingsService.Current.Pencil = DrawSlider.GetDefault();
            }
        }
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            if (Cropper.IsCropEnabled)
            {
                Hide(ContentDialogResult.Secondary);
            }
            else
            {
                Canvas.RestoreState();

                Cropper.IsCropEnabled = true;
                Canvas.IsEnabled      = false;

                BasicToolbar.Visibility = Visibility.Visible;
                DrawToolbar.Visibility  = Visibility.Collapsed;
                DrawSlider.Visibility   = Visibility.Collapsed;

                SettingsService.Current.Pencil = DrawSlider.GetDefault();
            }
        }