You've already forked lazarus-ccr
* take into account the border to calc text position
* clean up the text draw code git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1438 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -44,9 +44,6 @@ uses
|
|||||||
LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
|
LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
|
||||||
Dialogs, GraphType, Db, DBCtrls, LMessages;
|
Dialogs, GraphType, Db, DBCtrls, LMessages;
|
||||||
|
|
||||||
Const
|
|
||||||
DefaultStyle = DT_SINGLELINE or DT_END_ELLIPSIS or DT_EXPANDTABS;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
{ Direction of fill }
|
{ Direction of fill }
|
||||||
TFillDirection = (fdLeftToRight, fdRightToLeft, ftTopToBottom, ftBottomToTop);
|
TFillDirection = (fdLeftToRight, fdRightToLeft, ftTopToBottom, ftBottomToTop);
|
||||||
@ -75,7 +72,6 @@ type
|
|||||||
procedure OnFontChanged(Sender: TObject);
|
procedure OnFontChanged(Sender: TObject);
|
||||||
protected
|
protected
|
||||||
{ Protected declarations }
|
{ Protected declarations }
|
||||||
procedure Assign(Source: TPersistent); override;
|
|
||||||
procedure SetCaption(const Value: TCaption); virtual;
|
procedure SetCaption(const Value: TCaption); virtual;
|
||||||
procedure SetFont(Value: TFont); virtual;
|
procedure SetFont(Value: TFont); virtual;
|
||||||
procedure SetMarginLeft(Value: Integer); virtual;
|
procedure SetMarginLeft(Value: Integer); virtual;
|
||||||
@ -85,6 +81,7 @@ type
|
|||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
constructor Create(AOwner: TCustomNetGradient); overload;
|
constructor Create(AOwner: TCustomNetGradient); overload;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure Assign(Source: TPersistent); override;
|
||||||
published
|
published
|
||||||
{ Published-Deklarationen }
|
{ Published-Deklarationen }
|
||||||
property Caption: TCaption read FCaption write SetCaption;
|
property Caption: TCaption read FCaption write SetCaption;
|
||||||
@ -411,36 +408,14 @@ var
|
|||||||
BeginRGBValue : array[0..2] of Byte; { Begin RGB values }
|
BeginRGBValue : array[0..2] of Byte; { Begin RGB values }
|
||||||
RGBDifference : array[0..2] of integer; { Difference between begin and end }
|
RGBDifference : array[0..2] of integer; { Difference between begin and end }
|
||||||
{ RGB values }
|
{ RGB values }
|
||||||
ColorBand , rp,cr: TRect; { Color band rectangular coordinates }
|
ColorBand , rp: TRect; { Color band rectangular coordinates }
|
||||||
I , x : Integer; { Color band index }
|
I : Integer; { Color band index }
|
||||||
R : Byte; { Color band Red value }
|
R : Byte; { Color band Red value }
|
||||||
G : Byte; { Color band Green value }
|
G : Byte; { Color band Green value }
|
||||||
B : Byte; { Color band Blue value }
|
B : Byte; { Color band Blue value }
|
||||||
WorkBmp : TBitmap; { Off screen working bitmap }
|
WorkBmp : TBitmap; { Off screen working bitmap }
|
||||||
DrawStyle : LongInt;
|
|
||||||
TS : TTextStyle;
|
TS : TTextStyle;
|
||||||
GlyphOffs : Integer;
|
BorderOffset: Integer;
|
||||||
//SbCapOffs : Integer;
|
|
||||||
|
|
||||||
procedure DoDrawText(const Text: string; ACanvas: TCanvas; AFont: TFont; var Rect: TRect; Flags: LongInt);
|
|
||||||
begin
|
|
||||||
with ACanvas do
|
|
||||||
begin
|
|
||||||
Font.Assign(AFont);
|
|
||||||
Rect.Left:=Rect.Left; //**
|
|
||||||
if not(Enabled) then
|
|
||||||
begin
|
|
||||||
OffsetRect(Rect, 1, 1);
|
|
||||||
Font.Color := clBtnHighlight;
|
|
||||||
DrawText(Handle, PChar(Text), Length(Text), Rect, Flags);
|
|
||||||
OffsetRect(Rect, -1, -1); //**
|
|
||||||
Font.Color := clBtnShadow;
|
|
||||||
DrawText(Handle, PChar(Text), Length(Text), Rect, Flags);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
DrawText(Handle, PChar(Text), Length(Text), Rect, Flags);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{ Create the working bitmap and set its width and height }
|
{ Create the working bitmap and set its width and height }
|
||||||
@ -539,120 +514,86 @@ begin
|
|||||||
|
|
||||||
{ Copy the working bitmap to the main canvas }
|
{ Copy the working bitmap to the main canvas }
|
||||||
Canvas.Draw(0, 0, WorkBmp);
|
Canvas.Draw(0, 0, WorkBmp);
|
||||||
|
|
||||||
// <TextOut>
|
|
||||||
//Canvas.Brush.Style:= bsClear;
|
|
||||||
Canvas.Font.Assign(FFont);
|
|
||||||
|
|
||||||
//Canvas.Textout(FTextLeft, FTextTop, FCaption); *** Enzo *** Implemetation
|
if FFlatBorder then
|
||||||
if FFlatBorder then
|
begin
|
||||||
begin
|
BorderOffset := BorderWidth;
|
||||||
if BorderWidth > 0 then
|
if BorderWidth > 0 then
|
||||||
begin
|
begin
|
||||||
Canvas.Pen.Width := BorderWidth;
|
Canvas.Pen.Width := BorderWidth;
|
||||||
Canvas.Pen.EndCap := pecSquare;
|
Canvas.Pen.EndCap := pecSquare;
|
||||||
Canvas.Pen.Color := FBorderColor;
|
Canvas.Pen.Color := FBorderColor;
|
||||||
//see if there's a better way of drawing a rectangle since
|
//see if there's a better way of drawing a rectangle since
|
||||||
// in BorderWidth >= 3 glitches occurs
|
// in BorderWidth >= 3 glitches occurs
|
||||||
Canvas.Polyline(GetBorderPoints(rp));
|
Canvas.Polyline(GetBorderPoints(rp));
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if FBevelOuter <> bvNone then
|
BorderOffset := 0;
|
||||||
Canvas.Frame3D(rp, 1, FBevelOuter);
|
if FBevelOuter <> bvNone then
|
||||||
if FBevelInner <> bvNone then
|
begin
|
||||||
Canvas.Frame3D(rp, 1, FBevelInner);
|
Canvas.Frame3D(rp, 1, FBevelOuter);
|
||||||
end;
|
Inc(BorderOffset);
|
||||||
|
end;
|
||||||
|
if FBevelInner <> bvNone then
|
||||||
|
begin
|
||||||
|
Canvas.Frame3D(rp, 1, FBevelInner);
|
||||||
|
Inc(BorderOffset);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
if Caption <> '' then begin
|
Canvas.Font.Assign(FFont);
|
||||||
Font.Assign(Self.Font);
|
TS := Canvas.TextStyle;
|
||||||
Rp := GetClientRect;
|
TS.Alignment := FAlignment;
|
||||||
Inc(Rp.Left, FTextLeft); //5=FMargin
|
TS.Layout := FLayout;
|
||||||
//if FGlyph.DisplayAlign = daLeft then
|
TS.Opaque := False;
|
||||||
// Inc(Rp.Left, GlyphOffs)
|
TS.SystemFont := Canvas.Font.IsDefault;
|
||||||
//else
|
|
||||||
// Dec(R.Right, GlyphOffs);
|
|
||||||
//Dec(R.Right, SbCapOffs);
|
|
||||||
case FAlignment of
|
|
||||||
taLeftJustify : begin
|
|
||||||
DrawStyle := DefaultStyle or DT_LEFT;
|
|
||||||
Inc(Rp.Left, FTextLeft);
|
|
||||||
end;
|
|
||||||
taRightJustify : begin
|
|
||||||
DrawStyle := DefaultStyle or DT_RIGHT;
|
|
||||||
Inc(Rp.Right, FTextLeft);
|
|
||||||
|
|
||||||
end;
|
if Caption <> '' then
|
||||||
taCenter : begin
|
begin
|
||||||
DrawStyle := DefaultStyle or DT_CENTER;
|
Rp := GetClientRect;
|
||||||
Inc(Rp.Left, FTextLeft);
|
InflateRect(Rp, -BorderOffset, -BorderOffset);
|
||||||
end;
|
|
||||||
end;
|
|
||||||
//DrawStyle := DefaultStyle or FAlignment; //Enzo DT_LEFT;
|
|
||||||
|
|
||||||
TS := Canvas.TextStyle;
|
case FAlignment of
|
||||||
TS.Alignment:= CaptionAlignment;
|
taLeftJustify:
|
||||||
//TS.Layout:= tlCenter;
|
Inc(Rp.Left, FTextLeft);
|
||||||
TS.Opaque:= false;
|
taRightJustify:
|
||||||
TS.Clipping:= false;
|
Dec(Rp.Right, FTextLeft);
|
||||||
TS.SystemFont:=Canvas.Font.IsDefault;
|
taCenter:
|
||||||
|
Inc(Rp.Left, FTextLeft * 2);
|
||||||
|
end;
|
||||||
|
|
||||||
CR := Rp;
|
case FLayout of
|
||||||
//cr.left := cr.Left + FTextLeft;
|
tlTop:
|
||||||
//rp.left :=rp.left + FTextLeft;
|
Inc(rp.Top, FTextTop);
|
||||||
rp.Top:= rp.Top + FTextTop;
|
tlBottom:
|
||||||
if FLayout <> tlTop then begin
|
Dec(rp.Bottom, FTextTop);
|
||||||
|
tlCenter:
|
||||||
|
Inc(rp.Top, FTextTop * 2);
|
||||||
|
end;
|
||||||
|
|
||||||
X := Canvas.TextHeight('W');
|
Canvas.TextRect(rp, rp.Left, rp.Top, Caption, TS);
|
||||||
DoDrawText(Caption, WorkBmp.Canvas, Self.Font, CR, DrawStyle or DT_CALCRECT);
|
end;
|
||||||
if FLayout = tlBottom then OffsetRect(Rp, 0, Height - CR.Bottom-2)
|
|
||||||
else OffsetRect(Rp, 0, (Height - CR.Bottom) div 2);
|
|
||||||
end;
|
|
||||||
// if Rp.Right - Rp.Left >= Canvas.TextWidth(Caption[1]) then
|
|
||||||
Canvas.TextRect(rp, rp.Left, rp.Top, Caption, TS);
|
|
||||||
|
|
||||||
|
if FSubCaption.Caption <> '' then
|
||||||
|
begin
|
||||||
|
Canvas.Font.Assign(FSubCaption.Font);
|
||||||
|
Rp := GetClientRect;
|
||||||
|
InflateRect(Rp, -BorderOffset, -BorderOffset);
|
||||||
|
TS.Alignment := taRightJustify;
|
||||||
|
Dec(Rp.Right, FSubCaption.MarginLeft);
|
||||||
|
case FLayout of
|
||||||
|
tlTop:
|
||||||
|
Inc(rp.Top, FSubCaption.MarginTop);
|
||||||
|
tlBottom:
|
||||||
|
Dec(rp.Bottom, FSubCaption.MarginTop);
|
||||||
|
tlCenter:
|
||||||
|
Inc(Rp.Top, FSubCaption.MarginTop * 2);
|
||||||
|
end;
|
||||||
|
Canvas.TextRect(rp, rp.Left, rp.Top, FSubCaption.Caption, TS);
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
//*** Enzo **** SubCaption
|
|
||||||
|
|
||||||
if (FSubCaption.Caption <> '') then begin
|
|
||||||
GlyphOffs := 0;
|
|
||||||
//SbCapOffs := 0;
|
|
||||||
Canvas.Font.Assign(FSubCaption.Font);
|
|
||||||
Rp := GetClientRect;
|
|
||||||
|
|
||||||
//DrawStyle := DefaultStyle or DT_RIGHT;
|
|
||||||
|
|
||||||
// if FLayout <> tlTop then begin
|
|
||||||
// rp:=GetClientRect;
|
|
||||||
X := canvas.TextHeight('W');
|
|
||||||
|
|
||||||
Inc(Rp.Left, ClientWidth - canvas.TextWidth(FSubCaption.Caption) - FSubCaption.MarginLeft);
|
|
||||||
if Rp.Left < SubCaption.FMarginLeft + GlyphOffs then Rp.Left := SubCaption.FMarginLeft + GlyphOffs;
|
|
||||||
//SbCapOffs := Rp.Right - Rp.Left;
|
|
||||||
CR := Rp;
|
|
||||||
Inc(cr.Left, SubCaption.FMarginLeft);
|
|
||||||
rp.Top:= rp.Top+SubCaption.FMarginTop;
|
|
||||||
DoDrawText(FSubCaption.Caption, WorkBmp.Canvas, Self.Font, CR, DT_CALCRECT);
|
|
||||||
if FLayout = tlBottom then begin
|
|
||||||
OffsetRect(Rp, 0, Height - X - Abs(canvas.TextHeight('W') - X) div 2);
|
|
||||||
end else if FLayout = tlTop then begin
|
|
||||||
Font.Assign(Self.Font);
|
|
||||||
end else
|
|
||||||
OffsetRect(Rp, 0, (Height - CR.Bottom) div 2);
|
|
||||||
Canvas.TextRect(rp, rp.Left, rp.Top, FSubCaption.Caption);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
// Border Outer and Inner
|
|
||||||
|
|
||||||
|
|
||||||
// Canvas.Frame3d(rp, 1, bvRaised);
|
|
||||||
// </TextOut>
|
|
||||||
|
|
||||||
{ Release the working bitmap resources }
|
{ Release the working bitmap resources }
|
||||||
WorkBmp.Free;
|
WorkBmp.Free;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user