Board index » cppbuilder » forms scalemode

forms scalemode


2007-05-21 12:44:54 AM
cppbuilder94
Hello all
I have a panel which contain many images boxes and lables.
I want to scroll this panel with the variable speeds.
For this i have code in a timer whose interval is set to 25 milli seconds.
ScrollSpeed = 1;
void __fastcall TfrmMain::Timer1Timer(TObject *Sender)
{
picTickerPanel->Left = picTickerPanel->Left + ScrollSpeed;
}
1.I want to decrease the speed
say ScrollSpeed = .5;
which is not working. Is there any way change the form scale mode to twips
etc.
2.I am getting flickering while scrolling, how to avoid this.
I tried DoubleBuffered = true and ControlStyle>>csOpaque. No use the label
controls are flickering.
any suggestion pls.
Thanks
SA
 
 

Re:forms scalemode

"bar" < XXXX@XXXXX.COM >wrote:
Quote
I have a panel which contain many images boxes and lables.
I want to scroll this panel with the variable speeds.
For this i have code in a timer whose interval is set to 25
milli seconds.

ScrollSpeed = 1;
void __fastcall TfrmMain::Timer1Timer(TObject *Sender)
{
picTickerPanel->Left = picTickerPanel->Left + ScrollSpeed;
}

1.I want to decrease the speed say ScrollSpeed = .5;
which is not working. Is there any way change the form scale
mode to twips etc.
Well on screen you have only pixels, so you can move only pixel-
wise. Hence setting the timer interval from 25 to 50 would solve
this problem. Otherwise you would have to store the float value
somewhere. For instance:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
const static double Interval = 0.5;
static double InitPosition = picTickerPanel->Left;
static double Offset = 0.0;
Offset += Interval;
picTickerPanel->Left = InitPosition + Offset;
}
Quote
2.I am getting flickering while scrolling, how to avoid this.
I tried DoubleBuffered = true and ControlStyle>>csOpaque. No
use the label controls are flickering.
You could paint what's needed in form's OnPaint instead of using
panel and labels (holding the current Offset in an instance variable). Then there would be no controls moving. Using
DoubleBuffered on the form and should make it smooth enough.
 

Re:forms scalemode

Quote
You could paint what's needed in form's OnPaint instead of using
panel and labels (holding the current Offset in an instance variable).
Then there would be no controls moving. Using
DoubleBuffered on the form and should make it smooth enough.
hi thorsten thanks for reply
sorry i didn't understand what you suggested.
The point is i have to scroll some of the pictures and text.
For this i am creating images boxes and lable controls dynamically, all
together placed in a panel and i am moving this panel.
Any suggestions
Thanks
SA
 

{smallsort}

Re:forms scalemode

"bar" < XXXX@XXXXX.COM >wrote:
Quote

The point is i have to scroll some of the pictures and text.
For this i am creating images boxes and lable controls dynamically, all
together placed in a panel and i am moving this panel.
I have used a TPaintBox inside a TScrollBox where I paint a
huge TBitmap and scroll it with only a slight occurance of
flicker and that's without using DoubleBuffered.
Using TImage(s) can greatly reduce performance especially if
they're stretched. I would suggest that you use TBitmaps and
AnsiStrings instead and be sure that if you are reducing the
image that you do so when you load the image instead of doing
it every time you paint it.
Assuming that you have one TLabel for every TBitmap, define a
new class (that derives from TComponent because of Owner(ship)
benifits) that will allocate and manage the Text and Image for
you. For example:
//-------------------------------------------------------------
class TLabeledImage : public TComponent
{
private:
int FLeft;
int FTop;
AnsiString FText;
Graphics::TBitmap *FImage;
public:
__fastcall TLabeledImage( TComponent* Owner, int, int, int, int, AnsiString&, Graphics::TBitmap* );
__fastcall ~TLabeledImage();
__property int Left = { read = FLeft };
__property int Top = { read = FTop };
__property AnsiString Text = { read = FText };
__property Graphics::TBitmap *Image = { read = FImage };
};
//-------------------------------------------------------------
__fastcall TLabeledImage::TLabeledImage( TComponent* Owner, int AWidth, int AHeight, int ALeft, int ATop, AnsiString &AText, Graphics::TBitmap *AImage ) : TComponent(Owner)
{
FImage = new Graphics::TBitmap();
FImage->PixelFormat = pf24bit;
FImage->Canvas->Brush->Style = bsClear; // Reported to speed-up bitmap operations
FImage->Width = AWidth;
FImage->Height = AHeight;
FImage->Canvas->StretchDraw( Rect(0,0,AWidth,AHeight), AImage );
FLeft = ALeft;
FTop = ATop;
FText = AText;
}
//-------------------------------------------------------------
__fastcall TLabeledImage::~TLabeledImage()
{
delete FImage;
}
//-------------------------------------------------------------
To use it the above class, allocate it as needed in the loop
where you load the images. For example (note that the
TPaintBox is set at the Owner):
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
int L = SomeInitialPos, T = SomeOtherInitialPos;
while( files still to load )
{
Bmp->LoadFromFile( SomeFileName );
new TLabeledImage( PaintBox1,
DesiredImageWidth,
DesiredImageHeight,
L,
T,
DesiredCaption,
Bmp );
if( L < SomeWidthLimit )
{
L += SomeNumberOfPixels;
}
else
{
L = SomeInitialPos;
H += SomeOtherNumberOfPixels;
}
}
PaintBox1->Height = H + MaybeSomeExtraPixels;
delete Bmp;
Then to draw the images, ad an OnPaint event to the TPaintBox
and make the code look like:
//-------------------------------------------------------------
void __fastcall TFormX::PaintBox1Paint(TObject *Sender)
{
TRect Dst, Src;
TPaintBox *Box = static_cast<TPaintBox*>( Sender );
for( int x = 0; x < Box->ComponentCount; ++x )
{
TLabeledImage *LI = static_cast<TLabeledImage*>( Box->Components[x] ); // might need reinterpret_cast here
Dst = Rect( LI->Left, LI->Top, LI->Left + LI->Image->Width, LI->Top + LI->Image->Height );
Src = Rect( 0, 0, LI->Image->Width, LI->Image->Height );
Box->Canvas->CopyRect( Dst, LI->Image->Canvas, Src );
Box->Canvas->TextOut( LI->Left + Something, LI->Top + Somethingelse, LI->Text );
}
}
//-------------------------------------------------------------
If you need to reuse the form without destroying it, you can
destroy all of the TLabeledImage by iterating the TPaintBox's
Components array. For example (Note that the array is iterated
backwards):
for( int x = PaintBox1->ComponentCount; x>0; --x )
{
delete PaintBox1->Components[ x - 1 ];
}
If you're not reusing the form, then because the TLabeledImages
are Owned by the TPaintBox and the TPaintBox is Owned by the
TForm, when the TForm is destroyed, the TPaintBox is also
destroyed which will cause all of the TLabeledImages that it
Ownes to be destroyed. IOW, a simple call to delete to destroy
the form is all that's needed.
You should not need to worry about scrolling any more because
the TScrollBox will automatically handle all of that for you
according to how you have positioned and sized the TPaintBox
but if you still want to, all you have to do is set the
TScrollBox's scroll positions.
~ JD
 

Re:forms scalemode

Hello JD
My target is i have form having a background image.
the code i used for painting.
TPicture *g = new TPicture();
g->LoadFromFile("C:\\GraphicName.gif");
for(int y = 0; y < frmMain->Height; y += g->Height)
{
for(int x = 0; x < frmMain->Width; x += g->Width)
Canvas->Draw(x, y, g->Graphic);
}
It is painting fine.
I have some imageboxes and labels creating at runtime, i need to scroll in a
line, so i took Panel as a container.
The PaintBox is not holding any control.
While scrolling this panel huge flickering is coming.
How to resolve this issue or can i any other technique.
Thanks
SA
 

Re:forms scalemode

"bar" < XXXX@XXXXX.COM >wrote:
Quote

My target is i have form having a background image.
the code i used for painting.

TPicture *g = new TPicture();
g->LoadFromFile("C:\\GraphicName.gif");
for(int y = 0; y < frmMain->Height; y += g->Height)
{
for(int x = 0; x < frmMain->Width; x += g->Width)
Canvas->Draw(x, y, g->Graphic);
}
It is painting fine.
But's this is where your problem is.
Draw is veeeerrrry slow. You need to be using TCanvas::CopyRect
or the Win32 API BitBlt. I'm uncertain how to proceed because
I haven't worked with a gif before but I would expect that at
a minimum, you can allocate a TBitmap and Draw to to it.
In the Form's OnResize event, size the TBitmap the same as the
Form's ClientRect and then do the Draw(ing) of the gif to the
TBitmap. Then the above code can be changed to use CopyRect or
BitBlt.
Of course, the same flicker will still show up but not when
scrolling. You just moved it to when the form is resized.
~ JD