Esempio n. 1
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)) continue;
                var p = (PictureBox)c;
                if (w > 0)
                {
                    p.Width = w;
                    p.Height = h;
                }
                if (w == -1)
                {
                    var window = c as CameraWindow;
                    if (window != null)
                    {
                        var cw = window;

                        if (cw.Camera != null)
                        {
                            var bmp = cw.LastFrame;
                            if (bmp != null)
                            {
                                p.Width = bmp.Width + 2;
                                p.Height = bmp.Height + 32;
                            }
                        }
                    }
                    else
                    {
                        p.Width = c.Width;
                        p.Height = c.Height;
                    }
                }
                int nh = p.Height;
                var cameraWindow = c as CameraWindow;
                if (cameraWindow?.VolumeControl != null)
                    nh += 40;
                var level = c as VolumeLevel;
                if (level != null)
                {
                    if (level.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))
                            {
                                var window = c as CameraWindow;
                                var cw = window;
                                if (cw?.VolumeControl != null)
                                    hoffset = 40;
                                var level = c as VolumeLevel;
                                if (level != null)
                                {
                                    if (level.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;
        }
Esempio n. 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))
                {
                    continue;
                }
                var p = (PictureBox)c;
                if (w > 0)
                {
                    p.Width  = w;
                    p.Height = h;
                }
                if (w == -1)
                {
                    var window = c as CameraWindow;
                    if (window != null)
                    {
                        var cw = window;

                        if (cw.Camera != null)
                        {
                            var bmp = cw.LastFrame;
                            if (bmp != null)
                            {
                                p.Width  = bmp.Width + 2;
                                p.Height = bmp.Height + 32;
                            }
                        }
                    }
                    else
                    {
                        p.Width  = c.Width;
                        p.Height = c.Height;
                    }
                }
                int nh           = p.Height;
                var cameraWindow = c as CameraWindow;
                if (cameraWindow?.VolumeControl != null)
                {
                    nh += 40;
                }
                var level = c as VolumeLevel;
                if (level != null)
                {
                    if (level.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))
                            {
                                var window = c as CameraWindow;
                                var cw     = window;
                                if (cw?.VolumeControl != null)
                                {
                                    hoffset = 40;
                                }
                                var level = c as VolumeLevel;
                                if (level != null)
                                {
                                    if (level.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;
        }