public override void PaintBackground(IGUIContext ctx, Widget widget)
        {
            base.PaintBackground(ctx, widget);

            if (widget.Selected)
            {
                RectangleF bounds = widget.Bounds;
                //bounds.Inflate (-1, 0);
                bounds.Offset(0, bounds.Height - HighlightWidth - 1);
                bounds.Height = HighlightWidth;
                ctx.FillRectangle(HighlightBrush, bounds);
            }
            else
            {
                //Pen leftBorderPen = Theme.Pens.Base01;
                //Pen rightBorderPen = Theme.Pens.Base02;

                RectangleF b = widget.Bounds;
                float      f = widget.ScaleFactor;

                float left = b.Left + f;
                using (Pen leftBorderPen = new Pen(Theme.Colors.Base01, f)) {
                    ctx.DrawLine(leftBorderPen, left, b.Top + Border, left, b.Bottom - Border);
                }
                float right = b.Right;
                using (Pen rightBorderPen = new Pen(Theme.Colors.Base02, f)) {
                    ctx.DrawLine(rightBorderPen, right, b.Top + Border, right, b.Bottom - Border);
                }
            }
        }
예제 #2
0
        //public void DrawGraphics(IKsOpenGLContext ctx, Rectangle bounds, bool TransformLocation)
        public void DrawGraphics(IGUIContext ctx, Rectangle bounds)
        {
            try
            {
                DrawAxis(ctx, bounds);

                if (Graphs != null)
                {
                    foreach (GraphBase graph in Graphs.Values)
                    {
                        if (graph.Visible)
                        {
                            //DrawGraph(ctx, graph, bounds);
                            ;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            if (ShowCross && bMouseHover && m_PointCatched != null)
            {
                try
                {
                    double X = m_PointCatched.X.SafeDouble();
                    double Y = m_PointCatched.Y.SafeDouble();

                    // ToDo: There is a 1 pixel offset that shouldn't be there
                    int xValue = (int)(bounds.X + Point2ClientX(X, bounds) + 1.5);
                    int yValue = (int)(bounds.Y + Point2ClientY(Y, bounds) + 1.5);

                    ctx.DrawLine(Theme.Pens.Blue, xValue, 0, xValue, bounds.Bottom);
                    ctx.DrawLine(Theme.Pens.Blue, 0, yValue, bounds.Right, yValue);
                }
                catch (Exception)
                {
                }
            }

            try
            {
                DrawNodes(ctx, bounds);
            }
            catch (Exception)
            {
            }
        }
        public override void DrawBorder(IGUIContext ctx, Widget widget)
        {
            if (BorderColorPen.Width > 0 && BorderColorPen.Color != Color.Empty)
            {
                RectangleF rBorder = widget.Bounds;
                if (Math.Abs(BorderDistance) > float.Epsilon)
                {
                    rBorder.Inflate(BorderDistance, BorderDistance);
                }

                float top = rBorder.Top.Ceil() + 0.5f;
                ctx.DrawLine(Theme.Pens.Base01, rBorder.Left, top, rBorder.Right, top);
                float bottom = rBorder.Bottom.Ceil() - 0.5f;
                ctx.DrawLine(BorderColorPen, rBorder.Left, bottom, rBorder.Right, bottom);
            }
        }
예제 #4
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            //base.OnPaint (ctx, bounds);

            if (Icon != 0 && IconFont != null)
            {
                float h = bounds.Height;
                float w = bounds.Right - h;
                if (Dock == Docking.Fill && Text == null)
                {
                    ctx.DrawLine(Style.BorderColorPen, w, bounds.Top, w, bounds.Bottom - 0.5f);
                }

                RectangleF rt = new RectangleF(w, bounds.Top + TextOffsetY, h, h);

                if (IconColor != Color.Empty && Enabled)
                {
                    using (Brush brush = new SolidBrush(IconColor)) {
                        ctx.DrawString(Icon.ToString(), IconFont, brush, rt, FontFormat.DefaultIconFontFormatCenter);
                    }
                }
                else
                {
                    ctx.DrawString(Icon.ToString(), IconFont, Style.ForeColorBrush, rt, FontFormat.DefaultIconFontFormatCenter);
                }
            }
        }
        public override void DrawHourLabel(IGUIContext gfx, RectangleF rect, int hour)
        {
            lock (m_SyncObj)
            {
                using (var pen = new Pen(Theme.HourLabelColor, 1.5f))
                    using (var brush = new SolidBrush(Theme.HourLabelColor))
                    {
                        rect.X     += 2;
                        rect.Width -= 2;

                        RectangleF HourRectangle = rect;
                        //HourRectangle.Offset(0, 1);
                        HourRectangle.Width = rect.Width;
                        gfx.DrawString(hour.ToString("##00"), HourFont, brush, HourRectangle, m_HourLabelFormat);

                        float delta = (rect.Width * 2f / 3f) - 4;
                        rect.X     += delta;
                        rect.Width -= delta;
                        rect.Height = rect.Height / 2f;
                        //rect.Y += 1;

                        gfx.DrawString("00", MinuteFont, brush, rect, m_HourLabelFormat);
                        gfx.DrawLine(pen, rect.Left + 2, rect.Bottom - 1, rect.Right - 7, rect.Bottom - 1);

                        rect.Y += rect.Height - 1;
                        gfx.DrawString("30", MinuteFont, brush, rect, m_HourLabelFormat);
                    }
            }
        }
 public override void DrawBorder(IGUIContext ctx, Widget widget)
 {
     if (widget.CanPaint && BorderColorPen != null)
     {
         RectangleF bounds = widget.Bounds;
         ctx.DrawLine(BorderColorPen, bounds.Right, bounds.Top, bounds.Right, bounds.Bottom);
     }
 }
 public override void DrawBorder(IGUIContext ctx, Widget widget)
 {
     if (Border > 0)
     {
         RectangleF bounds = widget.Bounds;
         ctx.DrawLine(BorderColorPen, bounds.Left, bounds.Bottom, bounds.Right, bounds.Bottom);
     }
 }
예제 #8
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);

            bounds.Offset(Padding.Left, Padding.Top);

            int lineHeight = RowManager.LineHeight;
            int offsetY    = (int)ScrollOffsetY;

            int      rowIndex = RowManager.FirstParagraphOnScreen;
            IGUIFont font     = RowManager.Font;

            try {
                while (rowIndex < RowManager.Paragraphs.Count)
                {
                    Paragraph para      = RowManager.Paragraphs[rowIndex];
                    Rectangle rowBounds = new Rectangle((int)bounds.Left + (int)ScrollOffsetX,
                                                        (int)(bounds.Top + para.Top + offsetY),
                                                        (int)bounds.Width,
                                                        lineHeight);

                    var glyphLines = para.ToGlyphs();

                    foreach (var line in glyphLines)
                    {
                        if (rowBounds.Bottom > bounds.Top)
                        {
                            font.Begin(ctx);
                            font.PrintTextLine(line.Select(g => g.Glyph).ToArray(), rowBounds, Style.ForeColorBrush.Color);
                            font.End();
                        }
                        rowBounds.Offset(0, lineHeight);
                        if (rowBounds.Top > bounds.Bottom)
                        {
                            break;
                        }
                    }

                    if (rowBounds.Top > bounds.Bottom)
                    {
                        break;
                    }

                    rowIndex++;
                }

                if (CursorOn && CursorVisible)
                {
                    RectangleF CursorRectangle = RowManager.CalcCursorRectangle();
                    int        x  = Math.Max((int)bounds.Left + 1, (int)(CursorRectangle.X + bounds.Left + ScrollOffsetX + 0.5f));
                    float      y1 = CursorRectangle.Top + bounds.Top + ScrollOffsetY + 2;
                    float      y2 = y1 + CursorRectangle.Height - 4;
                    ctx.DrawLine(CursorPen, x, y1, x, y2);
                }
            } catch (Exception ex) {
                ex.LogError();
            }
        }
        public override void PaintBackground(IGUIContext ctx, Widget widget)
        {
            if (widget == null || !widget.CanPaint)
            {
                return;
            }

            float      vmargin = widget.Padding.Height / 2;
            RectangleF bounds  = widget.Bounds;
            float      xh      = bounds.Left + (bounds.Width / 2);

            float lineWidth = widget.ScaleFactor;

            using (var pen = new Pen(Theme.Colors.Base01, lineWidth)) {
                ctx.DrawLine(pen, xh, bounds.Top + vmargin, xh, bounds.Bottom - vmargin);
            }
            using (var pen = new Pen(Theme.Colors.Base1, lineWidth)) {
                ctx.DrawLine(pen, xh + lineWidth, bounds.Top + vmargin, xh + lineWidth, bounds.Bottom - vmargin);
            }
        }
예제 #10
0
        private void DrawGraphLine(IGUIContext ctx, GraphBase graph, RectangleF bounds)
        {
            PointF PPaint;
            PointF PPaintLast = new PointF();

            Pen  pen      = null;
            bool PlotFlag = true;

            float offsetX = bounds.X;
            float offsetY = bounds.Y;

            try {
                //pen = new Pen(graph.GraphColor);
                pen       = new Pen(Color.FromArgb(200, Theme.Colors.Blue));
                pen.Width = DefaultCurveWidth;

                bool bFirstPoint = true;

                foreach (GraphPoint gp in Graph.Points)
                {
                    if (bFirstPoint)
                    {
                        bFirstPoint = false;
                        PPaintLast  = Point2Client((double)gp.X, (double)gp.Y, bounds);
                        continue;
                    }

                    //double x = Client2PointX(i, Bounds);
                    //double y = (double)graph.FX(x);
                    //double y = Client2PointY(i, Bounds);

                    PPaint = Point2Client((double)gp.X, (double)gp.Y, bounds);

                    if (PlotFlag && (PPaint.Y >= 0 || PPaintLast.Y >= 0) && (PPaint.Y <= Bounds.Height || PPaintLast.Y <= bounds.Height))
                    {
                        try
                        {
                            ctx.DrawLine(pen, PPaintLast.X + offsetX, PPaintLast.Y + offsetY, PPaint.X + offsetX, PPaint.Y + offsetY);
                        }
                        catch { }
                    }

                    PPaintLast = PPaint;

                    PlotFlag = true;
                }
            } catch (Exception ex) {
                ex.LogError();
            }
            finally {
                pen.Dispose();
            }
        }
예제 #11
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);

            if (IconFont == null)
            {
                return;
            }

            RectangleF iconBounds = new RectangleF(bounds.Left + Padding.Left,
                                                   bounds.Top + Padding.Top,
                                                   bounds.Width - Padding.Left - Padding.Top,
                                                   bounds.Height - Padding.Top - Padding.Bottom);

            SizeF fw = ctx.DrawString(((char)FontAwesomeIcons.fa_caret_down).ToString(), IconFont,
                                      Style.ForeColorBrush, iconBounds, FontFormat.DefaultIconFontFormatFar);

            float x = bounds.Right - Padding.Top - fw.Width - Padding.Top;

            ctx.DrawLine(Theme.Pens.Base03, x, bounds.Top + Padding.Top, x, bounds.Bottom - Padding.Bottom);
            ctx.DrawLine(Theme.Pens.Base01, x + 1, bounds.Top + Padding.Top, x + 1, bounds.Bottom - Padding.Bottom);
        }
예제 #12
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);

            RectangleF paddingBounds = PaddingBounds;

            float y = paddingBounds.Top + (paddingBounds.Height / 2f);
            //ctx.DrawLine (Theme.Pens.Red, paddingBounds.Left, y, paddingBounds.Right, y);

            Point p = BoxAlignment.AlignBoxes(paddingBounds, bounds, Format, Font.Ascender, Font.Descender);

            y = p.Y;
            ctx.DrawLine(Theme.Pens.Red, paddingBounds.Left, y, paddingBounds.Right, y);

            ctx.DrawString(Text, Font, Style.ForeColorBrush, bounds, Format);
        }
예제 #13
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);
            bounds.Inflate(-TextMargin.Width, -TextMargin.Height);

            if (!String.IsNullOrEmpty(Text))
            {
                ctx.DrawSelectedString(DisplayText, Font, SelStart, SelLength, bounds, TextOffsetX, Format,
                                       Style.ForeColorBrush.Color, Theme.Colors.HighLightBlue, Theme.Colors.White);
            }

            if (CursorOn && CursorVisible)
            {
                Style.ForeColorPen.Width = CursorLineWidth;
                float cp = Math.Max(3f, CursorPosPix + bounds.Left);
                ctx.DrawLine(Style.ForeColorPen, cp, bounds.Top + 1f, cp, bounds.Bottom - 2f);
            }
        }
예제 #14
0
        public override void OnPaintBackground(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaintBackground(ctx, bounds);

            try {
                if (BreakWidthRulerVisible && Padding.Right > 0)
                {
                    int breakWidth = (int)(bounds.Left + Padding.Left + BreakWidth);
                    ctx.DrawLine(Theme.Pens.Base01, breakWidth, bounds.Top, breakWidth, bounds.Bottom);
                }

                painter.Value.Clear();

                if (SelLength <= 0)
                {
                    return;
                }

                int Start        = SelStart;
                int End          = Start + SelLength;
                int paraIndexEnd = RowManager.FindParagraphIndexByPosition(End);

                int firstParagraphIndex = RowManager.FirstParagraphOnScreen;
                if (firstParagraphIndex > paraIndexEnd)
                {
                    return;
                }

                int   rowHeight = RowManager.LineHeight;
                float rowBorder = 1f * ScaleFactor;

                Paragraph         paraStart;
                ParagraphPosition ppStart;

                int paraIndex = RowManager.FindParagraphIndexByPosition(Start);

                int lineOffset = 0;

                if (paraIndex >= firstParagraphIndex)
                {
                    paraStart  = RowManager.Paragraphs [paraIndex];
                    ppStart    = paraStart.PositionAtIndex(Start - paraStart.PositionOffset);
                    lineOffset = ppStart.LineIndex;
                }
                else
                {
                    paraIndex  = firstParagraphIndex;
                    paraStart  = RowManager.Paragraphs [paraIndex];
                    lineOffset = firstParagraphIndex - paraStart.LineOffset;
                    ppStart    = paraStart.PositionAtIndex(0);
                }

                Paragraph         paraEnd = RowManager.Paragraphs[paraIndexEnd];
                ParagraphPosition ppEnd   = paraEnd.PositionAtIndex(End - paraEnd.PositionOffset);

                int absline    = paraStart.LineOffset + ppStart.LineIndex;
                int absEndLine = paraEnd.LineOffset + ppEnd.LineIndex;

                float xStart = ppStart.ColumnStart + bounds.Left + Padding.Left;
                float yStart = bounds.Top + Padding.Top + (absline * rowHeight) + ScrollOffsetY;
                float xEnd   = 0;

                if (absline == absEndLine)
                {
                    xEnd = ppEnd.ColumnStart + bounds.Left + Padding.Left;
                    painter.Value.AddRectangle(SelectionBrush, xStart, yStart, xEnd - xStart, rowHeight - rowBorder);

                    // >>> Paint end exit ,,
                    painter.Value.Flush();
                    return;
                }

                float startWidth = ppStart.ColumnStart;

                while (absline <= absEndLine)
                {
                    foreach (float w in paraStart.LineWidths().Skip(lineOffset))
                    {
                        if (absline++ == absEndLine || yStart > bounds.Bottom)
                        {
                            startWidth = ppEnd.ColumnStart;
                            painter.Value.AddRectangle(SelectionBrush, xStart, yStart, startWidth, rowHeight - rowBorder);

                            // >>> Paint end exit ,,
                            painter.Value.Flush();
                            return;
                        }

                        if (yStart + rowHeight > bounds.Top && yStart < bounds.Bottom)
                        {
                            painter.Value.AddRectangle(SelectionBrush, xStart, yStart, w - startWidth, rowHeight - rowBorder);
                        }
                        yStart    += rowHeight;
                        startWidth = 0;
                        xStart     = bounds.Left + Padding.Left;
                    }

                    paraIndex++;
                    if (paraIndex >= RowManager.Paragraphs.Count)
                    {
                        break;
                    }
                    paraStart  = RowManager.Paragraphs[paraIndex];
                    lineOffset = 0;
                }
            } catch (Exception ex) {
                ex.LogWarning();
            }
        }
예제 #15
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);

            float lineHeight      = LineHeight;
            float separatorHeight = SeparatorHeight;

            RectangleF rLine = bounds;

            rLine.Height = lineHeight;
            rLine.Width -= Padding.Right;
            rLine.Offset(0, Padding.Top);
            float textOffset = lineHeight + Padding.Left;

            bool buildTree = false;

            if (lastBounds != bounds || Tree == null)
            {
                try {
                    lastBounds         = bounds;
                    Tree               = new QuadTree(bounds);
                    itemStartPositions = new float[Menu.Count];
                    buildTree          = true;
                } catch (Exception ex) {
                    ex.LogError();
                }
            }

            for (int i = 0; i < Menu.Children.Count; i++)
            {
                IGuiMenuItem item = Menu.Children [i];

                float itemHeight = 0;

                if (item.IsSeparator)
                {
                    itemHeight = separatorHeight;
                    float y = rLine.Y + separatorHeight / 2;

                    using (Pen pen = new Pen(Theme.Colors.Base02, ScaleFactor))
                        ctx.DrawLine(pen, rLine.X + textOffset, y, rLine.X + rLine.Width, y);

                    y++;
                    using (Pen pen = new Pen(Theme.Colors.Base0, ScaleFactor))
                        ctx.DrawLine(pen, rLine.X + textOffset, y, rLine.X + rLine.Width, y);
                }
                else
                {
                    itemHeight = lineHeight;
                    WidgetStates state = WidgetStates.Default;
                    if (!item.Enabled)
                    {
                        state = WidgetStates.Disabled;
                    }
                    else if (item == m_ActiveItem)
                    {
                        if (IsFocused || Selected)
                        {
                            state = WidgetStates.Active;
                        }
                        else
                        {
                            state = WidgetStates.Selected;
                        }
                        ctx.FillRectangle(Styles.GetStyle(state).BackColorBrush,
                                          new RectangleF(rLine.X + 1, rLine.Y, rLine.Width + Padding.Right - 2, rLine.Height));
                    }

                    IWidgetStyle style = Styles.GetStyle(state);

                    if (IconFont != null)
                    {
                        char icon;
                        if (item.IsToggleButton)
                        {
                            icon = item.Checked ? (char)FontAwesomeIcons.fa_toggle_on : (char)FontAwesomeIcons.fa_toggle_off;
                        }
                        else
                        {
                            icon = (char)item.ImageIndex;
                        }

                        if (icon > 0)
                        {
                            RectangleF rIcon = rLine;
                            rIcon.Width = lineHeight;
                            ctx.DrawString(icon.ToString(), IconFont, style.ForeColorBrush, rIcon, FontFormat.DefaultIconFontFormatCenter);
                        }
                    }

                    if (Font != null)
                    {
                        RectangleF rText = new RectangleF(rLine.X + textOffset, rLine.Y + 1, rLine.Width - textOffset, rLine.Height - 1);
                        ctx.DrawString(item.Text, Font, style.ForeColorBrush, rText, FontFormat.DefaultMnemonicLine);

                        if (item.HasChildren)
                        {
                            if (IconFont != null)
                            {
                                ctx.DrawString(((char)FontAwesomeIcons.fa_caret_right).ToString(), IconFont, style.ForeColorBrush, rText, FontFormat.DefaultSingleLineFar);
                            }
                        }
                        else
                        {
                            string modifier = ModifierString(item);
                            if (modifier != null)
                            {
                                ctx.DrawString(modifier, Font, style.ForeColorBrush, rText, FontFormat.DefaultSingleLineFar);
                            }
                        }
                    }
                }

                if (buildTree)
                {
                    try {
                        Tree.Add(new LayoutItem(rLine, item));
                        itemStartPositions[i] = rLine.Y;
                    } catch (Exception ex) {
                        ex.LogError();
                    }
                }

                rLine.Offset(0, itemHeight);
            }
        }
예제 #16
0
        private void DrawAxis(IGUIContext ctx, RectangleF bounds)
        {
            if (bounds.Width <= 0 || bounds.Height <= 0)
            {
                return;
            }

            if (AxisPen == null)
            {
                AxisPen = new Pen(Theme.Colors.Base03, AxisWidth);
            }
            else
            {
                AxisPen.Width = AxisWidth;
            }

            Brush TextBrush = Theme.Brushes.Base03;

            // Size-Change
            bool bSizeXChange = OldBounds.Width > 0 && OldBounds.Width != bounds.Width;
            bool bSizeYChange = OldBounds.Height > 0 && OldBounds.Height != bounds.Height;

            if (bSizeXChange)
            {
                double ratioX = (double)(bounds.Width - PlotMargin * 6) / (double)(OldBounds.Width - PlotMargin * 6);
                m_CenterPoint.X = (int)Math.Round((double)m_CenterPoint.X * ratioX);

                if (!bSizeYChange)
                {
                    double ratioY = (double)(Bounds.Height - PlotMargin * 6) / (double)(OldBounds.Height - PlotMargin * 6) * (AspectRatio(Bounds) / AspectRatio(OldBounds));
                    m_CenterPoint.Y = (int)Math.Round((double)m_CenterPoint.Y * ratioY);
                }
            }

            if (bSizeYChange)
            {
                double ratioY = (double)(Bounds.Height - PlotMargin * 6) / (double)(OldBounds.Height - PlotMargin * 6) * (AspectRatio(Bounds) / AspectRatio(OldBounds));
                m_CenterPoint.Y = (int)Math.Round((double)m_CenterPoint.Y * ratioY);
            }

            OldBounds = bounds;

            float offsetX = bounds.X;
            float offsetY = bounds.Y;

            // Zero Point
            PointF Zero = Point2Client(0, 0, bounds).Add(offsetX, offsetY);

            // Pfeile
            PointF EndX = new PointF(bounds.Right - PlotMargin, Zero.Y);
            PointF EndY = new PointF(Zero.X, PlotMargin + offsetY);

            bool bXAxisPainted = false;
            bool bYAxisPainted = false;

            // Achsen
            if (Zero.Y < Bounds.Bottom - PlotMargin && Zero.Y > PlotMargin + offsetY)
            {
                bXAxisPainted = true;
                ctx.DrawLine(AxisPen, PlotMargin + offsetX, Zero.Y, Bounds.Right - PlotMargin, Zero.Y);
                // Y-Achse Pfeil
                ctx.DrawLine(AxisPen, EndY.X, EndY.Y, EndY.X - 3, EndY.Y + 6);
                ctx.DrawLine(AxisPen, EndY.X, EndY.Y, EndY.X + 3, EndY.Y + 6);
            }

            if (Zero.X < Bounds.Right - PlotMargin && Zero.X > PlotMargin + offsetX)
            {
                bYAxisPainted = true;
                ctx.DrawLine(AxisPen, Zero.X, PlotMargin + offsetY, Zero.X, Bounds.Bottom - PlotMargin);
                // X-Achse Pfeil
                ctx.DrawLine(AxisPen, EndX.X, EndX.Y, EndX.X - 6, EndX.Y - 3);
                ctx.DrawLine(AxisPen, EndX.X, EndX.Y, EndX.X - 6, EndX.Y + 3);
            }

            // giving some extra margin (PlotMargin * 1.5)
            // should look more beautiful at the borders.
            double MinX = Client2PointX(PlotMargin * 1.5, Bounds);
            double MaxX = Client2PointX(Bounds.Width - PlotMargin * 1.5, Bounds);
            double MinY = Client2PointY(Bounds.Height - PlotMargin * 1.5, Bounds);
            double MaxY = Client2PointY(PlotMargin * 1.5, Bounds);

            double dx = MaxX - MinX;
            double dy = MaxY - MinY;

            if (dx <= 0d || dy <= 0d)
            {
                return;
            }

            double stepX = 1;
            double stepY = 1;

            // http://en.wikipedia.org/wiki/Power_of_two

            if (dx / 40.0 > 1)
            {
                stepX = Math.Pow(2, Math.Floor(Math.Log(dx / 20, 2)));
            }
            else if (dx / 20.0 < 1)
            {
                stepX = Math.Pow(2, Math.Ceiling(Math.Log(dx / 40, 2)));
            }

            if (XAxisDataType == AxisDataTypes.axNumeric)
            {
                stepY = stepX * (yRange / xRange);
                //stepY = stepX;
            }
            else
            {
                if (dy / 40.0 > 1)
                {
                    stepY = Math.Pow(2, Math.Floor(Math.Log(dy / 20, 2)));
                }
                else if (dy / 20.0 < 1)
                {
                    stepY = Math.Pow(2, Math.Ceiling(Math.Log(dy / 40, 2)));
                }
            }

            if (stepX <= 0 || stepY <= 0)
            {
                return;
            }

            PointF pStep;
            double iStart = 0;

            // ************** Linien ***************

            Pen penGrid     = new Pen(Color.FromArgb(64, GridColor));
            Pen penGridBold = new Pen(GridColor);

            // Vertikale Linien
            // Links

            int iBold = 0;
            Pen LinePen;

            iStart = ((int)(MaxX / stepX)) * stepX;
            iStart = Math.Min(iStart, 0);
            iBold  = (int)Math.Abs(iStart / stepX);

            float tickLen = 3f.Scale(ScaleFactor);

            for (double i = iStart - stepX; i >= MinX; i -= stepX)
            {
                iBold++;
                if (iBold % 5 == 0)
                {
                    LinePen = penGridBold;
                }
                else
                {
                    LinePen = penGrid;
                }

                pStep = Point2Client(i, 0, Bounds).Add(offsetX, offsetY);

                if (DrawGrid)
                {
                    ctx.DrawLine(LinePen, pStep.X, PlotMargin + offsetY, pStep.X, Bounds.Bottom - PlotMargin);
                }

                if (bXAxisPainted)
                {
                    ctx.DrawLine(AxisPen, pStep.X, pStep.Y - tickLen, pStep.X, pStep.Y + tickLen);
                }
            }

            // Rechts

            iStart = ((int)(MinX / stepX)) * stepX;
            iStart = Math.Max(iStart, 0);
            iBold  = (int)Math.Abs(iStart / stepX);

            for (double i = iStart + stepX; i <= MaxX; i += stepX)
            {
                iBold++;
                if (iBold % 5 == 0)
                {
                    LinePen = penGridBold;
                }
                else
                {
                    LinePen = penGrid;
                }

                pStep = Point2Client(i, 0, Bounds).Add(offsetX, offsetY);

                if (DrawGrid)
                {
                    ctx.DrawLine(LinePen, pStep.X, PlotMargin + offsetY, pStep.X, bounds.Bottom - PlotMargin);
                }

                if (bXAxisPainted)
                {
                    ctx.DrawLine(AxisPen, pStep.X, pStep.Y - tickLen, pStep.X, pStep.Y + tickLen);
                }
            }

            // Horizontale Linien
            // Untere Hälfte

            iStart = ((int)(MaxY / stepY)) * stepY;
            iStart = Math.Min(iStart, 0);
            iBold  = (int)Math.Abs(iStart / stepY);

            for (double i = iStart - stepY; i >= MinY; i -= stepY)
            {
                iBold++;
                if (iBold % 5 == 0)
                {
                    LinePen = penGridBold;
                }
                else
                {
                    LinePen = penGrid;
                }

                pStep = Point2Client(0, i, Bounds).Add(offsetX, offsetY);

                if (DrawGrid)
                {
                    ctx.DrawLine(LinePen, PlotMargin + offsetX, pStep.Y, Bounds.Right - PlotMargin, pStep.Y);
                }

                if (bYAxisPainted)
                {
                    ctx.DrawLine(AxisPen, pStep.X - tickLen, pStep.Y, pStep.X + tickLen, pStep.Y);
                }
            }

            // Obere Hälfte

            iStart = ((int)(MinY / stepY)) * stepY;
            iStart = Math.Max(iStart, 0);
            iBold  = (int)Math.Abs(iStart / stepY);

            for (double i = iStart + stepY; i <= MaxY; i += stepY)
            {
                iBold++;
                if (iBold % 5 == 0)
                {
                    LinePen = penGridBold;
                }
                else
                {
                    LinePen = penGrid;
                }

                pStep = Point2Client(0, i, Bounds).Add(offsetX, offsetY);

                if (DrawGrid)
                {
                    ctx.DrawLine(LinePen, PlotMargin + offsetX, pStep.Y, Bounds.Right - PlotMargin, pStep.Y);
                }

                if (bYAxisPainted)
                {
                    ctx.DrawLine(AxisPen, pStep.X - tickLen, pStep.Y, pStep.X + tickLen, pStep.Y);
                }
            }

            penGrid.Dispose();
            penGridBold.Dispose();

            // ************************ Labels **********************
            //int lineheight = (int)Font.LineSpacing + 2;

            stepX *= 5;
            stepY *= 5;

            // Links
            iStart = ((int)(MaxX / stepX)) * stepX;
            iStart = Math.Min(iStart, 0);

            float fontHeight     = Font.Height;
            int   fontHalfHeight = (int)(Font.Height / 2f + 0.5f);

            for (double i = iStart - stepX; i >= MinX; i -= stepX)
            {
                pStep = Point2Client(i, 0, Bounds).Add(offsetX, offsetY);
                ctx.DrawString(FormatLabel(i, 0), Font, TextBrush, pStep.X, pStep.Y - (fontHeight * 2f), CenterFontFormat);
            }

            // Rechts
            iStart = ((int)(MinX / stepX)) * stepX;
            iStart = Math.Max(iStart, 0);

            for (double i = iStart + stepX; i <= MaxX; i += stepX)
            {
                pStep = Point2Client(i, 0, Bounds).Add(offsetX, offsetY);
                ctx.DrawString(FormatLabel(i, 0), Font, TextBrush, pStep.X, pStep.Y, CenterFontFormat);
            }

            // Unten
            iStart = ((int)(MaxY / stepY)) * stepY;
            iStart = Math.Min(iStart, 0);

            for (double i = iStart - stepY; i >= MinY; i -= stepY)
            {
                pStep = Point2Client(0, i, Bounds).Add(offsetX, offsetY);
                ctx.DrawString(FormatLabel(i, 1), Font, TextBrush, pStep.X - fontHalfHeight, pStep.Y - fontHeight, BelowAxisFontFormat);
            }

            // Oben
            iStart = ((int)(MinY / stepY)) * stepY;
            iStart = Math.Max(iStart, 0);

            for (double i = iStart + stepY; i <= MaxY; i += stepY)
            {
                pStep = Point2Client(0, i, Bounds).Add(offsetX, offsetY);
                ctx.DrawString(FormatLabel(i, 1), Font, TextBrush, pStep.X + fontHalfHeight, pStep.Y - fontHeight, AboveAxisFontFormat);
            }
        }
예제 #17
0
        private void DrawAverageLine(IGUIContext ctx, RectangleF bounds, float captHeight)
        {
            float verticalPosition = (float)CalcVerticalPosition(AverageValue) + bounds.Top + captHeight;

            ctx.DrawLine(ChartStyle.AvgLinePen.Pen, bounds.Left, verticalPosition, bounds.Right, verticalPosition);
        }