Lazarus

Programming => General => Topic started by: bobby100 on July 02, 2022, 10:11:57 am

Title: Redraw issues, how to optimize the code?
Post by: bobby100 on July 02, 2022, 10:11:57 am
I am using Eye candy controls for user interface.
To display the current state of the sliders at moving the slider, I use a TPanel (pnHint) with a TLabel (lbHint) on it (see screenshot, the cursor isn't shown in the capture, but I was at moving the slider as the capture is done). Both TPanel and TLabel are set to Autosize. When TLabel is set to Visible := False, the TPanel isn't visible.
Here is the code that displays the label:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.slSliderChange(Sender: TObject);
  2. var
  3.   pt: TPoint;
  4.   ctrl: TControl;
  5. begin
  6.   pt := ScreenToClient(Mouse.CursorPos);
  7.   lbHint.Caption := IntToStr(trunc(TECSlider(Sender).Position));
  8.   ctrl := ControlAtPos(pt, [capfRecursive, capfAllowWinControls]);
  9.     if Assigned(ctrl) then
  10.     begin
  11.         pnHint.Left := ctrl.Left + ctrl.Width - lbHint.Width
  12.     end
  13.     else
  14.         pnHint.Left := pt.Y;
  15.   pnHint.Top := pt.Y;
  16.   //pnHint.BringToFront;
  17.   lbHint.Visible := True;
  18. end;
  19.  
  20. procedure TfrmMain.slSliderMouseUp(Sender: TObject; Button: TMouseButton;
  21.   Shift: TShiftState; X, Y: Integer);
  22. begin
  23.   lbHint.Visible := False;
  24. end;
As it can be seen, the panel and label follows the cursor (which is nice), but if the slider is moved too fast - there are redrawing artifacts (ghosts).

Any advices what can be optimized here?
Using Hints from the controls isn't a solution.
Title: Re: Redraw issues, how to optimize the code?
Post by: dje on July 02, 2022, 01:02:54 pm
I tried your setup/code using 4 TTrackBar's on a Raspberry Pi, and saw no "ghosting", so Im guessing the issue is with the extra rendering Eye Candy uses.

Have you tried calling slSlider.Update or slSlider.Paint?  Or, sometimes Application.ProcessMessages works.

As a fallback solution. Does the hint really need to move with the mouse? I've seen similar interfaces with static hint popup.
Title: Re: Redraw issues, how to optimize the code?
Post by: bobby100 on July 02, 2022, 01:37:13 pm
Thanks for taking a look derek.john.evans

The whole interface is a bit slow at rendering because of 102 sliders on the screen, nested in TPanels, further nested in TabSheets
https://github.com/BobanSpasic/MiniDexedLibrarian - there is a Win64 executable in Bin directory if you want to take a look. Just the first slider on the Performance Edit tab, Reverb Size, has the Hint code.
The hint does not really need to move with the cursor. That was simply the easiest way to bring the hint label close to the currently moving slider.
I'll try to fixate the position somewhere on the current slider. No 'ghosting' but I suppose it will need more calculation of the coordinates.
TinyPortal © 2005-2018