Link to home
Start Free TrialLog in
Avatar of Gwena
Gwena

asked on

Help! My scrolling text is very jerky

I have been trying create a smooth scrolling text effect without
much success :-(

When I used a label the text was both jerky and flickery...
I finally figured out that putting the text onto a panel and
sliding the panel sideways got rid of the flicker...but the jerky
start and stop motion remains. I use the timer to slide the panel
across the form... maybe I need a better timer or a better way to
use the standard one... anybody out there know how to fix this?

..Gwen..
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gwena
Gwena

ASKER

Hi Simonet :-)

Thanx for the info!   I will try that code first thing in the morning...I sure hope it works... I am at my wits end trying to get the flickering jerkies out of this scrolling text :)

p.s.  I saw that post about your website being plagiarized :-(  what a !@#$% that guy is! ..please don't take your site down though...I like your site.
Avatar of Gwena

ASKER

Hi Simonet :-)

Thanx for the info!   I will try that code first thing in the morning...I sure hope it works... I am at my wits end trying to get the flickering jerkies out of this scrolling text :)

p.s.  I saw that post about your website being plagiarized :-(  what a !@#$% that guy is! ..please don't take your site down though...I like your site.
Avatar of Gwena

ASKER

Hi Simonet...

I must be doing something wrong here.. I renamed the code above to marquee.pas
and then installed it as a component in D3
But when I try to use it the panel just remains
blank....I put several strings into the strings list but no text appears.
 
The events all seem to work OK..

Did I install the component wrong?

I tried installing in D2 but I get an error
"class Tbevel not found" when I try to
put strings into the strings list.

...Gwen..
It only works in runtime. You don't see any scrolling text in design-time. Besides, you have to call TMarquee.Activate in order to make it work.

Alex
here ya go:
This code is in a timer event

  {// draw bitmap in appropriate position(moving L->R)
  BitBlt(bnr.Canvas.Handle,amt,0,scrll.Width-amt,bnr.Height,scrll.Canvas.Handle,0,0,SRCCOPY);
  BitBlt(bnr.Canvas.Handle,0,0,amt,bnr.Height,scrll.Canvas.Handle,scrll.Width-amt,0,SRCCOPY);}
  // draw bitmap in appropriate position(moving R->L)
  BitBlt(bnr.Canvas.Handle,0,0,scrll.Width-amt,bnr.Height,scrll.Canvas.Handle,amt,0,SRCCOPY);
  BitBlt(bnr.Canvas.Handle,scrll.width-amt,0,amt,bnr.Height,scrll.Canvas.Handle,0,0,SRCCOPY);

it scrolls a bitmap, I used it to scroll text by using the textout function.  It works okay for me
oh yeah, a couple other things:
amt is the number of pixels to scroll
and bnr is a label that I used to scroll the text on.
Avatar of Gwena

ASKER

Hi Simonet :-)

That marquee effect looks pretty good...
Can it scroll from left to right and right to left
or does it just do up and down ?

I get an error when I stop a program that uses the marquee.. it says  'marquee1 has no parent window'   ?

Avatar of Gwena

ASKER

Hi ckaneta :-)

Your code looks like it might be what I need...
But I'm having trouble getting it to work...
could you please show me an example program
that uses this code... you could put it here or
email it to me at gwena@gurlmail.com
It is always a huge help to me to see working examples of code.... I'm still pretty much a Delphi
newbie.

...Gwen..
Why are you using BitBlt that copies a part of the bitmap instead of ScrollWindowEx that uses hardware support (if available)?
ScrollWindow is in most of the case the fastest, easiest and flickerfreeest solution (as long you don't use DirectX).
Gwena, the component I sent you only does vertical scrolling. I'll see if I can find a horizontal marquee on my library.

Alex
Here's an example:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, ExtDlgs, Buttons;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    tmr: TTimer;
    dir: TRadioGroup;
    scroll: TSpeedButton;
    lodpic: TSpeedButton;
    img1: TImage;
    pict: TOpenPictureDialog;
    settxt: TSpeedButton;
    Edit1: TEdit;
    procedure tmrTimer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure lodpicClick(Sender: TObject);
    procedure scrollClick(Sender: TObject);
    procedure settxtClick(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
   scrtxt : String;
   pos    : Integer;
   bmp    : TBitmap; //Bitmap to scroll
   procedure setscr;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
{------------------------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
 begin
  bmp:=TBitmap.Create;  pos:=0; scrtxt:='';
  pict.InitialDir:=ExtractFilePath(application.exename);
 end;
procedure TForm1.FormActivate(Sender: TObject);   begin {} end;
procedure TForm1.FormDestroy(Sender: TObject);    begin bmp.Destroy; end;
{------------------------------------------------------------------------------}
procedure TForm1.tmrTimer(Sender: TObject);
 begin
  if dir.ItemIndex = 0 then begin
              // draw bitmap in appropriate position(moving L->R)
   BitBlt(label1.Canvas.Handle, pos, 0, bmp.Width-pos, label1.Height,
          bmp.Canvas.Handle, 0, 0, SRCCOPY);
   BitBlt(label1.Canvas.Handle, 0, 0, pos, label1.Height, bmp.Canvas.Handle,
          bmp.Width-pos, 0, SRCCOPY);
  end else if dir.ItemIndex = 1 then begin
             // draw bitmap in appropriate position(moving R->L)
   BitBlt(label1.Canvas.Handle, 0, 0, bmp.Width-pos, label1.Height,
          bmp.Canvas.Handle, pos, 0, SRCCOPY);
   BitBlt(label1.Canvas.Handle, bmp.width-pos, 0, pos, label1.Height,
          bmp.Canvas.Handle, 0, 0, SRCCOPY);
  end;
  InvalidateRect(label1.canvas.Handle, nil, false );
  inc(pos, 5); if (pos >= bmp.width) and (bmp.width<>0) then
   pos:=pos mod bmp.width;
 end;

procedure TForm1.setscr;                     // set up bitmap to scroll
var img : TBitmap; ht,w : Integer;
 begin
  img:=TBitmap.Create;       label1.canvas.font:=label1.font;
  if scrtxt = '' then begin
   img.LoadFromFile(pict.FileName);
  end else begin
   ht:=(label1.Height div 2) - (img.Canvas.TextHeight('H') div 2);
   img.height:=label1.height;
   img.width:=8*length(scrtxt)+15;
   img.canvas.Brush.color:=clWhite; img.canvas.floodfill(1,1,clBlack,fsSurface);
   img.canvas.pen.color:=label1.font.color;
   img.Canvas.TextOut(1,ht,scrtxt);
  end;

  bmp.Height:=img.height;     bmp.width:=0;   w:=img.width;
  while bmp.width < label1.width do begin
   bmp.width:=bmp.width+img.width;
   bmp.Canvas.CopyRect(Rect(bmp.width-w, 0, bmp.width, img.height),
                       img.canvas, Rect(0, 0, img.width, img.height));
  end;
  img.Destroy;
 end;
{------------------------------------------------------------------------------}
procedure TForm1.scrollClick(Sender: TObject);
 begin
  tmr.Enabled:=not(tmr.Enabled);
  if tmr.Enabled then scroll.caption:='Stop' else scroll.caption:='Start';
 end;
procedure TForm1.lodpicClick(Sender: TObject);
 begin
  pict.FileName:=''; edit1.text:=''; scrtxt:='';
  if pict.Execute then begin
   img1.Picture.LoadFromFile(pict.FileName);
   setscr;
  end;
 end;
procedure TForm1.settxtClick(Sender: TObject);
 begin
  if edit1.text <> '' then begin
   scrtxt := edit1.text;
   setscr;  pict.FileName:='';
  end;
 end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 begin if key = #13 then settxtClick(Sender); end;

end.
Avatar of Gwena

ASKER

It's not exactly what I was after since it scrolls up/down instead of right/left  ... but I found a good use for the code in another project... so I'm going to use it... so here is the 75 points :-)