Beispiel #1
0
        private void DrawColorEntryMarker(Graphics graphics, Point point, Size size, Color color, Color borderColor)
        {
            Point[] markerPoints = new Point[5];
            markerPoints[0] = new Point(point.X, point.Y);
            markerPoints[1] = new Point(point.X + size.Width / 2, point.Y + size.Width / 2);
            markerPoints[2] = new Point(point.X + size.Width / 2, point.Y + size.Height - 1);
            markerPoints[3] = new Point(point.X - size.Width / 2, point.Y + size.Height - 1);
            markerPoints[4] = new Point(point.X - size.Width / 2, point.Y + size.Width / 2);

            Brush b = new SolidBrush(borderColor);

            graphics.FillPolygon(b, markerPoints);
            b.Dispose();
            Pen p = new Pen(borderColor);

            graphics.DrawPolygon(p, markerPoints);
            p.Dispose();

            Rectangle rect = new Rectangle(point.X - size.Width / 2 + 1, point.Y + size.Width / 2 + 1, size.Width - 2, size.Height - size.Width / 2 - 2);

            Gradient.FillCheckerboardRectangle(graphics, rect, rect.Width / 3);
            b = new SolidBrush(color);
            graphics.FillRectangle(b, rect);
            b.Dispose();
        }
Beispiel #2
0
        private void DrawGradient()
        {
            Graphics graphics = Graphics.FromImage(gradientPanelBackBuffer);

            graphics.Clear(gradientPanel.BackColor);
            if (CurrentGradient != null)
            {
                Gradient.FillCheckerboardRectangle(graphics, gradientRectangle, 8);
                CurrentGradient.Draw(graphics, gradientRectangle, 0.0, 1.0, Gradient.Direction.Horizontal);

                graphics.DrawRectangle(Pens.Black, new Rectangle(gradientRectangle.Left - 1, gradientRectangle.Top - 1, gradientRectangle.Width + 2, gradientRectangle.Height + 1));

                DrawColorEntryMarkers();
                RefreshGradientList(true);
            }
            graphics.Dispose();
        }
Beispiel #3
0
        protected override void OnDrawItem(DrawItemEventArgs ea)
        {
            if (ea.Index != -1 && Items.Count > 0)
            {
                Gradient item               = (Gradient)Items[ea.Index];
                Bitmap   backBufferBitmap   = new Bitmap(ea.Bounds.Width, ea.Bounds.Height);
                Graphics backBufferGraphics = Graphics.FromImage(backBufferBitmap);


                backBufferGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                Brush b = new SolidBrush(BackColor);
                ea.Graphics.FillRectangle(b, ea.Bounds);
                b.Dispose();
                ea.DrawBackground();

                Rectangle rect = new Rectangle(4, 4, backBufferBitmap.Width - this.NameWidth - 4, backBufferBitmap.Height - 8);
                Gradient.FillCheckerboardRectangle(backBufferGraphics, rect, 3);
                item.Draw(backBufferGraphics, rect, 0, 1, Gradient.Direction.Horizontal);
                backBufferGraphics.DrawRectangle(Pens.Black, new Rectangle(3, 3, backBufferBitmap.Width - this.NameWidth - 3, backBufferBitmap.Height - 7));

                Color textColor;
                if ((ea.State & DrawItemState.Selected).Equals(DrawItemState.Selected))
                {
                    textColor = SystemColors.HighlightText;
                }
                else
                {
                    textColor = this.ForeColor;
                }

                Size  textSize     = TextRenderer.MeasureText(backBufferGraphics, item.Name, this.Font);
                Point textLocation = new Point(backBufferBitmap.Width - this.NameWidth + this.NamePadding, (ea.Bounds.Height - textSize.Height) / 2);
                TextRenderer.DrawText(backBufferGraphics, item.Name, this.Font, textLocation, textColor);

                ea.Graphics.DrawImage(backBufferBitmap, ea.Bounds.Location);

                backBufferBitmap.Dispose();
                backBufferGraphics.Dispose();

                ea.DrawFocusRectangle();

                base.OnDrawItem(ea);
            }
        }
Beispiel #4
0
        private void DrawColorRange(Graphics graphics, Font colorRangeScaleFont, RouteLineSettings routeLineSettings, Brush colorRangeScaleBrush)
        {
            // draw the color range

            // calculate various sizes
            var sf             = new StringFormat();
            var colorRangeSize = new Size(Math.Max(100, Math.Min(300, Image.Width - 300)), 16);
            var colorRangeScaleLabelMaxSize =
                graphics.MeasureString(Properties.ColorRangeProperties.NumericConverter.ToString((double?)Properties.ColorRangeProperties.ScaleCreator.LastMarkerValue),
                                       colorRangeScaleFont);
            var colorRangeScaleUnitSize = graphics.MeasureString(" " + Properties.ColorRangeProperties.ScaleUnit, colorRangeScaleFont);
            var colorRangeRectangle     =
                new Rectangle(
                    new Point(
                        Image.Width - exportImageBorderWidth - 16 - (int)colorRangeScaleUnitSize.Width -
                        (int)colorRangeScaleLabelMaxSize.Width / 2 - colorRangeSize.Width, 20), colorRangeSize);

            // checkerboard background for color range
            Gradient.FillCheckerboardRectangle(graphics, colorRangeRectangle, 8);

            // color range
            routeLineSettings.ColorRange.Gradient.Draw(graphics, colorRangeRectangle, 0, 1, Gradient.Direction.Horizontal,
                                                       routeLineSettings.AlphaAdjustment);

            // color range scale markers and labels
            var lastX = 0;

            for (var value = Properties.ColorRangeProperties.ScaleCreator.FirstMarkerValue;
                 value <= Properties.ColorRangeProperties.ScaleCreator.LastMarkerValue;
                 value += Properties.ColorRangeProperties.ScaleCreator.MarkerInterval)
            {
                var x = colorRangeRectangle.Left +
                        (int)
                        ((value - routeLineSettings.ColorRange.StartValue) /
                         (routeLineSettings.ColorRange.EndValue - routeLineSettings.ColorRange.StartValue) *
                         colorRangeRectangle.Width);
                var p = new Pen(Color.FromArgb(192, Color.Black));
                graphics.DrawLine(p, x, colorRangeRectangle.Top, x, colorRangeRectangle.Bottom);
                p.Dispose();

                // draw label string, but only if the space is sufficient
                if (value == Properties.ColorRangeProperties.ScaleCreator.FirstMarkerValue || x - lastX > colorRangeScaleLabelMaxSize.Width)
                {
                    sf.Alignment     = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Near;
                    graphics.DrawString(Properties.ColorRangeProperties.NumericConverter.ToString((double?)value), colorRangeScaleFont, colorRangeScaleBrush, x,
                                        colorRangeRectangle.Bottom + 2F, sf);
                    lastX = x;
                }
            }

            // color range border
            graphics.DrawRectangle(Pens.Gray,
                                   new Rectangle(colorRangeRectangle.Left - 1, colorRangeRectangle.Top - 1,
                                                 colorRangeRectangle.Width + 2, colorRangeRectangle.Height + 1));

            // color range scale strings
            // caption
            sf.Alignment     = StringAlignment.Far;
            sf.LineAlignment = StringAlignment.Near;
            graphics.DrawString(Properties.ColorRangeProperties.ScaleCaption + " ", colorRangeScaleFont, colorRangeScaleBrush,
                                colorRangeRectangle.Left - colorRangeScaleLabelMaxSize.Width / 2F, colorRangeRectangle.Bottom + 2F, sf);

            // unit
            sf.Alignment     = StringAlignment.Near;
            sf.LineAlignment = StringAlignment.Near;
            graphics.DrawString(" " + Properties.ColorRangeProperties.ScaleUnit, colorRangeScaleFont, colorRangeScaleBrush,
                                colorRangeRectangle.Right + colorRangeScaleLabelMaxSize.Width / 2F, colorRangeRectangle.Bottom + 2F, sf);
        }
        private void Draw()
        {
            if (backBufferGraphics == null || preventRedraw)
            {
                return;
            }

            // use backbuffering
            Graphics g = backBufferGraphics;

            // clear background
            g.Clear(BackColor);

            // gradient
            double intervalLength = (colorRange.EndValue - colorRange.StartValue);
            double startLocation  = 0.0 - (colorRange.StartValue - minValue) / intervalLength;
            double endLocation    = 1.0 + (maxValue - colorRange.EndValue) / intervalLength;

            Gradient.FillCheckerboardRectangle(g, colorRangeRectangle, 8);
            ColorRange.Gradient.Draw(g, colorRangeRectangle, startLocation, endLocation, Gradient.Direction.Horizontal, alphaAdjustment);

            // start value slider
            DrawSlider(new Point(ValueToX(colorRange.StartValue), colorRangeRectangle.Bottom + 1));

            // end value slider
            DrawSlider(new Point(ValueToX(colorRange.EndValue), colorRangeRectangle.Bottom + 1));

            // border
            g.DrawRectangle(Pens.Gray, new Rectangle(colorRangeRectangle.Left - 1, colorRangeRectangle.Top - 1, colorRangeRectangle.Width + 1, colorRangeRectangle.Height + 1));

            // marker lines and labels
            SizeF labelSize;
            int   startY;

            if (NumericConverter == null)
            {
                labelSize = new SizeF(0F, 0F);
                startY    = colorRangeRectangle.Top;
            }
            else
            {
                labelSize = g.MeasureString(NumericConverter.ToString(scaleCreator.LastMarkerValue) + "    ", Font);
                startY    = colorRangeRectangle.Top + (int)labelSize.Height;
            }
            float lastLabelX = (float)colorRangeRectangle.Left - labelSize.Width / 2;

            for (double value = scaleCreator.FirstMarkerValue; value <= scaleCreator.LastMarkerValue; value += scaleCreator.MarkerInterval)
            {
                Pen p = new Pen(Color.FromArgb(192, Color.Black));
                g.DrawLine(
                    p,
                    (int)ValueToX(value),
                    startY,
                    ValueToX(value),
                    (int)colorRangeRectangle.Bottom
                    );
                p.Dispose();
                if (NumericConverter != null)
                {
                    float labelX = (float)ValueToX(value);
                    // only draw label if it is enough space to the last one
                    if (labelX > lastLabelX + labelSize.Width && labelX + labelSize.Width / 2 < (float)colorRangeRectangle.Right)
                    {
                        g.DrawString(
                            "  " + NumericConverter.ToString(value),
                            Font,
                            Brushes.Black,
                            new PointF(labelX - labelSize.Width / 2, (float)colorRangeRectangle.Top)
                            );
                        lastLabelX = labelX;
                    }
                }
            }

            // copy to screen
            sliderPanel.CreateGraphics().DrawImageUnscaled(backBufferBitmap, new Point(0, 0));
        }