Ejemplo n.º 1
0
        public ImageEditorWindow()
        {
            InitializeComponent();

            if (DataContext is ImageEditorViewModel vm)
            {
                vm.PropertyChanged += (S, E) =>
                {
                    if (E.PropertyName == nameof(vm.TransformedBitmap))
                    {
                        UpdateInkCanvas();
                    }
                };

                vm.InkCanvas = InkCanvas;

                InkCanvas.Strokes.StrokesChanged += (S, E) =>
                {
                    var item = new StrokeHistory();

                    item.Added.AddRange(E.Added);
                    item.Removed.AddRange(E.Removed);

                    vm.AddInkHistory(item);
                };

                void SelectionMovingOrResizing(object Sender, InkCanvasSelectionEditingEventArgs Args)
                {
                    vm.AddSelectHistory(new SelectHistory
                    {
                        NewRect   = Args.NewRectangle,
                        OldRect   = Args.OldRectangle,
                        Selection = InkCanvas.GetSelectedStrokes()
                    });
                }

                InkCanvas.SelectionMoving   += SelectionMovingOrResizing;
                InkCanvas.SelectionResizing += SelectionMovingOrResizing;

                vm.Window = this;
            }

            Image.SizeChanged += (S, E) => UpdateInkCanvas();

            ModesBox.SelectedIndex = 0;

            _settings = ServiceProvider.Get <Settings>().ImageEditor;

            ColorPicker.SelectedColor = _settings.BrushColor.ToWpfColor();
            SizeBox.Value             = _settings.BrushSize;

            InkCanvas.DefaultDrawingAttributes.FitToCurve = true;
        }
Ejemplo n.º 2
0
        public InkCanvasViewModel(ImageEditorSettings Settings)
        {
            SelectedColor = Settings
                            .ToReactivePropertyAsSynchronized(
                M => M.BrushColor,
                M => M.ToWpfColor(),
                M => M.ToDrawingColor());

            BrushSize = Settings
                        .ToReactivePropertyAsSynchronized(M => M.BrushSize);

            SelectedTool = new ReactivePropertySlim <ExtendedInkTool>(ExtendedInkTool.Tools.First());
        }