📄 mmlabel.pas
字号:
{========================================================================}
{= (c) 1995-98 SwiftSoft Ronald Dittrich =}
{========================================================================}
{= All Rights Reserved =}
{========================================================================}
{= D 01099 Dresden = Fax.: +49 (0)351-8037944 =}
{= Loewenstr.7a = info@swiftsoft.de =}
{========================================================================}
{= Actual versions on http://www.swiftsoft.de/mmtools.html =}
{========================================================================}
{= This code is for reference purposes only and may not be copied or =}
{= distributed in any format electronic or otherwise except one copy =}
{= for backup purposes. =}
{= =}
{= No Delphi Component Kit or Component individually or in a collection=}
{= subclassed or otherwise from the code in this unit, or associated =}
{= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
{= without express permission from SwiftSoft. =}
{= =}
{= For more licence informations please refer to the associated =}
{= HelpFile. =}
{========================================================================}
{= $Date: 27.07.98 - 16:29:34 $ =}
{========================================================================}
unit MMLabel;
{$I COMPILER.INC}
interface
uses
{$IFDEF WIN32}
Windows,
{$ELSE}
WinTypes,
WinProcs,
{$ENDIF}
SysUtils,
Messages,
Classes,
Graphics,
Controls,
StdCtrls,
Forms,
MMObj,
MMUtils,
MMString;
type
TMMLabelDepth = 0..20;
TMMLabelDirection = (ldNone, ldUp, ldUpRight, ldRight, ldDownRight,
ldDown, ldDownLeft, ldLeft, ldUpLeft);
TMMLabelStyle = (lsNone,lsCustom,lsRaised,lsSunken,lsShadow,lsFlying);
{ Range for rotation }
TMMAngle = 0..360;
{ Options for varying the shadow/highlight for the label }
TMMLabelOption = (loNormal, loExtrude);
type
{-- TMMLabel ----------------------------------------------------------}
TMMLabel = class(TMMGraphicControl)
private
FAlignment : TAlignment;
{$IFNDEF BUILD_ACTIVEX}
FTransparent : Boolean;
{$ENDIF}
DDegToRad : Double;
DCosAngle : Double;
DSinAngle : Double;
DCosSquared : Double;
DSinSquared : Double;
FBitmap : TBitmap;
FDepthHighlight : TMMLabelDepth;
FDepthShadow : TMMLabelDepth;
FDirectionHighlight: TMMLabelDirection;
FDirectionShadow : TMMLabelDirection;
FColorHighlight : TColor;
FColorShadow : TColor;
FStyleHighlight : TMMLabelOption;
FStyleShadow : TMMLabelOption;
FEffectStyle : TMMLabelStyle;
FAsButton : Boolean;
FAngle : TMMAngle;
FChangingStyle : Boolean; { Is preset style being invoked ? }
procedure SetAlignment(aValue: TAlignment);
{$IFNDEF BUILD_ACTIVEX}
procedure SetTransparent(aValue: Boolean);
{$ENDIF}
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure SetDepth(Index: integer; aValue: TMMLabelDepth);
procedure SetDirection(Index: integer; aValue: TMMLabelDirection);
procedure SetColor(Index: integer; aValue: TColor);
procedure SetStyle(Index: integer; aValue: TMMLabelOption);
procedure SetEffect(aValue: TMMLabelStyle);
procedure SetAsButton(aValue: Boolean);
procedure SetAngle(aValue: TMMAngle);
procedure SetTextAngle(Canvas: TCanvas; aValue: TMMAngle);
procedure SetBitmap(aBitmap: TBitmap);
procedure BitmapChanged(Sender: TObject);
protected
procedure Paint; override;
function GetPalette: HPalette; override;
procedure MouseDown(Button: TMouseButton; ssShift: TShiftState; X, Y: Integer); override;
procedure MouseMove(ssShift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; ssShift: TShiftState; X, Y: Integer); override;
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property Align;
property Caption;
property Color;
property Cursor;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property ParentColor;
property ParentFont;
property ParentShowHint;
property ShowHint;
property Visible;
property Width default 142;
property Height default 33;
property Bevel;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
{$IFNDEF BUILD_ACTIVEX}
property Transparent: Boolean read FTransparent write SetTransparent default True;
{$ELSE}
property Transparent;
{$ENDIF}
property Bitmap: TBitmap read FBitmap write SetBitmap;
property DepthHighlight: TMMLabelDepth index 0 read FDepthHighlight write SetDepth default 1;
property DepthShadow: TMMLabelDepth index 1 read FDepthShadow write SetDepth default 1;
property DirectionHighlight: TMMLabelDirection index 0 read FDirectionHighlight write SetDirection default ldUpLeft;
property DirectionShadow: TMMLabelDirection index 1 read FDirectionShadow write SetDirection default ldDownRight;
property ColourHighlight: TColor index 0 read FColorHighlight write SetColor default clWhite;
property ColourShadow: TColor index 1 read FColorShadow write SetColor default clGray;
property StyleHighlight: TMMLabelOption index 0 read FStyleHighlight write SetStyle default loNormal;
property StyleShadow: TMMLabelOption index 1 read FStyleShadow write SetStyle default loNormal;
property EffectStyle: TMMLabelStyle read FEffectStyle write SetEffect default lsRaised;
property AsButton: Boolean read FAsButton write SetAsButton default False;
property Angle: TMMAngle read FAngle write SetAngle default 0;
end;
implementation
type
TDirXY = (drX, drY);
const
{ Offsets for drawing in the nominated directions }
IOffsets: array [TMMLabelDirection, TDirXY] of -1..1 =
((0,0),(0,-1),(+1,-1),(+1,0),(+1,+1),(0,+1),(-1,+1),(-1,0),(-1,-1));
{== TMMLabel ===========================================================}
constructor TMMLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFNDEF BUILD_ACTIVEX}
ControlStyle := ControlStyle - [csOpaque];
FTransparent := True;
{$ELSE}
Transparent := True;
{$ENDIF}
{$IFDEF WIN32}
ControlStyle := ControlStyle + [csReplicatable];
{$ENDIF}
FBitmap := TBitmap.Create;
FBitmap.OnChange := BitmapChanged;
FDepthHighlight := 1;
FDepthShadow := 1;
FDirectionHighlight := ldUpLeft;
FDirectionShadow := ldDownRight;
FStyleHighlight := loNormal;
FStyleShadow := loNormal;
FEffectStyle := lsRaised;
FColorHighlight := clWhite;
FColorShadow := clGray;
FAsButton := False;
FAngle := 0;
FChangingStyle := False;
DDegToRad := PI / 180;
DCosAngle := 1; { Cos(FAngle * DDegToRad) }
DCosSquared := 1;
DSinAngle := 0; { Sin(FAngle * DDegToRad) }
DSinSquared := 0;
Width := 142;
Height := 33;
Font.Color := clBlack;
Font.Name := 'Times New Roman';
Font.Size := 20;
ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;
{-- TMMLabel ------------------------------------------------------------}
destructor TMMLabel.Destroy;
begin
FBitmap.Onchange := nil;
FBitmap.Free;
inherited Destroy;
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetBitmap(aBitmap: TBitmap);
begin
FBitmap.Assign(aBitmap);
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.BitmapChanged(Sender: TObject);
begin
Invalidate;
end;
{-- TMMLabel ------------------------------------------------------------}
function TMMLabel.GetPalette: HPalette;
begin
if not FBitmap.Empty then Result := FBitmap.Palette
else Result := inherited GetPalette;
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetAlignment(aValue: TAlignment);
begin
if (FAlignment <> aValue) then
begin
FAlignment := aValue;
Invalidate;
end;
end;
{$IFNDEF BUILD_ACTIVEX}
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetTransparent(aValue: Boolean);
begin
if (FTransparent <> aValue) then
begin
FTransparent := aValue;
if aValue then ControlStyle := ControlStyle - [csOpaque]
else ControlStyle := ControlStyle + [csOpaque];
Invalidate;
end;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK1}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{$ENDIF}
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.CMTextChanged(var Message: TMessage);
begin
Invalidate;
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.CMFontChanged(var Message: TMessage);
begin
inherited;
Invalidate;
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetDepth(Index: integer; aValue: TMMLabelDepth);
begin
case Index of
0: if (FDepthHighlight = aValue) then exit
else FDepthHighlight := aValue;
1: if (FDepthShadow = aValue) then exit
else FDepthShadow := aValue;
end;
{ Default to custom style when changed }
if not FChangingStyle then SetEffect(lsCustom);
Invalidate;
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetDirection(Index: integer; aValue: TMMLabelDirection);
begin
case Index of
0: if (FDirectionHighlight = aValue) then exit
else FDirectionHighlight := aValue;
1: if (FDirectionShadow = aValue) then exit
else FDirectionShadow := aValue;
end;
{ Default to custom style when changed }
if not FChangingStyle then SetEffect(lsCustom);
Invalidate;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK2}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetColor(Index: integer; aValue: TColor);
begin
case Index of
0: if (FColorHighlight = aValue) then exit
else FColorHighlight := aValue;
1: if (FColorShadow = aValue) then exit
else FColorShadow := aValue;
end;
Invalidate;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK3}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetStyle(Index: integer; aValue: TMMLabelOption);
begin
case Index of
0: if (FStyleHighlight = aValue) then exit
else FStyleHighlight := aValue;
1: if (FStyleShadow = aValue) then exit
else FStyleShadow := aValue;
end;
Invalidate;
end;
{-- TMMLabel ------------------------------------------------------------}
procedure TMMLabel.SetEffect(aValue: TMMLabelStyle);
begin
if (FEffectStyle <> aValue) then
begin
FChangingStyle := True; { So it doesn't reset to custom }
FEffectStyle := aValue;
SetColor(0,clWhite);
case FEffectStyle of
lsRaised:
begin
SetDirection(0,ldUpLeft);
SetDirection(1,ldDownRight);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -