One question, from inside Lazarus I load a spritesheet and set the various parameters (frame count, columns etc) to display the animation in a TCastleControlBase. I was wondering how to get scrollbars if possible. If the image is bigger than TCastleControlBase it is obviously not displayed completely but it is not possible to obtain scrollbars? I found a workaround (visible in my application available on GitHub) but I don’t like it. Is there any other solution?
Unfortunately I didn’t look through your application thoroughly, but of what I saw, you’re using TDrawableImage.Draw
and TSprite.Draw
, right? In this situation on one hand it’ll be quite trivial, on the other - will require a simple workaround:
In this case I’d have made 2 scrollbars and in CastleControl1Render
I’d made something like:
ImageX := (CastleControl1.Width div 2) - (MainImage.Width div 2) - FloatSliderX.Value * FloatSliderXScale;
ImageY := CastleControl1.Height div 2 - MainImage.Height div 2 - FloatSliderY.Value * FloatSliderYScale;
MainImage.Draw(ImageX, ImageY);
However, we’ll have to make this manipulation for every image on the stage, so, it might be reasonable to “cache” something like ShiftY := FloatSliderY.Value * FloatSliderYScale
and subtract it at every Draw
call.
I don’t see any alternative solution right away, as TCastleScrollView
adds only vertical scrollbar, so it won’t do the job out of the box.
Within CGE control, we only have a vertical scrollbar for now, by TCastleScrollView
or TCastleScrollViewManual
. You can place TCastleViewport
inside TCastleScrollView.ClientArea
and this way have a vertical scrollbar.
If you use LCL, it may be easier to use LCL scrollbar.
-
As Eugene shows you can use LCL scrollbars to influence the drawing position of something inside the control.
-
Another approach, if you just want to put a scrollbar around whole TCastleControlBase, is to just put it in TScrollBox. This is trivial and works OK in my test – attaching a source + screenshot. I assigned a trivial OnRender callback to prove that I’m actually scrolling the control content.
control_in_scrollbox.zip (126.9 KB)
( sorry for double-posting accidentally )
( Offtopic note: you have have experienced today problems posting on this forum, due to server misbehaving It is fixed now. )
You are right as always.
I was making a mistake. TCastleControlBase was set to Align = alClient. I set two options through a TRadioGroup, Fit image and Original size. Unfortunately in the second option I assigned the size to TCasteControlBase without setting Align to alNone. Sorry.