From: Marco W. <in...@ca...> - 2005-02-23 10:29:15
|
I've added a new property to the nodes: published property Layout: TTextLayout read fTextLayout write SetTextLayout default tlCenter; And a routine implementation using it: function TGraphNode.GetTextRect: TRect; var MaxTextRect: TRect; DrawTextFlags: Integer; h: integer; begin if Text <> '' then begin MaxTextRect := GetMaxTextRect; DrawTextFlags := DT_WORDBREAK or DT_NOPREFIX or DT_END_ELLIPSIS or DT_EDITCONTROL or TextAlignFlags[Alignment]; Owner.Canvas.Font := Font; Result := MaxTextRect; h := Windows.DrawText( Owner.Canvas.Handle, PChar(Text), Length(Text), Result, Owner.DrawTextBiDiModeFlags(DrawTextFlags) or DT_CALCRECT); if Result.Right > MaxTextRect.Right then Result.Right := MaxTextRect.Right; if Result.Bottom > MaxTextRect.Bottom then Result.Bottom := MaxTextRect.Bottom; if not IsRectEmpty(Result) then begin { MW stripped any vertical alignment from the horizontal stuff. } case Alignment of taLeftJustify: OffsetRect(Result, Left, 0); taRightJustify: OffsetRect(Result, Left + (MaxTextRect.Right - Result.Right) - Margin, 0); else OffsetRect(Result, Left + (MaxTextRect.Right - Result.Right) div 2, 0); end; { MW added vertical alignment } case Layout of tlTop: OffsetRect(Result, 0, Top); tlCenter: OffsetRect(Result, 0, Top + (MaxTextRect.Bottom - Result.Bottom) div 2); tlBottom: OffsetRect(Result, 0, (MaxTextRect.Bottom-Result.Bottom) - h); end; end; end else FillChar(Result, SizeOf(Result), 0); end; |