Changeset 13114
- Timestamp:
- 11/04/15 13:50:43 (9 years ago)
- Location:
- branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs
r13106 r13114 37 37 private bool SuppressRender { get; set; } 38 38 39 public PictureBox PictureBox { get { return pictureBox; } }40 41 public Color BackgroundColor {42 get { return chart != null ? chart.BackgroundColor : Color.Empty; }43 set {44 if (chart == null || chart.BackgroundColor == value) return;45 chart.BackgroundColor = value;46 }47 }48 49 39 private IChart chart; 50 40 public IChart Chart { … … 112 102 SuppressRender = false; 113 103 if (Chart != null) GenerateImage(); 104 } 105 106 public void RefreshPicture() { 107 pictureBox.Refresh(); 108 } 109 110 public void UpdatePicture() { 111 pictureBox.Update(); 112 } 113 114 public Graphics CreatePictureGraphics() { 115 return pictureBox.CreateGraphics(); 114 116 } 115 117 -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/PanChartMode.cs
r13108 r13114 35 35 public PanChartMode(ChartControl control) : base(control) { } 36 36 37 public override void HandleOnMouseUp(object sender, MouseEventArgs e) {38 base.HandleOnMouseUp(sender, e);39 40 switch (e.Button) {41 case MouseButtons.Middle:42 chartControl.Chart.Unzoom();43 break;44 }45 }46 47 37 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { 48 38 try { … … 56 46 } 57 47 } finally { 58 chartControl. PictureBox.Update();48 chartControl.UpdatePicture(); 59 49 base.HandleOnMouseMove(sender, e); 60 50 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/RulerChartMode.cs
r13108 r13114 43 43 public RulerChartMode(ChartControl control) : base(control) { } 44 44 45 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 46 try { 47 if (startPoint.HasValue) { 48 if (startPoint.Value == e.Location) { 49 startPoint = null; 50 chartControl.RefreshPicture(); 51 } 52 } else 53 startPoint = e.Location; 54 } finally { 55 base.HandleOnMouseDown(sender, e); 56 } 57 } 58 45 59 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { 46 if (startPoint.HasValue) { 47 try { 48 chartControl.PictureBox.Refresh(); 49 DrawCross(startPoint.Value); 50 DrawCross(e.Location); 51 DrawLineBetweenLocations(startPoint.Value, e.Location); 52 } finally { 53 chartControl.PictureBox.Update(); 54 base.HandleOnMouseMove(sender, e); 60 try { 61 if (startPoint.HasValue) { 62 chartControl.RefreshPicture(); 63 using (var graphics = chartControl.CreatePictureGraphics()) { 64 DrawCross(graphics, startPoint.Value); 65 DrawCross(graphics, e.Location); 66 DrawLineBetweenLocations(graphics, startPoint.Value, e.Location); 67 } 55 68 } 69 } finally { 70 base.HandleOnMouseMove(sender, e); 56 71 } 57 72 } 58 73 59 74 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 60 base.HandleOnMouseUp(sender, e); 61 62 switch (e.Button) { 63 case MouseButtons.Left: 64 if (!startPoint.HasValue) 65 startPoint = e.Location; 66 else { 67 if (e.Location != startPoint.Value) 68 DrawInfoBox(e.Location); 69 else { 70 chartControl.PictureBox.Refresh(); 71 chartControl.PictureBox.Update(); 75 try { 76 switch (e.Button) { 77 case MouseButtons.Left: 78 if (startPoint.HasValue && startPoint.Value != e.Location) { 79 using (var graphics = chartControl.CreatePictureGraphics()) 80 DrawInfoBox(graphics, e.Location); 81 startPoint = null; 72 82 } 73 74 startPoint = null;75 }76 break;83 break; 84 } 85 } finally { 86 base.HandleOnMouseUp(sender, e); 77 87 } 78 88 } 79 89 80 protected virtual void DrawCross(Point point) { 81 using (var graphics = chartControl.PictureBox.CreateGraphics()) 90 protected virtual void DrawCross(Graphics graphics, Point point) { 82 91 using (var pen = new Pen(Color.Red)) { 83 92 graphics.DrawLine(pen, point.X - 3, point.Y - 3, point.X + 3, point.Y + 3); … … 86 95 } 87 96 88 protected virtual void DrawLineBetweenLocations(Point startLocation, Point endLocation) { 89 using (var graphics = chartControl.PictureBox.CreateGraphics()) 97 protected virtual void DrawLineBetweenLocations(Graphics graphics, Point startLocation, Point endLocation) { 90 98 using (var pen = new Pen(Color.Red)) 91 99 graphics.DrawLine(pen, startLocation.X, startLocation.Y, endLocation.X, endLocation.Y); 92 100 } 93 101 94 protected virtual void DrawInfoBox( Point location) {102 protected virtual void DrawInfoBox(Graphics graphics, Point location) { 95 103 var offsetP = new Size(location.X - startPoint.Value.X, location.Y - startPoint.Value.Y); 96 104 var offsetW = chartControl.Chart.TransformPixelToWorld(offsetP); … … 98 106 double lengthP = Math.Sqrt(Math.Pow(offsetP.Width, 2) + Math.Pow(offsetP.Height, 2)); 99 107 double lengthW = Math.Sqrt(Math.Pow(offsetW.Width, 2) + Math.Pow(offsetW.Height, 2)); 100 string text = string.Format("Pixel: {0} {1}World: {2:##.###}", Math.Round(lengthP), Environment.NewLine, Math.Round(lengthW, 3));108 string text = string.Format("Pixel: {0} " + Environment.NewLine + "World: {1:##.###}", Math.Round(lengthP), Math.Round(lengthW, 3)); 101 109 102 using (var graphics = chartControl.PictureBox.CreateGraphics()) { 103 var textSize = graphics.MeasureString(text, SystemFonts.DefaultFont); 104 int width = (int)Math.Ceiling(textSize.Width); 105 int height = (int)Math.Ceiling(textSize.Height); 110 var textSize = graphics.MeasureString(text, SystemFonts.DefaultFont); 111 int width = (int)Math.Ceiling(textSize.Width); 112 int height = (int)Math.Ceiling(textSize.Height); 106 113 107 108 109 110 } 114 graphics.FillRectangle(Brushes.White, location.X, location.Y, width, height); 115 graphics.DrawRectangle(Pens.Red, location.X, location.Y, width, height); 116 graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, location.X, location.Y + 2); 117 111 118 } 112 119 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/SelectChartMode.cs
r13108 r13114 33 33 34 34 public override void HandleOnKeyDown(object sender, KeyEventArgs e) { 35 base.HandleOnKeyDown(sender, e); 36 37 switch (e.KeyCode) { 38 case Keys.Delete: 39 if (e.KeyCode == Keys.Delete) { 40 try { 41 chartControl.SuspendRendering(); 42 foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives) 43 chartControl.Chart.Group.Remove(primitive); 44 } finally { chartControl.ResumeRendering(); } 45 } 46 break; 35 try { 36 switch (e.KeyCode) { 37 case Keys.Delete: 38 if (e.KeyCode == Keys.Delete) { 39 try { 40 chartControl.SuspendRendering(); 41 foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives) 42 chartControl.Chart.Group.Remove(primitive); 43 } finally { chartControl.ResumeRendering(); } 44 } 45 break; 46 } 47 } finally { 48 base.HandleOnKeyDown(sender, e); 47 49 } 48 50 } 49 51 50 52 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 51 base.HandleOnMouseDown(sender, e);52 53 53 try { 54 chartControl.SuspendRendering(); 55 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 56 foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation))) 57 sp.Selected = false; 58 var p = chartControl.Chart.GetPrimitive(e.Location); 59 if (p != null) p.Selected = true; 60 } finally { chartControl.ResumeRendering(); } 61 } 62 63 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 64 base.HandleOnMouseUp(sender, e); 65 66 switch (e.Button) { 67 case MouseButtons.Middle: 68 try { 69 chartControl.SuspendRendering(); 70 foreach (var p in chartControl.Chart.Group.SelectedPrimitives) 71 p.Selected = false; 72 } finally { chartControl.ResumeRendering(); } 73 break; 54 switch (e.Button) { 55 case MouseButtons.Left: 56 try { 57 chartControl.SuspendRendering(); 58 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 59 foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation))) 60 sp.Selected = false; 61 var p = chartControl.Chart.GetPrimitive(e.Location); 62 if (p != null) p.Selected = true; 63 } finally { chartControl.ResumeRendering(); } 64 break; 65 } 66 } finally { 67 base.HandleOnMouseDown(sender, e); 74 68 } 75 69 } … … 92 86 } 93 87 } finally { 94 chartControl. PictureBox.Update();88 chartControl.UpdatePicture(); 95 89 base.HandleOnMouseMove(sender, e); 96 90 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomInChartMode.cs
r13108 r13114 38 38 39 39 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 40 base.HandleOnMouseUp(sender, e); 41 42 switch (e.Button) { 43 case MouseButtons.Left: 44 var lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X), Math.Max(e.Y, buttonDownPoint.Y)); 45 var upperRight = new Point(Math.Max(e.X, buttonDownPoint.X), Math.Min(e.Y, buttonDownPoint.Y)); 46 if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) 47 chartControl.Chart.ZoomIn(lowerLeft, upperRight); 48 else chartControl.Chart.ZoomIn(buttonDownPoint); 49 break; 50 case MouseButtons.Middle: 51 chartControl.Chart.Unzoom(); 52 break; 40 try { 41 switch (e.Button) { 42 case MouseButtons.Left: 43 var lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X), Math.Max(e.Y, buttonDownPoint.Y)); 44 var upperRight = new Point(Math.Max(e.X, buttonDownPoint.X), Math.Min(e.Y, buttonDownPoint.Y)); 45 if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) 46 chartControl.Chart.ZoomIn(lowerLeft, upperRight); 47 else chartControl.Chart.ZoomIn(buttonDownPoint); 48 break; 49 case MouseButtons.Middle: 50 chartControl.Chart.Unzoom(); 51 break; 52 } 53 } finally { 54 base.HandleOnMouseUp(sender, e); 53 55 } 54 56 } … … 58 60 switch (e.Button) { 59 61 case MouseButtons.Left: 60 chartControl. PictureBox.Refresh();61 using (var graphics = chartControl. PictureBox.CreateGraphics())62 chartControl.RefreshPicture(); 63 using (var graphics = chartControl.CreatePictureGraphics()) 62 64 using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) { 63 65 graphics.DrawRectangle(pen, … … 70 72 } 71 73 } finally { 72 chartControl. PictureBox.Update();74 chartControl.UpdatePicture(); 73 75 base.HandleOnMouseMove(sender, e); 74 76 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomOutChartMode.cs
r13107 r13114 36 36 37 37 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 38 base.HandleOnMouseUp(sender, e); 39 40 switch (e.Button) { 41 case MouseButtons.Left: 42 chartControl.Chart.ZoomOut(); 43 break; 44 case MouseButtons.Middle: 45 chartControl.Chart.Unzoom(); 46 break; 38 try { 39 switch (e.Button) { 40 case MouseButtons.Left: 41 chartControl.Chart.ZoomOut(); 42 break; 43 case MouseButtons.Middle: 44 chartControl.Chart.Unzoom(); 45 break; 46 } 47 } finally { 48 base.HandleOnMouseUp(sender, e); 47 49 } 48 50 }
Note: See TracChangeset
for help on using the changeset viewer.