Recent

Author Topic: Zoom of a form  (Read 1982 times)

luca

  • Jr. Member
  • **
  • Posts: 90
Zoom of a form
« on: August 24, 2020, 05:07:01 pm »
I'd like to implement a form that can zoom its contents.
Something like the scale factor in Firemonkey app.

Do you know if it's possible in Lazarus?

Regards
Luca

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Zoom of a form
« Reply #1 on: August 24, 2020, 05:12:30 pm »
I never try Firemonkey. But I know Lazarus can do such thing. On the link below go to User Interface category then click the Scaling a Form demo:

https://wiki.freepascal.org/Portal:HowTo_Demos

Unfortunately it did not work correctly on Lazarus 1.8.0, not sure if the bug has been already fixed or not.
« Last Edit: August 24, 2020, 05:15:01 pm by Handoko »

luca

  • Jr. Member
  • **
  • Posts: 90
Re: Zoom of a form
« Reply #2 on: August 24, 2020, 05:24:30 pm »
Hi,
Firemonkey is implemented in Delphi as an alternative to VCL applications.

Your solution it's ok for graphical elements but is not exactly what I'm looking for; I'd like to have something similar to CTRL + {+/-} zooming function in a browser: controls, fonts and all graphical elements are reduced maintaing the rigth proportions.

My idea is to have a sort of ScalingPanel to implement this feature.

Regards
Luca

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Zoom of a form
« Reply #3 on: August 24, 2020, 05:36:39 pm »
Hi!

A demo with the BGRA library.
I use it because it makes good images if you zoom in.
You can download the BGRAbitmapPack from the Online Package Manager.

Take a Form, an Image and a Button.
Code: Pascal  [Select][+][-]
  1.  
  2. uses ...., BGRABitmap, BGRADefaultBitmap, BGRABitmapTypes;
  3.  
  4.  
  5. procedure TForm1.Button1Click(Sender: TObject);
  6. var R, small : Trect;
  7.     bmp: TBGRABitmap;
  8. begin
  9. Image1.Canvas.brush.color := clWhite;
  10. Image1.Canvas.fillrect (0,0,Image1.width, Image1.Height);
  11.  
  12. bmp := TBGRAbitmap.create;
  13. bmp.LoadFromDevice(Form1.Canvas.Handle);
  14. small := Rect(50,50,50+bmp.width div 2, 50+bmp.height div 2);
  15. BGRAReplace(bmp,bmp.GetPart(small));
  16. BGRAReplace (bmp,bmp.Resample(bmp.width * 2, bmp.Height * 2) );
  17. R := Rect(0,0,bmp.width, bmp.height);
  18. Image1.Canvas.CopyRect (R,bmp.canvas,R);
  19. bmp.free;
  20. end;                            
  21.  
We copy the canvas of Form1 into bmp.
Then we  take a part of the image starting at 50/50.
Now we resize it to the double size.
And finally we draw it on the Image.canvas.

Winni

jamie

  • Hero Member
  • *****
  • Posts: 7662
Re: Zoom of a form
« Reply #4 on: August 24, 2020, 06:12:07 pm »
That reminds me..

 The little ICON MS uses when you click your middle button over the Web browser, it gives you a different cursor,..

If I was to use that cursor would I expect to have a failing app on older OSes ? nothing less than W2k/Xp or course.
The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Zoom of a form
« Reply #5 on: August 24, 2020, 06:45:50 pm »
My idea is to have a sort of ScalingPanel to implement this feature.

I'm not sure but maybe you can try TFrame:
https://wiki.freepascal.org/Frames

TFrame is a kind of form that can be inserted into a form, and it has scale feature.

 

TinyPortal © 2005-2018