Пример #1
0
        private List<Label> CollectColumnLabels2(Panel panel, ViewContext vc, int col)
        {
            List<Label> labels = new List<Label>();
            foreach (Control c in panel.Controls)
            {
                Label l = c as Label;
                if (l == null)
                    continue;
                Lesson lsn = l.Tag as Lesson;
                if (lsn == null)
                    continue;

                if (l.Location.X >= vc.minX + (col + 1) * vc.cellWidth ||
                    l.Location.X + l.Width < vc.minX + col * vc.cellWidth)
                    continue;
                labels.Add(l);
            }
            return labels;
        }
Пример #2
0
        private void ExpandRight(Panel panel, ViewContext vc)
        {
            for (int col = vc.cols - 1; col >= 0; col--)
            {
                List<Label> labels = CollectColumnLabels2(panel, vc, col);
                if (labels.Count == 0)
                    continue;

                int[] rightmost = new int[panel.Height];
                foreach (Label l in labels)
                {
                    int rb = l.Location.X + l.Width;
                    for (int y = l.Location.Y; y <= l.Location.Y + l.Height; y++)
                    {
                        if (y < 0 || y >= panel.Height)
                            continue;

                        if (rb > rightmost[y])
                            rightmost[y] = rb;
                    }
                }
                foreach (Label l in labels)
                {
                    int rb = l.Location.X + l.Width;
                    bool hit = false;
                    for (int y = l.Location.Y; y <= l.Location.Y + l.Height; y++)
                    {
                        if (y < 0 || y >= panel.Height)
                            continue;

                        if (rb != rightmost[y])
                        {
                            hit = true;
                            break;
                        }
                    }
                    if (!hit)
                        l.Width = (vc.minX + (col + 1) * vc.cellWidth - l.Location.X);
                }
            }
        }
Пример #3
0
        private List<Label> CollectColumnLabels(Panel panel, ViewContext vc, int col)
        {
            List<Label> labels = new List<Label>();
            foreach (Control c in panel.Controls)
            {
                Label l = GetLabel(c, ref vc);
                if (l == null)
                    continue;
                if (vc.x1 / vc.elements > col || vc.x2 / vc.elements < col)
                    continue;
                if (vc.movedAlready.Contains(l))
                    continue;
                labels.Add(l);
            }

            labels.Sort((l1, l2) => l1.Height.CompareTo(l2.Height));
            return labels;
        }
Пример #4
0
        private void PackRectangles(Panel panel, ViewContext vc)
        {
            vc.elemcols = (vc.cols + 1) * vc.elements + 1;
            vc.elemrows = vc.rows;

            for (int col = vc.cols - 1; col >= 0; col--)
            {
                List<Label> labels = CollectColumnLabels(panel, vc, col);
                if (labels.Count == 0)
                    continue;

                int estChannels = EstimateChannels(labels, vc, col);
                if (estChannels == 0)
                    continue;

                for (int channels = estChannels; channels <= vc.elements; channels++)
                {
                    int channelWidth = vc.cellWidth / channels - 1;
                    Packer packer = new Packer(vc.elemrows, vc.elements);

                    bool failed = false;
                    foreach (Label l in labels)
                    {
                        GetLabel(l, ref vc);
                        int c = packer.Place(vc.y1, vc.y2);
                        if (c < 0)
                        {
                            failed = true;
                            break;
                        }

                        l.Width = channelWidth;
                        l.Location = new Point(
                            vc.minX + vc.cellWidth * col + c * channelWidth,
                            l.Location.Y);
                    }
                    if (!failed)
                        break;
                }

                foreach (Label l in labels)
                    vc.movedAlready.Add(l);
            }
        }
Пример #5
0
        private Label GetLabel(Control c, ref ViewContext vc)
        {
            Label l = c as Label;
            if (l == null)
                return null;
            if (l.Location.Y < vc.minY || l.Location.X < vc.minX)
                return null;
            Lesson lsn = l.Tag as Lesson;
            if (lsn == null)
                return null;

            //vc.y1 = IndexOnStringArray(m_enumTimeSlot, lsn.Start);
            //vc.y2 = IndexOnStringArray(m_enumTimeSlot, lsn.End);

            int roomIndex = RoomIndex(lsn.Room);
            vc.x1 = (l.Location.X - vc.minX - roomIndex * vc.cellRoomWidth)           / vc.cellRoomWidth;
            vc.x2 = (l.Location.X - vc.minX - roomIndex * vc.cellRoomWidth + l.Width) / vc.cellRoomWidth - 1;
            vc.x2max = (l.Location.X - vc.minX - (roomList.Count - 1) * vc.cellRoomWidth + l.Width) / vc.cellRoomWidth - 1;
            vc.y1 = (l.Location.Y - vc.minY - vc.labelHeight / 2)            / vc.cellHight;
            vc.y2 = (l.Location.Y - vc.minY - vc.labelHeight / 2 + l.Height) / vc.cellHight - 1;

            if (vc.x1 < 0 || vc.x2 < 0 || vc.x1 > vc.elemcols || vc.x2 > vc.elemcols ||
                vc.y1 < 0 || vc.y2 < 0 || vc.y1 > vc.elemrows || vc.y2 > vc.elemrows)
                return null;

            return l;
        }
Пример #6
0
        private int EstimateChannels(List<Label> labels, ViewContext vc, int col)
        {
            int[] perRow = new int[m_enumTimeSlot.Count() + 1];

            foreach (Label l in labels)
            {
                GetLabel(l, ref vc);
                for (int y = vc.y1; y <= vc.y2; y++)
                    perRow[y]++;
            }

            return perRow.Max() + 1;
        }
Пример #7
0
 private void DrawTimeSlotsAsLeftColumn(Panel panel, ViewContext vc)
 {
     int prev = -1000;
     for (int j = 0; j < m_enumTimeSlot.Length; j++)
     {
         int y = vc.minY + vc.cellHight * j + 5;
         if (y - prev < 100)
             continue;
         prev = y;
         Label l = new Label()
         {
             Text = m_enumTimeSlot[j],
             Width = 50,
             Height = vc.labelHeight,
             Location = new Point(5, y),
             Parent = panel,
             TextAlign = ContentAlignment.MiddleLeft
         };
     }
 }
Пример #8
0
 private void DrawRoomsAsTopRow(Panel panel, ViewContext vc)
 {
     int i = 0;
     foreach (Room r in roomList)
     {
         Label l = new Label()
         {
             Text = r.Name,
             Width = vc.cellRoomWidth,
             Height = vc.labelHeight,
             Location = new Point(
                 vc.minX + vc.cellRoomWidth * i + 5,
                 5),
             Parent = panel,
             TextAlign = ContentAlignment.MiddleCenter,
             BackColor = r.RoomColor,
             ForeColor = ComplementColor(r.RoomColor)
         };
         i++;
     }
 }
Пример #9
0
 private void DrawMonthDaysAsTopRow(DateTime dt, Panel panel, ViewContext vc)
 {
     int i = 0;
     foreach (string d in MonthOf(dt))
     {
         Label l = new Label()
         {
             Text = d,
             ForeColor = Color.Black,
             BackColor = Color.White,
             Width = vc.cellWidth,
             Height = vc.labelHeight,
             Location = new Point(
                 vc.minX + vc.cellWidth * i + 5,
                 5),
             Parent = panel,
             TextAlign = ContentAlignment.TopLeft
         };
         i++;
     }
 }
Пример #10
0
        public void ViewShowDay()
        {
            if (roomList.Count == 0)
                return;
            DisposeChildren(panelViewDay);

            int fullWidth = panelViewDay.Width -
                    butViewNext.Width - butViewPrev.Width - 10;
            int fullheight = panelViewDay.Height -
                    butViewZoomIn.Height - butViewZoomOut.Height - 10;

            m_viewMinDate = new DateTime(m_chosenDate.Year, m_chosenDate.Month, m_chosenDate.Day, 0, 0, 0);
            m_viewMaxDate = new DateTime(m_chosenDate.Year, m_chosenDate.Month, m_chosenDate.Day, 23, 59, 59);

            ViewContext vc = new ViewContext(
                fullWidth,
                (fullheight - 20) / m_enumTimeSlot.Length,
                (fullWidth - 60) / roomList.Count,
                roomList.Count,
                m_enumTimeSlot.Length,
                roomList.Count,
                60, 40, 20);

            DrawRoomsAsTopRow(panelViewDay, vc);
            DrawTimeSlotsAsLeftColumn(panelViewDay, vc);
            foreach (Lesson l in FindLessonsForView())
            {
                int x, ys, ye;
                Color roomColor;
                GetLocationInRooms(l, out x, out ys, out ye, out roomColor);

                Label lb = new Label()
                {
                    Text = l.Description,
                    Width = vc.cellRoomWidth - 10,
                    Height = vc.cellHight * (ye - ys + 1) - lessonLabelVertMargin,
                    Location = new Point(
                        vc.minX + vc.cellRoomWidth * x + 5,
                        vc.minY + vc.cellHight * ys + lessonLabelVertMargin / 2),
                    Parent = panelViewDay,
                    BackColor = LessonStateBackColor(l.State),
                    ForeColor = LessonStateForeColor(l.State),
                    BorderStyle = BorderStyle.FixedSingle,
                    Tag = l
                };

                MarkCollisions(lb, panelViewDay);

                lb.ContextMenuStrip = ctxMenuLesson;
                lb.MouseHover += new System.EventHandler(this.butViewShowLesson_MouseHover);
                lb.MouseDown += new System.Windows.Forms.MouseEventHandler(this.butViewShowLesson_MouseDown);
                lb.DoubleClick += new System.EventHandler(this.butViewShowLesson_DoubleClick);
            }
            panelViewDay.Refresh();
        }
Пример #11
0
        public void ViewShowWeek()
        {
            DisposeChildren(panelViewWeek);
            int fullWidth = panelViewWeek.Width -
                butViewNext.Width - butViewPrev.Width - 10;
            int fullheight = panelViewWeek.Height -
                butViewZoomIn.Height - butViewZoomOut.Height - 10;

            m_viewMinDate = WeekStart(m_chosenDate);
            m_viewMaxDate = WeekEnd(m_chosenDate);

            ViewContext vc = new ViewContext(
                fullWidth / m_enumWeekdayNames.Length,
                fullheight / m_enumTimeSlot.Length,
                fullWidth / m_enumWeekdayNames.Length / roomList.Count,
                roomList.Count,
                m_enumTimeSlot.Length,
                7,
                60, 40, 20);

            DrawWeekDaysAsTopRow(m_chosenDate, panelViewWeek, vc);
            DrawTimeSlotsAsLeftColumn(panelViewWeek, vc);
            foreach (Lesson l in FindLessonsForView())
            {
                int x, ys, ye;
                l.GetLocationInWeek(out x, out ys, out ye);

                Label lb = new Label()
                {
                    Text = l.ShortDescription,
                    Width = vc.cellRoomWidth,
                    Height = vc.cellHight * (ye - ys + 1) - lessonLabelVertMargin,
                    Location = new Point(
                        vc.minX + vc.cellWidth * x + vc.cellRoomWidth * RoomIndex(l.Room),
                        vc.minY + vc.cellHight * ys + lessonLabelVertMargin / 2),
                    Parent = panelViewWeek,
                    BackColor = LessonStateBackColor(l.State),
                    ForeColor = LessonStateForeColor(l.State),
                    BorderStyle = BorderStyle.FixedSingle,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Tag = l
                };
                lb.ContextMenuStrip = ctxMenuLesson;
                lb.MouseHover += new System.EventHandler(this.butViewShowLesson_MouseHover);
                lb.MouseDown += new System.Windows.Forms.MouseEventHandler(this.butViewShowLesson_MouseDown);
                lb.DoubleClick += new System.EventHandler(this.butViewShowLesson_DoubleClick);
            }

            PackRectangles(panelViewWeek, vc);
            ExpandRight(panelViewWeek, vc);
            MarkAllCollisions(panelViewWeek);
        }