Rotate() публичный Метод

public Rotate ( double angle ) : void
angle double
Результат void
Пример #1
0
        /// <summary>
        /// Draw the robot taking into account the center x and y position of the map which
        /// will be different from the true center x and y positions on the drawing context.
        /// This method will result in a red wheeled robot with black tyres being drawn at
        /// the robots location on the map.
        ///
        /// The scale value is currently unused but it could be useful if the map was scaled
        /// in some way for example a mini-map may be 10 times smaller than the original
        /// results in 1:10 scale robot.
        /// </summary>
        /// <param name="cairoContext">Cairo context to draw to (assuming a map).</param>
        /// <param name="centerX">Center x position of map to draw onto.</param>
        /// <param name="centerY">Center y position of map to draw onto.</param>
        /// <param name="scale">Scale currently unused.</param>
        public void Draw(Cairo.Context cairoContext, int centerX, int centerY, double scale)
        {
            // Scale up to centimeters.
            int width  = (int)(robot.Width * 100);
            int height = (int)(robot.Height * 100);
            int x      = (int)(robot.X * 100);
            int y      = (int)(robot.Y * 100);

            // Set a red colour.
            cairoContext.SetSourceRGB(255, 0, 0);

            cairoContext.LineWidth = 1.0;
            cairoContext.LineCap   = LineCap.Butt;

            cairoContext.Translate(centerX + x, centerY - y);
            cairoContext.Rotate(relativeRotation);              // Rotate the robot based on its orientation in radians.

            // Draw the robot as a triangle.
            cairoContext.MoveTo(0, -height / 2);
            cairoContext.LineTo(-width / 2, height / 2);
            cairoContext.LineTo(width / 2, height / 2);
            cairoContext.LineTo(0, -height / 2);
            cairoContext.Stroke();

            // Reset the drawing context.
            cairoContext.Rotate(-relativeRotation);
            cairoContext.Translate(-(centerX + x), -(centerY - y));
        }
        void DrawBuildEffect(Cairo.Context context, Gdk.Rectangle area, double progress, double opacity)
        {
            context.Save();
            LayoutRoundedRectangle(context, area);
            context.Clip();

            Gdk.Point center = new Gdk.Point(area.Left + 19, (area.Top + area.Bottom) / 2);
            context.Translate(center.X, center.Y);
            var circles = new [] {
                new { Radius = 200, Thickness = 12, Speed = 1, ArcLength = Math.PI * 1.50 },
                new { Radius = 195, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.50 },
                new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 },
                new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 },
                new { Radius = 240, Thickness = 12, Speed = 3, ArcLength = Math.PI * 1.50 },
                new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 },
                new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 },
                new { Radius = 215, Thickness = 20, Speed = 2, ArcLength = Math.PI * 1.25 }
            };

            double zmod  = 1.0d;
            double zporg = progress;

            foreach (var arc in circles)
            {
                double zoom = 1.0d;
                zoom = (double)Math.Sin(zporg * Math.PI * 2 + zmod);
                zoom = ((zoom + 1) / 6.0d) + .05d;

                context.Rotate(Math.PI * 2 * progress * arc.Speed);
                context.MoveTo(arc.Radius * zoom, 0);
                context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength);
                context.LineWidth = arc.Thickness * zoom;
                context.SetSourceColor(CairoExtensions.ParseColor("B1DDED", 0.35 * opacity));
                context.Stroke();
                context.Rotate(Math.PI * 2 * -progress * arc.Speed);

                progress = -progress;

                context.Rotate(Math.PI * 2 * progress * arc.Speed);
                context.MoveTo(arc.Radius * zoom, 0);
                context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength);
                context.LineWidth = arc.Thickness * zoom;
                context.Stroke();
                context.Rotate(Math.PI * 2 * -progress * arc.Speed);

                progress = -progress;

                zmod += (float)Math.PI / circles.Length;
            }

            context.LineWidth = 1;
            context.ResetClip();
            context.Restore();
        }
Пример #3
0
        private void DrawShape(Cairo.Context g, int width, int height)
        {
            int inner_x = radius + border + inner;
            int cx      = Center.X;
            int cy      = Center.Y;

            g.Operator = Operator.Source;
            g.Source   = new SolidPattern(new Cairo.Color(0, 0, 0, 0));
            g.Rectangle(0, 0, width, height);
            g.Paint();

            g.NewPath();
            g.Translate(cx, cy);
            g.Rotate(angle);

            g.Source   = new SolidPattern(new Cairo.Color(0.2, 0.2, 0.2, .6));
            g.Operator = Operator.Over;
            g.Rectangle(0, -(border + inner), inner_x, 2 * (border + inner));
            g.Arc(inner_x, 0, inner + border, 0, 2 * Math.PI);
            g.Arc(0, 0, radius + border, 0, 2 * Math.PI);
            g.Fill();

            g.Source   = new SolidPattern(new Cairo.Color(0, 0, 0, 1.0));
            g.Operator = Operator.DestOut;
            g.Arc(inner_x, 0, inner, 0, 2 * Math.PI);
#if true
            g.Fill();
#else
            g.FillPreserve();

            g.Operator = Operator.Over;
            RadialGradient rg = new RadialGradient(inner_x - (inner * 0.3), inner * 0.3, inner * 0.1, inner_x, 0, inner);
            rg.AddColorStop(0, new Cairo.Color(0.0, 0.2, .8, 0.5));
            rg.AddColorStop(0.7, new Cairo.Color(0.0, 0.2, .8, 0.1));
            rg.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0));
            g.Source = rg;
            g.Fill();
            rg.Destroy();
#endif
            g.Operator = Operator.Over;
            g.Matrix   = new Matrix();
            g.Translate(cx, cy);
            if (source != null)
            {
                SetSourcePixbuf(g, source, -source.Width / 2, -source.Height / 2);
            }

            g.Arc(0, 0, radius, 0, 2 * Math.PI);
            g.Fill();

            if (overlay != null)
            {
                SetSourcePixbuf(g, overlay, -overlay.Width / 2, -overlay.Height / 2);
                g.Arc(0, 0, radius, angle, angle + Math.PI);
                g.ClosePath();
                g.FillPreserve();
                g.Source = new SolidPattern(new Cairo.Color(1.0, 1.0, 1.0, 1.0));
                g.Stroke();
            }
        }
Пример #4
0
        void OnExpose(object sender, EventArgs args)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(this.Window);

            cr.LineWidth = 3;
            cr.LineCap   = LineCap.Round;

            int width, height;

            width  = Allocation.Width;
            height = Allocation.Height;

            cr.Translate(width / 2, height / 2);

            for (int i = 0; i < 8; i++)
            {
                cr.SetSourceRGBA(0, 0, 0, trs[count % 8, i]);
                cr.MoveTo(0.0, -10.0);
                cr.LineTo(0.0, -40.0);
                cr.Rotate(Math.PI / 4);
                cr.Stroke();
            }

            cr.GetTarget().Dispose();
            cr.Dispose();
        }
Пример #5
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }
            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (background_buffer == null)
                {
                    if (Orientation == DockPosition.Bottom || Orientation == DockPosition.Top)
                    {
                        background_buffer = new DockySurface(allocation.Width, allocation.Height, cr.Target);
                    }
                    else
                    {
                        // switch width and height so we can rotate it later
                        background_buffer = new DockySurface(allocation.Height, allocation.Width, cr.Target);
                    }
                    DrawBackground(background_buffer);
                }

                switch (Orientation)
                {
                case DockPosition.Top:
                    cr.Scale(1, -1);
                    cr.Translate(0, -background_buffer.Height);
                    break;

                case DockPosition.Left:
                    cr.Rotate(Math.PI * .5);
                    cr.Translate(0, -background_buffer.Height);
                    break;

                case DockPosition.Right:
                    cr.Rotate(Math.PI * -0.5);
                    cr.Translate(-background_buffer.Width, 0);
                    break;
                }

                cr.Operator = Operator.Source;
                background_buffer.Internal.Show(cr, 0, 0);

                (cr.Target as IDisposable).Dispose();
            }

            return(base.OnExposeEvent(evnt));
        }
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            //Draw outline rectangles:
            context.Rectangle(hlwidth, hlwidth, texture.Width - lwidth, texture.Height - lwidth);
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.LineWidth = lwidth;
            context.StrokePreserve();
            double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));

            context.SetSourceRGB(sat, sat, sat);
            context.Fill();

            double dim = 4;

            context.MoveTo(-dim, 0);
            context.LineTo(outwards ? 0 : -dim, outwards ? 0 : dim);
            context.LineTo(0, dim);
            context.MoveTo(-dim, dim);
            context.LineTo(0, 0);
            context.ClosePath();
            Cairo.Path arrow = context.CopyPath();
            context.NewPath();

            double margin = 2 + hlwidth;
            PointD center = new PointD(texture.Width * 0.5, texture.Height * 0.5);
            PointD transl = new PointD(center.X - margin, -(center.Y - margin));

            context.LineWidth = lwidth;
            sat = (with_state == 1 ? 0.0 : 1.0);
            context.SetSourceRGB(sat, sat, sat);

            context.Translate(center.X, center.Y);
            for (int i = 0; i < 4; i++)
            {
                context.Rotate(Math.PI * 0.5 * i);
                context.Translate(transl.X, transl.Y);
                context.AppendPath(arrow);
                context.Stroke();
                context.Translate(-transl.X, -transl.Y);
            }

            ((IDisposable)arrow).Dispose();
            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
    static void draw(Cairo.Context gr, int width, int height)
    {
        int          w, h;
        ImageSurface image;

        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        image = new ImageSurface("data/e.png");
        w     = image.Width;
        h     = image.Height;

        gr.Translate(0.5, 0.5);
        gr.Rotate(45 * M_PI / 180);
        gr.Scale(1.0 / w, 1.0 / h);
        gr.Translate(-0.5 * w, -0.5 * h);

        image.Show(gr, 0, 0);
        image.Destroy();
    }
Пример #8
0
        public static void RotatePng(ParsedPath pngPath, ImageRotation rotation)
        {
            if (rotation == ImageRotation.None)
            {
                return;
            }

            using (ImageSurface originalImage = new ImageSurface(pngPath))
            {
                int w;
                int h;

                if (rotation == ImageRotation.Left || rotation == ImageRotation.Right)
                {
                    w = originalImage.Height;
                    h = originalImage.Width;
                }
                else
                {
                    w = originalImage.Width;
                    h = originalImage.Height;
                }

                double[] rotationRadians = { 0, -Math.PI / 2, Math.PI / 2, Math.PI };

                using (ImageSurface rotatedImage = new ImageSurface(Format.Argb32, w, h))
                {
                    using (Cairo.Context g = new Cairo.Context(rotatedImage))
                    {
                        g.Translate(rotatedImage.Width / 2.0, rotatedImage.Height / 2.0);
                        g.Rotate(rotationRadians[(int)rotation]);
                        g.Translate(-originalImage.Width / 2.0, -originalImage.Height / 2.0);

                        g.SetSourceSurface(originalImage, 0, 0);
                        g.Paint();
                    }

                    rotatedImage.WriteToPng(pngPath);
                }
            }
        }
Пример #9
0
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            Rectangle r = ClientRectangle;
            Point m = r.Center;

            gr.Save ();

            double aUnit = Math.PI*2.0 / (Maximum - Minimum);
            gr.Translate (m.X, r.Height *1.1);
            gr.Rotate (Value/4.0 * aUnit - Math.PI/4.0);
            gr.Translate (-m.X, -m.Y);

            gr.LineWidth = 2;
            Foreground.SetAsSource (gr);
            gr.MoveTo (m.X,0.0);
            gr.LineTo (m.X, -m.Y*0.5);
            gr.Stroke ();

            gr.Restore ();
        }
Пример #10
0
        protected override void CreateTexture(Clutter.CairoTexture texture, int with_state)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double lwidth   = 1;
            double hlwidth  = lwidth * 0.5;
            double rotation = Math.PI * (3 - (double)sense) * 0.5;
            PointD center   = new PointD(texture.Width * 0.5, texture.Height * 0.5);

            //Set the correct orientation:
            context.Translate(center.X, center.Y);
            context.Rotate(rotation);
            context.Translate(-center.X, -center.Y);

            //Draw border:
            context.MoveTo(texture.Width * 0.5, hlwidth);
            context.ArcNegative(texture.Width, center.Y, (texture.Height - lwidth) / 2, 1.5 * Math.PI, 0.5 * Math.PI);
            context.LineTo(texture.Width * 0.5, texture.Height - hlwidth);
            context.Arc(texture.Width * 0.5, center.Y, (texture.Height - lwidth) / 2, 0.5 * Math.PI, 1.5 * Math.PI);
            context.ClosePath();
            context.LineWidth = lwidth;
            context.SetSourceRGBA(1.0, 1.0, 1.0, with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));
            context.FillPreserve();
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.Stroke();

            //Draw arrow:
            context.MoveTo(center.X, center.Y - texture.Height * 0.25);
            context.LineTo(center.X - texture.Height * 0.25, center.Y);
            context.LineTo(center.X, center.Y + texture.Height * 0.25);
            context.LineWidth = lwidth * 1.5;
            context.SetSourceRGB(0.0, 0.0, 0.0);
            context.Stroke();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
    static void draw(Cairo.Context gr, int width, int height)
    {
        int            w, h;
        ImageSurface   image;
        Matrix         matrix;
        SurfacePattern pattern;

        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        image = new ImageSurface("data/e.png");
        w     = image.Width;
        h     = image.Height;

        pattern        = new SurfacePattern(image);
        pattern.Extend = Cairo.Extend.Repeat;

        gr.Translate(0.5, 0.5);
        gr.Rotate(M_PI / 4);
        gr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2));
        gr.Translate(-0.5, -0.5);

        matrix = new Matrix();
        matrix.InitScale(w * 5.0, h * 5.0);

        pattern.Matrix = matrix;

        gr.Pattern = pattern;

        gr.Rectangle(new PointD(0, 0),
                     1.0, 1.0);
        gr.Fill();

        pattern.Destroy();
        image.Destroy();
    }
Пример #12
0
 public virtual void Paint(Context ctx)
 {
     PointD size = this.MeasureSize (ctx);
     PaintContour (ctx,size);
     KnownColors.SetFontFacePieceName(ctx);
     TextExtents te = ctx.TextExtents(this.Name), ten;
     double y0 = 0.5d*(size.Y-te.Width);
     ctx.MoveTo(0.5d*Margin,y0);
     ctx.Save();
     ctx.Rotate(0.5d*Math.PI);
     ctx.ShowText(this.Name);
     ctx.Restore();
     double x0 = Margin+te.Height;
     KnownColors.SetFontFaceNormal(ctx);
     te = ctx.TextExtents(OptionalString);
     y0 = 2.0d*Margin;
     int index = 0x00;
     PointD siz;
     foreach(IPuzzlePiece ipp in this.arguments) {
         ctx.Save();
         ctx.Translate(x0,Margin);
         if(ipp == null) {
             siz = new PointD(MinimumWidth,size.Y-4.0d*Margin);
             ctx.Rectangle(Margin,Margin,siz.X,siz.Y);
             ctx.Pattern = KnownColors.ConstructionPattern;
             ctx.FillPreserve();
         }
         else {
             siz = ipp.MeasureSize(ctx);
         }
         ctx.Rectangle(0.0d,0.0d,siz.X+2.0d*Margin,siz.Y+2.0d*Margin);
         ctx.Color = KnownColors.Black;
         ctx.StrokePreserve();
         if(ipp == null) {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Translate(Margin,Margin);
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(MinimumWidth,0.0d);
             ctx.RelLineTo(0.0d,5.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowDownPattern;
             ctx.Fill();
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(0.0d,siz.Y);
             ctx.RelLineTo(5.0d,0.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowRightPattern;
             ctx.Fill();
         }
         else {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Color = KnownColors.Black;
             ctx.Translate(Margin,Margin);
             ipp.Paint(ctx);
         }
         ctx.Restore();
         subpieces[index] = new Rectangle(x0+Margin,2.0d*Margin,siz.X,siz.Y);
         x0 += siz.X+3.0d*Margin;
         if(index >= NumberOfArguments-NumberOfOptionalArguments) {
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+te.Width),siz.Y+3.0d*Margin-2.0d);
             ctx.ShowText(OptionalString);
         }
         if(this.ArgumentNames != null && index < arguments.Length) {
             ten = ctx.TextExtents(this.ArgumentNames[index]);
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+ten.Width),-te.YBearing+Margin+2.0d);
             ctx.ShowText(this.ArgumentNames[index]);
         }
         index++;
     }
 }
Пример #13
0
        private void DrawPiece(Context cr, PieceType Piece, PieceDirection Direction, double x, double y)
        {
            int idx = (int)Piece;
            if (idx < (int)PieceType.FUHYOU || idx > (int)PieceType.OUSHOU)
                return;

            cr.Save();
            cr.Translate(x, y);
            if (Direction == PieceDirection.DOWN)
            {
                cr.Rotate(180 * Math.PI / 180);
                cr.Translate(-FIELD_SIZE,-FIELD_SIZE);
            }
            cr.Scale(FIELD_SIZE/PieceGraphics[idx].Dimensions.Width, FIELD_SIZE/PieceGraphics[idx].Dimensions.Width);
            if (idx == (int)PieceType.OUSHOU && Direction == PieceDirection.DOWN)
            {
                GyokushouGraphic.RenderCairo(cr);
            }
            else
            {
                PieceGraphics[idx].RenderCairo(cr);
            }

            cr.Restore();
        }
Пример #14
0
    public Flower( )
    {
        int idx      = -1;
        int last_idx = -1;

        int petal_size = PETAL_MIN + rand() % PETAL_VAR;
        int size       = petal_size * 8;

        int n_groups = rand() % 3 + 1;

        this.ctex = new CairoTexture((uint)size, (uint)size);

        // the using statement make sure the cr is disposed at the end,
        // otherwise we get no bling
        using (Cairo.Context cr = this.ctex.Create())
        {
            cr.Tolerance = 0.1;

            // Clear
            cr.Operator = Operator.Clear;
            cr.Paint();
            cr.Operator = Operator.Over;

            cr.Translate(size / 2, size / 2);

            // petals
            for (int i = 0; i < n_groups; i++)
            {
                int n_petals = rand() % 5 + 4;
                cr.Save();

                cr.Rotate(rand() % 6);

                do
                {
                    idx = (rand() % (colors.Length / 3)) * 3;
                } while (idx == last_idx);

                cr.SetSourceRGBA(colors[idx], colors[idx + 1], colors[idx + 2], 0.5);

                int pm1 = rand() % 20;
                int pm2 = rand() % 4;

                for (int j = 0; j < n_petals; j++)
                {
                    cr.Save();

                    cr.Rotate(((2 * Math.PI) / n_petals) * j);

                    cr.NewPath();
                    cr.MoveTo(0, 0);

                    cr.RelCurveTo(petal_size, petal_size, (pm2 + 2) * petal_size,
                                  petal_size, (2 * petal_size) + pm1, 0);

                    cr.RelCurveTo(0 + (pm2 * petal_size), -petal_size, -petal_size,
                                  -petal_size, -((2 * petal_size) + pm1), 0);

                    cr.ClosePath();
                    cr.Fill();
                    cr.Restore();
                }

                petal_size -= rand() % (size / 8);

                cr.Restore();
            }

            // flower center
            do
            {
                idx = (rand() % (colors.Length / 4 / 3)) * 3;
            } while (idx == last_idx);

            if (petal_size < 0)
            {
                petal_size = rand() % 10;
            }

            cr.SetSourceRGBA(colors[idx], colors[idx + 1], colors[idx + 2], 0.5);

            cr.Arc(0, 0, petal_size, 0, Math.PI * 2);
            cr.Fill();
        }
    }
Пример #15
0
		public void image(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

			cr.Translate (0.5, 0.5);
			cr.Rotate (45* Math.PI/180);
			cr.Scale  (1.0/w, 1.0/h);
			cr.Translate (-0.5*w, -0.5*h);

			cr.SetSourceSurface (image, 0, 0);
			cr.Paint ();
			image.Destroy ();
		}
Пример #16
0
		public void imagepattern(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			
			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

			SurfacePattern pattern = new SurfacePattern (image);
			pattern.Extend = Extend.Repeat;

			cr.Translate (0.5, 0.5);
			cr.Rotate (Math.PI / 4);
			cr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
			cr.Translate (- 0.5, - 0.5);

			Matrix matrix = new Matrix ();
			matrix.InitScale (w * 5.0, h * 5.0);
			pattern.Matrix = matrix;

			cr.Source = pattern;

			cr.Rectangle (0, 0, 1.0, 1.0);
			cr.Fill ();

			pattern.Destroy ();
			image.Destroy ();
		}
Пример #17
0
    /**
    The Draw method draws the clock on the given Cairo.Context in a width by
    height -area.

    Draw clears the canvas, sets up the clock transform and calls the clock
    drawing methods. In the clock transform, the clock area coords go from
    -1.0 to 1.0, rotation 0 is at 12:00 and rotation increases clockwise.
    The clock drawing functions are DrawClockFace, DrawHourHand, DrawMinuteHand,
    DrawSecondHand and DrawPin. The transform origin is at the middle of the
    window and the transform preserves the aspect ratio.

    All operations on the context take place inside a Save-Restore -pair.

    @param cr Cairo.Context to draw on.
    @param width The width of the drawable area.
    @param height The height of the drawable area.
      */
    void Draw(Context cr, uint width, uint height)
    {
        uint boxSize = Math.Min (width, height);

        DateTime date = DateTime.Now;

        cr.Save ();
          // Clear the canvas
          cr.Color = new Color (1, 1, 1);
          cr.Rectangle (0, 0, width, height);
          cr.Fill ();

        // Set canvas transform so that the coords go from -1.0 to 1.0,
        // rotation 0.0 is 12:00 and rotation increases clockwise.
        //
        // First, center the clock box to the window.
          cr.Translate ((width - boxSize) / 2.0, (height - boxSize) / 2.0);
        // Then scale the box so that -1.0 .. 1.0 spans the whole box.
          cr.Scale (boxSize / 2.0, boxSize / 2.0);
        // And move the origin to the center of the box.
          cr.Translate (1.0, 1.0);
        // Finally, rotate CCW by 90 degrees to make rotation 0 point up.
        // We don't need to flip the rotation direction, because angle grows
        // clockwise in the "Y grows down" default transform.
          cr.Rotate (-Math.PI / 2.0);

          // Draw the clock
          DrawClockFace (cr);
          DrawHourHand (cr, (uint)date.Hour);
          DrawMinuteHand (cr, (uint)date.Minute);
          DrawSecondHand (cr, (uint)date.Second);
          DrawPin (cr);
        cr.Restore ();
    }
Пример #18
0
    /**
    Draws the hour hand of the clock.

    @param cr The context to draw on.
    @param hour The hour as an uint between 0 and 23.
      */
    void DrawHourHand(Context cr, uint hour)
    {
        double rot = (double)(hour % 12) / 12.0;
        cr.Save ();
          cr.Rotate (rot * Math.PI * 2.0);
          cr.Rectangle (0.0, -0.1, 0.6, 0.2);
          cr.Color = new Color (0, 0, 0);
          cr.Fill ();
        cr.Restore ();
    }
Пример #19
0
        public override void DrawArrow (Context cr, Gdk.Rectangle alloc, double rotation)
        {
            rotation -= Math.PI / 2.0;

            double x1 = alloc.X;
            double x2 = alloc.Right;
            double x3 = alloc.X + alloc.Width / 2.0;
            double y1 = alloc.Y;
            double y2 = alloc.Bottom;

            double cx = x3;
            double cy = alloc.Y + alloc.Height / 2.0;

            if (rotation != 0) {
                // Rotate about the center of the arrow
                cr.Translate (cx, cy);
                cr.Rotate (rotation);
                cr.Translate (-cx, -cy);
            }

            cr.LineWidth = 1.0;

            bool hz = (rotation % (Math.PI / 2.0)) == 0;
            double dx = hz ? 0 : 0.5;
            double dy = hz ? 0.5 : 0.5;
            cr.Translate (dx, dy);

            cr.MoveTo (x1, y1);
            cr.LineTo (x2, y1);
            cr.LineTo (x3, y2);
            cr.LineTo (x1, y1);

            cr.Color = Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
            cr.FillPreserve ();
            cr.Color = Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal);
            cr.Stroke ();

            cr.Translate (-dx, -dy);

            if (rotation != 0) {
                cr.Translate (cx, cy);
                cr.Rotate (-rotation);
                cr.Translate (-cx, -cy);
            }
        }
Пример #20
0
        public void Rotate90CW()
        {
            int w = PintaCore.Workspace.ImageSize.X;
            int h = PintaCore.Workspace.ImageSize.Y;

            Layer dest = PintaCore.Layers.CreateLayer (string.Empty, h, w);

            using (Cairo.Context g = new Cairo.Context (dest.Surface)) {
                g.Translate (h / 2d, w / 2d);
                g.Rotate (Math.PI / 2);
                g.Translate (-w / 2d, -h / 2d);
                g.SetSource (Surface);

                g.Paint ();
            }

            Surface old = Surface;
            Surface = dest.Surface;
            (old as IDisposable).Dispose ();
        }
Пример #21
0
        private ImageSurface CreateImage(string text, double fontsize, Color wordColor = default(Color), double angle = 0)
        {
            if (text == string.Empty)
                return new ImageSurface(Format.Argb32, 0, 0);
            //			Font font1 = new Font(font,(float)size,FontStyle.Bold);

            g.SetFontSize(fontsize);
            TextExtents te = g.TextExtents(text);

            ImageSurface bm;
            if(angle == 90.0) bm = new ImageSurface(Format.Argb32,(int)Math.Ceiling(te.Height),(int)Math.Ceiling(te.Width));
            else bm = new ImageSurface(Format.Argb32,(int)Math.Ceiling(te.Width),(int)Math.Ceiling(te.Height));
            Context g2 = new Context(bm);
            g2.ScaledFont = g.ScaledFont;
            g2.Color = wordColor;
            /*		g2.Color = new Color(1.0,1.0,1.0);
            g2.Paint();*/
            if(angle == 90.0) {
                g2.MoveTo(-1.0*te.YBearing,te.Width+te.XBearing);
                g2.Rotate(-0.5*Math.PI);
            }
            else g2.MoveTo(-1.0*te.XBearing,-1.0*te.YBearing);
            g2.ShowText(text);
            ((IDisposable)g2).Dispose();
               			return bm;
        }
Пример #22
0
        /// <summary>Draws a group.</summary>
        internal void DrawGroup(Context cr, Rectangle r, double roundSize, double lineWidth, double space, Pango.Layout l, Gtk.Widget expandButton, RibbonGroup w)
        {
            double lineWidth05 = lineWidth/2, lineWidth15 = 3*lineWidth05;
            LinearGradient linGrad;

            double x0 = r.X + roundSize, x1 = r.X + r.Width - roundSize;
            double y0 = r.Y + roundSize, y1 = r.Y + r.Height - roundSize;
            cr.Arc (x1, y1, roundSize - lineWidth05, 0, Math.PI/2);
            cr.Arc (x0 + lineWidth, y1, roundSize - lineWidth05, Math.PI/2, Math.PI);
            cr.Arc (x0, y0, roundSize - lineWidth15, Math.PI, 3*Math.PI/2);
            cr.Arc (x1, y0 + lineWidth, roundSize - lineWidth05, 3*Math.PI/2, 0);
            cr.LineTo (x1 + roundSize - lineWidth05, y1);
            cr.LineWidth = lineWidth;
            cr.Color = colorScheme.Bright;
            cr.Stroke ();

            if(l != null)
            {
                int lblWidth, lblHeight;
                Pango.CairoHelper.UpdateLayout (cr, l);
                l.GetPixelSize(out lblWidth, out lblHeight);

                if(w.LabelPosition == Position.Top || w.LabelPosition == Position.Bottom)
                {
                    double labelY;
                    double bandHeight = lblHeight + 2*space;

                    if(w.LabelPosition == Position.Top)
                    {
                        cr.Arc (x0, y0, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                        cr.Arc (x1, y0, roundSize - lineWidth05, 3*Math.PI/2, 0);
                        double bandY = y0 - roundSize + 2*lineWidth + bandHeight;
                        cr.LineTo (x1 + roundSize - lineWidth15, bandY);
                        cr.LineTo (x0 - roundSize + lineWidth05, bandY);
                        linGrad = new LinearGradient (0, bandY - bandHeight, 0, bandY);
                        linGrad.AddColorStop (0.0, colorScheme.Dark);
                        linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                        cr.Pattern = linGrad;
                        cr.Fill ();
                        linGrad.Destroy ();

                        labelY = bandY - bandHeight - space;
                    }
                    else
                    {
                        cr.Arc (x1, y1, roundSize - lineWidth15, 0, Math.PI/2);
                        cr.Arc (x0, y1 - lineWidth, roundSize - lineWidth05, Math.PI/2, Math.PI);
                        double bandY = y1 + roundSize - 2*lineWidth - bandHeight;
                        cr.LineTo (x0 - roundSize + lineWidth05, bandY);
                        cr.LineTo (x1 + roundSize - lineWidth15, bandY);
                        linGrad = new LinearGradient (0, bandY, 0, bandY + bandHeight);
                        linGrad.AddColorStop (0.0, colorScheme.Dark);
                        linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                        cr.Pattern = linGrad;
                        cr.Fill ();
                        linGrad.Destroy ();

                        labelY = bandY;
                    }

                    double frameSize = 2*lineWidth + space;
                    double availableHorizontalSpace = r.Width - 2 * frameSize;
                    if(expandButton.Visible) availableHorizontalSpace -= expandButton.WidthRequest + space;

                    cr.Save ();
                    cr.Rectangle (r.X + frameSize, labelY, availableHorizontalSpace, bandHeight);
                    cr.Clip ();

                    cr.Color = new Color(1, 1, 1);
                    Pango.CairoHelper.UpdateLayout (cr, l);
                    cr.MoveTo (r.X + frameSize + Math.Max(0, (availableHorizontalSpace - lblWidth) / 2), labelY + space);
                    Pango.CairoHelper.ShowLayout (cr, l);

                    cr.Restore();
                }
                else	// label at right or left
                {
                    double labelX;
                    double bandWidth = lblHeight + 2*space;

                    if(w.LabelPosition == Position.Left)
                    {
                        cr.Arc (x0, y1, roundSize - lineWidth05, Math.PI/2, Math.PI);
                        cr.Arc (x0, y0, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                        double bandX = x0 - roundSize + 2*lineWidth + bandWidth;
                        cr.LineTo (bandX, y0 - roundSize + lineWidth05);
                        cr.LineTo (bandX, y1 + roundSize - lineWidth15);
                        linGrad = new LinearGradient (bandX - bandWidth, 0, bandX, 0);
                        linGrad.AddColorStop (0.0, colorScheme.Dark);
                        linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                        cr.Pattern = linGrad;
                        cr.Fill ();
                        linGrad.Destroy ();

                        labelX = bandX - bandWidth - space;
                    }
                    else
                    {
                        cr.Arc (x1, y0 - lineWidth05, roundSize - lineWidth15, 3*Math.PI/2, 0);
                        cr.Arc (x1, y1, roundSize - lineWidth15, 0, Math.PI/2);
                        double bandX = x1 + roundSize - 2*lineWidth - bandWidth;
                        cr.LineTo (bandX, y1 + roundSize - lineWidth15);
                        cr.LineTo (bandX, y0 - roundSize + lineWidth05);
                        linGrad = new LinearGradient (bandX, 0, bandX + bandWidth, 0);
                        linGrad.AddColorStop (0.0, colorScheme.Dark);
                        linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                        cr.Pattern = linGrad;
                        cr.Fill ();
                        linGrad.Destroy ();

                        labelX = bandX + space;
                    }

                    double frameSize = 2*lineWidth + space;
                    double availableVerticalSpace = r.Height - 2 * frameSize;
                    if(expandButton.Visible) availableVerticalSpace -= expandButton.HeightRequest + space;

                    cr.Save ();
                    cr.Rectangle (labelX, r.Y + frameSize, bandWidth, availableVerticalSpace);
                    cr.Clip ();
                    cr.Rotate (-Math.PI / 2);

                    cr.Color = new Color(1, 1, 1);
                    Pango.CairoHelper.UpdateLayout (cr, l);
                    double shift = Math.Max(0, (availableVerticalSpace - lblWidth) / 2);
                    if(expandButton.Visible) shift += expandButton.HeightRequest + space;
                    cr.MoveTo (-(r.Y + r.Height - 2 * space - shift), labelX + space);
                    Pango.CairoHelper.ShowLayout (cr, l);

                    cr.Restore();
                }
            }

            cr.MoveTo (x1 + roundSize - lineWidth15, y1);
            cr.Arc (x1, y1, roundSize - lineWidth15, 0, Math.PI/2);
            cr.Arc (x0, y1 - lineWidth, roundSize - lineWidth05, Math.PI/2, Math.PI);
            cr.Arc (x0, y0, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
            cr.Arc (x1 - lineWidth, y0, roundSize - lineWidth05, 3*Math.PI/2, 0);
            cr.LineTo (x1 + roundSize - lineWidth15, y1);
            cr.LineWidth = lineWidth;
            linGrad = new LinearGradient (0, r.Y, 0, r.Y + r.Height - lineWidth);
            linGrad.AddColorStop (0.0, ColorScheme.GetColorRelative (colorScheme.PrettyDark, 0.1));
            linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
            cr.Pattern = linGrad;
            cr.Stroke ();
            linGrad.Destroy ();
        }
Пример #23
0
        public void Rotate90CW()
        {
            double w = PintaCore.Workspace.ImageSize.X;
            double h = PintaCore.Workspace.ImageSize.Y;

            Layer dest = PintaCore.Layers.CreateLayer ("", (int)h, (int)w);

            using (Cairo.Context g = new Cairo.Context (dest.Surface)) {
                g.Translate (h / 2, w / 2);
                g.Rotate (Math.PI / 2);
                g.Translate (-w / 2, -h / 2);
                g.SetSource (Surface);

                g.Paint ();
            }

            Surface old = Surface;
            Surface = dest.Surface;
            (old as IDisposable).Dispose ();
        }
Пример #24
0
    /**
    Draws the minute hand of the clock.

    @param cr The context to draw on.
    @param minute The minute as an uint between 0 and 59.
      */
    void DrawMinuteHand(Context cr, uint minute)
    {
        double rot = (double)minute / 60.0;
        cr.Save ();
          cr.Rotate (rot * Math.PI * 2.0);
          cr.Rectangle (0.0, -0.05, 0.8, 0.1);
          cr.Color = new Color (0, 0, 0);
          cr.Fill ();
        cr.Restore ();
    }
Пример #25
0
		void RenderMonthName (Context cr)
		{
			string month = StartDate.ToString ("MMMM").ToUpper ();
			
			using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {
				layout.FontDescription = new Gtk.Style().FontDescription;
				layout.FontDescription.Weight = Pango.Weight.Bold;
				layout.Ellipsize = Pango.EllipsizeMode.None;
				layout.Width = Pango.Units.FromPixels (Allocation.Height);
				layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Allocation.Height / 6);
				
				cr.Save ();
				cr.Color = new Cairo.Color (1, 1, 1, .5);
				layout.SetText (month);
				
				Pango.Rectangle inkRect, logicalRect;
				layout.GetPixelExtents (out inkRect, out logicalRect);
				double scale = Math.Min (1, Math.Min (Allocation.Height / (double) inkRect.Width, (Allocation.Width / 9.0) / (double) logicalRect.Height));
				
				cr.Rotate (Math.PI / -2.0);
				cr.MoveTo ((Allocation.Height - scale * inkRect.Width) / 2 - Allocation.Height, Allocation.Width / 9 - scale * logicalRect.Height);
				if (scale < 1)
					cr.Scale (scale, scale);
				
				Pango.CairoHelper.LayoutPath (cr, layout);
				cr.Fill ();
				cr.Restore ();
				
				layout.FontDescription.Dispose ();
				layout.Context.Dispose ();
			}
		}
Пример #26
0
        void DrawShape(Context g, int width, int height)
        {
            int inner_x = radius + border + inner;
            int cx = Center.X;
            int cy = Center.Y;

            g.Operator = Operator.Source;
            g.SetSource (new SolidPattern (new Cairo.Color (0,0,0,0)));
            g.Rectangle (0, 0, width, height);
            g.Paint ();

            g.NewPath ();
            g.Translate (cx, cy);
            g.Rotate (angle);

            g.SetSource (new SolidPattern (new Cairo.Color (0.2, 0.2, 0.2, .6)));
            g.Operator = Operator.Over;
            g.Rectangle (0, - (border + inner), inner_x, 2 * (border + inner));
            g.Arc (inner_x, 0, inner + border, 0, 2 * Math.PI);
            g.Arc (0, 0, radius + border, 0, 2 * Math.PI);
            g.Fill ();

            g.SetSource (new SolidPattern (new Cairo.Color (0, 0, 0, 1.0)));
            g.Operator = Operator.DestOut;
            g.Arc (inner_x, 0, inner, 0, 2 * Math.PI);
            #if true
            g.Fill ();
            #else
            g.FillPreserve ();

            g.Operator = Operator.Over;
            RadialGradient rg = new RadialGradient (inner_x - (inner * 0.3), inner * 0.3 , inner * 0.1, inner_x, 0, inner);
            rg.AddColorStop (0, new Cairo.Color (0.0, 0.2, .8, 0.5));
            rg.AddColorStop (0.7, new Cairo.Color (0.0, 0.2, .8, 0.1));
            rg.AddColorStop (1.0, new Cairo.Color (0.0, 0.0, 0.0, 0.0));
            g.Source = rg;
            g.Fill ();
            rg.Destroy ();
            #endif
            g.Operator = Operator.Over;
            g.Matrix = new Matrix ();
            g.Translate (cx, cy);
            if (source != null)
            CairoHelper.SetSourcePixbuf (g, source, -source.Width / 2, -source.Height / 2);

            g.Arc (0, 0, radius, 0, 2 * Math.PI);
            g.Fill ();

            if (overlay != null) {
                CairoHelper.SetSourcePixbuf (g, overlay, -overlay.Width / 2, -overlay.Height / 2);
                g.Arc (0, 0, radius, angle, angle + Math.PI);
                g.ClosePath ();
                g.FillPreserve ();
                g.SetSource (new SolidPattern (new Cairo.Color (1.0, 1.0, 1.0, 1.0)));
                g.Stroke ();
            }
        }
Пример #27
0
 /** FAST */
 void DrawBackground(Context cr, uint width, uint height)
 {
     cr.Save ();
       DrawClear (cr, width, height);
       double t = DateTime.Now.ToFileTime() / 1e7;
       cr.Save ();
     Color ca = Renderer.DirectoryFGColor;
     ca.A = 0.3;
     cr.Color = ca;
     cr.LineWidth = 0.5;
     cr.Translate (270, -50);
     cr.Rotate (0.15);
     for (double y=0; y<6; y++) {
     for (double i=0; i<6-y; i++) {
       cr.Save ();
         double hr = 45;
         double iscale = Math.Sin(-i/20 * Math.PI*2 + CylinderRotation);
         double xscale = Math.Cos(-i/20 * Math.PI*2 + 0.1 + CylinderRotation);
         cr.Translate (iscale * hr * 3, -100 + y*hr*(2*1.732) + hr*(i%2)*1.732);
         hr = 45;
         cr.Scale (xscale, 1);
         cr.NewPath ();
         cr.MoveTo (0, -hr);
         cr.LineTo (0.866*hr, -0.5*hr);
         cr.LineTo (0.866*hr, 0.5*hr);
         cr.LineTo (0, hr);
         cr.LineTo (-0.866*hr, 0.5*hr);
         cr.LineTo (-0.866*hr, -0.5*hr);
         cr.ClosePath ();
         cr.Color = ca;
         cr.Stroke ();
         cr.Color = Renderer.SocketColor;
         cr.Translate (0.75 * -0.866*hr, 0.75 * -0.5*hr);
         double x2 = cr.Matrix.X0, y2 = cr.Matrix.Y0;
         cr.IdentityMatrix ();
         cr.Arc (x2,y2, 1, 0, Math.PI*2);
         cr.Fill ();
       cr.Restore ();
     }
     }
     CylinderRotation += 0.02;
       cr.Restore ();
       if (CurrentDirEntry.InProgress || (t - LastProgress < 3)) {
     if (FirstProgress == 0) { FirstProgress = LastProgress = t; }
     if (CurrentDirEntry.InProgress) LastProgress = t;
     double opacity = Math.Min(3, t-FirstProgress) - Math.Max(0, t-LastProgress);
     t = (t * 0.1) % Math.PI*2;
     Color c = Renderer.RegularFileColor;
     c.A = 0.1*opacity;
     cr.Color = c;
     cr.LineWidth = 1;
     double n = 6;
     double af = Math.PI*2/n;
     double r = 400*(4.4+0.3*cosScale(opacity/3));
     for (double i=0; i<n; i++) {
       cr.Arc (-400*4, 1000/4, r, t+i*af, t+(i+0.7)*af);
       cr.Stroke ();
     }
     for (double i=0; i<n; i++) {
       cr.Arc (-400*4, 1000/4, r+5, -t+i*af, -t+(i+0.7)*af);
       cr.Stroke ();
     }
     if (CurrentDirEntry.InProgress) {
       cr.NewPath ();
         // find FSCache.LastTraversed [or ancestor] y position from model
         // draw line there
       cr.NewPath ();
     }
     LimitedRedraw = true;
       } else {
     FirstProgress = 0;
     LastProgress = 0;
       }
     cr.Restore ();
 }
Пример #28
0
        private void DrawOnHandPieces(Context cr, Position pos, bool BlackPlayer)
        {
            cr.Save();
            cr.Rectangle(0, 0, ON_HAND_AREA_WIDTH, 9 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
            cr.Color = BorderColor;
            cr.FillPreserve();
            cr.Color = new Color(0.6, 0.5, 0.55);
            cr.LineWidth = 3;
            cr.Stroke();

            if (BlackPlayer)
            {
                cr.Translate(0, 8 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
            }

            for (int i = 0; i < (int)PieceType.PIECE_TYPES_COUNT; i++)
            {
                int player_nr = BlackPlayer ? 0 : 1;
                if (pos.OnHandPieces[player_nr, i] != 0)
                {
                    //highlight selected piece
                    if (gi != null && gi.localPlayerMoveState != LocalPlayerMoveState.Wait
                        && gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
                        && gi.GetLocalPlayerMove().OnHandPiece != PieceType.NONE
                        && gi.GetLocalPlayerMove().OnHandPiece == (PieceType)i
                        && !((gi.CurPlayer == gi.BlackPlayer) ^ BlackPlayer))
                    {
                        cr.Rectangle(0, 0, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = new Color(0.8, 0.835, 0.4);
                        cr.Fill();
                    }

                    //draw piece
                    cr.Save();
                    if (!BlackPlayer)
                    {
                        cr.Rotate(180 * Math.PI / 180);
                        cr.Translate(-FIELD_SIZE, -FIELD_SIZE);
                    }
                    cr.Scale(FIELD_SIZE / PieceGraphics[i].Dimensions.Width, FIELD_SIZE / PieceGraphics[i].Dimensions.Width);
                    PieceGraphics[i].RenderCairo(cr);
                    cr.Restore();

                    //draw amount
                    cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
                    cr.SetFontSize(FIELD_SIZE / 3 * 0.9);
                    cr.Color = new Color(0, 0, 0);

                    String amount_str = "x " + pos.OnHandPieces[player_nr, i].ToString();
                    TextExtents extents = cr.TextExtents(amount_str);
                    double x = (FIELD_SIZE);
                    // - (extents.Width/2 + extents.XBearing);
                    double y = (FIELD_SIZE / 2) - (extents.Height / 2 + extents.YBearing);

                    cr.MoveTo(x, y);
                    cr.ShowText(amount_str);

                    double offset = BlackPlayer ? -FIELD_SIZE - PADDING : FIELD_SIZE + PADDING;
                    cr.Translate(0, offset);
                }
            }
            cr.Restore();
        }
Пример #29
0
    /**
    Draws the second hand of the clock.

    @param cr The context to draw on.
    @param second The second as an uint between 0 and 59.
      */
    void DrawSecondHand(Context cr, uint second)
    {
        double rot = (double)second / 60.0;
        cr.Save ();
          cr.Rotate (rot * Math.PI * 2.0);
          cr.Rectangle (0.0, -0.025, 0.9, 0.05);
          cr.Color = new Color (0, 0, 0);
          cr.Fill ();
        cr.Restore ();
    }
Пример #30
0
        public static void RotatePng(ParsedPath pngPath, ImageRotation rotation)
        {
            if (rotation == ImageRotation.None)
                return;

            using (ImageSurface originalImage = new ImageSurface(pngPath))
            {
                int w;
                int h;

                if (rotation == ImageRotation.Left || rotation == ImageRotation.Right)
                {
                    w = originalImage.Height;
                    h = originalImage.Width;
                }
                else
                {
                    w = originalImage.Width;
                    h = originalImage.Height;
                }

                double[] rotationRadians = {0, -Math.PI / 2, Math.PI / 2, Math.PI };

                using (ImageSurface rotatedImage = new ImageSurface(Format.Argb32, w, h))
                {
                    using (Cairo.Context g = new Cairo.Context(rotatedImage))
                    {
                        g.Translate(rotatedImage.Width / 2.0, rotatedImage.Height / 2.0);
                        g.Rotate(rotationRadians[(int)rotation]);
                        g.Translate(-originalImage.Width / 2.0, -originalImage.Height / 2.0);

                        g.SetSourceSurface(originalImage, 0, 0);
                        g.Paint();
                    }

                    rotatedImage.WriteToPng(pngPath);
                }
            }
        }
Пример #31
0
		void MakeAnalogIcon (Context cr, int size)
		{
			int center = size / 2;
			int radius = center;
			
			RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-drop-shadow.svg"), radius * 2);
			RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face-shadow.svg"), radius * 2);
			RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face.svg"), radius * 2);
			RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-marks.svg"), radius * 2);
			
			cr.Translate (center, center);
			cr.Color = new Cairo.Color (.15, .15, .15);
			
			cr.LineWidth = Math.Max (1, size / 48);
			cr.LineCap = LineCap.Round;
			double minuteRotation = 2 * Math.PI * (DateTime.Now.Minute / 60.0) + Math.PI;
			cr.Rotate (minuteRotation);
			cr.MoveTo (0, radius - radius * .35);
			cr.LineTo (0, -radius * .15);
			cr.Stroke ();
			cr.Rotate (-minuteRotation);
			
			cr.Color = new Cairo.Color (0, 0, 0);
			double hourRotation = 2 * Math.PI * (DateTime.Now.Hour / (ShowMilitary ? 24.0 : 12.0)) + 
					Math.PI + (Math.PI / (ShowMilitary ? 12.0 : 6.0)) * DateTime.Now.Minute / 60.0;
			cr.Rotate (hourRotation);
			cr.MoveTo (0, radius - radius * .5);
			cr.LineTo (0, -radius * .15);
			cr.Stroke ();
			cr.Rotate (-hourRotation);
			
			cr.Translate (-center, -center);
			
			RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-glass.svg"), radius * 2);
			RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-frame.svg"), radius * 2);
		}
Пример #32
0
        public void draw(Context cr)
        {
            PointD p = model.position;

            cr.Save();
            cr.Translate (p.X-image.Width/2, p.Y-image.Height/2);
            cr.Rotate (model.ang);
            cr.SetSource(image);
            cr.Paint();

            cr.Restore();
        }
 private void PaintEdges(Context ctx, int w, int h, IEnumerable<NotatedEdge> edges)
 {
     PointD pc, pd;
     foreach(NotatedEdge edge in edges) {
         PointD pa = new PointD(w*edge.Item1.X, h*edge.Item1.Y);
         PointD pb = new PointD(w*edge.Item2.X, h*edge.Item2.Y);
         Utils.CutTowardsCenter(pa, pb, AlgorithmRadius, out pc, out pd);
         double dxr = pc.X-pd.X;
         double dyr = pc.Y-pd.Y;
         double r = Math.Sqrt(dxr*dxr+dyr*dyr);
         ctx.MoveTo(pc);
         ctx.LineTo(pd);
         ctx.Stroke();
         ctx.Save();
         ctx.Translate(pc.X, pc.Y);
         ctx.Rotate(Math.Atan2(pb.Y-pa.Y, pb.X-pa.X));
         double v = 0.0d;//double v = tm/e.Delay;
         foreach(EdgeNotation msg in edge.Item3) {
             TextExtents te = ctx.TextExtents(msg.Item2);
             ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
             ctx.ShowText(msg.Item2);
         }
         ctx.Restore();
         ctx.Save();
         ctx.Translate(pd.X, pd.Y);
         ctx.Rotate(Math.Atan2(pa.Y-pb.Y, pa.X-pb.X));
         foreach(EdgeNotation msg in edge.Item4) {
             TextExtents te = ctx.TextExtents(msg.Item2);
             ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
             ctx.ShowText(msg.Item2);
         }
         ctx.Restore();
     }
 }