Recent

Author Topic: What is the best way to add long press event to button class?  (Read 5217 times)

aradeonas

  • Hero Member
  • *****
  • Posts: 824
What is the best way to add long press event to button class?
« on: December 22, 2014, 01:48:27 pm »
Hi,
For windows this link is a really good answer but also it should work in Linux.
http://stackoverflow.com/questions/9629063/what-is-the-best-way-to-add-long-press-event-to-button-class
How can I do that without using windows unit?
Thanks

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: What is the best way to add long press event to button class?
« Reply #1 on: December 22, 2014, 01:58:59 pm »
What I would to use is a TTimer.

The idea:
  • Put a TTimer in the Form, set the interval to 2000 (or the time you want in milliseconds), write the OnTimer event, and set Enabled to FALSE.
  • Now, set Form event "OnMouseDown" to enable the TTimer object.
  • Also, set Form event "OnMouseUp" to disable the TTimer object.
That should work. Maybe you should also set events "OnMouseExit", and don't forget to disable the TTimer in the "onTimer" event.
« Last Edit: December 22, 2014, 02:00:46 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: What is the best way to add long press event to button class?
« Reply #2 on: December 22, 2014, 02:02:47 pm »
Thanks.
Yes obviously I can do that but that link answer is cleaner and  I want to know how can do something like that in Lazarus and use it in Linux and Windows.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: What is the best way to add long press event to button class?
« Reply #3 on: December 22, 2014, 02:17:01 pm »
I disagree.  The use of TTimer is clean enough for me (except you don't use comprehensive object names, nor comments, nor documentation...).

Anyway, the use of messages and/or low-level components and APIs (i.e. "NewFormWndProc") is platform-dependant, so AFAIK there's no way to use them in a cross-platform way.

Windows GDI is way different than XWindow, which is different than GTK (even in same OS!), which is incompatible with Cocoa... That's why LCL sources are huge.  They must encapsulate a lot of different stuff.
« Last Edit: December 22, 2014, 02:19:16 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: What is the best way to add long press event to button class?
« Reply #4 on: December 22, 2014, 02:18:15 pm »
Thank you vary much.

CM630

  • Hero Member
  • *****
  • Posts: 1081
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: What is the best way to add long press event to button class?
« Reply #5 on: December 22, 2014, 04:06:51 pm »
If you intend to use it often, you could make your own control. For example you can try the ArrowStar control from here.
AFIR, I have used 4 separate timers there, but surely I could have done it with one.

Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: What is the best way to add long press event to button class?
« Reply #6 on: December 22, 2014, 06:45:42 pm »
TECSpeedBtn from EC-Controls can do it.

Put it on a form, set its Delay property to positive value [miliseconds] and assign its OnHoldDown event.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

CM630

  • Hero Member
  • *****
  • Posts: 1081
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: What is the best way to add long press event to button class?
« Reply #7 on: December 22, 2014, 08:55:53 pm »
TECSpeedBtn from EC-Controls can do it.

Put it on a form, set its Delay property to positive value [miliseconds] and assign its OnHoldDown event.
I just tried to install it, but:
Quote
C:\lazarus\lpk\ecc\ecspinctrls.pas(536,14) Error: There is no method in an ancestor class to be overridden: "TECSpinEditSpacing.GetSpace(TAnchorKind):LongInt;"
C:\lazarus\lpk\ecc\ecspinctrls.pas(537,15) Error: There is no method in an ancestor class to be overridden: "TECSpinEditSpacing.GetSpaceAround(var RECT);"
C:\lazarus\lpk\ecc\ecspinctrls.pas(664,1) Fatal: There were 2 errors compiling module, stopping

Anyway, in the ArrowStar I have the following properties:
RepeatFastRate,  RepeatSlowRate , RepeatsUntilFastRate (all int).
The concept is that after  RepeatsUntilFastRate is reached, the OnClick (in you case OnHoldDown) event is generated faster. Such behaviour is quite common in different devices, for example clocks and wathes (when adjusting time).
If you don't have such behaviuor, I would recoomend you to add it.
« Last Edit: December 22, 2014, 09:49:34 pm by paskal »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: What is the best way to add long press event to button class?
« Reply #8 on: December 22, 2014, 09:31:22 pm »
Thank you both.
I will test these.

 

TinyPortal © 2005-2018