Recent

Author Topic: [ solved ] Image not shown after use scrollbar  (Read 1970 times)

Jumbo

  • New Member
  • *
  • Posts: 29
[ solved ] Image not shown after use scrollbar
« on: September 29, 2023, 01:44:29 pm »
This is a silly thing, just created a program with an image on a form with a scrollbar H|V

On top there is another image which can be moved using the mouse.
It acts as a kind of second mousepointer, because I can figure out how to make a real mousepointer.

So far so good.

Now I need to view a part of the image outside the "viewport" ? and use therefore the scollbar.

Now the second image is gone, now way to have it shown, even when I try to show it using a mouseclick.
When I scroll back to the last viewed part, the image2 pops back in view.

Even stranger,  when just moved the scrollbar a little, and image2 is still in view, it want move no more.

Any idea, or what do you want to know more.. Any help is welcome.

Code: [Select]
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin 
if(Button = TMouseButton.mbRight)then
  begin
    Image2.Show();
    Image2.Top := Y -32;
    Image2.Left := X -32;
  end;
end;

Above code want bring image2 into view....
« Last Edit: October 02, 2023, 04:26:20 pm by Jumbo »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Image not shown after use scrollbar
« Reply #1 on: September 29, 2023, 03:14:12 pm »
It is hard to decipher your text / read you.
Add a small demo project with your issue to have a look at / understand you better.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Jumbo

  • New Member
  • *
  • Posts: 29
Re: Image not shown after use scrollbar
« Reply #2 on: September 29, 2023, 05:13:42 pm »
I will upload the whole or part of the project.

Jumbo

  • New Member
  • *
  • Posts: 29
Re: Image not shown after use scrollbar
« Reply #3 on: September 29, 2023, 07:24:54 pm »
Alright, I uploaded the whole project...
Maybe the problem lies in the way I do things ?
I am not a very talented lazarus programmer so to say.. ;)

b.t.w. the project is just a first setup. to try some things out.
« Last Edit: October 02, 2023, 04:17:55 pm by Jumbo »

Handoko

  • Hero Member
  • *****
  • Posts: 5377
  • My goal: build my own game engine using Lazarus
Re: Image not shown after use scrollbar
« Reply #4 on: September 29, 2023, 09:54:37 pm »
Problem solved. See the attached video.

What you did basically is correct. But there is something you might not know. Lazarus standard visual controls are not optimized for performance, their main goal is for cross platform compatibility. So the system may skip updating the screen if it 'thinks' it is not necessary to refresh it. The problem you saw is the result of lack of screen updates. It can be solved easily by adding "Invalidate" command on the line #157 in unit1.pas. Try it, then you will soon realize you're now having a new problem. It is extremely slow. That why, the system needs to skip that screen updating for 'better' performance.

If you're doing the same way but using a good graphics library, there should be no such problem. Or if you're using Free Basic, you maybe don't have this issue because Free Basic graphics library is optimized for performance.

So what have we learned today? If you want to do 'serious' graphics using Lazarus, don't use the standard visual components. Instead choose a graphics library that is suitable for your case.

https://wiki.freepascal.org/Graphics_libraries

The link above is a list of commonly used graphics libraries that can be used by Lazarus. Some are easy to use but slow, and some are fast but hard to use.

Actually there are many things can be done to improve the performance of your code without using any third party graphics library. It requires redesigned the way the program shows/draws the images and mouse pointer but the performance gain isn't much, not worth.
« Last Edit: September 29, 2023, 10:03:19 pm by Handoko »

Jumbo

  • New Member
  • *
  • Posts: 29
Re: Image not shown after use scrollbar
« Reply #5 on: September 29, 2023, 10:14:11 pm »
Handoko, thank you for your response.

I will do some test with the advise.  I think it is solved that way !
« Last Edit: September 30, 2023, 12:03:06 pm by Jumbo »

Jumbo

  • New Member
  • *
  • Posts: 29
Re: Image not shown after use scrollbar
« Reply #6 on: October 02, 2023, 04:24:31 pm »
It indeed becomse (too) slow.  So I ditched it, made redesign with bitmaps.
Then make a cutout from original bitmap and show it streched on the image on the form.

But, other problems arise. Will figure out some way....

Thanks for the response. always fun to learn something.

 

TinyPortal © 2005-2018