Provides mouse input for target object.
상속: IDisposable
예제 #1
0
        /// <summary>
        /// Attach project editor to container control.
        /// </summary>
        public void AttachEditor()
        {
            _projectEditor = this.DataContext as ProjectEditor;
            _containerControl = this.Find<ContainerViewControl>("containerControl");
            _zoomBorder = this.Find<ZoomBorder>("zoomBorder");

            if (_projectEditor != null && _containerControl != null && _zoomBorder != null)
            {
                _projectEditor.Invalidate = () => _containerControl.InvalidateVisual();
                _projectEditor.ResetZoom = () => _zoomBorder.Reset();
                _projectEditor.AutoFitZoom = () => _zoomBorder.AutoFit();
                _projectEditor.LoadLayout = () => { };
                _projectEditor.SaveLayout = () => { };
                _projectEditor.ResetLayout = () => { };

                _zoomBorder.InvalidatedChild = InvalidateChild;

                _inputProcessor = new InputProcessor(
                    new AvaloniaInputSource(
                        _zoomBorder,
                        _containerControl,
                        _zoomBorder.FixInvalidPointPosition), 
                    _projectEditor);
            }
        }
예제 #2
0
        /// <summary>
        /// Attach project editor to container control.
        /// </summary>
        public void AttachEditor()
        {
            _projectEditor = this.DataContext as ProjectEditor;

            if (_projectEditor != null)
            {
                _projectEditor.Invalidate = () => { };
                _projectEditor.ResetZoom = () => zoomBorder.Reset();
                _projectEditor.AutoFitZoom = () => zoomBorder.AutoFit();
                _projectEditor.LoadLayout = () => OnLoadLayout();
                _projectEditor.SaveLayout = () => OnSaveLayout();
                _projectEditor.ResetLayout = () => OnResetLayout();

                zoomBorder.InvalidatedChild = InvalidateChild;

                _inputProcessor = new InputProcessor(
                    new WpfInputSource(
                        zoomBorder, 
                        drawableControl, 
                        (point) => point), 
                    _projectEditor);

                zoomBorder.AllowDrop = true;
                zoomBorder.DragEnter += ZoomBorder_DragEnter;
                zoomBorder.Drop += ZoomBorder_Drop;
            }
        }
예제 #3
0
        public MainWindow(IServiceProvider serviceProvider)
        {
            InitializeComponent();

            bool isClosing = false;

            _serviceProvider = serviceProvider;
            _projectEditor = _serviceProvider.GetService<ProjectEditor>();

            _previewWindow = new SvgWindow();

            _previewWindow.svgButton.Click += (sender, e) =>
            {
                UpdateSvg();
            };

            _previewWindow.Closing += (sender, e) =>
            {
                if (!isClosing)
                {
                    _previewWindow.Hide();
                    e.Cancel = true;
                }
            };

            Loaded += (seender, e) =>
            {
                _projectEditor.CurrentTool = _projectEditor.Tools.FirstOrDefault(t => t.Name == "Selection");
                _projectEditor.CurrentPathTool = _projectEditor.PathTools.FirstOrDefault(t => t.Name == "Line");
                _projectEditor.OnNewProject();
                _projectEditor.Invalidate = () =>
                {
                    skiaView.InvalidateVisual();
                    if (_previewWindow.svgLive.IsChecked == true)
                    {
                        UpdateSvg();
                    }
                };

                skiaView.Renderer = _projectEditor.Renderers[0];
                skiaView.Container = _projectEditor.Project.CurrentContainer;
                skiaView.Presenter = new EditorPresenter();
                skiaView.Focusable = true;
                skiaView.Focus();
                skiaView.InvalidateVisual();

                _inputProcessor = new InputProcessor(
                    new WpfInputSource(
                        skiaView,
                        skiaView,
                        skiaView.FixPointOffset),
                    _projectEditor);
            };

            Closing += (sender, e) =>
            {
                _inputProcessor.Dispose();
                isClosing = true;
                _previewWindow.Close();
            };

            KeyDown += (sender, e) =>
            {
                bool isControl = Keyboard.Modifiers == ModifierKeys.Control;

                if (isControl)
                {
                    switch (e.Key)
                    {
                        case Key.P:
                            _previewWindow.Show();
                            break;
                        case Key.N:
                            NewProject();
                            break;
                        case Key.O:
                            OpenProject();
                            break;
                        case Key.S:
                            SaveProject();
                            break;
                        case Key.E:
                            Export(_projectEditor.Project.CurrentContainer);
                            break;
                        case Key.Z:
                            _projectEditor.OnUndo();
                            break;
                        case Key.Y:
                            _projectEditor.OnRedo();
                            break;
                        case Key.X:
                            _projectEditor.OnCut();
                            break;
                        case Key.C:
                            _projectEditor.OnCopy();
                            break;
                        case Key.V:
                            _projectEditor.OnPaste();
                            break;
                        case Key.A:
                            _projectEditor.OnSelectAll();
                            break;
                        case Key.G:
                            _projectEditor.OnGroupSelected();
                            break;
                        case Key.U:
                            _projectEditor.OnUngroupSelected();
                            break;
                    }
                }
                else
                {
                    switch (e.Key)
                    {
                        case Key.N:
                            _projectEditor.OnToolNone();
                            break;
                        case Key.S:
                            _projectEditor.OnToolSelection();
                            break;
                        case Key.P:
                            _projectEditor.OnToolPoint();
                            break;
                        case Key.L:
                            _projectEditor.OnToolLine();
                            break;
                        case Key.A:
                            _projectEditor.OnToolArc();
                            break;
                        case Key.B:
                            _projectEditor.OnToolCubicBezier();
                            break;
                        case Key.Q:
                            _projectEditor.OnToolQuadraticBezier();
                            break;
                        case Key.H:
                            _projectEditor.OnToolPath();
                            break;
                        case Key.M:
                            _projectEditor.OnToolMove();
                            break;
                        case Key.R:
                            _projectEditor.OnToolRectangle();
                            break;
                        case Key.E:
                            _projectEditor.OnToolEllipse();
                            break;
                        case Key.T:
                            _projectEditor.OnToolText();
                            break;
                        case Key.I:
                            _projectEditor.OnToolImage();
                            break;
                        case Key.K:
                            _projectEditor.OnToggleDefaultIsStroked();
                            break;
                        case Key.F:
                            _projectEditor.OnToggleDefaultIsFilled();
                            break;
                        case Key.D:
                            _projectEditor.OnToggleDefaultIsClosed();
                            break;
                        case Key.J:
                            _projectEditor.OnToggleDefaultIsSmoothJoin();
                            break;
                        case Key.G:
                            _projectEditor.OnToggleSnapToGrid();
                            break;
                        case Key.C:
                            _projectEditor.OnToggleTryToConnect();
                            break;
                        case Key.Y:
                            _projectEditor.OnToggleCloneStyle();
                            break;
                        case Key.Delete:
                            _projectEditor.OnDeleteSelected();
                            break;
                        case Key.Escape:
                            _projectEditor.OnDeselectAll();
                            break;
                    }
                }
            };
        }