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


C# Context.Translate方法代码示例

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


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

示例1: PatternsAndImages

		public void PatternsAndImages (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			
			ctx.SetColor (Colors.Black);
			// Dashed lines

			ctx.SetLineWidth (2);
			ctx.SetLineDash (15, 10, 10, 5, 5);
			ctx.Rectangle (10, 10, 100, 100);
			ctx.Stroke ();
			ctx.SetLineDash (0);
			
			// Image
			var arcColor = new Color (1, 0, 1);
			ImageBuilder ib = new ImageBuilder (30, 30);
			ib.Context.Arc (15, 15, 15, 0, 360);
			ib.Context.SetColor (arcColor);
			ib.Context.Fill ();
			ib.Context.SetColor (Colors.DarkKhaki);
			ib.Context.Rectangle (0, 0, 5, 5);
			ib.Context.Fill ();
			var img = ib.ToVectorImage ();
			ctx.DrawImage (img, 0, 0);
			ctx.DrawImage (img, 0, 50, 50, 10);
			
			ctx.Arc (100, 100, 15, 0, 360);
			arcColor.Alpha = 0.4;
			ctx.SetColor (arcColor);
			ctx.Fill ();
			
			// ImagePattern
			
			ctx.Save ();
			
			ctx.Translate (x + 130, y);
			ctx.Pattern = new ImagePattern (img);
			ctx.Rectangle (0, 0, 100, 100);
			ctx.Fill ();
			ctx.Restore ();
			
			ctx.Restore ();
			
			// Setting pixels
			
			ctx.SetLineWidth (1);
			for (int i=0; i<50;i++) {
				for (var j=0; j<50;j++) {
					Color c = Color.FromHsl (0.5, (double)i / 50d, (double)j / 50d);
					ctx.Rectangle (i, j, 1, 1);
					ctx.SetColor (c);
					ctx.Fill ();
				}
			}
		}	
开发者ID:m13253,项目名称:xwt,代码行数:56,代码来源:DrawingPatternsAndImages.cs

示例2: Curves2

        public virtual void Curves2(Context ctx, double sx, double sy)
        {
            ctx.Save ();
            ctx.Translate (sx, sy);
            ctx.SetColor (Colors.Black);

            double x = 0, y = 40;
            double x1 = y - x, y1 = x1 + y, x2 = x + y, y2 = x, x3 = y1, y3 = y;

            ctx.MoveTo (x, y);
            ctx.CurveTo (x1, y1, x2, y2, x3, y3);

            ctx.SetLineWidth (2.0);
            ctx.Stroke ();

            ctx.SetColor (new Color (1, 0.2, 0.2, 0.6));
            ctx.SetLineWidth (1.0);
            ctx.MoveTo (x, y);
            ctx.LineTo (x1, y1);
            ctx.MoveTo (x2, y2);
            ctx.LineTo (x3, y3);
            ctx.Stroke ();

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

示例3: OnDraw

		protected override void OnDraw (Context ctx, Rectangle bounds)
		{
			ctx.Save ();
			ctx.Translate (bounds.Location);
			ctx.Scale (bounds.Width / Size.Width, bounds.Height / Size.Height);
			ToolkitEngine.VectorImageRecorderContextHandler.Draw (ctx.Handler, Toolkit.GetBackend (ctx), data);
			ctx.Restore ();
		}
开发者ID:TheBrainTech,项目名称:xwt,代码行数:8,代码来源:VectorImage.cs

示例4: Curves1

        public virtual void Curves1(Context ctx, double x, double y)
        {
            ctx.Save ();
            ctx.Translate (x, y);

            ctx.SetLineWidth (1);
            Action curve1 = () => {
                ctx.MoveTo (0, 30);
                ctx.CurveTo (20, 0, 50, 0, 60, 25);
            };
            // curve2 with lineTo; curve1 is closed
            Action curve2 = () => {
                ctx.LineTo (0, 0);
                ctx.CurveTo (20, 30, 50, 30, 60, 5);
            };
            Action paint = () => {
                curve1 ();
                curve2 ();
                ctx.ClosePath ();
                ctx.SetColor (new Color (0, 0, 0, .5));
                ctx.StrokePreserve ();
                ctx.SetColor (new Color (1, 0, 1, .5));
                ctx.Fill ();
            };
            paint ();

            ctx.Translate (0, 40);
            // curve2 with moveTo; curve1 is open
            curve2 = () => {
                ctx.MoveTo (0, 0);
                ctx.CurveTo (20, 30, 50, 30, 60, 5);
            };
            paint ();
            ctx.Restore ();

            //Todo: same stuff with arc
        }
开发者ID:RevolutionSmythe,项目名称:xwt,代码行数:37,代码来源:DrawingFigures.cs

示例5: OnDraw

        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            ctx.Save ();
            ctx.Translate (-hscroll.Value, -vscroll.Value);
            ctx.Rectangle (new Rectangle (0, 0, imageSize, imageSize));
            ctx.SetColor (Xwt.Drawing.Colors.White);
            ctx.Fill ();
            ctx.Arc (imageSize / 2, imageSize / 2, imageSize / 2 - 20, 0, 360);
            ctx.SetColor (new Color (0,0,1));
            ctx.Fill ();
            ctx.Restore ();

            ctx.Rectangle (0, 0, Bounds.Width, 30);
            ctx.SetColor (new Color (1, 0, 0, 0.5));
            ctx.Fill ();
        }
开发者ID:praveen9947,项目名称:xwt,代码行数:16,代码来源:ScrollWindowSample.cs

示例6: Rectangles

		public virtual void Rectangles (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			
			// Simple rectangles
			
			ctx.SetLineWidth (1);
			ctx.Rectangle (0, 0, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (15, 0, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Stroke ();
			
			ctx.SetLineWidth (3);
			ctx.Rectangle (0, 15, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (15, 15, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Stroke ();
			
			ctx.Restore ();
			
			// Rectangle with hole
			ctx.Save ();
			ctx.Translate (x + 50, y);
			
			ctx.Rectangle (0, 0, 40, 40);
			ctx.MoveTo (35, 35);
			ctx.RelLineTo (0, -20);
			ctx.RelLineTo (-20, 0);
			ctx.RelLineTo (0, 20);
			ctx.ClosePath ();
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Restore ();
			
			// Rounded Rectangle with Arcs
			ctx.Save ();
			ctx.Translate (x + 120, y);
			
			var r = 5;
			var l = 0;
			var t = 0;
			var w = 50;
			var h = 30;

			ctx.SetColor (Colors.Black);
			// top left  
			ctx.Arc (l + r, t + r, r, 180, 270);
			// top right 
			ctx.Arc (l + w - r, t + r, r, 270, 0);
			// bottom right  
			ctx.Arc (l + w - r, t + h - r, r, 0, 90);
			// bottom left 
			ctx.Arc (l + r, t + h - r, r, 90, 180);
			
			ctx.ClosePath ();
			ctx.StrokePreserve ();
			ctx.SetColor (Colors.AntiqueWhite);
			ctx.Fill ();
			ctx.Restore ();
		}
开发者ID:m13253,项目名称:xwt,代码行数:68,代码来源:DrawingFigures.cs

示例7: 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

示例8: OnDraw

        protected override sealed void OnDraw(Context ctx, Rectangle bounds)
        {
            var frame = GetFrame (ctx.ScaleFactor);
            var fixedWidth = frame.Bitmap.Width - 2 - frame.StretchableWidth;
            var fixedHeight = frame.Bitmap.Height - 2 - frame.StretchableHeight;
            double totalVariableWidth = bounds.Width - fixedWidth / frame.ScaleFactor;
            double totalVariableHeight = bounds.Height - fixedHeight / frame.ScaleFactor;
            double remainingVariableHeight = totalVariableHeight;

            double y = bounds.Y, yb = 1;
            int tileIndex = 0;

            ctx.Save ();
            if (totalVariableWidth < 0) {
                if (fixedWidth > 0)
                    ctx.Scale (bounds.Width / fixedWidth, 1);
                totalVariableWidth = 0;
            }
            if (totalVariableHeight < 0) {
                if (fixedHeight > 0)
                    ctx.Scale (1, bounds.Height / fixedHeight);
                totalVariableHeight = 0;
            }

            foreach (var vs in frame.VerticalSections) {

                double sh = CalcSectionSize (frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight);

                double x = bounds.X, xb = 1;
                double remainingVariableWidth = totalVariableWidth;

                foreach (var hs in frame.HorizontalSections) {
                    var sourceRegion = new Rectangle (xb, yb, hs.Size, vs.Size);
                    double sw = CalcSectionSize (frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth);
                    var targetRegion = new Rectangle (x, y, sw, sh);

                    if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile) {
                        var t = GetTile (frame, tileIndex, sourceRegion);
                        ctx.DrawImage (t, targetRegion);
                    } else {
                        double pw = hs.Size / frame.ScaleFactor;
                        double ph = vs.Size / frame.ScaleFactor;
                        if (hs.Mode == RenderMode.Stretch) {
                            pw = targetRegion.Width;
                        }
                        if (vs.Mode == RenderMode.Stretch) {
                            ph = targetRegion.Height;
                        }

                        ctx.Save ();
                        ctx.Translate (targetRegion.Location);
                        targetRegion.Location = Point.Zero;
                        ctx.Pattern = new ImagePattern (GetTile (frame, tileIndex, sourceRegion).WithSize (pw, ph));
                        ctx.NewPath ();
                        ctx.Rectangle (targetRegion);
                        ctx.Fill ();
                        ctx.Restore ();
                    }
                    x += sw;
                    xb += hs.Size;
                    tileIndex++;
                }
                yb += vs.Size;
                y += sh;
            }
            ctx.Restore ();
        }
开发者ID:jijamw,项目名称:xwt,代码行数:67,代码来源:NinePatchImage.cs

示例9: 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

示例10: OnDraw

        protected override void OnDraw(Context ctx)
        {
            ctx.Translate (-hscroll.Value, -vscroll.Value);
            ctx.Rectangle (new Rectangle (0, 0, imageSize, imageSize));
            ctx.SetColor (Color.White);
            ctx.Fill ();
            ctx.Arc (imageSize / 2, imageSize / 2, imageSize / 2 - 20, 0, 360);
            ctx.SetColor (new Color (0,0,1));
            ctx.Fill ();
            ctx.ResetTransform ();

            ctx.Rectangle (0, 0, Bounds.Width, 30);
            ctx.SetColor (new Color (1, 0, 0, 0.5));
            ctx.Fill ();
        }
开发者ID:joncham,项目名称:xwt,代码行数:15,代码来源:ScrollWindowSample.cs

示例11: 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

示例12: OnDraw

        /// <summary>
        /// Called when the widget needs to be redrawn
        /// </summary>
        /// <param name='ctx'>
        /// Drawing context
        /// </param>
        /// <param name="dirtyRect"></param>
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            if (Bounds.IsEmpty)
                return;

            base.OnDraw(ctx, dirtyRect);

            // apply scale factor
            dirtyRect.X /= scaleFactor;
            dirtyRect.Y /= scaleFactor;
            dirtyRect.Width /= scaleFactor;
            dirtyRect.Height /= scaleFactor;

            // actual drawing
            bool redraw = Draw(ctx, dirtyRect, scaleFactor);

            // draw minimap
            if (ShowMiniMap && MinWidth > 0 && MinHeight > 0) {
                Point size = new Point(180.0, 180.0 * (MinHeight / MinWidth));
                double minimapScale = Math.Min(size.X / MinWidth, size.Y / MinHeight);
                Point minimapPosition =
                    new Point(
                        scrollview.HorizontalScrollControl.Value + scrollview.HorizontalScrollControl.PageSize - size.X - 16,
                        scrollview.VerticalScrollControl.Value + 16);

                ctx.RoundRectangle(minimapPosition, size.X, size.Y, 6);
                ctx.SetColor(Colors.LightGray.WithAlpha(0.4));
                ctx.Fill();

                ctx.Save();
                ctx.Translate(minimapPosition);
                Draw(ctx, new Rectangle(0, 0, MinWidth, MinHeight), minimapScale);
                ctx.Restore();
            }

            // set canvas min size
            foreach (PipelineNode node in nodes) {
                Rectangle boundwe = node.BoundWithExtras;
                if (boundwe.Right * scaleFactor > MinWidth) {
                    MinWidth = boundwe.Right * scaleFactor + PipelineNode.NodeMargin.Right;
                }
                if (boundwe.Bottom * scaleFactor > MinHeight) {
                    MinHeight = boundwe.Bottom * scaleFactor + PipelineNode.NodeMargin.Bottom;
                }
                Point offset = new Point(Math.Max(0, -boundwe.Left), Math.Max(0, -boundwe.Top));
                if (offset != Point.Zero) {
                    TranslateAllNodesBy(offset);
                    redraw = true;
                    QueueDraw();
                }
            }

            // update things
            if (mouseAction.HasFlag(MouseAction.MoveNode)) {
                // move scrollbar
                Rectangle boundwe = lastSelectedNode.BoundWithExtras;
                boundwe.X *= scaleFactor;
                boundwe.Y *= scaleFactor;
                boundwe.Height *= scaleFactor;
                boundwe.Width *= scaleFactor;

                double viewportRight = scrollview.HorizontalScrollControl.Value + scrollview.Size.Width;
                double offsetH = (nodeToMoveOffset.X + boundwe.Width) * 0.5 / scaleFactor;
                if (boundwe.Right - offsetH > viewportRight) {
                    scrollview.HorizontalScrollControl.Value += boundwe.Right - offsetH - viewportRight;
                } else if (boundwe.Left + offsetH < scrollview.HorizontalScrollControl.Value) {
                    scrollview.HorizontalScrollControl.Value -= scrollview.HorizontalScrollControl.Value - offsetH - boundwe.Left;
                }

                double viewportBottom = scrollview.VerticalScrollControl.Value + scrollview.Size.Height;
                double offsetV = (nodeToMoveOffset.Y + boundwe.Height) * 0.5;
                if (boundwe.Bottom - offsetV > viewportBottom) {
                    scrollview.VerticalScrollControl.Value += boundwe.Bottom - offsetV - viewportBottom;
                } else if (boundwe.Top + offsetV < scrollview.VerticalScrollControl.Value) {
                    scrollview.VerticalScrollControl.Value -= scrollview.VerticalScrollControl.Value - offsetV - boundwe.Top;
                }
            }

            if ((mouseAction.HasFlag(MouseAction.AddEdge) || mouseAction.HasFlag(MouseAction.MoveEdge)) &&
                !mouseAction.HasFlag(MouseAction.AddEdgeNew)) {

                ctx.MoveTo(
                    connectNodesStartMarker.IsInput ?
                        connectNodesStartMarker.Bounds.Left * scaleFactor :
                        connectNodesStartMarker.Bounds.Right * scaleFactor,
                    connectNodesStartMarker.Bounds.Center.Y * scaleFactor
                );
                ctx.LineTo(connectNodesEnd.X * scaleFactor, connectNodesEnd.Y * scaleFactor);
                ctx.Stroke();
            }

            // set redraw finish?
            redrawQueued = redraw;
//.........这里部分代码省略.........
开发者ID:jfreax,项目名称:BAIMP,代码行数:101,代码来源:PipelineView.cs

示例13: OnDraw

        /// <summary>
        /// Draw text.
        /// </summary>
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            // If no template dont draw!
            if (Template == null)
                return;

            // Stop drawing (count size for request)
            CanDraw = false;

            // Clear
            ClearValues();

            // Set Context
            CTX = ctx;

            // Data set
            DrawText("{");
            NextLine();
            Right();
            DrawJson(Template);
            Left();
            DrawText("}");

            // Set image size - scrollbars!
            if (hscroll != null && vscroll != null && (hscroll.UpperValue != maxX || vscroll.UpperValue != Y+20))
            {
                hscroll.UpperValue = maxX;
                vscroll.UpperValue = Y + 20;
            }

            // Start drawing
            CanDraw = true;

            // Clear and draw again! - translate context!
            if (hscroll != null && vscroll != null)
                ctx.Translate(-hscroll.Value, -vscroll.Value);

            // Clear values!
            ClearValues();

            // Data set
            DrawText("{");
            NextLine();
            Right();
            DrawJson(Template);
            Left();
            DrawText("}");
        }
开发者ID:KIV-ASWI-PL2014,项目名称:Director,代码行数:53,代码来源:JSONCanvas.cs

示例14: OnDraw

        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw (ctx, dirtyRect);

            if (!pset) {
                ParentWindow.BoundsChanged += delegate {
                    QueueDraw ();
                };
                pset = true;
            }

            ctx.Rectangle (Bounds);
            ctx.SetColor (Colors.LightGray);
            ctx.Fill ();

            var size = Size;
            size.Width--;
            size.Height--;
            var fx = size.Width / Desktop.Bounds.Width;

            if (Desktop.Bounds.Height * fx > size.Height)
                fx = size.Height / Desktop.Bounds.Height;

            if (Desktop.Bounds.X < 0)
                ctx.Translate (-Desktop.Bounds.X * fx, 0);
            if (Desktop.Bounds.Y < 0)
                ctx.Translate (0, -Desktop.Bounds.Y * fx);

            ctx.SetLineWidth (1);
            foreach (var s in Desktop.Screens) {
                if (s.Bounds != s.VisibleBounds) {
                    var vr = new Rectangle ((int)(s.Bounds.X * fx), (int)(s.Bounds.Y * fx), (int)(s.Bounds.Width * fx), (int)(s.Bounds.Height * fx));
                    vr = vr.Offset (0.5, 0.5);
                    ctx.Rectangle (vr);
                    ctx.SetColor (Colors.White);
                    ctx.FillPreserve ();
                    ctx.SetColor (Colors.Black);
                    ctx.Stroke ();
                }
                var r = new Rectangle ((int)(s.VisibleBounds.X * fx), (int)(s.VisibleBounds.Y * fx), (int)(s.VisibleBounds.Width * fx), (int)(s.VisibleBounds.Height * fx));
                r = r.Offset (0.5, 0.5);
                ctx.Rectangle (r);
                ctx.SetColor (new Color (0.4, 0.62, 0.83));
                ctx.FillPreserve ();
                ctx.SetColor (Colors.Black);
                ctx.Stroke ();

                TextLayout tl = new TextLayout (ctx);
                tl.Text = s.DeviceName;
                tl.Font = Font;
                ctx.DrawTextLayout (tl, r.Center.X - tl.Width / 2, r.Center.Y - tl.Height / 2);
            }

            var wr = ParentWindow.ScreenBounds;
            wr = new Rectangle ((int)(wr.X * fx), (int)(wr.Y * fx), (int)(wr.Width * fx), (int)(wr.Height * fx));
            ctx.Rectangle (wr);
            ctx.SetColor (Colors.Azure.WithAlpha (0.5));
            ctx.FillPreserve ();
            ctx.SetColor (Colors.Azure);
            ctx.Stroke ();
        }
开发者ID:garuma,项目名称:xwt,代码行数:61,代码来源:ScreensSample.cs

示例15: 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


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