home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Shapes / Ellipse.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-10-22  |  1.9 KB  |  61 lines

  1. unit Ellipse;
  2. {*******************************************************************************
  3.   ShapesDemo
  4.   Written by David Clegg, davidclegg@optusnet.com.au.
  5.  
  6.   This unit contains the Ellipse class used to render an ellipse onto a GDI+
  7.   drawing surface.
  8. *******************************************************************************}
  9.  
  10. interface
  11.  
  12. uses
  13.   Shape, System.Drawing, System.Drawing.Drawing2D;
  14.  
  15. type
  16.  
  17.   /// <summary>
  18.   /// Class to draw an Ellipse.
  19.   /// </summary>
  20.   TEllipse = class(TShape)
  21.   protected
  22.     function GetShape(pStartPoint, pEndPoint: Point): GraphicsPath; override;
  23.   public
  24.     procedure DrawEllipse(pBrush: Brush; pStartPoint, pEndPoint: Point);
  25.     procedure OutlineEllipse(pPen: Pen; pStartPoint, pEndPoint: Point);
  26.   end;
  27.  
  28. implementation
  29.  
  30. /// <summary>
  31. /// Return a GraphicsPath representing the bounds of the Ellipse based on
  32. /// pStartPoint and pEndPoint.
  33. /// </summary>
  34. function TEllipse.GetShape(pStartPoint, pEndPoint: Point): GraphicsPath;
  35. begin
  36.   Result := GraphicsPath.Create;
  37.   Result.AddEllipse(DoGetRectangle(pStartPoint, pEndPoint));
  38. end;
  39.  
  40. /// <summary>
  41. /// Alternative method to draw an Elipse. Not as good as the
  42. /// inherited Draw method as it doesn't cater for if an endPoint X or Y
  43. /// value is less than its corresponding startPoint value.
  44. /// </summary>
  45. procedure TEllipse.DrawEllipse(pBrush: Brush; pStartPoint,pEndPoint: Point);
  46. begin
  47.   Canvas.FillEllipse(pBrush, DoGetRectangle(pStartPoint, pEndPoint));
  48. end;
  49.  
  50. /// <summary>
  51. /// Alternative method to draw an Elipse outline. Not as good as the
  52. /// inherited Draw method as it doesn't cater for if an endPoint X or Y
  53. /// value is less than its corresponding startPoint value.
  54. /// </summary>
  55. procedure TEllipse.OutlineEllipse(pPen: Pen; pStartPoint, pEndPoint: Point);
  56. begin
  57.   Canvas.DrawEllipse(pPen, DoGetRectangle(pStartPoint, pEndPoint));
  58. end;
  59.  
  60. end.
  61.