예제 #1
0
        private void Svg_MouseMove(object sender, MouseEventArgs e)
        {
            var point = e.GetPosition(skElementSvg);

            if (items.SelectedItem is Item item && item.Drawable != null)
            {
                var skPoint  = new SKPoint((float)point.X, (float)point.Y);
                var drawable = item.Drawable.HitTest(skPoint);
                if (drawable != null)
                {
                    Debug.WriteLine($"{point} {drawable.GetType().Name}");
#if false
                    if (drawable is DrawablePath drawablePath)
                    {
                        var sb = new StringBuilder();
                        CSharpCodeGen.Generate(drawablePath.Path, sb);
                        CSharpCodeGen.Generate(drawablePath.Transform, sb);
                        Debug.WriteLine(sb.ToString());
                    }
#endif
                }
            }
        }
예제 #2
0
        public MainWindow()
        {
            this.InitializeComponent();
            this.AttachDevTools();

            this.Closing += (sender, e) =>
            {
                if (this.DataContext is MainWindowViewModel vm)
                {
                    if (vm.Layout is IDock dock)
                    {
                        dock.Close();
                    }
                }
                ;
            };

            this.FindControl <MenuItem>("FileNew").Click += (sender, e) =>
            {
                if (this.DataContext is MainWindowViewModel vm)
                {
                    if (vm.Layout is IDock root)
                    {
                        root.Close();
                    }
                    vm.Factory = new EmptyDockFactory();
                    vm.Layout  = vm.Factory.CreateLayout();
                    vm.Factory.InitLayout(vm.Layout);
                }
            };

            this.FindControl <MenuItem>("FileOpen").Click += async(sender, e) =>
            {
                var dlg = new OpenFileDialog();
                dlg.Filters.Add(new FileDialogFilter()
                {
                    Name = "Json", Extensions = { "json" }
                });
                dlg.Filters.Add(new FileDialogFilter()
                {
                    Name = "All", Extensions = { "*" }
                });
                var result = await dlg.ShowAsync(this);

                if (result != null)
                {
                    if (this.DataContext is MainWindowViewModel vm)
                    {
                        IDock layout = _serializer.Load <RootDock>(result.FirstOrDefault());
                        if (vm.Layout is IDock root)
                        {
                            root.Close();
                        }
                        vm.Layout = layout;
                        vm.Factory.InitLayout(vm.Layout);
                    }
                }
            };

            this.FindControl <MenuItem>("FileSaveAs").Click += async(sender, e) =>
            {
                var dlg = new SaveFileDialog();
                dlg.Filters.Add(new FileDialogFilter()
                {
                    Name = "Json", Extensions = { "json" }
                });
                dlg.Filters.Add(new FileDialogFilter()
                {
                    Name = "All", Extensions = { "*" }
                });
                dlg.InitialFileName  = "Layout";
                dlg.DefaultExtension = "json";
                var result = await dlg.ShowAsync(this);

                if (result != null)
                {
                    if (this.DataContext is MainWindowViewModel vm)
                    {
                        _serializer.Save(result, vm.Layout);
                    }
                }
            };

            this.FindControl <MenuItem>("FileGenerateCode").Click += async(sender, e) =>
            {
                var dlg = new SaveFileDialog();
                dlg.Filters.Add(new FileDialogFilter()
                {
                    Name = "C#", Extensions = { "cs" }
                });
                dlg.Filters.Add(new FileDialogFilter()
                {
                    Name = "All", Extensions = { "*" }
                });
                dlg.InitialFileName  = "ViewModel";
                dlg.DefaultExtension = "cs";
                var result = await dlg.ShowAsync(this);

                if (result != null)
                {
                    if (this.DataContext is MainWindowViewModel vm)
                    {
                        ICodeGen codeGeb = new CSharpCodeGen();
                        codeGeb.Generate(vm.Layout, result);
                    }
                }
            };

            this.FindControl <MenuItem>("ViewEditor").Click += (sender, e) =>
            {
                if (this.DataContext is MainWindowViewModel vm)
                {
                    var editorView = new EditorTool
                    {
                        Id    = "Editor",
                        Title = "Editor"
                    };

                    var layout = new ToolDock
                    {
                        Id          = nameof(IToolDock),
                        Proportion  = double.NaN,
                        Title       = nameof(IToolDock),
                        CurrentView = editorView,
                        DefaultView = editorView,
                        Views       = vm.Factory.CreateList <IView>
                                      (
                            editorView
                                      )
                    };

                    vm.Factory.Update(layout, vm.Layout);

                    var window = vm.Factory.CreateWindowFrom(layout);
                    if (window != null)
                    {
                        if (vm.Layout is IDock root)
                        {
                            vm.Factory.AddWindow(root, window);
                        }
                        window.X      = 0;
                        window.Y      = 0;
                        window.Width  = 800;
                        window.Height = 600;
                        window.Present(false);
                    }
                }
            };

            this.FindControl <MenuItem>("OptionsDragBehaviorIsEnabled").Click += (sender, e) =>
            {
                bool isEnabled = (bool)GetValue(DragBehavior.IsEnabledProperty);
                SetValue(DragBehavior.IsEnabledProperty, !isEnabled);
            };

            this.FindControl <MenuItem>("OptionsDropBehaviorIsEnabled").Click += (sender, e) =>
            {
                bool isEnabled = (bool)GetValue(DropBehavior.IsEnabledProperty);
                SetValue(DropBehavior.IsEnabledProperty, !isEnabled);
            };
        }