Ejemplo n.º 1
0
        private void TimeLineViewPort_Paint(object sender, PaintEventArgs e)
        {
            int width  = AutoScrollMinSize.Width > this.Width ? AutoScrollMinSize.Width : this.Width;
            int height = AutoScrollMinSize.Height > this.Height ? AutoScrollMinSize.Height : this.Height;

            width -= 30;
            Bitmap   buffer = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(buffer);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.Clear(Color.White);

            Brush highlightBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));

            for (int i = 0; i < list.Length; i++)
            {
                g.DrawLine(Pens.AliceBlue, 1, listStartY + i * 50, width - 2, listStartY + i * 50);
                if (i == selectedItem)
                {
                    g.FillRectangle(highlightBrush, new Rectangle(0, listStartY + i * 50, width - 1, 50));
                }
            }

            if (db == null)
            {
                e.Graphics.Clear(Color.AliceBlue);
                e.Graphics.DrawString("No case loaded", new Font("Arial", 8), Brushes.Black, new Point(50, listStartY + 50));
                return;
            }


            for (int c = 0; c < list.Length; c++)
            {
                Bitmap   distributionImage = new Bitmap(750 * 2, 30);
                Graphics dg = Graphics.FromImage(distributionImage);

                dg.Clear(Color.FromArgb(192, 222, 222, 255));

                long[] distribution = db.GetDistribution(300, list[c]);

                long max = 0;
                for (int i = 0; i < 300; i++)
                {
                    if (distribution[i] != 0)
                    {
                        //distribution[i] = 1 + (long)(Math.Log10(distribution[i]));
                        if (distribution[i] > max)
                        {
                            max = distribution[i];
                        }
                    }
                }

                g.DrawString(list[c], new Font("Arial", 8), c == selectedItem ? Brushes.White : Brushes.Black, new Point(10, listStartY + 10 + 50 * c));

                if (max == 0)
                {
                    continue;
                }

                for (int i = 0; i < 300; i++)
                {
                    int value = (int)((decimal)25 * (decimal)distribution[i] / (decimal)max);
                    if (distribution[i] != 0)
                    {
                        value += 5;
                    }

                    dg.FillRectangle(Brushes.Red, new Rectangle(i * 5, 30 - value, 4, value));
                }

                g.DrawImage(distributionImage, 200, listStartY + 10 + 50 * c, width - 200, 30);
            }


            if (markAlignment == MarkAlignment.right)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(64, 255, 128, 128)), new Rectangle(200, listStartY + 0, pointerX - 200, AutoScrollMinSize.Height));
                g.DrawLine(new Pen(Color.FromArgb(64, 255, 0, 0), 3), new Point(200, listStartY + 0), new Point(pointerX, listStartY + AutoScrollMinSize.Height));
                g.DrawLine(new Pen(Color.FromArgb(64, 255, 0, 0), 3), new Point(pointerX, listStartY + 0), new Point(200, listStartY + AutoScrollMinSize.Height));
            }
            if (markAlignment == MarkAlignment.left)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(64, 255, 128, 128)), new Rectangle(pointerX, listStartY + 0, width - pointerX, AutoScrollMinSize.Height));
                g.DrawLine(new Pen(Color.FromArgb(64, 255, 0, 0), 3), new Point(pointerX, listStartY + 0), new Point(width, listStartY + AutoScrollMinSize.Height));
                g.DrawLine(new Pen(Color.FromArgb(64, 255, 0, 0), 3), new Point(width, listStartY + 0), new Point(pointerX, listStartY + AutoScrollMinSize.Height));
            }


            DateTime first = db.FirstTimeStamp();
            DateTime last  = db.LastTimeStamp();
            TimeSpan span  = last.Subtract(first);


            g.DrawLine(new Pen(Color.FromArgb(128, 0, 255, 0), 3), new Point(pointerX, listStartY + 0), new Point(pointerX, listStartY + AutoScrollMinSize.Height));
            long ticks = (long)((decimal)first.Ticks + (decimal)selectionPos * ((decimal)last.Ticks - (decimal)first.Ticks));

            g.DrawString(new DateTime(ticks).ToString(), new Font("Small Fonts", 6), Brushes.Black, new Point((int)pointerX + 4, listStartY + 12));

            if (pointerX != pointerX2)
            {
                g.DrawLine(new Pen(Color.FromArgb(128, 0, 255, 0), 3), new Point(pointerX2, listStartY + 0), new Point(pointerX2, listStartY + AutoScrollMinSize.Height));
                long ticks2 = (long)((decimal)first.Ticks + (decimal)selectionPos2 * ((decimal)last.Ticks - (decimal)first.Ticks));
                g.DrawString(new DateTime(ticks2).ToString(), new Font("Small Fonts", 6), Brushes.Black, new Point((int)pointerX2 + 4, listStartY + 22));

                g.FillRectangle(new SolidBrush(Color.FromArgb(64, 128, 128, 255)), new Rectangle(pointerX, listStartY + 0, pointerX2 - pointerX, AutoScrollMinSize.Height));
            }



            Color fromColor = Color.FromArgb(192, SystemColors.ButtonHighlight);
            Color toColor   = Color.FromArgb(128, SystemColors.ButtonShadow);

            Brush linearGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, width, listStartY), fromColor, toColor, 90f);

            g.FillRectangle(linearGradientBrush, new Rectangle(0, 0, width, listStartY));
            linearGradientBrush.Dispose();



            if ((last.Year - first.Year) < 60)
            {
                DateTime cursor = new DateTime(first.Year, 1, 1);
                g.DrawString("" + first.Year, new Font("Small Fonts", 6), Brushes.Black, new Point(4, 2));
                for (int i = 0; i <= (last.Year - first.Year); i++)
                {
                    int pos = positionFromTime(cursor);
                    if (pos != 0)
                    {
                        g.DrawLine(new Pen(Color.FromArgb(128, 150, 150, 150), 2), new Point(pos, 0), new Point(pos, listStartY + AutoScrollMinSize.Height));
                        g.DrawString("" + cursor.Year, new Font("Small Fonts", 6), Brushes.Black, new Point(pos + 4, 2));
                    }
                    cursor = cursor.AddYears(1);
                }
            }

            if (span.TotalDays / 30 < 60)
            {
                DateTime cursor = new DateTime(first.Year, first.Month, 1);
                g.DrawString("" + first.ToString("MMM"), new Font("Small Fonts", 6), Brushes.Black, new Point(4, 2 + 9));
                for (int i = 0; i <= span.TotalDays / 30 + 1; i++)
                {
                    int pos = positionFromTime(cursor);
                    if (pos != 0)
                    {
                        g.DrawLine(new Pen(Color.FromArgb(128, 150, 150, 150), 2), new Point(pos, 0), new Point(pos, listStartY + AutoScrollMinSize.Height));
                        g.DrawString(cursor.ToString("MMM"), new Font("Small Fonts", 6), Brushes.Black, new Point(pos + 4, 2 + 9));
                    }
                    cursor = cursor.AddMonths(1);
                }
            }

            if (span.TotalDays < 60)
            {
                DateTime cursor = new DateTime(first.Year, first.Month, first.Day);
                g.DrawString("" + first.Day, new Font("Small Fonts", 6), Brushes.Black, new Point(4, 2 + 9 + 9));
                for (int i = 0; i <= span.TotalDays + 1; i++)
                {
                    int pos = positionFromTime(cursor);
                    if (pos != 0)
                    {
                        g.DrawLine(new Pen(Color.FromArgb(128, 150, 150, 150), 2), new Point(pos, 0), new Point(pos, listStartY + AutoScrollMinSize.Height));
                        g.DrawString(cursor.ToString("dd"), new Font("Small Fonts", 6), Brushes.Black, new Point(pos + 4, 2 + 9 + 9));
                    }
                    cursor = cursor.AddDays(1);
                }
            }

            if (span.TotalHours < 60)
            {
                DateTime cursor = new DateTime(first.Year, first.Month, first.Day, first.Hour, 0, 0);
                g.DrawString("" + first.Hour, new Font("Small Fonts", 6), Brushes.Black, new Point(4, 2 + 9 + 9 + 9));
                for (int i = 0; i <= span.TotalHours + 1; i++)
                {
                    int pos = positionFromTime(cursor);
                    if (pos != 0)
                    {
                        g.DrawLine(new Pen(Color.FromArgb(128, 150, 150, 150), 2), new Point(pos, 0), new Point(pos, listStartY + AutoScrollMinSize.Height));
                        g.DrawString(cursor.ToString("HH"), new Font("Small Fonts", 6), Brushes.Black, new Point(pos + 4, 2 + 9 + 9 + 9));
                    }
                    cursor = cursor.AddHours(1);
                }
            }

            if (span.TotalMinutes < 60)
            {
                DateTime cursor = new DateTime(first.Year, first.Month, first.Day, first.Hour, first.Minute, 0);
                g.DrawString("" + first.Minute, new Font("Small Fonts", 6), Brushes.Black, new Point(4, 2 + 9 + 9 + 9 + 9));
                for (int i = 0; i <= span.TotalMinutes + 1; i++)
                {
                    int pos = positionFromTime(cursor);
                    if (pos != 0)
                    {
                        g.DrawLine(new Pen(Color.FromArgb(128, 150, 150, 150), 2), new Point(pos, 0), new Point(pos, listStartY + AutoScrollMinSize.Height));
                        g.DrawString(cursor.ToString("mm"), new Font("Small Fonts", 6), Brushes.Black, new Point(pos + 4, 2 + 9 + 9 + 9 + 9));
                    }
                    cursor = cursor.AddMinutes(1);
                }
            }

            if (selectedEventTimeStamp >= first && selectedEventTimeStamp <= last)
            {
                decimal selectedEventX = ((decimal)selectedEventTimeStamp.Ticks - (decimal)first.Ticks) / ((decimal)last.Ticks - (decimal)first.Ticks) * (decimal)(width - 200) + (decimal)200;
                g.DrawLine(new Pen(Color.FromArgb(128, 0, 0, 255), 2), new Point((int)selectedEventX, 0), new Point((int)selectedEventX, listStartY + AutoScrollMinSize.Height));
            }



            e.Graphics.DrawImage(buffer, AutoScrollPosition);
        }