Пример #1
0
        public NodePanel()
        {
            this.DoubleBuffered = true;
            this.ResizeRedraw   = true;
            Overlay             = new GraphicalOverlay
            {
                Owner = this
            };

            this.Paint    += NodePanel_Paint;
            Overlay.Paint += GraphicalOverlay_Paint;

            AllowDrop  = true;
            DragEnter += Panel1_DragEnter;
            DragDrop  += Panel1_DragDrop;
            LinePen    = new Pen(Color.OrangeRed, 2);

            //_HScrollBar = new HScrollBar();
            //_HScrollBar.ValueChanged += (_, __) =>
            //{
            //    foreach (var c in this.Controls.Cast<Control>().Where(x => x is BaseNode))
            //    {
            //        c.Location = c.Location.SubX(_HScrollBar.Value - LastX);
            //    }
            //    this.Refresh();
            //    LastX = _HScrollBar.Value;
            //};

            //_VScrollBar = new VScrollBar();

            //_VScrollBar.ValueChanged += (_, __) =>
            //{
            //    foreach (var c in this.Controls.Cast<Control>().Where(x => x is BaseNode))
            //    {
            //        c.Location = c.Location.SubY(_VScrollBar.Value - LastY);
            //    }
            //    this.Refresh();
            //    LastY = _VScrollBar.Value;
            //};

            //this.Controls.Add(_HScrollBar);
            //this.Controls.Add(_VScrollBar);

            this.Size = new Size(1000, 1000);

            Nodes = new Dictionary <string, Type>();
        }
        public FrmGraphicsEditor()
        {
            InitializeComponent();
            PolyEditMode = EnumPolyEditMode.MoveImage;



            Overlay = new GraphicalOverlay()
            {
                Owner = pbDrawSpace
            };

            Overlay.Paint += Overlay_Paint;
            InitTSEvents();
            InitPbDrawSpace();

            btnNewTTImage.Click += BtnTTImageNew_Click;
            btnDelTTImage.Click += (_, __) => { if (lbTTImages.SelectedItem != null)
                                                {
                                                    selectedScene.TTImages.RemoveAt(lbTTImages.SelectedIndex); RefreshTTImages(); Overlay.Refresh();
                                                }
            };
            btnMoveUpTTImage.Click += (_, __) => { if (lbTTImages.SelectedIndex > 0)
                                                   {
                                                       SwapImages(lbTTImages.SelectedIndex, lbTTImages.SelectedIndex - 1); RefreshTTImages(); Overlay.Refresh();
                                                   }
            };
            btnMoveDownTTImage.Click += (_, __) => { if (lbTTImages.SelectedIndex < lbTTImages.Items.Count - 1)
                                                     {
                                                         SwapImages(lbTTImages.SelectedIndex, lbTTImages.SelectedIndex + 1); RefreshTTImages(); Overlay.Refresh();
                                                     }
            };

            var SceneContext = new ContextMenu();

            SceneContext.MenuItems.Add("New", (_, __) =>
            {
                if (MainForm.Project == null)
                {
                    return;
                }
                using (var f = new frmScene(MainForm.Project.Scenes.ToArray()))
                {
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        MainForm.Project.Scenes.Add(f.Result);
                        RefreshScenes();
                        lbScenes.SelectedIndex = lbScenes.Items.Count - 1;
                    }
                }
            });
            SceneContext.MenuItems.Add("Edit", (_, __) =>
            {
                if (MainForm.Project == null || lbScenes.SelectedItem == null)
                {
                    return;
                }

                using (var f = new frmScene(MainForm.Project.Scenes.ToArray(), MainForm.Project.Scenes[lbScenes.SelectedIndex]))
                {
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        var s           = MainForm.Project.Scenes[lbScenes.SelectedIndex];
                        s.Name          = f.Result.Name;
                        s.ResolutionDPI = f.Result.ResolutionDPI;
                        s.CanvasSize    = f.Result.CanvasSize;

                        RefreshScenes();
                    }
                }
            });
            lbScenes.ContextMenu = SceneContext;

            lbOids.SelectedIndexChanged     += LbOids_SelectedIndexChanged;
            lbScenes.SelectedIndexChanged   += LB_Scenes_SelectedIndexChanged;
            tsPolygons.SelectedIndexChanged += (_, __) =>
            {
                if (selectedSceneOid != null)
                {
                    int i = tsPolygons.SelectedIndex;
                    if (i > -1 && selectedSceneOid.Polygons.Count > 0)
                    {
                        selectedpolygon = selectedSceneOid.Polygons[i];
                        Overlay.Refresh();
                    }
                }
            };

            btnOnSwitchOid.Click += (_, __) =>
            {
                if (selectedScene == null)
                {
                    return;
                }

                lbOids.SelectedIndex = -1;
                tsPolygons.Items.Clear();


                if (selectedScene.StartOid == null)
                {
                    selectedScene.StartOid = new SceneOid("os_start");
                    selectedSceneOid       = selectedScene.StartOid;
                }
                if (selectedScene.StartOid.Polygons == null || selectedScene.StartOid.Polygons.Count == 0)
                {
                    selectedSceneOid = selectedScene.StartOid;
                    tsAddPoly.PerformClick();
                }
                selectedSceneOid = selectedScene.StartOid;


                tsPolygons.Items.AddRange(selectedSceneOid.Polygons.ToArray());
                if (tsPolygons.Items.Count > 0)
                {
                    tsPolygons.SelectedIndex = 0;
                }
            };

            RefreshScenes();
            RefreshNodes();
            tsImgMove.PerformClick();
        }