1 | using System.Collections.Generic;
|
---|
2 | using System.Drawing;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Visualization {
|
---|
5 | public class LegendItem {
|
---|
6 | public LegendItem(string label, Color color) {
|
---|
7 | Label = label;
|
---|
8 | Color = color;
|
---|
9 | }
|
---|
10 |
|
---|
11 | public string Label { get; set; }
|
---|
12 | public Color Color { get; set; }
|
---|
13 | }
|
---|
14 |
|
---|
15 |
|
---|
16 | public class LegendShape : IShape {
|
---|
17 | private readonly Color color;
|
---|
18 |
|
---|
19 | private readonly IList<LegendItem> legendItems = new List<LegendItem>();
|
---|
20 | private readonly RectangleD rect;
|
---|
21 |
|
---|
22 | public LegendShape(double x1, double y1, double x2, double y2, double z, Color color) {
|
---|
23 | rect = new RectangleD(x1, y1, x2, y2);
|
---|
24 | Z = z;
|
---|
25 | this.color = color;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public double Z { get; set; }
|
---|
29 |
|
---|
30 | #region IShape Members
|
---|
31 |
|
---|
32 | public RectangleD BoundingBox {
|
---|
33 | get { return rect; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
|
---|
37 | using (var pen = new Pen(color, 1))
|
---|
38 | using (Brush brush = new SolidBrush(color)) {
|
---|
39 | Rectangle screenRect = Transform.ToScreen(rect, viewport, clippingArea);
|
---|
40 |
|
---|
41 | graphics.DrawRectangle(pen, screenRect);
|
---|
42 | graphics.FillRectangle(brush, screenRect);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | #endregion
|
---|
47 |
|
---|
48 | public void AddLegendItem(LegendItem item) {
|
---|
49 | legendItems.Add(item);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void RemoveLegendItem(LegendItem item) {
|
---|
53 | legendItems.Remove(item);
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void ClearLegendItems() {
|
---|
57 | legendItems.Clear();
|
---|
58 | }
|
---|
59 | }
|
---|
60 | } |
---|