示例#1
0
        public void Serialization()
        {
            var scheme = new ColorScheme();

            scheme.AssignFreeColor("me");
            scheme.AssignFreeColor("you");

            var serializer = new DataContractJsonSerializer(typeof(ColorScheme));

            // Serialize
            var stream = new MemoryStream();

            serializer.WriteObject(stream, scheme);
            var bytes = stream.ToArray();
            var json  = Encoding.UTF8.GetString(bytes);

            // Deserialize
            stream.Close();
            stream = new MemoryStream(bytes);
            var deserialized = (ColorScheme)serializer.ReadObject(stream);

            // Colors are the same
            Assert.AreEqual(scheme.GetBrush("me").ToString(), deserialized.GetBrush("me").ToString());
            Assert.AreEqual(scheme.GetBrush("you").ToString(), deserialized.GetBrush("you").ToString());
        }
示例#2
0
        public void AddingTooMuchColors()
        {
            var scheme = new ColorScheme();

            // Add names until no more colors are available
            while (scheme.AssignFreeColor(Guid.NewGuid().ToString()))
            {
            }

            Assert.IsFalse(scheme.AssignFreeColor("me"));

            // Even if we do not have a color, the name is added.
            // The coloring can be edited later.
            Assert.IsTrue(scheme.Names.Contains("me"));

            // me has the default color
            var name         = scheme.GetBrush("me").Color.ToString();
            var defaultColor = DefaultDrawingPrimitives.DefaultColor.ToString();

            Assert.AreEqual(defaultColor, name);
        }
示例#3
0
        /**
         * Fills the control with a gradient background.
         */

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);

            if (!_verticalViewMode)
            {
                pevent.Graphics.FillRectangle(
                    ColorScheme.GetBrush(_colorScheme, "LinksBar.Background", ClientRectangle, SystemBrushes.Control),
                    ClientRectangle);
            }
            else
            {
                Rectangle rc = ClientRectangle;
                pevent.Graphics.FillRectangle(
                    ColorScheme.GetBrush(_colorScheme, "LinksBar.VerticalBackground", rc, SystemBrushes.Control),
                    rc);
            }
            using (Pen dividerPen = new Pen(Color.FromArgb(184, 181, 200)))
            {
                pevent.Graphics.DrawLine(dividerPen, 0, Height - 1, Width - 1, Height - 1);
            }
        }
示例#4
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);
            Rectangle rcFill;

            if (_fillHeight > 0)
            {
                rcFill = new Rectangle(0, 0, ClientRectangle.Width, 150);
            }
            else
            {
                rcFill = ClientRectangle;
            }
            Brush backBrush = ColorScheme.GetBrush(_colorScheme, _colorSchemeKey,
                                                   rcFill, SystemBrushes.Control);

            pevent.Graphics.FillRectangle(backBrush, rcFill);

            if (PaintSidebarBackground != null)
            {
                PaintSidebarBackground(this, pevent);
            }
        }
示例#5
0
        public void Create(string filename, Dictionary <string, uint> workByDevelopers,
                           ColorScheme colorMapperMapping, bool legend)
        {
            double allWork = workByDevelopers.Values.Sum(w => w);

            // For the fractal
            var width  = 200;
            var height = 200;

            var remainingWidth  = width;
            var remainingHeight = height;

            // Reserve plenty of space. Trimmed later.
            var bitmap   = new System.Drawing.Bitmap(2000, 2000);
            var graphics = Graphics.FromImage(bitmap);

            var sorted = workByDevelopers.ToList().OrderByDescending(pair => pair.Value).ToList();

            var oneUnitOfWork = width * height / allWork;
            var x             = 0;
            var y             = 0;

            var vertical = true;

            var index = 0;

            foreach (var developersWork in sorted)
            {
                var brush = colorMapperMapping.GetBrush(developersWork.Key);

                if (legend)
                {
                    var legendY = index * 30;
                    var legendX = 250;
                    graphics.DrawString(developersWork.Key, new Font(FontFamily.GenericSansSerif, 12), Brushes.Black,
                                        legendX + 25, legendY);
                    graphics.FillRectangle(brush, legendX, legendY, 20, 20);
                }

                var workArea = developersWork.Value;

                var pixelArea = oneUnitOfWork * workArea;
                if (index == sorted.Count - 1)
                {
                    // Due to rounding there is always some pixels left. Give the last
                    // developer the remaining space.
                    pixelArea = remainingWidth * remainingHeight;
                }

                if (vertical)
                {
                    var widthOfWork = (int)Math.Round(pixelArea / remainingHeight);
                    graphics.FillRectangle(brush, x, y, widthOfWork, remainingHeight);

                    graphics.DrawRectangle(Pens.Black, x, y, widthOfWork, remainingHeight);

                    x += widthOfWork;
                    remainingWidth -= widthOfWork;
                }
                else
                {
                    var heightOfWork = (int)Math.Round(pixelArea / remainingWidth);
                    graphics.FillRectangle(brush, x, y, remainingWidth, heightOfWork);

                    graphics.DrawRectangle(Pens.Black, x, y, remainingWidth, heightOfWork);

                    y += heightOfWork;
                    remainingHeight -= heightOfWork;
                }

                // Toggle next orientation
                vertical = !vertical;

                index++;
            }

            graphics.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1);

            BitmapManipulation.TrimBitmap(bitmap).Save(filename);
        }