Recent

Author Topic: Refreshing while the cursor moves  (Read 1253 times)

Davidous

  • Full Member
  • ***
  • Posts: 107
Refreshing while the cursor moves
« on: July 04, 2019, 09:20:46 pm »
Hello All!

It seems that I always have new questions. :)
I'm working on a MouseMove event. When the cursor is moved a line (that is originally a TPanel) moves with it. My problem is, that it seems to resresh only after a while, until that time I can see many white lines.
You can see that on the attached picture. Is there a way to somehow improve the refresh rate of the TPanel and not to see that many white lines?

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Refreshing while the cursor moves
« Reply #1 on: July 04, 2019, 10:17:50 pm »
Set the panel to DoubleBuffered:= True;
I don't know if I understand this, but maybe you should reconsider the whole design?  :)

by the way: Form.DoubleBuffered:= True or Panel.DoubleBuffered:= True won't help you if there is a serious mistake inside your code ...
« Last Edit: July 04, 2019, 10:33:22 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Davidous

  • Full Member
  • ***
  • Posts: 107
Re: Refreshing while the cursor moves
« Reply #2 on: July 04, 2019, 10:39:02 pm »
Doublebuffered:=True didn't help.
I have four synched graphs under each other and when I doubleclick one of them I want a vertical line to appear. It's top is the top of the first graph and it's bottom is the bottom of the fourth graph.
Right now this vertical line is that TPanel. I have no better solution so far, but that does not mean, that there is none :)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Refreshing while the cursor moves
« Reply #3 on: July 04, 2019, 10:59:09 pm »
I can move a panel without problems. Ok, it's not like opengl but no problems at all, so I don't think the panel is the problem.  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Davidous

  • Full Member
  • ***
  • Posts: 107
Re: Refreshing while the cursor moves
« Reply #4 on: July 04, 2019, 11:36:18 pm »
Thank you for your help.
My last try was just to refresh the graphs and it worked! :D

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Refreshing while the cursor moves
« Reply #5 on: July 05, 2019, 01:05:47 am »
Have you considered using a less weighty component (a TShape or a TBevel)?

Using a panel for this sounds ... wasteful, somehow :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Refreshing while the cursor moves
« Reply #6 on: July 05, 2019, 10:45:44 am »
Why don't you use the machinery built into TAChart? Please follow these steps (see attached demo):
  • Add a TConstantLine series to each chart. Set their "LineStyle" to lsVertical, "Position" such that the vertical lines are in the center of the x axis (just a good initial value): in the demo the x axis ranges between 0 and 10, so I put the lines to 5. Set the "Pen.Color" to an appropriate line color.
  • Add a TChartTools component to each chart. Link the "Tools" property of each chart to the corresponding component.
  • Double-click on the first ChartTools component, add a "Data point drag" tool.
  • Set the "Shift" property of the drag tool to an appropriate combination of shift parameters, e.g. [ssLeft, ssCtrl] to activate the tool with the left mouse button while CTRL is pressed.
  • Set the "AffectedSeries" property of the drag tool to the index of the TConstantLine series to avoid unintentional dragging of true data points
  • Repeat for the ChartTools component of the 2nd chart.
  • Now you can drag - at runtime - the vertical constant line series by dragging the vertical bar with the left mouse button and holding the CTRL key down. The second bar, however, is not yet synchronized
  • Write event handlers for the "OnDrag" event of the drag tool to synchronize the line of the other chart. The handler should also inhibit dragging the vertical line out of the data range. This is how I did it in the demo, you can assign this code to the "OnDrag" event of both drag tools:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ChartToolset1DataPointDragTool1Drag(
  2.   ASender: TDataPointDragTool; var AGraphPoint: TDoublePoint);
  3. var
  4.   ex: TDoubleRect;
  5. begin
  6.   // Avoid dragging beyond the chart's axis range
  7.   ex := ASender.Chart.LogicalExtent;
  8.   if AGraphPoint.X < ex.a.x then
  9.     AGraphPoint.X := ex.a.x
  10.   else if AGraphPoint.X > ex.b.x then
  11.     AGraphPoint.X := ex.b.x;
  12.  
  13.   // Synchronize the position of the ConstantLine series in the other chart.
  14.   if ASender.Chart = Chart1 then
  15.     Chart2ConstantLine1.Position := AGraphPoint.X
  16.   else if ASender.Chart = Chart2 then
  17.     Chart1ConstantLine1.Position := AGraphPoint.X;
  18. end;
  19.  
« Last Edit: July 05, 2019, 10:18:37 pm by wp »

Davidous

  • Full Member
  • ***
  • Posts: 107
Re: Refreshing while the cursor moves
« Reply #7 on: July 06, 2019, 01:42:32 am »
Thank you! :)

 

TinyPortal © 2005-2018