当前位置: 首页>>代码示例>>C#>>正文


C# Context.Rotate方法代码示例

本文整理汇总了C#中Xwt.Drawing.Context.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Rotate方法的具体用法?C# Context.Rotate怎么用?C# Context.Rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Xwt.Drawing.Context的用法示例。


在下文中一共展示了Context.Rotate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawTick


//.........这里部分代码省略.........
                else {
                    // start location.
                    textCenterX = tickStart.X;
                    textCenterY = tickStart.Y;

                    // offset due to text box size.
                    textCenterX -= 0.5 * x1 * textSize.Width;
                    textCenterY -= 0.5 * y1 * textSize.Height;

                    // bring text away from the axis a little bit.
                    textCenterX -= x1*(2.0+FontScale);
                    textCenterY -= y1*(2.0+FontScale);
                }

                // If tick text is angled..
                if (TickTextAngle != 0) {

                    // determine the point we want to rotate text about.
                    Point textScaledTickVector = new Point (
                                                TickScale * x1 * (textSize.Height/2),
                                                TickScale * y1 * (textSize.Height/2) );
                    Point rotatePoint;
                    if (TickTextNextToAxis) {
                        rotatePoint = new Point (
                                            tickStart.X - textScaledTickVector.X,
                                            tickStart.Y - textScaledTickVector.Y);
                    }
                    else {
                        rotatePoint = new Point (
                                            tickEnd.X + textScaledTickVector.X,
                                            tickEnd.Y + textScaledTickVector.Y);
                    }

                    double actualAngle;
                    if (FlipTickText) {
                        double radAngle = TickTextAngle * Math.PI / 180;
                        rotatePoint.X += textSize.Width * Math.Cos (radAngle);
                        rotatePoint.Y += textSize.Width * Math.Sin (radAngle);
                        actualAngle = TickTextAngle + 180;
                    }
                    else {
                        actualAngle = TickTextAngle;
                    }

                    ctx.Save ();

                    ctx.Translate (rotatePoint.X, rotatePoint.Y);
                    ctx.Rotate (actualAngle);

                    Point [] recPoints = new Point [2];
                    recPoints[0] = new Point (0.0, -textSize.Height/2);
                    recPoints[1] = new Point (textSize.Width, textSize.Height);
                    ctx.TransformPoints (recPoints);

                    double t_x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                    double t_x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                    double t_y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                    double t_y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                    boundingBox = Rectangle.Union (boundingBox, new Rectangle (t_x1, t_y1, (t_x2-t_x1), (t_y2-t_y1)));

                    ctx.DrawTextLayout (layout, 0, -textSize.Height/2);

                    t_x2 -= tickStart.X;
                    t_y2 -= tickStart.Y;
                    t_x2 *= 1.25;
                    t_y2 *= 1.25;

                    labelOffset = new Point (t_x2, t_y2);

                    ctx.Restore ();

                    //ctx.Rectangle (boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height);
                    //ctx.Stroke ();

                }
                else 				{
                    double bx1 = (textCenterX - textSize.Width/2);
                    double by1 = (textCenterY - textSize.Height/2);
                    double bx2 = textSize.Width;
                    double by2 = textSize.Height;

                    Rectangle drawRect = new Rectangle (bx1, by1, bx2, by2);
                    // ctx.Rectangle (drawRect);

                    boundingBox = Rectangle.Union (boundingBox, drawRect);

                    // ctx.Rectangle (boundingBox);

                    ctx.DrawTextLayout (layout, bx1, by1);

                    textCenterX -= tickStart.X;
                    textCenterY -= tickStart.Y;
                    textCenterX *= 2.3;
                    textCenterY *= 2.3;

                    labelOffset = new Point (textCenterX, textCenterY);
                }
            }
        }
开发者ID:hwthomas,项目名称:XwPlot,代码行数:101,代码来源:Axis.cs

示例2: DrawLabel

        /// <summary>
        /// Draw the Axis Label
        /// </summary>
        /// <param name="ctx>The Drawing Context with which to draw.</param>
        /// <param name="offset">offset from axis. Should be calculated so as to make sure axis label misses tick labels.</param>
        /// <param name="axisPhysicalMin">The physical position corresponding to the world minimum of the axis.</param>
        /// <param name="axisPhysicalMax">The physical position corresponding to the world maximum of the axis.</param>
        /// <returns>boxed Rectangle indicating bounding box of label. null if no label printed.</returns>
        public object DrawLabel(Context ctx, Point offset, Point axisPhysicalMin, Point axisPhysicalMax)
        {
            if (Label != "") {

                // first calculate any extra offset for axis label spacing.
                double extraOffsetAmount = LabelOffset;
                extraOffsetAmount += 2; // empirically determed - text was too close to axis before this.
                if (AutoScaleText && LabelOffsetScaled) {
                    extraOffsetAmount *= FontScale;
                }
                // now extend offset.
                double offsetLength = Math.Sqrt (offset.X*offset.X + offset.Y*offset.Y);
                if (offsetLength > 0.01) {
                    double x_component = offset.X / offsetLength;
                    double y_component = offset.Y / offsetLength;

                    x_component *= extraOffsetAmount;
                    y_component *= extraOffsetAmount;

                    if (LabelOffsetAbsolute) {
                        offset.X = x_component;
                        offset.Y = y_component;
                    }
                    else {
                        offset.X += x_component;
                        offset.Y += y_component;
                    }
                }

                // determine angle of axis in degrees
                double theta = Math.Atan2 (
                    axisPhysicalMax.Y - axisPhysicalMin.Y,
                    axisPhysicalMax.X - axisPhysicalMin.X);
                theta = theta * 180.0 / Math.PI;

                Point average = new Point (
                    (axisPhysicalMax.X + axisPhysicalMin.X)/2,
                    (axisPhysicalMax.Y + axisPhysicalMin.Y)/2);

                ctx.Save ();

                ctx.Translate (average.X + offset.X , average.Y + offset.Y);	// this is done last.
                ctx.Rotate (theta);												// this is done first.

                TextLayout layout = new TextLayout ();
                layout.Font = labelFontScaled;
                layout.Text = Label;
                Size labelSize = layout.GetSize ();

                //Draw label centered around zero.
                ctx.DrawTextLayout (layout, -labelSize.Width/2, -labelSize.Height/2);

                // now work out physical bounds of Rotated and Translated label.
                Point [] recPoints = new Point [2];
                recPoints[0] = new Point (-labelSize.Width/2, -labelSize.Height/2);
                recPoints[1] = new Point ( labelSize.Width/2, labelSize.Height/2);
                ctx.TransformPoints (recPoints);

                double x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                double x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                double y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                double y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                ctx.Restore ();

                // and return label bounding box.
                return new Rectangle (x1, y1, (x2-x1), (y2-y1));
            }
            return null;
        }
开发者ID:hwthomas,项目名称:XwPlot,代码行数:78,代码来源:Axis.cs

示例3: DrawFocus

 void DrawFocus(Context ctx, Point p)
 {
     // Draw a 'zoom'-style Focus at specified point
     double focusRadius = 32;
     double r = 12, w = focusRadius - 1;
     Point o = Point.Zero;	// Drawing origin
     // Align single-thickness lines on 0.5 pixel coords
     o.X += 0.5;
     o.Y += 0.5;
     ctx.Save ();
     ctx.Translate (p);	// Final translation
     // Hairlines in X-direction
     ctx.MoveTo (o.X + r, o.Y);
     ctx.LineTo (o.X + w, o.Y);
     ctx.MoveTo (o.X - r, o.Y);
     ctx.LineTo (o.X - w, o.Y);
     // Hairlines in Y-direction
     ctx.MoveTo (o.X, o.Y + r);
     ctx.LineTo (o.X, o.Y + w);
     ctx.MoveTo (o.X, o.Y - r);
     ctx.LineTo (o.X, o.Y - w);
     // Inner single-thickness circle
     ctx.MoveTo (o.X + r, o.Y);
     ctx.Arc (o.X, o.Y, r, 0, 360);
     ctx.SetColor (Colors.Black);
     ctx.SetLineWidth (1);
     ctx.Stroke ();
     // Double thickness outer arcs. Draw at (0,0) and rotate
     o = Point.Zero;
     r = 22;
     ctx.Rotate (5);
     ctx.MoveTo (r, 0);
     ctx.Arc (o.X, o.Y, r, 0, 80);
     ctx.MoveTo (o.X, r);
     ctx.Arc (o.X, o.Y, r, 90, 170);
     ctx.MoveTo (-r, o.Y);
     ctx.Arc (o.X, o.Y, r, 180, 260);
     ctx.MoveTo (o.X, -r);
     ctx.Arc (o.X, o.Y, r, 270, 350);
     ctx.SetLineWidth (2);
     ctx.Stroke ();
     ctx.Restore ();
 }
开发者ID:hwthomas,项目名称:XwPlot,代码行数:43,代码来源:PlotZoom.cs

示例4: Path

		public void Path (Context ctx, double px, double py)
		{
			ctx.Save ();
			ctx.Translate (px, py);

			var path = new DrawingPath ();

			path.MoveTo (0.44, 18);
			path.LineTo (-1, 18);
			path.LineTo (-1, 26);
			path.LineTo (0.44, 26);
			path.LineTo (0, 42);
			path.LineTo (29, 21.98);
			path.LineTo (29, 21.98);
			path.LineTo (0, 2);
			path.LineTo (0.44, 18);

			ctx.AppendPath (path);
			ctx.SetColor (Colors.Black);
			ctx.SetLineWidth (2);
			ctx.Stroke ();

			var path2 = path.CopyPath ();

			path2.LineTo (15, 8);
			path2.ClosePath ();

			ctx.Rotate (180);
			ctx.AppendPath (path2);
			ctx.SetColor (Colors.Red);
			ctx.SetLineDash (0, 5);
			ctx.Stroke ();

			ctx.Restore ();
		}
开发者ID:m13253,项目名称:xwt,代码行数:35,代码来源:DrawingFigures.cs

示例5: DrawFocus

        void DrawFocus(Context ctx, Point p)
        {
            // Draw a 'zoom'-style Focus at specified point.
            // Following values draw at (0,0) with Size (64,64)
            double r1 = 12, r2 = 22, w = 31;
            Point o = Point.Zero;	// Drawing origin
            // Align single-thickness lines on 0.5 pixel coords
            o.X += 0.5;
            o.Y += 0.5;

            ctx.Save ();
            ctx.SetColor (Colors.Black);
            ctx.SetLineWidth (1);
            ctx.Translate (p);	// Final translation to point p
            // draw as 4 quadrants, each rotated by +90 degrees
            for (double theta = 0; theta < 300; theta += 90) {
                ctx.Rotate (theta);
                // Hairline in X-direction, ending at x=r1
                ctx.MoveTo (o.X + w, o.Y);
                ctx.LineTo (o.X + r1, o.Y);
                // Inner single-thickness arc
                ctx.Arc (o.X, o.Y, r1, 0, 90);
                ctx.Stroke ();
                // Double thickness outer arc, 10 - 80 degrees. Draw at (0,0) and rotate
                ctx.Save ();
                ctx.Rotate (10);
                ctx.MoveTo (r2, 0);
                ctx.Arc (0, 0, r2, 0, 70);
                ctx.SetLineWidth (2);
                ctx.Stroke ();
                ctx.Restore ();
            }
            ctx.Restore ();
        }
开发者ID:hwthomas,项目名称:XwPlot,代码行数:34,代码来源:OverlayTest.cs


注:本文中的Xwt.Drawing.Context.Rotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。