// Gets a PlotIcon for a given legend group. Returns cached version if available public static PlotIcon GetIconForGroup(int group) { int colorTotal = SettingsPlotIcon.paletteColor.Count; int shapeTotal = SettingsPlotIcon.paletteShape.Count; if (SettingsPlot.IsTopographic()) { colorTotal = 1; // Force a unique shape per group in topography mode, as color becomes indistinguishable } // Reduce the group number to find repeating icons // For example, 3 shapes and 5 colors makes 15 icons. Group 15 is therefore the same as group 0. group %= colorTotal * shapeTotal; // Return this ploticon if it has already been generated. if (plotIconCache.ContainsKey(group)) { return(plotIconCache[group]); } // Identify which item from each palette should be used. // First iterate through every color, then every palette, and repeat. int colorIndex = group % colorTotal; int shapeIndex = (group / colorTotal) % shapeTotal; // Generate the PlotIcon Color color = SettingsPlot.IsTopographic() ? SettingsPlotTopograph.legendColor : SettingsPlotIcon.paletteColor[colorIndex]; PlotIconShape shape = SettingsPlotIcon.paletteShape[shapeIndex]; PlotIcon plotIcon = new PlotIcon(color, shape); // Register the icon in the cache and return it - Don't cache topography icons as they override the color if (!SettingsPlot.IsTopographic()) { plotIconCache.Add(group, plotIcon); } return(plotIcon); }
// Draw and return the icon image public Image GetIconImage() { // Regenerate the icon image in topography mode, since we tend to update the color if (iconImage != null && !SettingsPlot.IsTopographic()) { return(iconImage); } if (shape.crosshairInner) { icon.DrawLine(pen, halfSize, quartSize, halfSize, threeQuartSize); // Vertical icon.DrawLine(pen, quartSize, halfSize, threeQuartSize, halfSize); // Horizontal } if (shape.crosshairOuter) { icon.DrawLine(pen, halfSize, size, halfSize, threeQuartSize); // Top icon.DrawLine(pen, halfSize, 0, halfSize, quartSize); // Bottom icon.DrawLine(pen, 0, halfSize, quartSize, halfSize); // Left icon.DrawLine(pen, size, halfSize, threeQuartSize, halfSize); // Right } if (shape.diamond) { PointF[] diamondCorners = { new PointF(halfSize, quartSize), // Top new PointF(quartSize, halfSize), // Bottom new PointF(halfSize, threeQuartSize), // Left new PointF(threeQuartSize, halfSize), // Right }; if (shape.fill) { icon.FillPolygon(brush, diamondCorners); } else { icon.DrawPolygon(pen, diamondCorners); } } if (shape.square || shape.circle) { Rectangle halfRadiusRect = new Rectangle((int)quartSize, (int)quartSize, (int)halfSize, (int)halfSize); if (shape.square) { if (shape.fill) { icon.FillRectangle(brush, halfRadiusRect); } else { icon.DrawRectangle(pen, halfRadiusRect); } } if (shape.circle) { if (shape.fill) { icon.FillEllipse(brush, halfRadiusRect); } else { icon.DrawEllipse(pen, halfRadiusRect); } } } iconImage = ImageTools.AdjustARGB(bitmap, Color.FromArgb((int)(iconOpacityPercent / 100f * 255f), color)); iconImage = ImageTools.AddDropShadow(iconImage, lineWidth, (int)(shadowOpacityPercent / 100f * 255f)); return(iconImage); }