- Code: Select all
{ TPictureNode }
TPictureNode = class( TPolygonalNode )
protected
procedure DefineVertices( const ARect: TRect; var Points: TPoints ); override;
public Canvas: TCanvas;
end;
{ TPostnetNode }
TPostnetNode = class( TGraphNode )
protected
procedure Initialize; override; // this creates a TBarcode Component
procedure BoundsChanged( dX, dY, dCX, dCY: Integer ); override; // this redraws the barcode
procedure DrawPostnet( Canvas: TCanvas ); // method to draw the barcode
function CreateRegion: HRGN; override;
procedure DrawBorder( Canvas: TCanvas ); override;
function LinkIntersect( const LinkPt: TPoint; const LinkAngle: Double ): TPoints; override;
end;
{ TPostnetNode }
procedure TPostnetNode.Initialize;
begin
Height := 80;
Width := 300;
fBarcode := TStPNBarCode.Create( nil );
fBarcode.Top := 50;
fBarcode.Left := 230;
fBarcode.Height := 80;
fBarcode.Width := 300;
fBarcode.Visible := False;
fBarcode.PostalCode := '12345';
DrawPostnet( fBackground.Bitmap.Canvas );
Invalidate;
inherited Initialize;
end;
procedure TPostnetNode.Destroy;
begin
fBarcode.Free;
end;
procedure TPostnetNode.BoundsChanged( dX, dY, dCX, dCY: Integer );
begin
DrawPostnet( fBackground.Bitmap.Canvas );
inherited BoundsChanged( dX, dY, dCX, dCY );
end;
procedure TPostnetNode.DrawPostnet( Canvas: TCanvas );
var
P: TPoint;
begin
P := Point( 0, 0 );
fBarCode.PaintToCanvas( fBackground.Bitmap.Canvas, P );
end;
procedure TPostnetNode.DrawBorder( Canvas: TCanvas );
begin
Canvas.Rectangle( Left, Top, Left + Width, Top + Height );
end;
function TPostnetNode.LinkIntersect( const LinkPt: TPoint; const LinkAngle: Double ): TPoints;
begin
Result := IntersectLineRect( LinkPt, LinkAngle, BoundsRect );
end;
function TPostnetNode.CreateRegion: HRGN;
begin
Result := CreateRectRgn( Left, Top, Left + Width + 1, Top + Height + 1 );
end;
Both nodes funcion except that in order to see the barcode I have to open a background image for the barcode to become visible.
The barcode is painted as:
- Code: Select all
procedure TPostnetNode.DrawPostnet( Canvas: TCanvas );
var
P: TPoint;
begin
P := Point( 0, 0 );
fBarCode.PaintToCanvas( fBackground.Bitmap.Canvas, P );
end;
All I need is a canvas so is a fBackground.Bitmap necessary?
The Postnet barcode is from the now open source TurboPower SysTools package so the number of units that has to be added to the TSimpleGraph is only four small SysTools units.
My questions are:
1. What is the best way to create a picture node and a postnet barcode node to TSimpleGraph?
2. Should both the TPictureNode and the TPostnetNode be created as a TPolygonalNode or a TGraphNode?
3. How would you create the background bitmap when the TPostnetNode is created? Where would you create the background bitmap to draw the Postnet barcode?
4. I assume that the best place to get access to a TCanvas is the background bitmap or can a TCanvas be used?
5. Are you interested in looking over the changes when I finish.
Regards,
Bill



