Beispiel #1
0
        private void LayoutObjects(int w, int h)
        {
            _pnlCameras.HorizontalScroll.Value = 0;
            _pnlCameras.VerticalScroll.Value   = 0;
            _pnlCameras.Refresh();
            int num = _pnlCameras.Controls.Count;

            if (num == 0)
            {
                return;
            }
            // Get data.
            var rectslist = new List <Rectangle>();

            foreach (Control c in _pnlCameras.Controls)
            {
                bool skip = false;
                if (c is CameraWindow || c is VolumeLevel || c is FloorPlanControl)
                {
                    var p = (PictureBox)c;
                    if (w > 0)
                    {
                        p.Width  = w;
                        p.Height = h;
                    }
                    if (w == -1)
                    {
                        if (c is CameraWindow)
                        {
                            var cw = ((CameraWindow)c);
                            if (cw.Camera != null && cw.Camera.LastFrame != null)
                            {
                                p.Width  = cw.Camera.LastFrame.Width + 2;
                                p.Height = cw.Camera.LastFrame.Height + 32;
                            }
                        }
                        else
                        {
                            p.Width  = c.Width;
                            p.Height = c.Height;
                        }
                    }
                    int nh = p.Height;
                    if (c is CameraWindow)
                    {
                        if (((CameraWindow)c).VolumeControl != null)
                        {
                            nh += 40;
                        }
                    }
                    if (c is VolumeLevel)
                    {
                        if (((VolumeLevel)c).Paired)
                        {
                            skip = true;
                        }
                    }
                    if (!skip)
                    {
                        rectslist.Add(new Rectangle(0, 0, p.Width, nh));
                    }
                }
            }
            // Arrange the rectangles.
            Rectangle[] rects    = rectslist.ToArray();
            int         binWidth = _pnlCameras.Width;
            var         proc     = new C2BPProcessor();

            proc.SubAlgFillOneColumn(binWidth, rects);
            rectslist = rects.ToList();
            bool assigned        = true;
            var  indexesassigned = new List <int>();

            while (assigned)
            {
                assigned = false;
                foreach (Rectangle r in rectslist)
                {
                    for (int i = 0; i < _pnlCameras.Controls.Count; i++)
                    {
                        Control c = _pnlCameras.Controls[i];
                        if (c is CameraWindow || c is VolumeLevel || c is FloorPlanControl)
                        {
                            bool skip    = false;
                            int  hoffset = 0;
                            if (!indexesassigned.Contains(i))
                            {
                                if (c is CameraWindow)
                                {
                                    var cw = ((CameraWindow)c);
                                    if (cw.VolumeControl != null)
                                    {
                                        hoffset = 40;
                                    }
                                }
                                if (c is VolumeLevel)
                                {
                                    if (((VolumeLevel)c).Paired)
                                    {
                                        skip = true;
                                    }
                                }
                                if (!skip && c.Width == r.Width && c.Height + hoffset == r.Height)
                                {
                                    PositionPanel((PictureBox)c, new Point(r.X, r.Y), r.Width, r.Height - hoffset);
                                    rectslist.Remove(r);
                                    assigned = true;
                                    indexesassigned.Add(i);
                                    break;
                                }
                            }
                        }
                    }
                    if (assigned)
                    {
                        break;
                    }
                }
            }
            NeedsRedraw = true;
        }
Beispiel #2
0
        public void LayoutObjects(int w, int h)
        {
            _pnlCameras.HorizontalScroll.Value = 0;
            _pnlCameras.VerticalScroll.Value = 0;
            _pnlCameras.Refresh();
            int num = _pnlCameras.Controls.Count;
            if (num == 0)
                return;
            // Get data.
            var rectslist = new List<Rectangle>();

            foreach (Control c in _pnlCameras.Controls)
            {
                bool skip = false;
                if (c is CameraWindow || c is VolumeLevel || c is FloorPlanControl)
                {
                    var p = (PictureBox)c;
                    if (w > 0)
                    {
                        p.Width = w;
                        p.Height = h;
                    }
                    if (w == -1)
                    {
                        if (c is CameraWindow)
                        {
                            var cw = ((CameraWindow)c);
                            if (cw.Camera != null && !cw.LastFrameNull)
                            {
                                p.Width = cw.LastFrame.Width + 2;
                                p.Height = cw.LastFrame.Height + 32;
                            }
                        }
                        else
                        {
                            p.Width = c.Width;
                            p.Height = c.Height;
                        }
                    }
                    int nh = p.Height;
                    if (c is CameraWindow)
                    {
                        if (((CameraWindow)c).VolumeControl != null)
                            nh += 40;
                    }
                    if (c is VolumeLevel)
                    {
                        if (((VolumeLevel)c).Paired)
                            skip = true;
                    }
                    if (!skip)
                    {
                        rectslist.Add(new Rectangle(0, 0, p.Width, nh));
                    }
                }
            }
            // Arrange the rectangles.
            Rectangle[] rects = rectslist.ToArray();
            int binWidth = _pnlCameras.Width;
            var proc = new C2BPProcessor();
            proc.SubAlgFillOneColumn(binWidth, rects);
            rectslist = rects.ToList();
            bool assigned = true;
            var indexesassigned = new List<int>();
            while (assigned)
            {
                assigned = false;
                foreach (Rectangle r in rectslist)
                {
                    for (int i = 0; i < _pnlCameras.Controls.Count; i++)
                    {
                        Control c = _pnlCameras.Controls[i];
                        if (c is CameraWindow || c is VolumeLevel || c is FloorPlanControl)
                        {
                            bool skip = false;
                            int hoffset = 0;
                            if (!indexesassigned.Contains(i))
                            {
                                if (c is CameraWindow)
                                {
                                    var cw = ((CameraWindow)c);
                                    if (cw.VolumeControl != null)
                                        hoffset = 40;
                                }
                                if (c is VolumeLevel)
                                {
                                    if (((VolumeLevel)c).Paired)
                                        skip = true;
                                }
                                if (!skip && c.Width == r.Width && c.Height + hoffset == r.Height)
                                {
                                    PositionPanel((PictureBox)c, new Point(r.X, r.Y), r.Width, r.Height - hoffset);
                                    rectslist.Remove(r);
                                    assigned = true;
                                    indexesassigned.Add(i);
                                    break;
                                }
                            }
                        }
                    }
                    if (assigned)
                        break;
                }
            }
            NeedsRedraw = true;
        }