SimpleGraph: DrawEndPoint ...

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

SimpleGraph: DrawEndPoint ...

Postby BadJoker » April 4th, 2006, 11:44 pm

Hi,

I have developed some new end point for links in SimpleGraph and I used to use CANVAS to draw them.

Code: Select all
function DrawEndPoint(Canvas: TCanvas; const Pt: TPoint; const Angle: Double; Style: TLinkBeginEndStyle; Size: Integer): TPoint; virtual;


but in the new version, this has been changed with a function called PointStyleRect.

Now I am confused that I got error message that saying Undeclared indetifier: 'Canvas'

I am using this function to draw an arc with an Angle:



Code: Select all
procedure PlotArc(const Canvas: TCanvas;
                 const Center: TPoint;
                 const Radius: Integer;
                 const StartAngle: Single;
                 const StopAngle: Single);

   // This is a nested function for PlotArc.

   function GetPositionForAngle(const Angle: Single): TPoint;

   var
     CosAngle: Extended;
     SinAngle: Extended;

   begin
     SinCos(DegToRad(Angle), SinAngle, CosAngle);
     Result.X := Round(Center.X + Radius * SinAngle);
     Result.Y := Round(Center.Y - Radius * CosAngle);
   end;

// Main part of PlotArc.

var
 Index: Integer;

begin
 with GetPositionForAngle(StartAngle) do
   Canvas.MoveTo(X, Y);

 for Index := Ceil(StartAngle) to Floor(StopAngle) do
   with GetPositionForAngle(Index) do
     Canvas.LineTo(X, Y);

 with GetPositionForAngle(StopAngle) do
   Canvas.LineTo(X, Y);
end;


and as you can see for that reason I need to get the handle of canvas to draw that arc. It was working fine it version 2 tho.

so would you please tell me how can I do that with the new version?
BadJoker
Active Member
Active Member
 
Posts: 7
Joined: April 3rd, 2006, 11:14 pm

Postby Kambiz » April 5th, 2006, 6:28 am

The following function draws the endpoint. The function returns the intersection of link's segment and endpoint.

Code: Select all
function DrawPointStyle(Canvas: TCanvas; const Pt: TPoint; const Angle: Double;
  Style: TLinkBeginEndStyle; Size: Integer): TPoint; virtual;


The following function returns the amount of pixels that the endpoint occupies on the link's segment. It is used for calculating the relative size of the endpoint, which depends on the pen's width. Also, it is used for proper positioning of the label.

Code: Select all
function PointStyleOffset(Style: TLinkBeginEndStyle; Size: Integer): Integer; virtual;


The following function returns the bounding rectangle of the endpoint. And, it is used for calculating VisualRect of the object. The function should return the proper bounding rectangle, otherwise control does not update the object properly.

Code: Select all
function PointStyleRect(const Pt: TPoint; const Angle: Double;
  Style: TLinkBeginEndStyle; Size: Integer): TRect; virtual;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Kambiz » April 5th, 2006, 6:43 am

By the way, it's more effecient to change your function as follow:

Code: Select all
procedure PlotArc(const Canvas: TCanvas;
                 const Center: TPoint;
                 const Radius: Integer;
                 const StartAngle: Single;
                 const StopAngle: Single);

   function GetPositionForAngle(const Angle: Single): TPoint;
   var
     CosAngle: Extended;
     SinAngle: Extended;
   begin
     SinCos(DegToRad(Angle), SinAngle, CosAngle);
     Result.X := Round(Center.X + Radius * SinAngle);
     Result.Y := Round(Center.Y - Radius * CosAngle);
   end;

begin
  Canvas.PenPos := GetPositionForAngle(StartAngle);
  AngleArc(Canvas.Handle, Center.X, Center.Y, Radius,
    StartAngle - 90, StartAngle - StopAngle);  // for compatibility with your function
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby BadJoker » April 5th, 2006, 10:07 am

Thank you Mr. Kambiz
That has solved my problem and it is working fine now : )
Cheers
BadJoker
Active Member
Active Member
 
Posts: 7
Joined: April 3rd, 2006, 11:14 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron