コード例 #1
0
        private void DrawPreview()
        {
            if (_noEvents)
            {
                return;
            }

            if (picPreview.Image != null)
            {
                picPreview.Image.Dispose();
            }

            Rectangle rect = picPreview.ClientRectangle;
            Bitmap    bmp  = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics  g    = Graphics.FromImage(bmp);
            IntPtr    ptr  = g.GetHdc();

            //int ptr = g.GetHdc().ToInt32();

            // creating shape to draw
            _options.DrawPoint(ptr, 0.0f, 0.0f, rect.Width, rect.Height, Colors.ColorToUInteger(this.BackColor));

            g.ReleaseHdc();
            picPreview.Image = bmp;
        }
コード例 #2
0
        /// <summary>
        /// Draws shapefile category.
        /// </summary>
        private void DrawShapefileCategorySymbology(int hdcInt, int top, ShapeDrawingOptions options, int categoryIndex, bool hasCheckbox)
        {
            var categoryHeight = _layer.GetCategoryHeight(options);
            var categoryWidth  = _layer.GetCategoryWidth(options);

            var backColor = Convert.ToUInt32(ColorTranslator.ToOle(Legend.BackColor));

            var left = _bounds.Left + Constants.TextLeftPad;

            if (hasCheckbox)
            {
                left += Constants.CategoryCheckboxWidthWithPadding;
            }

            if (categoryWidth != Constants.IconWidth)
            {
                left -= (categoryWidth - Constants.IconWidth) / 2;
            }

            var topCentering = (Constants.ItemHeight - Constants.IconHeight) / 2 - 1;

            switch (_layer.LegendLayerType)
            {
            case LegendLayerType.PointShapefile:
                options.DrawPoint(hdcInt, left, top, categoryWidth + 1, categoryHeight + 1, backColor);
                break;

            case LegendLayerType.LineShapefile:
                options.DrawLine(
                    hdcInt,
                    left,
                    top + topCentering,
                    categoryWidth - 1,
                    Constants.IconHeight - 1,
                    false,
                    categoryWidth,
                    categoryHeight,
                    backColor);
                break;

            case LegendLayerType.PolygonShapefile:
                options.DrawRectangle(
                    hdcInt,
                    left,
                    top + topCentering,
                    categoryWidth - 1,
                    Constants.IconHeight - 1,
                    false,
                    categoryWidth,
                    categoryHeight,
                    backColor);
                break;
            }

            _layer.Elements.Add(LayerElementType.ColorBox, new Rectangle(left, top, categoryWidth, categoryHeight), categoryIndex);
        }
コード例 #3
0
        /// <summary>
        /// Draws preview on the appearance tab
        /// </summary>
        private void DrawAppearancePreview()
        {
            ShpfileType shapeType = _shapefile.ShapefileType;

            for (int i = 0; i < 2; i++)
            {
                ShapeDrawingOptions sdo = new ShapeDrawingOptions();
                PictureBox          pct = new PictureBox();

                pct = pictureBox1;
                sdo = _shapefile.DefaultDrawingOptions;

                if (pct.Image != null)
                {
                    pct.Image.Dispose();
                }

                Rectangle rect = pct.ClientRectangle;
                Bitmap    bmp  = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                Graphics  g    = Graphics.FromImage(bmp);
                IntPtr    ptr  = g.GetHdc();

                if (shapeType == ShpfileType.SHP_POINT || shapeType == ShpfileType.SHP_POINTM || shapeType == ShpfileType.SHP_POINTZ ||
                    shapeType == ShpfileType.SHP_MULTIPOINT || shapeType == ShpfileType.SHP_MULTIPOINTM || shapeType == ShpfileType.SHP_MULTIPOINTZ)
                {
                    sdo.DrawPoint(ptr.ToInt32(), 0.0f, 0.0f, rect.Width, rect.Height, Colors.ColorToUInteger(Color.White));
                }
                else if (shapeType == ShpfileType.SHP_POLYLINE || shapeType == ShpfileType.SHP_POLYLINEZ || shapeType == ShpfileType.SHP_POLYLINEM)
                {
                    if (sdo.UseLinePattern)
                    {
                        sdo.DrawLine(ptr.ToInt32(), 20.0f, 0.0f, 0, 0, true, rect.Width - 40, rect.Height, Colors.ColorToUInteger(Color.White));
                    }
                    else
                    {
                        int w = rect.Width - 40;
                        int h = rect.Height - 40;
                        sdo.DrawLine(ptr.ToInt32(), (rect.Width - w) / 2, (rect.Height - h) / 2, w, h, true, rect.Width, rect.Height, Colors.ColorToUInteger(Color.White));
                    }
                }
                else if (shapeType == ShpfileType.SHP_POLYGON || shapeType == ShpfileType.SHP_POLYGONZ || shapeType == ShpfileType.SHP_POLYGONM)
                {
                    sdo.DrawRectangle(ptr.ToInt32(), rect.Width / 2 - 40, rect.Height / 2 - 40, 80, 80, true, rect.Width, rect.Height, Colors.ColorToUInteger(Color.White));
                }

                g.ReleaseHdc(ptr);
                pct.Image = bmp;
            }
        }
コード例 #4
0
        /// <summary>
        /// 绘制单元格
        /// </summary>
        private void dgvCategories_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex != CMN_STYLE)
            {
                return;
            }
            if (e.RowIndex >= 0 && e.RowIndex < _shapefile.Categories.Count)
            {
                System.Drawing.Image img = e.Value as System.Drawing.Image;
                if (img == null)
                {
                    return;
                }

                ShapefileCategory cat = _shapefile.Categories.get_Item(e.RowIndex);
                if (cat == null)
                {
                    return;
                }
                ShapeDrawingOptions sdo = cat.DrawingOptions;

                Graphics g = Graphics.FromImage(img);
                g.Clear(Color.White);
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode     = SmoothingMode.HighQuality;

                if (_shapefile.ShapefileType == ShpfileType.SHP_POLYGON)
                {
                    sdo.DrawRectangle(g.GetHdc(), 0, 0, img.Width - 1, img.Height - 1, true, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor));
                }
                else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE)
                {
                    sdo.DrawLine(g.GetHdc(), 0, 0, img.Width - 1, img.Height - 1, true, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor));
                }
                else if (_shapefile.ShapefileType == ShpfileType.SHP_POINT)
                {
                    sdo.DrawPoint(g.GetHdc(), 0.0f, 0.0f, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor));
                }

                g.ReleaseHdc();
                g.Dispose();
            }
        }
コード例 #5
0
        /// <summary>
        /// Fills the image list with icons according to the selected colors
        /// </summary>
        public void RefreshImageList()
        {
            if (m_style == ImageComboStyle.Common)
            {
                return;
            }

            m_list.Images.Clear();

            int width;

            if (m_style == ImageComboStyle.PointShape)
            {
                width = 20;
            }
            else if (m_style == ImageComboStyle.ColorSchemeGraduated || m_style == ImageComboStyle.ColorSchemeRandom)
            {
                width = this.Width - 24;
            }
            else
            {
                width = 64;
            }

            Size sz = new Size(width, 16);

            m_list.ImageSize = sz;

            int _imgHeight = m_list.ImageSize.Height;
            int _imgWidth  = m_list.ImageSize.Width;

            Rectangle rect = new Rectangle(m_paddX, m_paddY, _imgWidth - 1 - m_paddX * 2, _imgHeight - 1 - m_paddY * 2);

            Color foreColor = this.Enabled ? Color.Black : Color.Gray;

            for (int i = 0; i < _itemCount; i++)
            {
                Bitmap   img = new Bitmap(_imgWidth, _imgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                Graphics g   = Graphics.FromImage(img);

                switch (m_style)
                {
                // frame type combo
                case ImageComboStyle.FrameType:
                {
                    if (i == 0)
                    {
                        g.FillRectangle(new SolidBrush(_color1), rect);
                        g.DrawRectangle(new Pen(foreColor), rect);
                    }
                    else if (i == 1)
                    {
                        g.FillEllipse(new SolidBrush(_color1), rect);
                        g.DrawEllipse(new Pen(foreColor), rect);
                    }
                    else if (i == 2)
                    {
                        float left   = rect.X;
                        float right  = rect.X + rect.Width;
                        float top    = rect.Y;
                        float bottom = rect.Y + rect.Height;

                        GraphicsPath path = new GraphicsPath();
                        path.StartFigure();
                        path.AddLine(left + (rect.Height / 4), top, right - (rect.Height / 4), top);

                        path.AddLine(right - (rect.Height / 4), top, right, (top + bottom) / 2);
                        path.AddLine(right, (top + bottom) / 2, right - (rect.Height / 4), bottom);

                        path.AddLine(right - (rect.Height / 4), bottom, left + (rect.Height / 4), bottom);

                        path.AddLine(left + (rect.Height / 4), bottom, left, (top + bottom) / 2);
                        path.AddLine(left, (top + bottom) / 2, left + (rect.Height / 4), top);

                        path.CloseFigure();
                        g.FillPath(new SolidBrush(_color1), path);
                        g.DrawPath(new Pen(foreColor), path);
                        path.Dispose();
                        break;
                    }
                    break;
                }

                // linear gradient combo
                case ImageComboStyle.LinearGradient:
                {
                    if ((tkLinearGradientMode)i == tkLinearGradientMode.gmNone)
                    {
                        g.FillRectangle(new SolidBrush(_color1), rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                    }
                    else
                    {
                        LinearGradientBrush lgb = new LinearGradientBrush(rect, _color1, _color2, (LinearGradientMode)i);
                        g.FillRectangle(lgb, rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                        lgb.Dispose();
                    }
                    break;
                }

                //  line style combo
                case ImageComboStyle.LineStyle:
                {
                    Pen pen = new Pen(_outlineColor);
                    pen.DashStyle = (DashStyle)i;
                    pen.Width     = 2;
                    g.DrawLine(pen, new System.Drawing.Point(rect.Left, rect.Top + rect.Height / 2),
                               new System.Drawing.Point(rect.Right, rect.Top + rect.Height / 2));
                    break;
                }

                //  line width combo
                case ImageComboStyle.LineWidth:
                {
                    Pen pen = new Pen(_outlineColor);
                    pen.Width = i + 1;
                    g.DrawLine(pen, new System.Drawing.Point(rect.Left, rect.Top + rect.Height / 2),
                               new System.Drawing.Point(rect.Right, rect.Top + rect.Height / 2));
                    break;
                }

                case ImageComboStyle.PointShape:
                {
                    ShapeDrawingOptions sdo = new ShapeDrawingOptions();
                    sdo.FillColor  = Colors.ColorToUInteger(this._color1);
                    sdo.LineColor  = Colors.ColorToUInteger(this._outlineColor);
                    sdo.PointShape = (tkPointShapeType)i;
                    sdo.PointType  = tkPointSymbolType.ptSymbolStandard;
                    sdo.PointSize  = 12;
                    if (sdo.PointShape == tkPointShapeType.ptShapeStar)
                    {
                        sdo.PointSidesCount = 5;
                        sdo.PointRotation   = 17;
                        sdo.PointSize       = 14;
                    }
                    else if (sdo.PointShape == tkPointShapeType.ptShapeArrow)
                    {
                        sdo.PointSize     = 14;
                        sdo.PointRotation = 0;
                    }
                    else
                    {
                        sdo.PointSidesCount = 4;
                        sdo.PointRotation   = 0;
                        sdo.PointSize       = 12;
                    }

                    IntPtr ptr = g.GetHdc();
                    sdo.DrawPoint(ptr, 0.0f, 0.0f, _imgWidth, _imgHeight, Colors.ColorToUInteger(this.BackColor));
                    g.ReleaseHdc(ptr);
                    break;
                }

                case ImageComboStyle.HatchStyle:
                {
                    HatchBrush br = new HatchBrush((HatchStyle)i, _color1, Color.Transparent);
                    g.FillRectangle(br, rect);
                    g.DrawRectangle(new Pen(_outlineColor), rect);
                    br.Dispose();
                    break;
                }

                case ImageComboStyle.HatchStyleWithNone:
                {
                    if (i == 0)
                    {
                        g.FillRectangle(new SolidBrush(_color1), rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                    }
                    else
                    {
                        HatchBrush br = new HatchBrush((HatchStyle)(i - 1), _color1, Color.Transparent);
                        g.FillRectangle(br, rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                        br.Dispose();
                    }
                    break;
                }

                case ImageComboStyle.ColorSchemeGraduated:
                {
                    if (_colorSchemes != null)
                    {
                        ColorBlend blend = (_colorSchemes.List[i] as ColorBlend);
                        if (blend != null)
                        {
                            LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, Color.White, 0.0f);
                            lgb.InterpolationColors = blend;
                            g.FillRectangle(lgb, rect);
                            g.DrawRectangle(new Pen(_outlineColor), rect);
                            lgb.Dispose();
                            break;
                        }
                    }
                    break;
                }

                case ImageComboStyle.ColorSchemeRandom:
                {
                    if (_colorSchemes != null)
                    {
                        ColorBlend blend = (_colorSchemes.List[i] as ColorBlend);
                        if (blend != null)
                        {
                            MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
                            if (scheme != null)
                            {
                                int    n   = 0;
                                Random rnd = new Random();
                                while (n < _imgWidth)
                                {
                                    Color      clr      = Colors.UintToColor(scheme.get_RandomColor(rnd.NextDouble()));
                                    SolidBrush brush    = new SolidBrush(clr);
                                    Rectangle  rectTemp = new Rectangle(rect.X + n, rect.Y, 8, rect.Height);
                                    g.FillRectangle(brush, rectTemp);
                                    g.DrawRectangle(new Pen(_outlineColor), rectTemp);
                                    brush.Dispose();
                                    n += 8;
                                }
                            }
                        }
                    }
                    break;
                }

                default: return;
                }
                // adding an image
                m_list.Images.Add(img);
            }
        }
コード例 #6
0
        public bool DrawPoint(IntPtr hdc, float x, float y, int clipWidth = 0, int clipHeight = 0, Color?backColor = null)
        {
            var hdcInt = hdc.ToInt32();

            return(_style.DrawPoint(hdcInt, x, y, clipWidth, clipHeight, backColor.ToUInt()));
        }