Changeset 1234 for trunk/sources
- Timestamp:
- 02/28/09 23:12:10 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Visualization
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/CompositeShape.cs
r987 r1234 8 8 protected RectangleD boundingBox = RectangleD.Empty; 9 9 10 public virtual void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {10 public virtual void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 11 11 foreach (IShape shape in shapes) { 12 shape.Draw(graphics, viewport, clippingArea);12 shape.Draw(graphics, parentViewport, parentClippingArea); 13 13 } 14 14 } -
trunk/sources/HeuristicLab.Visualization/Grid.cs
r1233 r1234 3 3 namespace HeuristicLab.Visualization { 4 4 public class Grid : WorldShape { 5 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {5 public override void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 6 6 shapes.Clear(); 7 7 8 8 foreach (double y in AxisTicks.GetTicks(YAxis.PixelsPerInterval, 9 viewport.Height,9 parentViewport.Height, 10 10 ClippingArea.Height, 11 11 ClippingArea.Y1)) { … … 18 18 19 19 foreach (double x in AxisTicks.GetTicks(XAxis.PixelsPerInterval, 20 viewport.Width,20 parentViewport.Width, 21 21 ClippingArea.Width, 22 22 ClippingArea.X1)) { … … 41 41 shapes.Add(lineZeroY); 42 42 43 base.Draw(graphics, viewport, clippingArea);43 base.Draw(graphics, parentViewport, parentClippingArea); 44 44 } 45 45 } -
trunk/sources/HeuristicLab.Visualization/HorizontalLineShape.cs
r1233 r1234 21 21 } 22 22 23 24 /// <summary> 25 /// Draws the HorizontalLineShape. 26 /// </summary> 27 /// <param name="graphics">graphics handle to draw to</param> 28 /// <param name="viewport">rectangle in value-coordinates to display</param> 29 /// <param name="clippingArea">rectangle in screen-coordinates to draw</param> 30 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) { 23 public override void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 31 24 minLineShape.X1 = ClippingArea.X1; 32 25 minLineShape.X2 = ClippingArea.X2; 33 26 maxLineShape.X1 = ClippingArea.X1; 34 27 maxLineShape.X2 = ClippingArea.X2; 35 base.Draw(graphics, viewport, clippingArea);28 base.Draw(graphics, parentViewport, parentClippingArea); 36 29 } 37 30 -
trunk/sources/HeuristicLab.Visualization/IShape.cs
r635 r1234 2 2 3 3 namespace HeuristicLab.Visualization { 4 /// <summary> 5 /// This is the base interface that has to be implemented by all shapes. 6 /// 7 /// View port 8 /// The view port is the available drawing area on the screen. 9 /// It is specified in the GDI coordinate system. 10 /// 11 /// Clipping area 12 /// The clipping area is the range of values visible on the view port. 13 /// Values outside this area will not be visible (they "get clipped"). 14 /// It can either be inherited from the parent, or it can be overriden 15 /// to create distorted realities (see world shapes). 16 /// It is specified in a world coordinate system. 17 /// 18 /// Bounding box 19 /// The bounding box is the location and the size of a shape on its parent. 20 /// It is specified in the parent's world coordinate system. 21 /// </summary> 4 22 public interface IShape { 5 void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea); 23 /// <summary> 24 /// Draws the shape 25 /// </summary> 26 /// <param name="graphics">The Graphics object used to draw the shape</param> 27 /// <param name="parentViewport">The parent's view port</param> 28 /// <param name="parentClippingArea">The parent's clipping area</param> 29 void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea); 30 31 /// <summary> 32 /// The shape's bounding box 33 /// </summary> 6 34 RectangleD BoundingBox { get; } 7 35 } -
trunk/sources/HeuristicLab.Visualization/LineShape.cs
r1233 r1234 57 57 /// </summary> 58 58 /// <param name="graphics">graphics handle to draw to</param> 59 /// <param name=" viewport">rectangle in value-coordinates to display</param>60 /// <param name=" clippingArea">rectangle in screen-coordinates to draw</param>61 public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {62 Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);59 /// <param name="parentViewport">rectangle in value-coordinates to display</param> 60 /// <param name="parentClippingArea">rectangle in screen-coordinates to draw</param> 61 public void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 62 Rectangle screenRect = Transform.ToScreen(boundingBox, parentViewport, parentClippingArea); 63 63 64 64 graphics.DrawLine(GetPen(), screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top); -
trunk/sources/HeuristicLab.Visualization/RectangleShape.cs
r1233 r1234 25 25 } 26 26 27 public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {28 Rectangle screenRect = Transform.ToScreen(rectangle, viewport, clippingArea);27 public void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 28 Rectangle screenRect = Transform.ToScreen(rectangle, parentViewport, parentClippingArea); 29 29 30 30 graphics.DrawRectangle(GetPen(), screenRect); -
trunk/sources/HeuristicLab.Visualization/TextShape.cs
r1182 r1234 68 68 #region IShape Members 69 69 70 public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {71 int screenX = Transform.ToScreenX(x, viewport, clippingArea);72 int screenY = Transform.ToScreenY(y, viewport, clippingArea);70 public void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 71 int screenX = Transform.ToScreenX(x, parentViewport, parentClippingArea); 72 int screenY = Transform.ToScreenY(y, parentViewport, parentClippingArea); 73 73 74 74 SizeF size = graphics.MeasureString(text, font); -
trunk/sources/HeuristicLab.Visualization/Transform.cs
r931 r1234 2 2 3 3 namespace HeuristicLab.Visualization { 4 /// <summary> 5 /// GDI (or screen) coordinate system 6 /// The GDI coordinate system is specified in pixels. X goes from left to right 7 /// and Y goes from top to bottom. 8 /// 9 /// World coordinate system 10 /// A world coordinate system can be freely specified. X goes from left to 11 /// right and Y goes from bottom to top. 12 /// 13 /// The transformation between world- and screen-coordinate systems is done using 14 /// a view port and a clipping area. 15 /// </summary> 4 16 public static class Transform { 5 6 17 /// <summary> 7 /// Screen to world transformations18 /// Transforms a rectangle in screen coordinates to world coordinates 8 19 /// </summary> 9 /// <param name="rect"> </param>10 /// <param name="viewport"> </param>11 /// <param name="clippingArea"> </param>12 /// <returns> </returns>20 /// <param name="rect">The rectangle in screen coordinates that should be transformed</param> 21 /// <param name="viewport">The target view port</param> 22 /// <param name="clippingArea">The target clipping area</param> 23 /// <returns>The rectangle rect transformed to world coordinates</returns> 13 24 public static RectangleD ToWorld(Rectangle rect, Rectangle viewport, RectangleD clippingArea) { 14 25 double x1 = ToWorldX(rect.Left, viewport, clippingArea); … … 19 30 } 20 31 32 /// <summary> 33 /// Transforms a 2d point in screen coordinates to world coordinates 34 /// </summary> 35 /// <param name="point">The point in screen coordinates that should be transformed</param> 36 /// <param name="viewport">The target view port</param> 37 /// <param name="clippingArea">The target clipping area</param> 38 /// <returns>The point transformed to world coordinates</returns> 21 39 public static PointD ToWorld(Point point, Rectangle viewport, RectangleD clippingArea) { 22 40 double x = ToWorldX(point.X, viewport, clippingArea); … … 25 43 } 26 44 45 /// <summary> 46 /// Transforms a point on the X-axis in screen coordinates to world coordinates 47 /// </summary> 48 /// <param name="x">The point on the X-axis in screen coordinates that should be transformed</param> 49 /// <param name="viewport">The target view port</param> 50 /// <param name="clippingArea">The target clipping area</param> 51 /// <returns>The point transformed to world coordinates</returns> 27 52 public static double ToWorldX(int x, Rectangle viewport, RectangleD clippingArea) { 28 53 return clippingArea.X1 + clippingArea.Width/viewport.Width*(x - viewport.Left); 29 54 } 30 55 56 /// <summary> 57 /// Transforms a point on the Y-axis in screen coordinates to world coordinates 58 /// </summary> 59 /// <param name="y">The point on the Y-axis in screen coordinates that should be transformed</param> 60 /// <param name="viewport">The target view port</param> 61 /// <param name="clippingArea">The target clipping area</param> 62 /// <returns>The point transformed to world coordinates</returns> 31 63 public static double ToWorldY(int y, Rectangle viewport, RectangleD clippingArea) { 32 64 return clippingArea.Y1 - clippingArea.Height/viewport.Height*(y - viewport.Bottom); … … 34 66 35 67 /// <summary> 36 /// World to screen transformations68 /// Transforms a rectangle in world coordinates to screen coordinates 37 69 /// </summary> 38 /// <param name="rect"> </param>39 /// <param name="viewport"> </param>40 /// <param name="clippingArea"> </param>41 /// <returns> </returns>70 /// <param name="rect">The rectangle in world coordinates that should be transformed</param> 71 /// <param name="viewport">The target view port</param> 72 /// <param name="clippingArea">The target clipping area</param> 73 /// <returns>The rectangle rect transformed to screen coordinates</returns> 42 74 public static Rectangle ToScreen(RectangleD rect, Rectangle viewport, RectangleD clippingArea) { 43 75 int left = ToScreenX(rect.X1, viewport, clippingArea); … … 48 80 } 49 81 82 /// <summary> 83 /// Transforms a 2d point in world coordinates to screen coordinates 84 /// </summary> 85 /// <param name="point">The point in world coordinates that should be transformed</param> 86 /// <param name="viewport">The target view port</param> 87 /// <param name="clippingArea">The target clipping area</param> 88 /// <returns>The point transformed to screen coordinates</returns> 50 89 public static Point ToScreen(PointD point, Rectangle viewport, RectangleD clippingArea) { 51 90 int x = ToScreenX(point.X, viewport, clippingArea); … … 54 93 } 55 94 95 /// <summary> 96 /// Transforms a point on the X-axis in world coordinates to screen coordinates 97 /// </summary> 98 /// <param name="x">The point on the X-axis in world coordinates that should be transformed</param> 99 /// <param name="viewport">The target view port</param> 100 /// <param name="clippingArea">The target clipping area</param> 101 /// <returns>The point transformed to screen coordinates</returns> 56 102 public static int ToScreenX(double x, Rectangle viewport, RectangleD clippingArea) { 57 103 return (int)(viewport.Left + viewport.Width/clippingArea.Width*(x - clippingArea.X1)); 58 104 } 59 105 106 /// <summary> 107 /// Transforms a point on the Y-axis in world coordinates to screen coordinates 108 /// </summary> 109 /// <param name="y">The point on the Y-axis in world coordinates that should be transformed</param> 110 /// <param name="viewport">The target view port</param> 111 /// <param name="clippingArea">The target clipping area</param> 112 /// <returns>The point transformed to screen coordinates</returns> 60 113 public static int ToScreenY(double y, Rectangle viewport, RectangleD clippingArea) { 61 114 return (int)(viewport.Bottom - viewport.Height/clippingArea.Height*(y - clippingArea.Y1)); -
trunk/sources/HeuristicLab.Visualization/WorldShape.cs
r1182 r1234 4 4 5 5 namespace HeuristicLab.Visualization { 6 /// <summary> 7 /// World shapes are composite shapes that have their own coordinate system 8 /// which is independent from their parent's coordinate system. 9 /// </summary> 6 10 public class WorldShape : IShape { 7 private RectangleD clippingArea; 11 private RectangleD clippingArea; // own clipping area 8 12 private RectangleD boundingBox; 9 13 … … 13 17 : this(new RectangleD(0, 0, 1, 1), new RectangleD(0, 0, 1, 1)) {} 14 18 19 /// <param name="clippingArea">The new clipping area of this world shape</param> 20 /// <param name="boundingBox">The location and the size of this world shape in the parent's coordinate system</param> 15 21 public WorldShape(RectangleD clippingArea, RectangleD boundingBox) { 16 22 this.clippingArea = clippingArea; … … 18 24 } 19 25 20 public virtual void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {26 public virtual void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 21 27 GraphicsState gstate = graphics.Save(); 22 28 23 Rectangle innerViewport = Transform.ToScreen(boundingBox, viewport, clippingArea); 29 // calculate our drawing area on the screen using our location and 30 // size in the parent (boundingBox), the parent's viewport and the 31 // parent's clipping area 32 Rectangle viewport = Transform.ToScreen(boundingBox, parentViewport, parentClippingArea); 24 33 25 graphics.SetClip( innerViewport);34 graphics.SetClip(viewport); 26 35 27 36 foreach (IShape shape in shapes) { 28 shape.Draw(graphics, innerViewport, this.clippingArea); 37 // draw child shapes using our own clipping area 38 shape.Draw(graphics, viewport, clippingArea); 29 39 } 30 40 … … 37 47 } 38 48 49 /// <summary> 50 /// The world shape's own clipping area. 51 /// This overrides the clipping area of the parent shape. 52 /// </summary> 39 53 public RectangleD ClippingArea { 40 54 get { return clippingArea; } -
trunk/sources/HeuristicLab.Visualization/XAxis.cs
r1233 r1234 13 13 } 14 14 15 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {15 public override void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 16 16 shapes.Clear(); 17 17 18 foreach (double x in AxisTicks.GetTicks(PixelsPerInterval, viewport.Width,18 foreach (double x in AxisTicks.GetTicks(PixelsPerInterval, parentViewport.Width, 19 19 ClippingArea.Width, 20 20 ClippingArea.X1)) { … … 26 26 } 27 27 28 base.Draw(graphics, viewport, clippingArea);28 base.Draw(graphics, parentViewport, parentClippingArea); 29 29 } 30 30 } -
trunk/sources/HeuristicLab.Visualization/YAxis.cs
r1233 r1234 13 13 } 14 14 15 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {15 public override void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) { 16 16 shapes.Clear(); 17 17 18 foreach (double y in AxisTicks.GetTicks(PixelsPerInterval, viewport.Height,18 foreach (double y in AxisTicks.GetTicks(PixelsPerInterval, parentViewport.Height, 19 19 ClippingArea.Height, 20 20 ClippingArea.Y1)) { … … 26 26 } 27 27 28 base.Draw(graphics, viewport, clippingArea);28 base.Draw(graphics, parentViewport, parentClippingArea); 29 29 } 30 30 }
Note: See TracChangeset
for help on using the changeset viewer.