📄 jvqbuttons.pas
字号:
GlyphPos.X := ClientSize.X - Margin - GlyphSize.X;
TextPos.X := GlyphPos.X - Spacing - TextSize.X;
end;
blGlyphTop:
begin
GlyphPos.Y := Margin;
TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
end;
blGlyphBottom:
begin
GlyphPos.Y := ClientSize.Y - Margin - GlyphSize.Y;
TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
end;
end;
{ fixup the result variables }
with GlyphPos do
begin
Inc(X, Client.Left + Offset.X);
Inc(Y, Client.Top + Offset.Y);
end;
OffsetRect(TextBounds, TextPos.X + Client.Left + Offset.X,
TextPos.Y + Client.Top + Offset.Y);
end;
function TJvButtonGlyph.Draw(Canvas: TCanvas; const Client: TRect;
const Offset: TPoint; const Caption: string; Layout: TButtonLayout;
Margin, Spacing: Integer; State: TButtonState; Transparent: Boolean): TRect;
var
GlyphPos: TPoint;
begin
CalcButtonLayout(Canvas, Client, Offset, Caption, Layout, Margin, Spacing,
GlyphPos, Result);
DrawButtonGlyph(Canvas, GlyphPos, State, Transparent);
DrawButtonText(Canvas, Caption, Result, State);
end;
function TJvButtonGlyph.DrawExternal(AGlyph: TBitmap; ANumGlyphs: TNumGlyphs; AColor: TColor; IgnoreOld: Boolean;
Canvas: TCanvas; const Client: TRect; const Offset: TPoint; const Caption: string;
Layout: TButtonLayout; Margin, Spacing: Integer; State: TButtonState; Transparent: Boolean): TRect;
var
OldGlyph: TBitmap;
OldNumGlyphs: TNumGlyphs;
OldColor: TColor;
begin
OldGlyph := FOriginal;
OldNumGlyphs := NumGlyphs;
OldColor := FColor;
try
FOriginal := AGlyph;
NumGlyphs := ANumGlyphs;
FColor := AColor;
GlyphChanged(FOriginal);
Result := Draw(Canvas, Client, Offset, Caption, Layout, Margin,
Spacing, State, Transparent);
finally
FOriginal := OldGlyph;
NumGlyphs := OldNumGlyphs;
FColor := OldColor;
if not IgnoreOld then
GlyphChanged(FOriginal);
end;
end;
procedure TJvButtonGlyph.CalcTextRect(Canvas: TCanvas; var TextRect: TRect;
Caption: string);
begin
TextRect := Rect(0, 0, TextRect.Right - TextRect.Left, 0);
DrawText(Canvas, Caption, Length(Caption), TextRect, DT_CALCRECT);
end;
procedure TJvHTButtonGlyph.DrawButtonText(Canvas: TCanvas; const Caption: string;
TextBounds: TRect; State: TButtonState);
var
Cap: string;
begin
Cap := '<ALIGN CENTER>' + Caption; // Kaczkowski
with Canvas do
begin
Brush.Style := bsClear;
if State = bsDisabled then
begin
OffsetRect(TextBounds, 1, 1);
Font.Color := clBtnHighlight;
ItemHtDraw(Canvas, TextBounds, [], Cap);
OffsetRect(TextBounds, -1, -1);
Font.Color := clBtnShadow;
ItemHtDraw(Canvas, TextBounds, [], Cap);
end
else
ItemHtDraw(Canvas, TextBounds, [], Cap);
end;
end;
procedure TJvHTButtonGlyph.CalcTextRect(Canvas: TCanvas; var TextRect: TRect;
Caption: string);
begin
TextRect := Rect(0, 0, ItemHtWidth(Canvas, TextRect, [], Caption),
ItemHtHeight(Canvas, Caption)); // Kaczkowski
end;
//=== { TJvaCaptionButton } ==================================================
//=== { TJvaColorButton } ====================================================
constructor TJvaColorButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FGlyphDrawer := TJvButtonGlyph.Create;
FCanvas := Canvas;
end;
destructor TJvaColorButton.Destroy;
begin
FreeAndNil(FGlyphDrawer);
inherited Destroy;
end;
procedure TJvaColorButton.Paint;
var
IsDown, IsDefault: Boolean;
State: TButtonState;
begin
if csDestroying in ComponentState then
Exit;
IsDown := Down;
IsDefault := Focused;
if not Enabled then
State := bsDisabled
else
if IsDown then
State := bsDown
else
State := bsUp;
if Assigned(FOnPaint) then
FOnPaint(Self, IsDown, IsDefault, State)
else
DefaultDrawing(IsDown, IsDefault, State);
end;
procedure TJvaColorButton.DefaultDrawing(const IsDown, IsDefault: Boolean; const State: TButtonState);
var
R: TRect;
Flags: Longint;
begin
if (csDestroying in ComponentState) or (FCanvas.Handle = nil) then
Exit;
R := ClientRect;
Flags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT;
if IsDown then
Flags := Flags or DFCS_PUSHED;
if State = bsDisabled then
Flags := Flags or DFCS_INACTIVE;
begin
{ DrawFrameControl doesn't allow for drawing a button as the
default button, so it must be done here. }
if IsFocused or IsDefault then
begin
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Pen.Width := 1;
FCanvas.Brush.Style := bsClear;
FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
{ DrawFrameControl must draw within this border }
InflateRect(R, -1, -1);
end;
{ DrawFrameControl does not draw a pressed button correctly }
if IsDown then
begin
FCanvas.Pen.Color := clBtnShadow;
FCanvas.Pen.Width := 1;
FCanvas.Brush.Color := Color {clBtnFace};
FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
InflateRect(R, -1, -1);
end
else
begin
DrawFrameControl(FCanvas.Handle, R, DFC_BUTTON, Flags);
FCanvas.Pen.Style := psSolid;
FCanvas.Pen.Color := Color {clBtnShadow};
FCanvas.Pen.Width := 1;
FCanvas.Brush.Color := Color;
FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
end;
end;
if IsFocused then
begin
R := ClientRect;
InflateRect(R, -1, -1);
end;
FCanvas.Font := Self.Font;
if IsDown then
OffsetRect(R, 1, 1);
FGlyphDrawer.DrawExternal(Glyph, NumGlyphs, Color, True, FCanvas, R, Point(0, 0), Caption, Layout, Margin,
Spacing, State, False {True});
if IsFocused and IsDefault then
begin
R := ClientRect;
InflateRect(R, -4, -4);
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Brush.Color := Color; {clBtnFace}
DrawFocusRect(FCanvas.Handle, R);
end;
end;
//=== { TJvNoFrameButton } ===================================================
constructor TJvNoFrameButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FGlyphDrawer := TJvButtonGlyph.Create;
FNoBorder := True;
end;
destructor TJvNoFrameButton.Destroy;
begin
FGlyphDrawer.Free;
FGlyphDrawer := nil;
inherited Destroy;
end;
procedure TJvNoFrameButton.Paint;
begin
if not Enabled then
begin
FState := bsDisabled;
// FDragging := False;
end
else
if FState = bsDisabled then
if Down and (GroupIndex <> 0) then
FState := bsExclusive
else
FState := bsUp;
if Assigned(FOnPaint) then
FOnPaint(Self, Down, False, FState)
else
DefaultDrawing(Down, FState);
end;
procedure TJvNoFrameButton.DefaultDrawing(const IsDown: Boolean; const State: TButtonState);
const
DownStyles: array [Boolean] of Integer = (BDR_RAISEDINNER, BDR_SUNKENOUTER);
FillStyles: array [Boolean] of Integer = (BF_MIDDLE, 0);
var
PaintRect: TRect;
Offset: TPoint;
begin
if Flat and not NoBorder then
inherited Paint
else
begin
Canvas.Font := Self.Font;
PaintRect := Rect(0, 0, Width, Height);
if not NoBorder then
begin
DrawEdge(Canvas.Handle, PaintRect, DownStyles[FState in [bsDown, bsExclusive]],
FillStyles[Transparent] or BF_RECT);
InflateRect(PaintRect, -1, -1);
end;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := Color;
Canvas.FillRect(PaintRect);
if NoBorder and (csDesigning in ComponentState) then
DrawDesignFrame(Canvas, PaintRect);
InflateRect(PaintRect, -1, -1);
if FState in [bsDown, bsExclusive] then
begin
if (FState = bsExclusive) then
begin
if Pattern = nil then
CreateBrushPattern(clBtnFace, clBtnHighlight);
Canvas.Brush.Bitmap := Pattern;
Canvas.FillRect(PaintRect);
end;
Offset.X := 1;
Offset.Y := 1;
end
else
begin
Offset.X := 0;
Offset.Y := 0;
end;
{O}
FGlyphDrawer.DrawExternal(Glyph, NumGlyphs, Color, True, Canvas, PaintRect, Offset, Caption, Layout, Margin,
Spacing, FState, False {True});
end;
end;
procedure TJvNoFrameButton.SetNoBorder(Value: Boolean);
begin
if FNoBorder <> Value then
begin
FNoBorder := Value;
Refresh;
end;
end;
//=== { TJvHTButton } ========================================================
constructor TJvHTButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FGlyphDrawer.Free;
FGlyphDrawer := TJvHTButtonGlyph.Create;
end;
destructor TJvHTButton.Destroy;
begin
TJvHTButtonGlyph(FGlyphDrawer).Free;
FGlyphDrawer := nil;
inherited Destroy;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQButtons.pas,v $';
Revision: '$Revision: 1.25 $';
Date: '$Date: 2004/09/11 21:07:02 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -