Пример #1
0
        int MeasureTicksSize(TickEnumerator e, AxisDimension ad)
        {
            int max = 0;
            Pango.Layout layout = new Pango.Layout (this.PangoContext);
            layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8");

            double start = GetStart (ad);
            double end = GetEnd (ad);

            e.Init (GetOrigin (ad));

            while (e.CurrentValue > start)
                e.MovePrevious ();

            for ( ; e.CurrentValue <= end; e.MoveNext ())
            {
                int tw = 0, th = 0;

                layout.SetMarkup (e.CurrentLabel);
                layout.GetPixelSize (out tw, out th);

                if (ad == AxisDimension.X) {
                    if (th > max)
                        max = th;
                } else {
                    if (tw > max)
                        max = tw;
                }
            }
            return max;
        }
Пример #2
0
        void DrawTicks(Gdk.Window win, Gdk.GC gc, TickEnumerator e, AxisPosition pos, AxisDimension ad, int tickSize, bool showLabels)
        {
            int rwidth, rheight;
            win.GetSize (out rwidth, out rheight);

            Pango.Layout layout = null;

            if (showLabels) {
                layout = new Pango.Layout (this.PangoContext);
                layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8");
            }

            bool isX = pos == AxisPosition.Top || pos == AxisPosition.Bottom;
            bool isTop = pos == AxisPosition.Top || pos == AxisPosition.Right;

            double start = GetStart (ad);
            double end = GetEnd (ad);

            e.Init (GetOrigin (ad));

            while (e.CurrentValue > start)
                e.MovePrevious ();

            int lastPosLabel;
            int lastPos;
            int lastTw = 0;

            if (isX) {
                lastPosLabel = reverseXAxis ? left + width + MinLabelGapX : left - MinLabelGapX;
                lastPos = left - minTickStep*2;
            }
            else {
                lastPosLabel = reverseYAxis ? top - MinLabelGapY : rheight + MinLabelGapY;
                lastPos = top + height + minTickStep*2;
            }

            for ( ; e.CurrentValue <= end; e.MoveNext ())
            {
                int px, py;
                int tw = 0, th = 0;
                int tick = tickSize;

                GetPoint (e.CurrentValue, e.CurrentValue, out px, out py);

                if (showLabels) {
                    layout.SetMarkup (e.CurrentLabel);
                    layout.GetPixelSize (out tw, out th);
                }

                if (isX) {
                    if (Math.Abs (px - lastPos) < minTickStep || px < left || px > left + width)
                        continue;
                    lastPos = px;

                    bool labelFits = false;
                    if ((Math.Abs (px - lastPosLabel) - (tw/2) - (lastTw/2)) >= MinLabelGapX) {
                        lastPosLabel = px;
                        lastTw = tw;
                        labelFits = true;
                    }

                    if (isTop) {
                        if (showLabels) {
                            if (labelFits)
                                win.DrawLayout (gc, px - (tw/2), top - AreaBorderWidth - th, layout);
                            else
                                tick = tick / 2;
                        }
                        win.DrawLine (gc, px, top, px, top + tick);
                    }
                    else {
                        if (showLabels) {
                            if (labelFits)
                                win.DrawLayout (gc, px - (tw/2), top + height + AreaBorderWidth, layout);
                            else
                                tick = tick / 2;
                        }
                        win.DrawLine (gc, px, top + height, px, top + height - tick);
                    }
                }
                else {
                    if (Math.Abs (lastPos - py) < minTickStep || py < top || py > top + height)
                        continue;
                    lastPos = py;

                    bool labelFits = false;
                    if ((Math.Abs (py - lastPosLabel) - (th/2) - (lastTw/2)) >= MinLabelGapY) {
                        lastPosLabel = py;
                        lastTw = th;
                        labelFits = true;
                    }

                    if (isTop) {
                        if (showLabels) {
                            if (labelFits)
                                win.DrawLayout (gc, left + width + AreaBorderWidth + 1, py - (th/2), layout);
                            else
                                tick = tick / 2;
                        }
                        win.DrawLine (gc, left + width, py, left + width - tick, py);
                    }
                    else {
                        if (showLabels) {
                            if (labelFits)
                                win.DrawLayout (gc, left - AreaBorderWidth - tw - 1, py - (th/2), layout);
                            else
                                tick = tick / 2;
                        }
                        win.DrawLine (gc, left, py, left + tick, py);
                    }
                }
            }
        }