Lazarus

Programming => LCL => Topic started by: dietmar on September 09, 2021, 06:41:38 pm

Title: Splash form "in pieces"
Post by: dietmar on September 09, 2021, 06:41:38 pm
Hi!

I designed a splash form with an image on it and a progress bar. Tested that on 2 different Notebooks. On the first one (where I designed it), I set Position to "poScreenCenter" and it just looks fine (resolution: 1600x900).

On the second one (resolution: 1920x1080) I get 2 problems:
1. The Splash form is not in the center, but out of it.
2. The progress bar isn't on the form any more, but somewhere in the middle of the desktop!?!

Does anyone have an explanation or even a solution for this behaviour?

Thx,
--Dietmar
Title: Re: Splash form "in pieces"
Post by: MarkMLl on September 09, 2021, 07:05:36 pm
No, but a good place to start would probably be in the Screen and ScreenInfo objects which allow you to get at the screen/monitor dimensions (with the caveat that I've not looked at this on Windows, only Linux/Solaris).

MarkMLl
Title: Re: Splash form "in pieces"
Post by: winni on September 09, 2021, 08:11:59 pm
Hi!

Not an explanation but a solution to center the SplashForm in the center:

Code: Pascal  [Select][+][-]
  1. procedure TSplashForm1.FormCreate(Sender: TObject);
  2. begin
  3.   left := (Screen.Width - self.Width) div 2;
  4.   Top :=  (Screen.Height - self.height) div 2;
  5. end;
  6.  


And the progressbar:
Make shure, that the parent of the progressbar is the SplashForm:

Right click on the progressbar  --> Change Parent


Winni
Title: Re: Splash form "in pieces"
Post by: dietmar on September 09, 2021, 10:25:22 pm
Thx, the centering now works...

But unfortunately, the progress bar already has the form as parent.
One crazy solution could be to calculate the position of the progress bar relatively to the form position...

--Dietmar
Title: Re: Splash form "in pieces"
Post by: dietmar on September 09, 2021, 10:32:52 pm
No, doesn't work this way. If I change the Left and Top values of the progress bar, it is completely hidden and no longer visible on the screen :/

--Dietmar
Title: Re: Splash form "in pieces"
Post by: winni on September 09, 2021, 10:40:01 pm
Hi!

Whatever you compute with the progressbar ...

Place the ProgressBar to your  needs.

Use the poroperty anchor in the OI:
Anchor it to all 4 sides.

If that does not help we need some code.

Winni
Title: Re: Splash form "in pieces"
Post by: wp on September 09, 2021, 11:16:53 pm
When it's only a splash form then it should not be too difficult for you to extract it and demonstrate the issue in a simple compilable project. Too much guessing otherwise.
Title: Re: Splash form "in pieces"
Post by: dietmar on September 13, 2021, 05:08:30 pm
Ok, here it is...

Please notice:
Since I left the SQLite Init Routines in the form (because perhaps they are the reason for the problem?), you have to copy sqlite.dll into the folder to get it working.

Thx,
--Dietmar
Title: Re: Splash form "in pieces"
Post by: dietmar on September 20, 2021, 03:45:24 pm
The strange thing I just noticed is that even calculating the screen center for the splash form like

Code: Pascal  [Select][+][-]
  1. procedure TSplashForm1.FormCreate(Sender: TObject);
  2. begin
  3.   left := (Screen.Width - self.Width) div 2;
  4.   Top :=  (Screen.Height - self.height) div 2;
  5. end;
  6.  

does not work :(

--Dietmar
Title: Re: Splash form "in pieces"
Post by: winni on September 20, 2021, 04:53:24 pm
The strange thing I just noticed is that even calculating the screen center for the splash form like

Code: Pascal  [Select][+][-]
  1. procedure TSplashForm1.FormCreate(Sender: TObject);
  2. begin
  3.   left := (Screen.Width - self.Width) div 2;
  4.   Top :=  (Screen.Height - self.height) div 2;
  5. end;
  6.  

does not work :(

--Dietmar

Hi!

Set the property position in the OI to poDesigned.

Otherwise the code does not work.

Winni
Title: Re: Splash form "in pieces"
Post by: robert rozee on September 20, 2021, 05:56:28 pm
the method i use (with a regular form) is:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Form1.Left:=(Form1.Monitor.WorkAreaRect.Width-Form1.Width) div 2;    // approximate centre of screen, ignores title bar height
  4.   Form1.Top:=(Form1.Monitor.WorkAreaRect.Height-Form1.Height) div 2;   // and side border widths, but is the best we can do.
  5.   AlphaBlendValue:=0;                                                  // start up invisible, Timer1 handler
  6.   AlphaBlend:=true                                                     // fades in over approximately 225ms (comment out for testing)
  7. end;
  8.  
  9.  
  10. procedure TForm1.Timer1Timer(Sender: TObject);                         // (15ms timer event)
  11. const startup:boolean=true;
  12.       holdoff:integer=-90;
  13. begin
  14.   if startup then                                                      // startup with AlphaBlend=true, slow fade in after holdoff
  15.   begin
  16.     if holdoff<0 then inc(holdoff, Timer1.Interval)
  17.                  else AlphaBlendValue:=min(AlphaBlendValue+17, 255);
  18.     if AlphaBlendValue=255 then
  19.     begin
  20.       AlphaBlend:=false;                                               // at 100% visibility turn off AlphaBlend
  21.       startup:=false                                                   // set end of startup flag, never end up here again
  22.     end
  23.   end
  24. end;


as winni said, set the property position in the object inspector to poDesigned.

the 90ms holdoff is to allow the form to 'snap' into position before it starts to become visible. without any holdoff, the form can be visibly seen moving on the screen. the above works in linux, as well as under winXP running in a VM.


cheers,
rob   :-)

Title: Re: Splash form "in pieces"
Post by: dietmar on September 21, 2021, 05:12:28 pm
Hm,

unfortunately, "poDesigned" didn't help either :(

--Dietmar
Title: Re: Splash form "in pieces"
Post by: dietmar on September 21, 2021, 10:29:02 pm
Hm, I think I just encountered a bug:

When I set Position to poDesigned, all seems ok. But when I restart Lazarus afterwards, it is set back to poScreenCenter! And I assume that when compiling the project, it is already "poScreenCenter" again and therefore the code doesn't work!

I searched the whole code whether there is any sign of setting it back, but I didn't found a line...

Can anyone confirm this behaviour?

--Dietmar
Title: Re: Splash form "in pieces"
Post by: MarkMLl on September 21, 2021, 10:38:25 pm
Hm, I think I just encountered a bug:

When I set Position to poDesigned, all seems ok. But when I restart Lazarus afterwards, it is set back to poScreenCenter! And I assume that when compiling the project, it is already "poScreenCenter" again and therefore the code doesn't work!

I searched the whole code whether there is any sign of setting it back, but I didn't found a line...

Can anyone confirm this behaviour?

Not as such, but I've been considering mentioning that my experience on Linux is that that setting is- at best- widget-set specific. It's like the old joke about social scientists' most robust prediction being "Some do, some don't".

So I'm afraid that I stick by my (much) earlier comment

Quote
No, but a good place to start would probably be in the Screen and ScreenInfo objects which allow you to get at the screen/monitor dimensions (with the caveat that I've not looked at this on Windows, only Linux/Solaris).

i.e. you need to dump what the various properties report in a way that doesn't itself mess up your user interface rather than trying to use them blindly.

MarkMLl
Title: Re: Splash form "in pieces"
Post by: winni on September 22, 2021, 12:34:18 am
Hm, I think I just encountered a bug:

When I set Position to poDesigned, all seems ok. But when I restart Lazarus afterwards, it is set back to poScreenCenter! And I assume that when compiling the project, it is already "poScreenCenter" again and therefore the code doesn't work!

I searched the whole code whether there is any sign of setting it back, but I didn't found a line...

Can anyone confirm this behaviour?

--Dietmar

Hi!

I cant confirm this. Everything works a exspected.
Lin64, gtk2, fpc 3.2, Laz 2.0.12

But you can enhance you code to:

Code: Pascal  [Select][+][-]
  1.     procedure TSplashForm1.FormCreate(Sender: TObject);
  2.     begin
  3.      self.position := poDesigned; // <-- !!!!!
  4.       left := (Screen.Width - self.Width) div 2;
  5.       Top :=  (Screen.Height - self.height) div 2;
  6.     end;
  7.  
     

Winni

Title: Re: Splash form "in pieces"
Post by: dietmar on September 24, 2021, 07:24:19 pm
I already tried that, but without success.

I think I give up now :(

Dietmar
Title: Re: Splash form "in pieces"
Post by: wp on September 25, 2021, 12:22:50 am
This is an issue related to the different screen resolution on both systems.

When I open your demo on my standard development system at 96pp everything is nicely centered. When I open it on a VM at 144ppi the form is centered too, but larger. you have an image background in the splash form which you use as a mask to get some kind of oval window. Of course, this does not scale. Since the image is in the upper left corner of the window the masked window is no longer centered. And the progressbar does no longer overlap with the image.

In order to center the splash form on the high-res screen you either provide several background images depending on the actual resolutions so that they fill the window in the same way as they do at 96ppi. Or you set the TImage properties Stretch and Proportional to true to scale the image into the window.

This way I was able to center the window at 144ppi. The progressbar is still off. This is due to your function MakeTransparentWindow which seems not to be compatibile with LCL scaling. When I comment out its call the the progressbar is inside the window at runtim, however at a different position. But you reposition the progressbar in the OnCreate event, and I did not check this.

So, in summary:
Set Image.Stretched = true and Image.Proportional = true. Look into the MakeTransparentWindow to find where it collides with LCLScaling.

The easiest way, however, is to leave everything as it is now, but set the splash form's Scaled to false -- this disables LCLScaling for the splash form. The disadvantage is that the splash form appears to be smaller on a high res screen, and the progressbar appears to be thinner - but you can increase its height accordingly: pbInit.Height := Scale96ToForm(pbInit.Height) in FormOnCreate.
Title: Re: Splash form "in pieces"
Post by: dietmar on September 25, 2021, 06:23:35 pm
WP, you are not only "a" hero member, but MY personal hero member!!

Now it finally works and I am very glad!
I just made the Splash image bigger and did as you wrote in your last paragraph...

Thanks a lot, also to all the others contributing here! Great work!

--Diet"made my weekend"mar ;)
TinyPortal © 2005-2018