public void SetLegendImage(KSeries series) { Image sdImage; int height = button.Font.Height; const int width = 50; const int padding = 0; const int frame = 3; const int left = 0; int thickness = (series.lineStyle == KLineStyle.Thick) ? 3 : (series.lineMode == KLineMode.Line) ? 1 : (height - 2 * frame - 1); int framedH = thickness + 2 * frame; int framedY = (height - 2 * padding - framedH) / 2; int framedW = width - 2 * padding; int framedX = left + padding; using (SKBitmap skBitmap = new SKBitmap(left + width, height)) using (SKCanvas skCanvas = new SKCanvas(skBitmap)) using (SKPaint back = new SKPaint { Style = SKPaintStyle.Fill, Color = new SKColor(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A) }) using (SKPaint white = new SKPaint { Style = SKPaintStyle.Fill, Color = new SKColor(255, 255, 255, 255) }) using (SKPaint color = new SKPaint { Style = SKPaintStyle.Fill, Color = series.color }) { skCanvas.DrawRect(new SKRect(0, 0, left + width, height), back); if (series.visible) { skCanvas.DrawRect(new SKRect(framedX, framedY, framedX + framedW, framedY + framedH), white); skCanvas.DrawRect(new SKRect(framedX + frame, framedY + frame, framedX + framedW - frame, framedY + frame + thickness), color); } sdImage = skBitmap.ToBitmap(); } this.button.Image = sdImage; this.button.AutoSize = false; this.button.Size = this.button.Image.Size; }
public void SetLegend() // Called by LegendUpdate { KSeries[] legend = KChartHandler.Legend(); guiControls.menuLegend.ClearMenuItems(); for (int i = legend.Length - 1; i >= 0; i--) { KSeries series = legend[i]; // captured in the OnClick closure series.lineButton = guiControls.menuLegend.NewMenuSection(); series.lineButton.SetLegendImage(series); series.lineButton.OnClick((object s, EventArgs e) => { OnLegendClick(legend, series); }); series.nameButton = guiControls.menuLegend.NewMenuItemButton(); series.nameButton.SetText(series.name); series.nameButton.OnClick((object s, EventArgs e) => { OnLegendClick(legend, series); }); guiControls.menuLegend.AddMenuRow(new KButton[2] { series.lineButton, series.nameButton }); //, pad }); } guiControls.menuLegend.Open(); }
public void OnLegendClick(KSeries[] legend, KSeries series) { if (guiControls.IsShiftDown()) { KChartHandler.ShiftInvertVisible(series.name); foreach (var seriesI in legend) { seriesI.lineButton.SetLegendImage(seriesI); } } else { KChartHandler.InvertVisible(series.name); series.lineButton.SetLegendImage(series); // accessing the shared series data structure! } KChartHandler.VisibilityRemember(); KChartHandler.ChartUpdate(null); // cannot provide style: would have to marshall it throug KGui but is ok to update }
public void SetLegendImage(KSeries series) { NSImage nsImage; int thickness = (series.lineStyle == KLineStyle.Thick) ? 3 : (series.lineMode == KLineMode.Line) ? 1 : 8; const int height = 16; const int width = 50; const int padding = 1; const int frame = 3; const int left = 0; int framedH = thickness + 2 * frame; int framedY = (height - 2 * padding - framedH) / 2; int framedW = width - 2 * padding; int framedX = left + padding; using (CGBitmapContext bitmap = CG.Bitmap(left + width, height)) { CG.DrawRect(bitmap, new CGRect(0, 0, left + width, height), CG.Color(new SKColor(0, 0, 0, 0))); // transparent if (series.visible) { CG.DrawRect(bitmap, new CGRect(framedX, framedY, framedW, framedH), CG.Color(SKColors.White)); CG.DrawRect(bitmap, new CGRect(framedX + frame, framedY + frame, framedW - 2 * frame, thickness), CG.Color(series.color)); } using (CGImage cgImage = bitmap.ToImage()) { nsImage = new NSImage(cgImage, new CGSize(cgImage.Width, cgImage.Height)); } } this.imageDM = nsImage; this.imageLM = nsImage; this.button.Image = nsImage; }