CreateToolboxIcon() public static method

public static CreateToolboxIcon ( Bitmap bm ) : ToolboxIcon
bm System.Drawing.Bitmap
return ToolboxIcon
Example #1
0
        // Create a point symbol that can be used to put this symbol onto a map inside
        // a box of the given size (in mm).
        public PointSymDef CreateSymdef(Map map, SymColor color, float boxSize)
        {
            Glyph glyph = new Glyph();

            for (int i = 0; i < strokes.Length; ++i)
            {
                strokes[i].AddToMapGlyph(glyph, color, boxSize);
            }
            glyph.ConstructionComplete();

            // Find a free OCAD ID number.
            string symbolId = map.GetFreeSymbolId(800);

            // Create the symdef
            PointSymDef symdef;

            symdef = new PointSymDef("Description: " + this.GetName(Util.CurrentLangName()), symbolId, glyph, false);

            // Create the toolbox image.
            Bitmap bm = new Bitmap(24, 24);

            using (Graphics g = Graphics.FromImage(bm)) {
                g.Clear(Color.White);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                if (kind >= 'T')
                {
                    g.SetClip(new RectangleF(0, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(0, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                    g.SetClip(new RectangleF(bm.Width / 2, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(-bm.Width * 5F / 3F, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                }
                else
                {
                    Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height));
                }
            }
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(bm);

            // Add the symdef to the map.
            map.AddSymdef(symdef);

            return(symdef);
        }
Example #2
0
        // Render a course onto a map.
        public Map RenderToMap(MapRenderOptions mapRenderOptions)
        {
            // Create the map to render into.
            Map map = new Map(MapUtil.TextMetricsProvider, null);

            if (Count == 0)
            {
                return(map);
            }

            SymColor[] colors = new SymColor[LAYERCOUNT];

            using (map.Write()) {
                // Create dictionary for holding Symdef state
                Dictionary <object, SymDef>         dict         = new Dictionary <object, SymDef>();
                Dictionary <SpecialColor, SymColor> customColors = new Dictionary <SpecialColor, SymColor>();

                // Create white color and white-out symdef.
                SymColor   white     = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[KeyWhiteOut] = whiteArea;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[KeyLayout] = layoutSymDef;

                // Create colors for the special colors.
                short customColorId = 61;
                foreach (CourseObj courseObject in this)
                {
                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        if (!customColors.ContainsKey(courseObject.CustomColor))
                        {
                            CmykColor cmyk = courseObject.CustomColor.CustomColor;
                            customColors.Add(courseObject.CustomColor, map.AddColor(string.Format("Color {0}", customColorId), customColorId,
                                                                                    cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false));
                            ++customColorId;
                        }
                    }
                }

                // Create colors for the regular colors in the correct order (lower on top).
                for (int layerIndex = LAYERCOUNT - 1; layerIndex >= 0; --layerIndex)
                {
                    if (colorName[layerIndex] != null)
                    {
                        // Create the symColor for rendering.
                        colors[layerIndex] = map.AddColor(colorName[layerIndex], ocadColorId[layerIndex],
                                                          colorC[layerIndex], colorM[layerIndex], colorY[layerIndex], colorK[layerIndex], colorOverprint[layerIndex]);
                    }
                }

                foreach (CourseObj courseObject in this)
                {
                    int layerIndex = (int)courseObject.layer;

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Black)
                    {
                        layerIndex = (int)CourseLayer.Descriptions;
                    }

                    SymColor color = colors[layerIndex];

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        color = customColors[courseObject.CustomColor];
                    }

                    courseObject.AddToMap(map, color, mapRenderOptions, dict);
                }
            }

            return(map);
        }