Lazarus

Programming => Widgetset => Cocoa => Topic started by: josh on July 07, 2019, 01:22:05 am

Title: Form Events, Mouse Events, slow graphics On cocoa
Post by: josh on July 07, 2019, 01:22:05 am
Hi

Attached is a simple program; to demonstrate a few issues.

The application runs some code during the form create;show and activate events; which will take  a few seconds per event.
It has a cocoa and carbon build option for easy switching; make sure you create the application bundle for proper test.

COmpile for carbon; and run from the IDE, all seems OK, and you can drag a button around.
Note that the ACTIVATE window appears and counts to 100.

Now compile for cocoa.
If RUN from the IDE, you will see the ACTIVATE event count up to 100.
NOW run the APP from the APP Bundle, you will have to wait longer for the form to show; but it does count; it appears after activate has finished.

Also try dragging and dropping any of the buttons; the screen keeps a count of the time the Mouse Down and Mouse Up, Mouse Move events are fired; you will see that in cocoa it is a lot more 'jerky' and the mouse up event is not fired to remove the drag panel. 

Sometimes when compiled for cocoa but not always the poistion of the panels are changed.

Using LAZ 2.1 SVN 61504 X86-64-darwin-cocoa, FPC 3.3.1

Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: josh on July 09, 2019, 09:27:55 am
Just updated to Latest SVN Version, and the issue still exists.

Can someone confirm the behaviour, so that I can submit the issues to bugtracker.

Thanks
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on July 09, 2019, 05:58:51 pm
please bug report
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: josh on August 15, 2019, 11:03:15 am
Just updated to Lazarus 61695 and latest FPC 3.1.1, and the issues still exists.
Any progress on the above issues?
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 15, 2019, 02:26:43 pm
it's a bit complex to resolve. Thanks for the sample.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 15, 2019, 04:14:17 pm
btw, the latest trunk revision should give you a better mouse handling.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: LazProgger on August 15, 2019, 04:49:40 pm
btw, the latest trunk revision should give you a better mouse handling.

It seems as if the mouse click position has wrong coordinates in last trunk for custom controls.

When clicking on the top part, you get coordinates for the bottom.
When clicking on the bottom part, you get coordinates for the top.

It seems as if the coordinates are mirrored.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 15, 2019, 04:51:29 pm
It seems as if the mouse click position has wrong coordinates in last trunk for custom controls.
...
It seems as if the coordinates are mirrored.
ah...i wonder if that's related to the support of borders.

any lightweight sample? (I'm using TTreeView as an example and it seems to be resolving mouse coordinates just fine)
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: LazProgger on August 15, 2019, 04:55:40 pm
ah...i wonder if that's related to the support of borders.

any lightweight sample?

No, but it's maybe related to the mouse event handling.

I'm on the run that moment, but I can try to create an example later.

That behavior was not there in the official release 2.04.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 15, 2019, 05:01:59 pm
No, but it's maybe related to the mouse event handling.
The most annoying part of Cocoa (AppKit) is their coordinate system, which goes from the bottom to the top. (just like any other).
Carbon did it the "normal" way  (from top to bottom)
UIKit (iOS) does it the "normal" way (from top to bottom)

CustomControl has been updated recently adding another "layer" into its implementation.
I'd think it adds the interference of some sort causing the mouse coordinates to be reverted again... (as there's a code present to mirror the coordinate from Cocoa to LCL)... hmm...

I'm on the run that moment, but I can try to create an example later.

That behavior was not there in the official release 2.04.
the change for the border support was introduced in trunk. (The change is risky, no matter how to do it. I believe you're experiencing the side-effect)
I can wait for the example.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 15, 2019, 09:02:27 pm
can't replicate:
Code: Pascal  [Select]
  1. type
  2.   TMyCustomControl = class(TCustomControl);
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. var
  6.   cs : TMyCustomControl;
  7. begin  
  8.   cs := TMyCustomControl.Create(Self);
  9.   cs.Parent:=Self;
  10.   cs.Color:=clBlue;
  11.   cs.BoundsRect:=Bounds(5,5,200,200);
  12.   cs.OnMouseDown:=@Form1MouseDown;
  13.   cs.OnMouseUp:=@Form1MouseUp;
  14.   cs.OnMouseMove:=@Form1MouseMove;  
  15. end;
is showing the proper Y values
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: LazProgger on August 15, 2019, 10:32:56 pm
Here is my example project.

On Windows, the coordinates are correct.
On macOS, the x-values are correct, the y-values are mirrored.

Is that working for you, too?

PS: I have tested a bit and the error seems to happen in LCLIntf.ScreenToClient(self.handle, p) while X and Y of the MouseDown event are correct.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 16, 2019, 04:14:14 pm
PS: I have tested a bit and the error seems to happen in LCLIntf.ScreenToClient(self.handle, p) while X and Y of the MouseDown event are correct.
r61705
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: josh on August 21, 2019, 11:07:10 pm
Hi

Trunk of Lazarus (61741) has fixed the mouse event firing issues.

still exists different behaviour of running from IDE and the app bundle (form activate the form is not shown).

The changing of panels seems to be caused by panel.bringtofront.

I have attached project that has a button that allows you to bringtofront a panel, if clicked you will see the panel jump location.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: skalogryz on August 22, 2019, 03:31:15 pm
still exists different behaviour of running from IDE and the app bundle (form activate the form is not shown).
the reason for this to happen is guessed (macOS compositing engine!), and the cure is unknown.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: LazProgger on August 22, 2019, 06:32:03 pm
PS: I have tested a bit and the error seems to happen in LCLIntf.ScreenToClient(self.handle, p) while X and Y of the MouseDown event are correct.
r61705

I finally came to test it today and it's working now as expected. Thanks!
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: josh on August 23, 2019, 12:48:14 pm
Hi

Looking at the behavior when bringtofront is called for a panel. It appears as though the Y ordinates have been flipped.
Is it possible an issue, because Cocoa screen ordinates start top,left and lazarus start bottom-left.

Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: LazProgger on August 23, 2019, 06:33:23 pm
Hi

Looking at the behavior when bringtofront is called for a panel. It appears as though the Y ordinates have been flipped.
Is it possible an issue, because Cocoa screen ordinates start top,left and lazarus start bottom-left.


Which revision are you using? Maybe this is also related to the LCLIntf.ScreenToClient bug, which was fixed in r61705.
Title: Re: Form Events, Mouse Events, slow graphics On cocoa
Post by: josh on August 23, 2019, 09:17:40 pm
rev 61748

When panel; is made visible it is in correct location; when bringtofront is called the y ordinate if like flipped. (ie a panel whos y is 10 from the top, is relocated to 10 from the bottom)