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


C# IGraphics.CreatePen方法代码示例

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


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

示例1: DrawControlLine

        public static void DrawControlLine(IGraphics g, Color c, DashStyle style, Coordinates loc1, Coordinates loc2, WorldTransform wt)
        {
            float pw = 1.25f / wt.Scale;

            using (IPen p = g.CreatePen()) {
                p.Color = c;
                p.Width = pw;
                p.DashStyle = style;

                g.DrawLine(p, Utility.ToPointF(loc1), Utility.ToPointF(loc2));
            }
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:12,代码来源:DrawingUtility.cs

示例2: DrawArrow

        public static void DrawArrow(IGraphics g, Coordinates startingLoc, Coordinates direction, double len, double headSize, Color lineColor, WorldTransform wt)
        {
            Coordinates endingLoc = startingLoc + direction.Normalize(len);
            Coordinates headPt0 = endingLoc + direction.Rotate(135*Math.PI/180.0).Normalize(headSize);
            Coordinates headPt1 = endingLoc + direction.Rotate(-135*Math.PI/180.0).Normalize(headSize);

            IPen pen = g.CreatePen();
            pen.Width = 3/wt.Scale;
            pen.Color = Color.White;

            PointF ptfStart = Utility.ToPointF(startingLoc);
            PointF ptfEnd = Utility.ToPointF(endingLoc);
            PointF ptfHeadPt0 = Utility.ToPointF(headPt0);
            PointF ptfHeadPt1 = Utility.ToPointF(headPt1);

            PointF[] headPts = new PointF[] { ptfHeadPt0, ptfEnd, ptfHeadPt1 };
            g.DrawLine(pen, ptfStart, ptfEnd);
            g.DrawLines(pen, headPts);

            pen.Width = 1/wt.Scale;
            pen.Color = lineColor;
            g.DrawLine(pen, ptfStart, ptfEnd);
            g.DrawLines(pen, headPts);
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:24,代码来源:DrawingUtility.cs

示例3: DrawZoomBox

        private void DrawZoomBox(IGraphics g, WorldTransform transform, Coordinates start, Coordinates end)
        {
            float x, y;
            float width, height;

            if (start.X < end.X) {
                x = (float)start.X;
                width = (float)(end.X - start.X);
            }
            else {
                x = (float)end.X;
                width = (float)(start.X - end.X);
            }

            if (start.Y < end.Y) {
                y = (float)start.Y;
                height = (float)(end.Y - start.Y);
            }
            else {
                y = (float)end.Y;
                height = (float)(start.Y - end.Y);
            }

            // create the rectangle
            RectangleF rect = new RectangleF(x, y, width, height);

            // draw the transparent background
            g.FillRectangle(Color.FromArgb(50, Color.Purple), rect);

            IPen pen = g.CreatePen();
            pen.Width = 1.0f/transform.Scale;
            pen.Color = Color.Purple;

            g.DrawRectangle(pen, rect);

            pen.Dispose();
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:37,代码来源:ZoomTool.cs

示例4: Render

        public void Render(IGraphics g, WorldTransform wt)
        {
            Coordinates wll = wt.WorldLowerLeft;
            Coordinates wur = wt.WorldUpperRight;

            PointF ll = new PointF((float)wll.X, (float)wll.Y);
            PointF ur = new PointF((float)wur.X, (float)wur.Y);

            float startX = (float)Math.Floor(wll.X / spacing) * spacing;
            float endX = (float)Math.Ceiling(wur.X / spacing) * spacing;
            float startY = (float)Math.Floor(wll.Y / spacing) * spacing;
            float endY = (float)Math.Ceiling(wur.Y / spacing) * spacing;

            IPen p = g.CreatePen();
            p.Color = color;
            p.Width = nominal_pixel_width/wt.Scale;

            string formatString;
            if (spacing >= 1) {
                formatString = "F0";
            }
            else if (spacing >= 0.1) {
                formatString = "F1";
            }
            else if (spacing >= 0.01) {
                formatString = "F2";
            }
            else {
                formatString = "F4";
            }

            // find the largest value (in magnitude) that we'll need to draw, assuming this will be the max length string
            float testVal = Math.Max(Math.Max(Math.Abs(startX), Math.Abs(endX)), Math.Max(Math.Abs(startY), Math.Abs(endY)));
            string testString = testVal.ToString(formatString);
            SizeF nomStringSize = g.MeasureString(testString, labelFont);
            SizeF unitStringSize = g.MeasureString(testString + " m", labelFont);

            float pixelSpacing = spacing * wt.Scale;
            bool drawLabels = showLabels && pixelSpacing >= (nomStringSize.Width + nominal_label_spacing*2);
            bool drawUnits = pixelSpacing >= (unitStringSize.Width + nominal_label_spacing*2);

            float labelSpacing = nominal_label_spacing/wt.Scale;

            // don't draw if there are too many lines
            if ((endX - startX) / spacing <= max_lines && (endY - startY) / spacing <= max_lines && pixelSpacing >= min_pixel_spacing) {
                for (float x = startX; x <= endX; x += spacing) {
                    g.DrawLine(p, new PointF(x, ll.Y), new PointF(x, ur.Y));
                }

                for (float y = startY; y <= endY; y += spacing) {
                    g.DrawLine(p, new PointF(ll.X, y), new PointF(ur.X, y));
                }

                if (drawLabels) {
                    float minX = ll.X + unitStringSize.Width/wt.Scale + 2*labelSpacing;
                    for (float x = startX; x <= endX; x += spacing) {
                        if (x > minX) {
                            g.DrawString(x.ToString(formatString) + (drawUnits ? " m" : ""), labelFont, Color.Black, new PointF(x + labelSpacing, ll.Y + labelSpacing + nomStringSize.Height/wt.Scale));
                        }
                    }

                    for (float y = startY; y <= endY; y += spacing) {
                        g.DrawString(y.ToString(formatString) + (drawUnits ? " m" : ""), labelFont, Color.Black, new PointF(ll.X + labelSpacing, y + labelSpacing));
                    }
                }
            }
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:67,代码来源:GridDisplayObject.cs

示例5: DrawControlPoint

        public static void DrawControlPoint(IGraphics g, Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, bool drawTextBox, WorldTransform wt)
        {
            // figure out the size the control box needs to be in world coordinates to make it
            // show up as appropriate in view coordinates

            // invert the scale
            float scaled_size = 0;
            if (style == ControlPointStyle.LargeBox || style == ControlPointStyle.LargeCircle || style == ControlPointStyle.LargeX) {
                scaled_size = cp_large_size / wt.Scale;
            }
            else {
                scaled_size = cp_small_size / wt.Scale;
            }

            float scaled_offset = 1 / wt.Scale;

            // assume that the world transform is currently applied correctly to the graphics
            RectangleF rect = new RectangleF(-scaled_size / 2, -scaled_size / 2, scaled_size, scaled_size);
            rect.Offset(Utility.ToPointF(loc));
            if (style == ControlPointStyle.LargeBox) {
                g.FillRectangle(Color.White, rect);

                // shrink the rect down a little (nominally 1 pixel)
                rect.Inflate(-scaled_offset, -scaled_offset);
                g.FillRectangle(color, rect);
            }
            else if (style == ControlPointStyle.LargeCircle) {
                g.FillEllipse(Color.White, rect);

                // shrink the rect down a little (nominally 1 pixel)
                rect.Inflate(-scaled_offset, -scaled_offset);
                g.FillEllipse(color, rect);
            }
            else if (style == ControlPointStyle.LargeX) {
                using (IPen p = g.CreatePen()) {
                    p.Width = 3/wt.Scale;
                    p.Color = Color.White;
                    g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom));
                    g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top));

                    p.Width = scaled_offset;
                    p.Color = color;
                    g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom));
                    g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top));
                }
            }
            else if (style == ControlPointStyle.SmallBox) {
                g.FillRectangle(color, rect);
            }
            else if (style == ControlPointStyle.SmallCircle) {
                g.FillEllipse(color, rect);
            }
            else if (style == ControlPointStyle.SmallX) {
                using (IPen p = g.CreatePen()) {
                    p.Width = 3/wt.Scale;
                    p.Color = color;
                    g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom));
                    g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top));
                }
            }

            if (!string.IsNullOrEmpty(label)) {
                SizeF strSize = g.MeasureString(label, label_font);
                float x = 0, y = 0;

                if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight) {
                    x = (float)loc.X + cp_label_space / wt.Scale;
                }
                else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter) {
                    x = (float)loc.X - strSize.Width / (2 * wt.Scale);
                }
                else if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft) {
                    x = (float)loc.X - (strSize.Width + cp_label_space) / wt.Scale;
                }

                if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) {
                    y = (float)loc.Y - cp_label_space / wt.Scale;
                }
                else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) {
                    y = (float)loc.Y + strSize.Height / (2 * wt.Scale);
                }
                else if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight) {
                    y = (float)loc.Y + (strSize.Height + cp_label_space) / wt.Scale;
                }

                PointF text_loc = new PointF(x, y);

                if (drawTextBox) {
                    RectangleF text_rect = new RectangleF(text_loc.X - 4/wt.Scale, text_loc.Y - 4/wt.Scale, strSize.Width/wt.Scale, strSize.Height/wt.Scale);
                    g.FillRectangle(Color.FromArgb(127, Color.White), text_rect);
                }

                g.DrawString(label, label_font, color, text_loc);
            }
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:95,代码来源:DrawingUtility.cs


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