home *** CD-ROM | disk | FTP | other *** search
- {************************************}
- {*** 3D Label Component ***}
- {************************************}
- {*** Max 1.5k ***}
- {*** Novosibirsk State University ***}
- {************************************}
-
- unit Label3d;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Classes, Graphics, StdCtrls;
-
- type
- TTextStyle = (tsNone, tsRaized, tsRecessed, tsShadow);
-
- TLabel3d = class (TLabel)
- private
- FTextStyle : TTextStyle;
- FShadowColor : TColor;
- FShadowDepth : Integer;
- procedure SetTextStyle( Value : TTextStyle );
- procedure SetShadowColor( Value : TColor );
- procedure SetShadowDepth( Value : Integer );
- procedure Draw3DText( R : TRect; Flags : Word );
- protected
- procedure Paint; override;
- public
- constructor Create( AOwner : TComponent ); override;
- published
- property ShadowColor : TColor read FShadowColor write SetShadowColor
- default clBtnShadow;
- property ShadowDepth : Integer read FShadowDepth write SetShadowDepth
- default 2;
- property TextStyle : TTextStyle read FTextStyle write SetTextStyle
- default tsRecessed;
- end;
-
- const
- TextAlignments : array [TAlignment] of Word = (dt_Left, dt_Right, dt_Center);
-
- procedure Register;
-
- implementation
-
- constructor TLabel3d.Create( AOwner : TComponent );
- begin
- inherited Create(AOwner);
- FTextStyle := tsRecessed;
- FShadowDepth := 2;
- FShadowColor := clBtnShadow;
- end;
-
- procedure TLabel3d.SetShadowColor(Value : TColor);
- begin
- if Value <> FShadowColor then begin
- FShadowColor := Value;
- Invalidate;
- end;
- end;
-
- procedure TLabel3d.SetShadowDepth(Value : Integer);
- begin
- if Value <> FShadowDepth then begin
- FShadowDepth := Value;
- Invalidate;
- end;
- end;
-
- procedure TLabel3d.SetTextStyle(Value : TTextStyle);
- begin
- if Value <> FTextStyle then begin
- FTextStyle := Value;
- Invalidate;
- end;
- end;
-
- procedure TLabel3d.Draw3DText(R : TRect; Flags : Word);
- var
- CaptionStz : array [0..255] of Char;
- TempRct : TRect;
- ULColor : TColor;
- LRColor : TColor;
- begin
- with Canvas do begin
- StrPCopy(CaptionStz, Caption);
- if WordWrap then Flags := Flags or dt_WordBreak;
- if not ShowAccelChar then Flags := Flags or dt_NoPrefix;
- Font := Self.Font;
- if FTextStyle in [tsRecessed, tsRaized] then begin
- case FTextStyle of
- tsRaized : begin
- ULColor := clBtnHighlight;
- LRColor := clBtnShadow;
- end;
- tsRecessed : begin
- ULColor := clBtnShadow;
- LRColor := clBtnHighlight;
- end;
- end;
- TempRct := R;
- OffsetRect(TempRct, 1, 1);
- Font.Color := LRColor;
- DrawText(Handle, CaptionStz, -1, TempRct, Flags);
- TempRct := R;
- OffsetRect(TempRct, -1, -1);
- Font.Color := ULColor;
- DrawText(Handle, CaptionStz, -1, TempRct, Flags);
- end else if FTextStyle = tsShadow then begin
- TempRct := R;
- OffsetRect(TempRct, FShadowDepth, FShadowDepth);
- Font.Color := FShadowColor;
- DrawText(Handle, CaptionStz, -1, TempRct, Flags);
- end;
- Font.Color := Self.Font.Color;
- if not Enabled then Font.Color := clGrayText;
- DrawText(Handle, CaptionStz, -1, R, Flags);
- end;
- end;
-
- procedure TLabel3d.Paint;
- begin
- with Canvas do begin
- if not Transparent then begin
- Brush.Color := Self.Color;
- Brush.Style := bsSolid;
- FillRect(ClientRect);
- end;
- Brush.Style := bsClear;
- Draw3DText(ClientRect, dt_ExpandTabs or TextAlignments[Alignment]);
- end;
- end;
-
- procedure Register;
- begin
- RegisterComponents('3D', [TLabel3d]);
- end;
-
- end.
-