Q&A
HOME
Tips & Tech
Q&A
Discuss
Download
자유게시판
홍보 / 광고
구인 / 구직
LOGIN
회원가입
문자열을 움직이는 것처럼 보이게 ...
Windows의 화면보호기 중 [사용자 입력문구]와 같은 기능을 하게 하고 싶은데
어떻게 해야 할까요?
즉,문자열은 15줄 정도로 한줄씩 화면 아래에서 위로 또는 좌에서 우로
움직이도록 하고 싶은데요....
Label Component를 15개 놓고 .Top과 .Visible 속성을 바꿔가면서 해봤는데,
화면이 너무 깜빡깜빡하게 나와서요.
다른 좋은 방법이 없을까요?
여러가지 의견 부탁드립니다.
3
COMMENTS
한
•
1999.05.21 21:33
july wrote:
> Windows의 화면보호기 중 [사용자 입력문구]와 같은 기능을 하게 하고 싶은데
> 어떻게 해야 할까요?
> 즉,문자열은 15줄 정도로 한줄씩 화면 아래에서 위로 또는 좌에서 우로
> 움직이도록 하고 싶은데요....
>
> Label Component를 15개 놓고 .Top과 .Visible 속성을 바꿔가면서 해봤는데,
> 화면이 너무 깜빡깜빡하게 나와서요.
>
> 다른 좋은 방법이 없을까요?
> 여러가지 의견 부탁드립니다.
관련 콤포넌트 소스입니다.
{----------------------------------------------------------
TScrollText: Version 1.0 14 October, 1996.
by Darryl West (dwest@dot.net.au)
----------------------------------------------------------
This component is released as Freeware. It was developed
using Delphi 2. If you have any suggestions, comments or
bugs please E-mail me.
----------------------------------------------------------}
unit ScrollText;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls;
type
TTextStyle = (tsNormal, tsRaised, tsLowered, tsShaddow);
TScrollDirection = (sdStatic, sdRightToLeft, sdLeftToRight, sdTopToBottom, sdBottomToTop);
TAlignment = (taCenter, taLeftJustify, taRightJustify);
TCustomScrollText = class(TGraphicControl)
private
FAlignment: TAlignment;
FTextStyle: TTextStyle;
FScrollDirection: TScrollDirection;
FTimer: TTimer;
FItems: TStringList;
FColor: TColor;
FContinuous: Boolean;
FFont: TFont;
FOnBegin, FOnStep, FOnEnd: TNotifyEvent;
FSteps, FSpeed, FDepth, LineHi, FCurrentStep, FTextWidth,
FTextHeight, XPos, YPos: Integer;
procedure SetAlignment(Value: TAlignment);
procedure SetContinuous(Value: Boolean);
procedure SetItems(Value: TStringList);
procedure DataChanged;
procedure SetTextStyle(Value: TTextStyle);
procedure SetDirection(Value: TScrollDirection);
procedure SetSteps(Value: Integer);
procedure SetSpeed(Value: Integer);
procedure SetColor(Value: TColor);
procedure SetFont(Value: TFont);
procedure SetDepth(Value: Integer);
procedure SetSizeParams;
procedure FontChanged(Sender: TObject);
procedure DoTextOut(ACanvas: TCanvas; X, Y: Integer; AText: string);
protected
procedure Paint; override;
procedure TimerTick(Sender: TObject);
property Alignment: TAlignment read FAlignment write SetAlignment;
property Depth: Integer read FDepth write SetDepth default 1;
property ScrollDirection: TScrollDirection read FScrollDirection
write SetDirection default sdRightToLeft;
property Items: TStringList read FItems write SetItems;
property OnBegin: TNotifyEvent read FOnBegin write FOnBegin;
property OnStep: TNotifyEvent read FOnStep write FOnStep;
property OnEnd: TNotifyEvent read FOnEnd write FOnEnd;
public
property CurrentStep: Integer read FCurrentStep;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ReverseDirection;
procedure ScrollStart(StartingStep: Integer);
procedure ScrollStop;
published
property TextStyle: TTextStyle read FTextStyle write SetTextStyle default tsNormal;
property Steps: Integer read FSteps write SetSteps default 66;
property Speed: Integer read FSpeed write SetSpeed default 200;
property Color: TColor read FColor write SetColor default clBtnFace;
property Continuous: Boolean read FContinuous write SetContinuous;
property Font: TFont read FFont write SetFont;
end;
TScrollText = class(TCustomScrollText)
published
property Align;
property Alignment;
property Color;
property Depth;
property Items;
property TextStyle;
property ParentShowHint;
property Font;
property ScrollDirection;
property ShowHint;
property Speed;
property Steps;
property Visible;
property OnBegin;
property OnStep;
property OnEnd;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Additional', [TScrollText]);
end;
constructor TCustomScrollText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csOpaque];
FItems := TStringList.Create;
FItems.Add('ScrollText');
Width := 200;
Height := 20;
FColor := clBtnFace;
FSteps := 80;
FCurrentStep := 0;
FDepth := 1;
FContinuous := True;
FTextStyle := tsNormal;
FAlignment := taCenter;
FFont := TFont.Create;
with FFont do begin
Name := 'Arial';
Size := 10;
Color := clBlack;
end;
FFont.OnChange := FontChanged;
FTimer := TTimer.Create(Self);
FSpeed := 100;
with FTimer do begin
Enabled := False;
OnTimer := TimerTick;
Interval := FSpeed;
end;
FScrollDirection := sdRightToLeft;
SetDirection(FScrollDirection); { Start scrolling if necessary. }
end;
destructor TCustomScrollText.Destroy;
begin
FItems.Free;
FTimer.Free;
FFont.Free;
inherited Destroy;
end;
procedure TCustomScrollText.SetItems(Value: TStringList);
begin
if FItems <> Value then begin
FItems.Assign(Value);
DataChanged;
end;
end;
procedure TCustomScrollText.DoTextOut(ACanvas: TCanvas; X, Y: Integer; AText: string);
var TextAdjustment: Integer;
begin
with ACanvas do begin
Font := FFont;
Brush.Style := bsClear;
if FAlignment = taCenter then
TextAdjustment := Round((FTextWidth / 2) - (TextWidth(AText) / 2))
else if FAlignment = taRightJustify then
TextAdjustment := Round(FTextWidth - TextWidth(AText))
else TextAdjustment := 0;
case FTextStyle of
tsRaised: begin
Font.Color := clBtnHighlight;
TextOut(X - FDepth + TextAdjustment, Y - FDepth, AText);
Font.Color := clBtnShadow;
TextOut(X + FDepth + TextAdjustment, Y + FDepth, AText);
end;
tsLowered: begin
Font.Color := clBtnShadow;
TextOut(X - FDepth + TextAdjustment, Y - FDepth, AText);
Font.Color := clBtnHighlight;
TextOut(X + FDepth + TextAdjustment, Y + FDepth, AText);
end;
tsShaddow: begin
Font.Color := clBtnShadow;
TextOut(X + FDepth + TextAdjustment, Y + FDepth, AText);
end;
end;
Font.Color := FFont.Color;
TextOut(X + TextAdjustment, Y, AText);
end;
end;
procedure TCustomScrollText.Paint;
var TmpBmp: TBitMap;
StartXPos, StartYPos, I: Integer;
PercentDone: Double;
begin
SetSizeParams;
TmpBmp := TBitMap.Create;
try
TmpBmp.Width := Width;
TmpBmp.Height := Height;
with TmpBmp.Canvas do begin
Font := FFont;
Brush.Color := FColor;
Brush.Style := bsSolid;
FillRect(ClipRect);
end;
if FTextWidth >= Width then XPos := 0 else XPos := (Width - FTextWidth) div 2;
if FTextHeight >= Height then YPos := 0 else YPos := (Height - FTextHeight) div 2;
if csDesigning in ComponentState then PercentDone := 0.5
else PercentDone := FCurrentStep / FSteps;
case FScrollDirection of
sdRightToLeft: begin
StartYPos := YPos;
StartXPos := Round((FTextWidth + Width) * (1 - PercentDone)) - FTextWidth;
end;
sdLeftToRight: begin
StartYPos := YPos;
StartXPos := Round((FTextWidth + Width) * PercentDone) - FTextWidth;
end;
sdBottomToTop: begin
StartXPos := XPos;
StartYPos := Round((FTextHeight + Height) * (1 - PercentDone)) - FTextHeight;
end;
sdTopToBottom: begin
StartXPos := XPos;
StartYPos := Round((FTextHeight + Height) * PercentDone) - FTextHeight;
end;
else begin { static }
StartXPos := XPos;
StartYPos := YPos;
end
end;
I := 0;
while I < FItems.Count do begin
DoTextOut(TmpBmp.Canvas, StartXPos, StartYPos, FItems.Strings[I]);
Inc(StartYPos, LineHi);
Inc(I);
end;
Canvas.Draw(0, 0, TmpBmp);
finally
TmpBmp.Free;
end;
end;
procedure TCustomScrollText.SetSizeParams;
var S: String;
I, SWidth: Integer;
Metrics: TTextMetric;
begin
with Canvas do begin
Font := FFont;
GetTextMetrics(Handle, Metrics);
LineHi := Metrics.tmHeight + Metrics.tmInternalLeading;
if FTextStyle in [tsRaised, tsLowered] then LineHi := LineHi + 2 * FDepth
else if FTextStyle in [tsShaddow] then LineHi := LineHi + FDepth;
end;
FTextWidth := 0;
I := 0;
while I < FItems.Count do begin
S := FItems.Strings[I];
SWidth := Canvas.TextWidth(S);
if FTextStyle in [tsRaised, tsLowered] then SWidth := SWidth + 2 * FDepth
else if FTextStyle in [tsShaddow] then SWidth := SWidth + FDepth;
if FTextWidth < SWidth then FTextWidth := SWidth;
Inc(I);
end;
FTextHeight := LineHi * FItems.Count;
if FTextWidth >= Width then XPos := 0 else XPos := (Width - FTextWidth) div 2;
if FTextHeight >= Height then YPos := 0 else YPos := (Height - FTextHeight) div 2;
end;
procedure TCustomScrollText.DataChanged;
begin
SetSizeParams;
Invalidate;
end;
procedure TCustomScrollText.SetTextStyle(Value: TTextStyle);
begin
if FTextStyle <> Value then begin
FTextStyle := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.SetDirection(Value: TScrollDirection);
begin
if FScrollDirection <> Value then begin
FScrollDirection := Value;
end;
if FScrollDirection = sdStatic then ScrollStop
else ScrollStart(FCurrentStep);
end;
procedure TCustomScrollText.SetContinuous(Value: Boolean);
begin
if FContinuous <> Value then begin
FContinuous := Value;
if FScrollDirection <> sdStatic then ScrollStart(FCurrentStep);
end;
end;
procedure TCustomScrollText.SetSteps(Value: Integer);
begin
if FSteps <> Value then begin
FSteps := Value;
if csDesigning in ComponentState then Invalidate;
end;
end;
procedure TCustomScrollText.SetSpeed(Value: Integer);
begin
if FSpeed <> Value then begin
if Value > 1000 then Value := 1000
else if Value < 1 then Value := 1;
FSpeed := Value;
if FTimer <> nil then FTimer.Interval := FSpeed;
end;
end;
procedure TCustomScrollText.SetColor(Value: TColor);
begin
if FColor <> Value then begin
FColor := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.FontChanged(Sender: TObject);
begin
DataChanged;
end;
procedure TCustomScrollText.SetFont(Value: TFont);
begin
if FFont <> Value then begin
FFont.Assign(Value);
DataChanged;
end;
end;
procedure TCustomScrollText.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.SetDepth(Value: Integer);
begin
if FDepth <> Value then begin
FDepth := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.ScrollStart(StartingStep: Integer);
begin
if FTimer.Enabled then Exit;
if (StartingStep >= 0) and (StartingStep <= FSteps) then FCurrentStep := StartingStep;
FTimer.Enabled := True;
end;
procedure TCustomScrollText.ScrollStop;
begin
FTimer.Enabled := False;
end;
procedure TCustomScrollText.ReverseDirection;
begin
if FScrollDirection = sdStatic then Exit;
FCurrentStep := FSteps - FCurrentStep;
case FScrollDirection of
sdLeftToRight: FScrollDirection := sdRightToLeft;
sdRightToLeft: FScrollDirection := sdLeftToRight;
sdTopToBottom: FScrollDirection := sdBottomToTop;
sdBottomToTop: FScrollDirection := sdTopToBottom;
end;
end;
procedure TCustomScrollText.TimerTick(Sender: TObject);
begin
if not FTimer.Enabled then Exit;
if (FCurrentStep = 0) and Assigned(FOnBegin) then FOnBegin(Self);
Inc(FCurrentStep);
Paint;
if Assigned(FOnStep) then FOnStep(Self);
if FCurrentStep > FSteps then begin
FTimer.Enabled := False;
if Assigned(FOnEnd) then FOnEnd(Self);
FCurrentStep := 0;
if FContinuous then ScrollStart(FCurrentStep);
end;
end;
end.
0
0
삭제
수정
댓글
kbna
•
1999.05.22 02:56
잘 받아 사용해 보았습니다. 감사합니다.
그런데 추가 질문이 있어 이렇게 다시 글을 올립니다.
배경에 그림이 있어 Label Component처럼 Transparent기능까지 할수 있으면
좋겠는데 안되네요.
어떻게 하죠? 고친다고 고쳐보는데 잘 안되네요...
조언 부탁드립니다.
0
0
삭제
수정
댓글
한
•
1999.05.26 02:23
kbna wrote:
> 잘 받아 사용해 보았습니다. 감사합니다.
>
> 그런데 추가 질문이 있어 이렇게 다시 글을 올립니다.
>
> 배경에 그림이 있어 Label Component처럼 Transparent기능까지 할수 있으면
> 좋겠는데 안되네요.
>
> 어떻게 하죠? 고친다고 고쳐보는데 잘 안되네요...
>
> 조언 부탁드립니다.
음냐...
답변이 늦었죠...죄송합니다.
요즘 하도 바빠서...긁적긁적...
이 콤포넌트의 소스를 잘 보시면
canvas를 사용해서 텍스트를 뿌려줍니다.
그 말은 곧 그래픽이라는 얘기죠....
제가 아직 그래픽에 대해서 잘 몰라서 Transparent
기능을 넣기는 힘들겠네요....긁적긁적...북북북...죄송...
그럼.... 꾸벅
0
0
삭제
수정
댓글
(NOTICE) You must be
logged in
to comment on this post.
july
•
1999.05.21 20:24
3
COMMENTS
/
0
LIKES
문자열을 움직이는 것처럼 보이게 ...
Windows의 화면보호기 중 [사용자 입력문구]와 같은 기능을 하게 하고 싶은데 어떻게 해야 할까요? 즉,문자열은 15줄 정도로 한줄씩 화면 아래에서 위로 또는 좌에서 우로 움직이도록 하고 싶은데요.... Label Component를 15개 놓고 .Top...
한
•
1999.05.21 21:33
july wrote: > Windows의 화면보호기 중 [사용자 입력문구]와 같은 기능을 하게 하고 싶은데 > 어떻게 해...
kbna
•
1999.05.22 02:56
잘 받아 사용해 보았습니다. 감사합니다. 그런데 추가 질문이 있어 이렇게 다시 글을 올립니다. 배경...
한
•
1999.05.26 02:23
kbna wrote: > 잘 받아 사용해 보았습니다. 감사합니다. > > 그런데 추가 질문이 있어 이렇게 다시 글...
지니
•
1999.05.21 20:17
1
COMMENTS
/
0
LIKES
문자위치 찾기(조건설정)
한
•
1999.05.21 21:50
지니 wrote: > > 초보입니다. Pos함수를 사용하여 문자의 위치를 > 알아낼수 있습니다만, 조건이 있을 ...
강신구
•
1999.05.21 19:49
1
COMMENTS
/
0
LIKES
Application.OnHint에 대해?
이정욱
•
1999.05.21 19:54
물론 가능합니다. 그러니까 다르게 생긴 풍선 도움말같은것이 가능하죠.. ^^; 강신구 wrote: > 안녕하...
김정수
•
1999.05.21 19:31
1
COMMENTS
/
0
LIKES
[요청]우편번호자료
이정욱
•
1999.05.21 22:31
한델(http://www.delphi.co.kr)자료실에 업로드를 해놓았습니다. 에구.. 조합형으로 되어있던것을 완성형...
북해
•
1999.05.21 18:26
1
COMMENTS
/
0
LIKES
디비그리드에서 수평,수직 이동바...
김영대
•
1999.05.21 21:00
북해 wrote: > 안녕하세요. DBGrid에서 수평,수직 이동바를 나타나지 않게 할 수는 없나요? > 볼랜드...
북해
•
1999.05.21 18:23
1
COMMENTS
/
0
LIKES
인스톨쉬드로 설치 디스켓을 만들었는데...
이정욱
•
1999.05.21 22:52
흐.. 물론 정확한 원인은 알수없지만... 제일 가능성 많은것은 Alias가 존재하지 않을때 입니다. 개발시 ...
초보
•
1999.05.21 18:01
1
COMMENTS
/
0
LIKES
AMD K6-II 에서 델파이 설치문제....(?)
이정욱
•
1999.05.21 19:50
제생각에는 CPU보다는 그래픽카드가 문제가 될수있다고 생각이 드네요. 몇몇보고를 보면 그래픽카드중에 ...
이호선
1999.05.21 17:44
0
COMMENTS
/
0
LIKES
Application 실행시 Exception Error
윤상필
•
1999.05.21 17:34
1
COMMENTS
/
0
LIKES
Send Mail ~~ 꼭부탁드립니다.매우 급함
이정욱
•
1999.05.21 23:00
어떤 SMTP컴포넌트를 사용하시는지요? 직접만드신것인지... 델파이에 있는 TNMSMTP를 사용하셨다면 ...
김태균
•
1999.05.21 13:49
1
COMMENTS
/
0
LIKES
TQuery의 복사본을 만들려고 하는데요.
신호성
•
1999.05.21 18:58
김태균 wrote: > 이렇게 하려고 합니다. > > Query1이 있는데 이것과 똑같은 Query를 하나 만들려고 ...
김용철
•
1999.05.21 11:14
1
COMMENTS
/
0
LIKES
혹시 Windows 2000에 D4 C/S 인스톨하는 방법....(급해요)
이정욱
•
1999.05.21 22:49
델파이는 윈NT용으로 따로 나오는것은 없습니다. 아마도 아직 윈2000이 윈98이나 이전버전의 지원 호환성...
Heaven
•
1999.05.21 09:53
1
COMMENTS
/
0
LIKES
스트링그리드에 대한 여러가지 질문...
김영대
•
1999.05.21 20:50
Heaven wrote: > 안녕하세요... > 여기서 도움을 많이 받는 heaven입니다. > > 제가 스트링그리드 사...
철이
1999.05.21 09:45
0
COMMENTS
/
0
LIKES
SQL에저장된이미지 불러오기
김영애
•
1999.05.21 08:38
1
COMMENTS
/
0
LIKES
퀵레포트요 ..좀 갈쳐 주세요~~
powerman
•
1999.05.21 09:54
김영애 wrote: > 저는 '매출내역서'를 출력하려구요.. > 이건 사원명을 중심으로 매출카드내역을 뽑는거...
영이...
1999.05.21 07:40
0
COMMENTS
/
0
LIKES
component가 바뀌었어요...
박진수
1999.05.21 04:45
0
COMMENTS
/
0
LIKES
progress DataBase..,
이선영
1999.05.21 03:49
0
COMMENTS
/
0
LIKES
db에 자료저장시 에러가 난 레코드로 자료이동방법?
초보운전
•
1999.05.21 03:44
3
COMMENTS
/
0
LIKES
연동하는 2개의 Memo콘트롤을..
신인재
•
1999.05.21 19:54
이미 두분이 답을 하셨군요.. 질문의 요지를 전 좀 다른 각도에서 생각을 해보았습니다. 아래와 같이 코...
이정욱
•
1999.05.21 06:56
파워러브 델파이 창간호에서 가져왔습니다. 1. 현재 라인번호 알아내기 메모에서 현재 Caret이 위치...
안치봉
•
1999.05.21 03:54
초보운전 wrote: > > 가능할까요?? > 폼에 나란히 Momo 콘트롤을 2개 설치하고 > 한쪽의 메모콘트롤에...
최석기
•
1999.05.21 03:20
2
COMMENTS
/
0
LIKES
AsyncPro로 만든 프로그램 배포시...
이정욱
•
1999.05.21 06:31
팩스드라이버는 모뎀에 없죠... 그냥 모뎀 드라이버만 제데로 설치되어 있어도 됩니다. 팩스프린터드라이...
최석기
•
1999.05.21 18:20
이정욱 wrote: > 팩스드라이버는 모뎀에 없죠... 그냥 모뎀 드라이버만 제데로 설치되어 있어도 됩니다. ...
박태식
•
1999.05.21 02:44
1
COMMENTS
/
0
LIKES
Query에 대한 부분입니다. 도와 주세요.
박성훈
•
1999.06.04 03:41
박태식 께서 말씀하시기를... > query로 조회하는 부분입니다. > 두개의 db에서 각각의 한field에서 > ...
july
1999/05/21 20:24
Views
233
Likes
0
Comments
3
Reports
0
Tag List
수정
삭제
목록으로
한델 로그인 하기
로그인 상태 유지
아직 회원이 아니세요? 가입하세요!
암호를 잊어버리셨나요?
> Windows의 화면보호기 중 [사용자 입력문구]와 같은 기능을 하게 하고 싶은데
> 어떻게 해야 할까요?
> 즉,문자열은 15줄 정도로 한줄씩 화면 아래에서 위로 또는 좌에서 우로
> 움직이도록 하고 싶은데요....
>
> Label Component를 15개 놓고 .Top과 .Visible 속성을 바꿔가면서 해봤는데,
> 화면이 너무 깜빡깜빡하게 나와서요.
>
> 다른 좋은 방법이 없을까요?
> 여러가지 의견 부탁드립니다.
관련 콤포넌트 소스입니다.
{----------------------------------------------------------
TScrollText: Version 1.0 14 October, 1996.
by Darryl West (dwest@dot.net.au)
----------------------------------------------------------
This component is released as Freeware. It was developed
using Delphi 2. If you have any suggestions, comments or
bugs please E-mail me.
----------------------------------------------------------}
unit ScrollText;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls;
type
TTextStyle = (tsNormal, tsRaised, tsLowered, tsShaddow);
TScrollDirection = (sdStatic, sdRightToLeft, sdLeftToRight, sdTopToBottom, sdBottomToTop);
TAlignment = (taCenter, taLeftJustify, taRightJustify);
TCustomScrollText = class(TGraphicControl)
private
FAlignment: TAlignment;
FTextStyle: TTextStyle;
FScrollDirection: TScrollDirection;
FTimer: TTimer;
FItems: TStringList;
FColor: TColor;
FContinuous: Boolean;
FFont: TFont;
FOnBegin, FOnStep, FOnEnd: TNotifyEvent;
FSteps, FSpeed, FDepth, LineHi, FCurrentStep, FTextWidth,
FTextHeight, XPos, YPos: Integer;
procedure SetAlignment(Value: TAlignment);
procedure SetContinuous(Value: Boolean);
procedure SetItems(Value: TStringList);
procedure DataChanged;
procedure SetTextStyle(Value: TTextStyle);
procedure SetDirection(Value: TScrollDirection);
procedure SetSteps(Value: Integer);
procedure SetSpeed(Value: Integer);
procedure SetColor(Value: TColor);
procedure SetFont(Value: TFont);
procedure SetDepth(Value: Integer);
procedure SetSizeParams;
procedure FontChanged(Sender: TObject);
procedure DoTextOut(ACanvas: TCanvas; X, Y: Integer; AText: string);
protected
procedure Paint; override;
procedure TimerTick(Sender: TObject);
property Alignment: TAlignment read FAlignment write SetAlignment;
property Depth: Integer read FDepth write SetDepth default 1;
property ScrollDirection: TScrollDirection read FScrollDirection
write SetDirection default sdRightToLeft;
property Items: TStringList read FItems write SetItems;
property OnBegin: TNotifyEvent read FOnBegin write FOnBegin;
property OnStep: TNotifyEvent read FOnStep write FOnStep;
property OnEnd: TNotifyEvent read FOnEnd write FOnEnd;
public
property CurrentStep: Integer read FCurrentStep;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ReverseDirection;
procedure ScrollStart(StartingStep: Integer);
procedure ScrollStop;
published
property TextStyle: TTextStyle read FTextStyle write SetTextStyle default tsNormal;
property Steps: Integer read FSteps write SetSteps default 66;
property Speed: Integer read FSpeed write SetSpeed default 200;
property Color: TColor read FColor write SetColor default clBtnFace;
property Continuous: Boolean read FContinuous write SetContinuous;
property Font: TFont read FFont write SetFont;
end;
TScrollText = class(TCustomScrollText)
published
property Align;
property Alignment;
property Color;
property Depth;
property Items;
property TextStyle;
property ParentShowHint;
property Font;
property ScrollDirection;
property ShowHint;
property Speed;
property Steps;
property Visible;
property OnBegin;
property OnStep;
property OnEnd;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Additional', [TScrollText]);
end;
constructor TCustomScrollText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csOpaque];
FItems := TStringList.Create;
FItems.Add('ScrollText');
Width := 200;
Height := 20;
FColor := clBtnFace;
FSteps := 80;
FCurrentStep := 0;
FDepth := 1;
FContinuous := True;
FTextStyle := tsNormal;
FAlignment := taCenter;
FFont := TFont.Create;
with FFont do begin
Name := 'Arial';
Size := 10;
Color := clBlack;
end;
FFont.OnChange := FontChanged;
FTimer := TTimer.Create(Self);
FSpeed := 100;
with FTimer do begin
Enabled := False;
OnTimer := TimerTick;
Interval := FSpeed;
end;
FScrollDirection := sdRightToLeft;
SetDirection(FScrollDirection); { Start scrolling if necessary. }
end;
destructor TCustomScrollText.Destroy;
begin
FItems.Free;
FTimer.Free;
FFont.Free;
inherited Destroy;
end;
procedure TCustomScrollText.SetItems(Value: TStringList);
begin
if FItems <> Value then begin
FItems.Assign(Value);
DataChanged;
end;
end;
procedure TCustomScrollText.DoTextOut(ACanvas: TCanvas; X, Y: Integer; AText: string);
var TextAdjustment: Integer;
begin
with ACanvas do begin
Font := FFont;
Brush.Style := bsClear;
if FAlignment = taCenter then
TextAdjustment := Round((FTextWidth / 2) - (TextWidth(AText) / 2))
else if FAlignment = taRightJustify then
TextAdjustment := Round(FTextWidth - TextWidth(AText))
else TextAdjustment := 0;
case FTextStyle of
tsRaised: begin
Font.Color := clBtnHighlight;
TextOut(X - FDepth + TextAdjustment, Y - FDepth, AText);
Font.Color := clBtnShadow;
TextOut(X + FDepth + TextAdjustment, Y + FDepth, AText);
end;
tsLowered: begin
Font.Color := clBtnShadow;
TextOut(X - FDepth + TextAdjustment, Y - FDepth, AText);
Font.Color := clBtnHighlight;
TextOut(X + FDepth + TextAdjustment, Y + FDepth, AText);
end;
tsShaddow: begin
Font.Color := clBtnShadow;
TextOut(X + FDepth + TextAdjustment, Y + FDepth, AText);
end;
end;
Font.Color := FFont.Color;
TextOut(X + TextAdjustment, Y, AText);
end;
end;
procedure TCustomScrollText.Paint;
var TmpBmp: TBitMap;
StartXPos, StartYPos, I: Integer;
PercentDone: Double;
begin
SetSizeParams;
TmpBmp := TBitMap.Create;
try
TmpBmp.Width := Width;
TmpBmp.Height := Height;
with TmpBmp.Canvas do begin
Font := FFont;
Brush.Color := FColor;
Brush.Style := bsSolid;
FillRect(ClipRect);
end;
if FTextWidth >= Width then XPos := 0 else XPos := (Width - FTextWidth) div 2;
if FTextHeight >= Height then YPos := 0 else YPos := (Height - FTextHeight) div 2;
if csDesigning in ComponentState then PercentDone := 0.5
else PercentDone := FCurrentStep / FSteps;
case FScrollDirection of
sdRightToLeft: begin
StartYPos := YPos;
StartXPos := Round((FTextWidth + Width) * (1 - PercentDone)) - FTextWidth;
end;
sdLeftToRight: begin
StartYPos := YPos;
StartXPos := Round((FTextWidth + Width) * PercentDone) - FTextWidth;
end;
sdBottomToTop: begin
StartXPos := XPos;
StartYPos := Round((FTextHeight + Height) * (1 - PercentDone)) - FTextHeight;
end;
sdTopToBottom: begin
StartXPos := XPos;
StartYPos := Round((FTextHeight + Height) * PercentDone) - FTextHeight;
end;
else begin { static }
StartXPos := XPos;
StartYPos := YPos;
end
end;
I := 0;
while I < FItems.Count do begin
DoTextOut(TmpBmp.Canvas, StartXPos, StartYPos, FItems.Strings[I]);
Inc(StartYPos, LineHi);
Inc(I);
end;
Canvas.Draw(0, 0, TmpBmp);
finally
TmpBmp.Free;
end;
end;
procedure TCustomScrollText.SetSizeParams;
var S: String;
I, SWidth: Integer;
Metrics: TTextMetric;
begin
with Canvas do begin
Font := FFont;
GetTextMetrics(Handle, Metrics);
LineHi := Metrics.tmHeight + Metrics.tmInternalLeading;
if FTextStyle in [tsRaised, tsLowered] then LineHi := LineHi + 2 * FDepth
else if FTextStyle in [tsShaddow] then LineHi := LineHi + FDepth;
end;
FTextWidth := 0;
I := 0;
while I < FItems.Count do begin
S := FItems.Strings[I];
SWidth := Canvas.TextWidth(S);
if FTextStyle in [tsRaised, tsLowered] then SWidth := SWidth + 2 * FDepth
else if FTextStyle in [tsShaddow] then SWidth := SWidth + FDepth;
if FTextWidth < SWidth then FTextWidth := SWidth;
Inc(I);
end;
FTextHeight := LineHi * FItems.Count;
if FTextWidth >= Width then XPos := 0 else XPos := (Width - FTextWidth) div 2;
if FTextHeight >= Height then YPos := 0 else YPos := (Height - FTextHeight) div 2;
end;
procedure TCustomScrollText.DataChanged;
begin
SetSizeParams;
Invalidate;
end;
procedure TCustomScrollText.SetTextStyle(Value: TTextStyle);
begin
if FTextStyle <> Value then begin
FTextStyle := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.SetDirection(Value: TScrollDirection);
begin
if FScrollDirection <> Value then begin
FScrollDirection := Value;
end;
if FScrollDirection = sdStatic then ScrollStop
else ScrollStart(FCurrentStep);
end;
procedure TCustomScrollText.SetContinuous(Value: Boolean);
begin
if FContinuous <> Value then begin
FContinuous := Value;
if FScrollDirection <> sdStatic then ScrollStart(FCurrentStep);
end;
end;
procedure TCustomScrollText.SetSteps(Value: Integer);
begin
if FSteps <> Value then begin
FSteps := Value;
if csDesigning in ComponentState then Invalidate;
end;
end;
procedure TCustomScrollText.SetSpeed(Value: Integer);
begin
if FSpeed <> Value then begin
if Value > 1000 then Value := 1000
else if Value < 1 then Value := 1;
FSpeed := Value;
if FTimer <> nil then FTimer.Interval := FSpeed;
end;
end;
procedure TCustomScrollText.SetColor(Value: TColor);
begin
if FColor <> Value then begin
FColor := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.FontChanged(Sender: TObject);
begin
DataChanged;
end;
procedure TCustomScrollText.SetFont(Value: TFont);
begin
if FFont <> Value then begin
FFont.Assign(Value);
DataChanged;
end;
end;
procedure TCustomScrollText.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.SetDepth(Value: Integer);
begin
if FDepth <> Value then begin
FDepth := Value;
DataChanged;
end;
end;
procedure TCustomScrollText.ScrollStart(StartingStep: Integer);
begin
if FTimer.Enabled then Exit;
if (StartingStep >= 0) and (StartingStep <= FSteps) then FCurrentStep := StartingStep;
FTimer.Enabled := True;
end;
procedure TCustomScrollText.ScrollStop;
begin
FTimer.Enabled := False;
end;
procedure TCustomScrollText.ReverseDirection;
begin
if FScrollDirection = sdStatic then Exit;
FCurrentStep := FSteps - FCurrentStep;
case FScrollDirection of
sdLeftToRight: FScrollDirection := sdRightToLeft;
sdRightToLeft: FScrollDirection := sdLeftToRight;
sdTopToBottom: FScrollDirection := sdBottomToTop;
sdBottomToTop: FScrollDirection := sdTopToBottom;
end;
end;
procedure TCustomScrollText.TimerTick(Sender: TObject);
begin
if not FTimer.Enabled then Exit;
if (FCurrentStep = 0) and Assigned(FOnBegin) then FOnBegin(Self);
Inc(FCurrentStep);
Paint;
if Assigned(FOnStep) then FOnStep(Self);
if FCurrentStep > FSteps then begin
FTimer.Enabled := False;
if Assigned(FOnEnd) then FOnEnd(Self);
FCurrentStep := 0;
if FContinuous then ScrollStart(FCurrentStep);
end;
end;
end.