Recent

Author Topic: OnMouseMove Event  (Read 8496 times)

kapibara

  • Hero Member
  • *****
  • Posts: 528
OnMouseMove Event
« on: December 16, 2013, 02:04:28 am »
I think I found out why the OnMouseMove Event doesnt fire without holding down a keyboard key.

The problem goes away if a ToolSet is added and connected to the chart. There doesnt even have to be a tool added to the toolset.

But if no ToolSet is added, TAChart uses a TBasicChartToolset instead, and it handles the OnMouseMove Event differently. Maybe this should be changed. Sometimes you want to toggle drawingmode on/off with a toolbutton for example, and not having to press a key. But a workaround seems to be just adding a toolset.
« Last Edit: December 16, 2013, 02:07:16 am by kapibara »
Lazarus trunk / fpc 3.0.4 / Debian 10 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 7547
Re: OnMouseMove Event
« Reply #1 on: December 16, 2013, 09:48:56 am »
I cannot confirm this behavior: new project - add chart, no Toolset - add OnMouseMove event handler calling ShowMessage('Hello') --> Message "Hello" shows up when the mouse is moved into the chart, no key pressed.

The issue that you are seeing must be related to the rest of your program
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

wp

  • Hero Member
  • *****
  • Posts: 7547
Re: OnMouseMove Event
« Reply #2 on: December 16, 2013, 10:35:07 am »
Looking at you other posting regarding the line tool, I understand you now: you mean that the OnMouseMove is not triggered while the mouse button is held down. This is true - and not expected.

Some debugging shows that, as you suspected, this is related to the builtin toolset providing the built-in zooming and panning capabilities. Obviously, even if AllowZoom is false, the MouseMove of the tool gets fired and catches the event off of the chart.

I don't know too much about the internal operation of the toolset to fix this behavior. I'll try what I can do, but I don't promise anything...

But I saw in the source of TAGraph that the builtin toolset is created by a public function OnInitBuiltInTool which is implemented in TATools to create a zoom and a pan tool. So, if you want to get rid of this behavior re-implement that function in your uLineTool unit in a way as you require:

Code: [Select]
unit uLineTool;
...

function NoBuiltinTools(AChart: TChart): TBasicChartToolset;
begin
  Result := TChartToolset.Create(AChart);
  // This is just an empty toolset. No more builtin tools to catch events
  // A first attempt to use nil for the result crashes the application.
end;

initialization
  OnInitBuiltinTools := @NoBuiltinTools;
end.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

kapibara

  • Hero Member
  • *****
  • Posts: 528
Re: OnMouseMove Event
« Reply #3 on: December 17, 2013, 05:29:06 pm »
Thats a nice workaround. Or to just drop an empty TChartToolSet on the form and assign it to the form. This is not a big deal for me.

But one has to know that BuiltInToolSet always occupies mousebuttons ssLeft and ssRight when no ToolSet is assigned to the chart. Then you can work around it like this. ssMiddle works anyway. I dont know if its a bug, because its designed like this. But its an unexpected behaviour and perhaps it could be resolved if Chart.ToolSet had choices like this:

None
BuiltIn
ChartToolset1
ChartToolset2 etc

If "None" is chosen, then the ssLeft and ssRight mousekeys shouldnt be hooked. This way the BuiltIn toolset could be easily disabled.

Or maybe there is an easier way.

Looking at the InitBuiltinTools function where ZoomDragTool and PanDragTool hooks the ssLeft and ssRight makes it more understandable how the mousebuttons are hooked:

Code: [Select]
function InitBuiltinTools(AChart: TChart): TBasicChartToolset;
var
  ts: TChartToolset;
begin
  ts := TChartToolset.Create(AChart);
  Result := ts;
  with TZoomDragTool.Create(AChart) do begin
    Shift := [ssLeft];
    Toolset := ts;
  end;
  with TPanDragTool.Create(AChart) do begin
    Shift := [ssRight];
    Toolset := ts;
  end;
  TReticuleTool.Create(AChart).Toolset := ts;
end;
« Last Edit: December 17, 2013, 07:36:51 pm by kapibara »
Lazarus trunk / fpc 3.0.4 / Debian 10 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 7547
Re: OnMouseMove Event
« Reply #4 on: December 17, 2013, 11:52:41 pm »
In my eyes, this is a bug. In the MouseMove method of the TZoomDragTool a line such as "if not IsActive then exit" is missing. This would be the correct code that fixes your issue:

Code: [Select]
procedure TZoomDragTool.MouseMove(APoint: TPoint);
begin
  if not IsActive then exit;
  SelectionRect := Rect(SelectionRect.Left, SelectionRect.Top, APoint.X, APoint.Y);
  Handled;
end;

To test modify this method in TATools.pas accordingly and recompile the TAChart package (no need to recompile Lazarus).

I'll prepare a bug report.

[EDIT] Filed bug report: http://mantis.freepascal.org/view.php?id=25439
« Last Edit: December 18, 2013, 05:26:11 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

kapibara

  • Hero Member
  • *****
  • Posts: 528
Re: OnMouseMove Event
« Reply #5 on: December 18, 2013, 08:26:20 pm »
I tested your code and it works perfectly here.

Good job! This issue has been there for a loong time.

In my eyes, this is a bug. In the MouseMove method of the TZoomDragTool a line such as "if not IsActive then exit" is missing. This would be the correct code that fixes your issue:

Code: [Select]
procedure TZoomDragTool.MouseMove(APoint: TPoint);
begin
  if not IsActive then exit;
  SelectionRect := Rect(SelectionRect.Left, SelectionRect.Top, APoint.X, APoint.Y);
  Handled;
end;

To test modify this method in TATools.pas accordingly and recompile the TAChart package
Lazarus trunk / fpc 3.0.4 / Debian 10 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 7547
Re: OnMouseMove Event
« Reply #6 on: January 16, 2014, 11:41:20 pm »
This issue has been fixed now officially for Lazarus 1.2 (or use trunk)
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018