コード例 #1
0
        protected void rotateContext(Cairo.Context context, Direction direction)
        {
            switch (direction)
            {
            case Direction.Down:
                context.Rotate(Math.PI);
                context.Translate(-fieldSize, -fieldSize);
                break;

            case Direction.Right:
                context.Rotate(Math.PI / 2);
                context.Translate(0, -fieldSize);
                break;

            case Direction.Left:
                context.Rotate(3 * Math.PI / 2);
                context.Translate(-fieldSize, 0);
                break;
            }
        }
コード例 #2
0
ファイル: Edge.cs プロジェクト: codyn-net/studio
        private static void DrawArrow(Cairo.Context graphics, double x, double y, double pos)
        {
            graphics.MoveTo(x, y);
            graphics.Rotate(pos);
            graphics.RelMoveTo(0, (pos + 0.5 * System.Math.PI < System.Math.PI ? -1 : 1) * s_arrowSize / 2);

            graphics.RelLineTo(-s_arrowSize, 0);
            graphics.RelLineTo(s_arrowSize, -s_arrowSize);
            graphics.RelLineTo(s_arrowSize, s_arrowSize);
            graphics.RelLineTo(-s_arrowSize, 0);

            graphics.Fill();
        }
        public static void DrawText(Cairo.Context context, float x, float y, double angle, string text)
        {
            var ext = context.TextExtents(text);

            context.Save();
            context.Translate(x, y);
            context.Rotate(angle - Math.PI / 2);
            context.Translate(-ext.Width / 2, 0);
            context.ShowText(text);
            context.Stroke();

            context.Restore();
        }
        void DrawQuota(Cairo.Context context, double angle, Color color)
        {
            context.Save();
            context.Rotate(angle * Math.PI / 180.0);
            context.MoveTo(0, -95);
            context.LineTo(1, -110);
            context.LineTo(-1, -110);
            context.ClosePath();
            var c = color.ToCairo();

            context.SetSourceRGBA(c.R, c.G, c.B, c.A);
            context.Stroke();
            context.Restore();
        }
コード例 #5
0
        public void DrawAxisTitle(Cairo.Context cr, string text, int x, int y,
                                  Orientation orientation)
        {
            cr.Save();

            if (orientation == Orientation.Vertical)
            {
                cr.Translate(x, y);
                cr.Rotate(Math.PI / 2);
                cr.SetFontSize(AXIS_TITLE_FONT_SIZE);
                cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Foreground(state)).R, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).G, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).B, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).A);

                //cr.Color = CairoHelper.GetCairoColor (gtk_style.Foreground (state));
                cr.ShowText(text);
            }
            else
            {
                DrawText(cr, AXIS_TITLE_FONT_SIZE, text, x, y);
            }

            cr.Restore();
        }
コード例 #6
0
ファイル: RenderCairo.cs プロジェクト: dukus/My-FyiReporting
        private void DrawStringTBLR(PageText pt, Cairo.Context g, Cairo.Rectangle r)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            g.Save();

            layout = CairoHelper.CreateLayout(g);

            //Pango fonts are scaled to 72dpi, Windows fonts uses 96dpi
            float fontsize = (si.FontSize * 72 / 96);
            var   font     = FontDescription.FromString($"{si.GetFontFamily().Name} {fontsize * PixelsX(1)}");

            if (si.FontStyle == FontStyleEnum.Italic)
            {
                font.Style = Style.Italic;
            }

            switch (si.FontWeight)
            {
            case FontWeightEnum.Bold:
            case FontWeightEnum.Bolder:
            case FontWeightEnum.W500:
            case FontWeightEnum.W600:
            case FontWeightEnum.W700:
            case FontWeightEnum.W800:
            case FontWeightEnum.W900:
                font.Weight = Weight.Bold;
                break;
            }

            FontDescription oldfont = layout.FontDescription;

            layout.FontDescription = font;

            switch (si.TextAlign)
            {
            case TextAlignEnum.Right:
                layout.Alignment = Alignment.Right;
                break;

            case TextAlignEnum.Center:
                layout.Alignment = Alignment.Center;
                break;

            case TextAlignEnum.Left:
            default:
                layout.Alignment = Alignment.Left;
                break;
            }

            layout.Width = Units.FromPixels((int)(r.Height - si.PaddingTop - si.PaddingBottom - 2));

            layout.Wrap = WrapMode.WordChar;
            layout.SetText(s);

            Rectangle logical;
            Rectangle ink;

            layout.GetExtents(out ink, out logical);
            double height = logical.Height / Scale.PangoScale;
            double y      = 0;
            double x      = 0;

            switch (si.VerticalAlign)
            {
            case VerticalAlignEnum.Top:
                x = r.X + si.PaddingLeft;
                break;

            case VerticalAlignEnum.Middle:
                x = r.X + (r.Width - height) / 2;
                break;

            case VerticalAlignEnum.Bottom:
                x = r.X + (r.Width - height) + si.PaddingLeft;
                break;
            }

            // draw the background
            DrawBackground(g, r, si);

            Cairo.Rectangle box = new Cairo.Rectangle(
                x,
                r.Y + r.Height - si.PaddingBottom - 1,
                r.Height - si.PaddingBottom - si.PaddingTop,
                r.Width - si.PaddingLeft + si.PaddingRight);

            g.Color = si.Color.ToCairoColor();

            g.Rotate(270 * Math.PI / 180.0);
            CairoHelper.UpdateLayout(g, layout);

            g.MoveTo(-box.Y, box.X);
            CairoHelper.ShowLayout(g, layout);

            layout.FontDescription = oldfont;
            g.Restore();
        }
コード例 #7
0
        private void DrawArcSegment(double xm1, double ym1, double xm2, double ym2, double xr, double yr, double alpha, bool isLargeArc, SweepDirection direction)
        {
            if (xr <= 0.000000001 || yr <= 0.000000001)
            {
                return;
            }

            var x1 = xm1 * Math.Cos(-alpha) - ym1 * Math.Sin(-alpha);
            var y1 = xm1 * Math.Sin(-alpha) + ym1 * Math.Cos(-alpha);

            var x2 = xm2 * Math.Cos(-alpha) - ym2 * Math.Sin(-alpha);
            var y2 = xm2 * Math.Sin(-alpha) + ym2 * Math.Cos(-alpha);

            var r = 0.0;

            if (xr > yr)
            {
                y1 = y1 * xr / yr;
                y2 = y2 * xr / yr;

                r = xr;
            }
            else
            {
                x1 = x1 * yr / xr;
                x2 = x2 * yr / xr;

                r = yr;
            }

            if (4 * r * r < (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
            {
                return;
            }

            var xc1 = 0.0;
            var xc2 = 0.0;
            var yc1 = 0.0;
            var yc2 = 0.0;

            if (Math.Abs(y1 - y2) > 0.000000001)
            {
                var A = (x1 - x2) / (y2 - y1);
                var B = (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) / (2 * (y2 - y1));

                var a = A * A + 1;
                var b = -2 * x1 + 2 * A * B - 2 * A * y1;
                var c = x1 * x1 + B * B - 2 * B * y1 + y1 * y1 - r * r;


                xc1 = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
                yc1 = A * xc1 + B;

                xc2 = (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
                yc2 = A * xc2 + B;
            }
            else
            {
                xc1 = (x1 + x2) / 2;
                yc1 = y1 + Math.Sqrt(r * r - (xc1 - x1) * (xc1 - x1));

                xc2 = (x1 + x2) / 2;
                yc2 = y1 - Math.Sqrt(r * r - (xc2 - x1) * (xc2 - x1));
            }

            var angle1 = Math.Abs(y1 - yc1) / r > 1 ? Math.PI / 2 : Math.Asin(Math.Abs(y1 - yc1) / r);

            if ((x1 < xc1) && (y1 >= yc1))
            {
                angle1 = Math.PI - angle1;
            }
            if (y1 < yc1)
            {
                if (x1 < xc1)
                {
                    angle1 = Math.PI + angle1;
                }
                else
                {
                    angle1 = -angle1;
                }
            }

            var angle2 = Math.Abs(y2 - yc1) / r > 1 ? Math.PI / 2 : Math.Asin(Math.Abs(y2 - yc1) / r);

            if ((x2 < xc1) && (y2 >= yc1))
            {
                angle2 = Math.PI - angle2;
            }
            if (y2 < yc1)
            {
                if (x2 < xc1)
                {
                    angle2 = Math.PI + angle2;
                }
                else
                {
                    angle2 = -angle2;
                }
            }

            var alfa1 = Math.Abs(y1 - yc2) / r > 1 ? Math.PI / 2 : Math.Asin(Math.Abs(y1 - yc2) / r);

            if ((x1 < xc2) && (y1 >= yc2))
            {
                alfa1 = Math.PI - alfa1;
            }
            if (y1 < yc2)
            {
                if (x1 < xc2)
                {
                    alfa1 = Math.PI + alfa1;
                }
                else
                {
                    alfa1 = -alfa1;
                }
            }

            var alfa2 = Math.Abs(y2 - yc2) / r > 1 ? Math.PI / 2 : Math.Asin(Math.Abs(y2 - yc2) / r);

            if ((x2 < xc2) && (y2 >= yc2))
            {
                alfa2 = Math.PI - alfa2;
            }
            if (y2 < yc2)
            {
                if (x2 < xc2)
                {
                    alfa2 = Math.PI + alfa2;
                }
                else
                {
                    alfa2 = -alfa2;
                }
            }

            cr.Save();

            cr.Rotate(alpha);

            if (xr > yr)
            {
                cr.Scale(1, yr / xr);
            }
            else
            {
                cr.Scale(xr / yr, 1);
            }

            if (direction == SweepDirection.Clockwise)
            {
                if (isLargeArc)
                {
                    if ((y1 < y2) || ((Math.Abs(y1 - y2) < 0.00000001) && (x1 > x2)))
                    {
                        cr.Arc(xc1, yc1, r, angle1, angle2);
                    }
                    else
                    {
                        cr.Arc(xc2, yc2, r, alfa1, alfa2);
                    }
                }
                else
                {
                    if ((y1 > y2) || ((Math.Abs(y1 - y2) < 0.00000001) && (x1 < x2)))
                    {
                        cr.Arc(xc1, yc1, r, angle1, angle2);
                    }
                    else
                    {
                        cr.Arc(xc2, yc2, r, alfa1, alfa2);
                    }
                }
            }
            else
            {
                if (isLargeArc)
                {
                    if ((y1 > y2) || ((Math.Abs(y1 - y2) < 0.00000001) && (x1 < x2)))
                    {
                        cr.ArcNegative(xc1, yc1, r, angle1, angle2);
                    }
                    else
                    {
                        cr.ArcNegative(xc2, yc2, r, alfa1, alfa2);
                    }
                }
                else
                {
                    if ((y1 < y2) || ((Math.Abs(y1 - y2) < 0.00000001) && (x1 > x2)))
                    {
                        cr.ArcNegative(xc1, yc1, r, angle1, angle2);
                    }
                    else
                    {
                        cr.ArcNegative(xc2, yc2, r, alfa1, alfa2);
                    }
                }
            }

            cr.Restore();
        }