Recent

Author Topic: Best way to move a panel ?  (Read 5955 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 2078
    • StrumPract is the musicians best friend
Best way to move a panel ?
« on: June 25, 2012, 04:28:49 am »
Hello Lazarus lovers.

I use the following code to move a panel with the mouse.
OK, the panel moves but not very fluently  :'(

Witch code gonna do that better ?

Many thanks

Code: [Select]
var
xinit, yinit : integer;

 procedure panelMouseDown(Sender: TObject;
                         Button: TMouseButton; Shift: TShiftState; X, Y: Integer
                         );
                       begin
   xinit := X ;
    yinit := Y ;
                       end;

  procedure panelMouseMove(Sender: TObject;
                         Shift: TShiftState; X, Y: Integer);
                       begin
                         if ssLeft in Shift then

  begin

if  xinit > x then panel.left := panel.left - xinit - x)
else panel.left :=  panel.left + (x - xinit) ;
   
if  yinit > Y then panel.Top := panel.Top - (yinit - Y)
else panel.Top :=  panel.Top + (Y - lyinit) ;
 
              end;
                       end;

 ;)
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Best way to move a panel ?
« Reply #1 on: June 25, 2012, 11:36:21 am »
Could you see if this is any better.

Fred vS

  • Hero Member
  • *****
  • Posts: 2078
    • StrumPract is the musicians best friend
Re: Best way to move a panel ?
« Reply #2 on: June 25, 2012, 03:07:07 pm »
@ KpjComp : Many thanks  :P
I gonna try it this night (but a first look, seems much better...).
Many thanks
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 2078
    • StrumPract is the musicians best friend
Re: Best way to move a panel ?
« Reply #3 on: June 25, 2012, 03:15:56 pm »
@ KpjComp :

Quote
project1.lpr(16,30) Error: Identifier not found "RequireDerivedFormResource"

PS: I use  lazarus 0.9.30 and fpc 2.4.2 for Linux 64, Linux 32, Windows 64, Windows 32 and Mac OSX 32....
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Best way to move a panel ?
« Reply #4 on: June 25, 2012, 03:21:01 pm »
I think it's something that newer versions of Lazarus add.
You can just delete it..

Fred vS

  • Hero Member
  • *****
  • Posts: 2078
    • StrumPract is the musicians best friend
Re: Best way to move a panel ?
« Reply #5 on: June 25, 2012, 03:24:59 pm »
OK KpjComp, your code is much better, thanks.

By the way, what is RequireDerivedFormResource ?
What do i miss if i do not use it ?
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Best way to move a panel ?
« Reply #6 on: June 25, 2012, 03:31:49 pm »
Quote
What do i miss if i do not use it ?

Not much really, it's all do with how Form's are created.

RequireDerivedFormResource makes sure that when the Forms Create method is called, a resource actually exists.   If you wanted to create a resourceless Form you should use CreateNew anyway, but if someone did TForm.Create and if the LFM file was missing would still succeed but have you wondering why your Form was blank

In the future, I'll try to remember to delete the line if I post an example. :)

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Best way to move a panel ?
« Reply #7 on: June 25, 2012, 03:54:50 pm »
For a bit of fun, if you wanted to move lots of TPanels, this technique works well.

I basically create an Imposter class for the TPanel ->
Code: [Select]
TPanel = class(ExtCtrls.TPanel)

This is a bit of a hack to allow you to keep your TPanel's at design time, but allow you to extend it's features.  You could add say a AllowMove properties etc, if you didn't want all TPanels to be moved etc.

Fred vS

  • Hero Member
  • *****
  • Posts: 2078
    • StrumPract is the musicians best friend
Re: Best way to move a panel ?
« Reply #8 on: June 25, 2012, 04:20:11 pm »
Whaouw, KpjComp, many thanks, i gonna try it...

Do you think i can use the same method for moving images ( to create custom sliders...) ?

 :-[ by the way, i gonna post a other topic that maybe you could help me too  :P
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Best way to move a panel ?
« Reply #9 on: June 25, 2012, 04:23:19 pm »
Quote
Do you think i can use the same method for moving images ( to create custom sliders...) ?

Yes, I see no reason why not.

Basically this technique is similar to creating a custom component, but avoids you having to register with the IDE.  The only downside is that extra properties you add don't appear in the IDE, and you would need to fill these in via code.  eg. If you did add a property called moveable, you could only set this in code.

Fred vS

  • Hero Member
  • *****
  • Posts: 2078
    • StrumPract is the musicians best friend
Re: Best way to move a panel ?
« Reply #10 on: June 25, 2012, 04:37:12 pm »
@ KpjComp : brilliant  ::)
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

 

TinyPortal © 2005-2018