Beispiel #1
0
        /// <summary>
        /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object
        /// </summary>
        /// <param name="g">The graphics object to draw to</param>
        /// <param name="printing">Boolean, true if printing to an actual print document</param>
        public override void Draw(Graphics g, bool printing)
        {
            if (_layoutMap == null || _layoutMap.Scale == 0)
            {
                return;
            }

            //Sets up the pens and brushes
            Brush scaleBrush = new SolidBrush(_color);
            Pen   scalePen   = new Pen(scaleBrush);

            //Calculates the width of one break in greographic units
            float unitLegnth    = g.MeasureString(_unitText, _font).Width * 2;
            float widthNoUnit   = (Size.Width - unitLegnth);
            Int64 geoBreakWidth = Convert.ToInt64((widthNoUnit / 100 * _layoutMap.Scale) / GetConversionFactor(_unit.ToString()) / (_numBreaks));

            //If the geobreakWidth is less than 1 we return and don't draw anything
            if (geoBreakWidth < 1)
            {
                return;
            }

            //Save the old transform
            Matrix oldTransform = g.Transform;

            g.TranslateTransform(Location.X, Location.Y);
            TextRenderingHint oldHint = g.TextRenderingHint;

            g.TextRenderingHint = _textHint;

            double n = Math.Pow(10, geoBreakWidth.ToString(CultureInfo.InvariantCulture).Length - 1);

            geoBreakWidth = Convert.ToInt64(Math.Floor(geoBreakWidth / n) * n);
            Int64 breakWidth = Convert.ToInt64((1D * geoBreakWidth / _layoutMap.Scale) * GetConversionFactor(_unit.ToString()) * 100D);
            float fontHeight = g.MeasureString(geoBreakWidth.ToString(CultureInfo.InvariantCulture), _font).Height;
            float leftStart  = g.MeasureString(Math.Abs(geoBreakWidth).ToString(CultureInfo.InvariantCulture), _font).Width / 2F;

            //Decides if a break should be drawn before the zero
            int startBreak = 0;

            if (_breakBeforeZero)
            {
                startBreak = -1;
            }

            g.DrawLine(scalePen, leftStart, fontHeight * 1.6f, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f);

            g.DrawString("1 : " + string.Format("{0:0, }", Map.Scale), _font, scaleBrush, leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * startBreak).ToString(), _font).Width / 2), fontHeight * 2.5F);

            for (int i = startBreak; i <= _numBreaks + startBreak; i++)
            {
                g.DrawLine(scalePen, leftStart, fontHeight * 1.1f, leftStart, fontHeight + (fontHeight * 1.1f));
                g.DrawString(Math.Abs(geoBreakWidth * i).ToString(CultureInfo.InvariantCulture), _font, scaleBrush, leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * i).ToString(), _font).Width / 2), 0);
                leftStart = leftStart + breakWidth;
            }
            g.DrawString(_unitText, _font, scaleBrush, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f);

            //Restore the old transform
            g.Transform         = oldTransform;
            g.TextRenderingHint = oldHint;
        }
Beispiel #2
0
        /// <summary>
        /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object
        /// </summary>
        /// <param name="g">The graphics object to draw to</param>
        /// <param name="printing">Boolean, true if printing to an actual print document</param>
        public override void Draw(Graphics g, bool printing)
        {
            GraphicsPath GP     = new GraphicsPath();
            StringFormat format = new StringFormat();

            format.LineAlignment = StringAlignment.Near;
            format.Alignment     = StringAlignment.Near;

            if (_layoutMap == null || _layoutMap.Scale == 0)
            {
                return;
            }

            // Sets up the pens and brushes
            Brush scaleBrush = new SolidBrush(_color);
            Pen   scalePen   = new Pen(scaleBrush);

            // Calculates the width of one break in greographic units
            float unitLegnth    = g.MeasureString(_unitText, _font).Width * 2;
            float widthNoUnit   = Size.Width - unitLegnth;
            long  geoBreakWidth = Convert.ToInt64((widthNoUnit / 100 * _layoutMap.Scale) / GetConversionFactor(_unit.ToString()) / _numBreaks);

            // If the geobreakWidth is less than 1 we return and don't draw anything
            if (geoBreakWidth < 1)
            {
                return;
            }

            // Save the old transform
            Matrix oldTransform = g.Transform;

            g.TranslateTransform(Location.X, Location.Y);
            TextRenderingHint oldHint = g.TextRenderingHint;

            g.TextRenderingHint = _textHint;

            double n = Math.Pow(10, geoBreakWidth.ToString(CultureInfo.InvariantCulture).Length - 1);

            geoBreakWidth = Convert.ToInt64(Math.Floor(geoBreakWidth / n) * n);
            long  breakWidth = Convert.ToInt64((1D * geoBreakWidth / _layoutMap.Scale) * GetConversionFactor(_unit.ToString()) * 100D);
            float fontHeight = g.MeasureString(geoBreakWidth.ToString(CultureInfo.InvariantCulture), _font).Height;
            float leftStart  = g.MeasureString(Math.Abs(geoBreakWidth).ToString(CultureInfo.InvariantCulture), _font).Width / 2F;

            // Decides if a break should be drawn before the zero
            int startBreak = 0;

            if (_breakBeforeZero)
            {
                startBreak = -1;
            }

            // CGX
            g.SetClip(Rectangle, CombineMode.Union);
            // fin CGX

            g.DrawLine(scalePen, leftStart, fontHeight * 1.6f, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f);

            //g.DrawString("1 : " + String.Format("{0:0, }", Map.Scale), _font, scaleBrush, leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * startBreak).ToString(), _font).Width / 2), fontHeight * 2.5F);
            //CGX
            PointF pointScale = new PointF(leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * startBreak).ToString(), _font).Width / 2), fontHeight * 2.5F);

            GP.AddString("1 : " + String.Format("{0:0 }", Map.Scale), _font.FontFamily, (int)_font.Style, _font.SizeInPoints * 96F / 72F, pointScale, format);

            for (int i = startBreak; i <= _numBreaks + startBreak; i++)
            {
                PointF pUp   = new PointF(leftStart, fontHeight + (fontHeight * 1.1f));
                PointF pDown = new PointF(leftStart, fontHeight * 1.1f);

                g.DrawLine(scalePen, leftStart, fontHeight * 1.1f, leftStart, fontHeight + (fontHeight * 1.1f));
                GP.AddString(Math.Abs(geoBreakWidth * i).ToString(CultureInfo.InvariantCulture), _font.FontFamily, (int)_font.Style, _font.SizeInPoints * 96F / 72F, new PointF(leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * i).ToString(), _font).Width / 2), 0), format);
                leftStart = leftStart + breakWidth;
            }
            GP.AddString(_unitText, _font.FontFamily, (int)_font.Style, _font.SizeInPoints * 96F / 72F, new PointF(leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f), format);

            g.FillPath(new SolidBrush(_color), GP);
            GP.Dispose();

            //Restore the old transform
            g.Transform         = oldTransform;
            g.TextRenderingHint = oldHint;
        }