Recent

Author Topic: MouseDown behaviour  (Read 6455 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
MouseDown behaviour
« on: June 07, 2011, 01:12:42 am »
Components TScrollBar, TTrackBar and others have this behaviour:
When I press mouse button (not click but only press left mouse button and hold it down) then Knob moves.
I don't have to click many times but I simply hold left mouse button.
How can I make this with my own component (without using my own Timers) ?
My component is derived from TCustomControl. I looked to sources of TScrollBar and I can't find anything there.

Thanks.
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/

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: MouseDown behaviour
« Reply #1 on: June 07, 2011, 01:33:18 am »
What does your component do?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9913
  • Debugger - SynEdit - and more
    • wiki
Re: MouseDown behaviour
« Reply #2 on: June 07, 2011, 01:42:46 am »
I believe you will need to instantiate a timer.

Scrollbar is a widget provided by the OS or Qt/Gtk. The continues scroll behavior is implemented there. So Lazarus needs no timer, it get's messages from Win,Gtk or Qt.

Why do you not want to use a timer?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: MouseDown behaviour
« Reply #3 on: June 07, 2011, 02:33:20 am »
Maybe you can extract something from this phenomenon:

Code: [Select]
procedure TForm1.Panel3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  N :integer = 0;
begin
  MouseCapture := True;
  while MouseCapture do
  begin
    Panel3.Canvas.TextOut(0,0, IntToStr(N)+'----------');
    Application.ProcessMessages;
    Inc(n);
  end;
end;       

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: MouseDown behaviour
« Reply #4 on: June 07, 2011, 02:57:03 am »
Quote
What does your component do?
Quote
Why do you not want to use a timer?
It will be component similar to trackbar.
I didn't want to use timer because I was looking for some simlpier (elegant) way.
OK. For timer I need to know first longer delay and next shorter delays (they seem to be the same as for KeyPress). For example on my system it is 660 miliseconds between first and second repeat and 40 miliseconds between all next repeats. Can we access these constatns in Lazarus?

Code: [Select]
  MouseCapture := True;
  while MouseCapture do
  begin
    Panel3.Canvas.TextOut(0,0, IntToStr(N)+'----------');
    Application.ProcessMessages;
    Inc(n);
  end;
This code (adapted) works but it is too fast (and hi CPU load). I had to insert "sleep(40)" into loop and it seems better.
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/

 

TinyPortal © 2005-2018