Recent

Author Topic: SpeedButton Flat  (Read 2770 times)

lelebass

  • New Member
  • *
  • Posts: 41
SpeedButton Flat
« on: May 20, 2020, 12:24:29 pm »
I came across a problem with my application, it looks like it is relative to how SpeedButton are rendered in different macOS versions.

I was able to reproduce the issue on a simple application with a SpeedButton on a form. Set the SpeedButton.Flat property to True and set the Form.Color:=clBlue.

Compiled with Lazarus 2.0.8 x64. The same application renders differently with Sierra and Mojave. The same code compiled on Windows 10 gives the same result as Mojave.

This is weird. I wonder what changed in Cocoa between the two OS release. Should I file a bug report?

Ciao,
Daniele

lelebass

  • New Member
  • *
  • Posts: 41
Re: SpeedButton Flat
« Reply #1 on: May 21, 2020, 04:05:58 pm »
Tested with Trunk, same results.  :(

Can this be linked to this bug?

https://bugs.freepascal.org/view.php?id=35555

I filed a new bug:

https://bugs.freepascal.org/view.php?id=37127

Ciao,
Daniele
« Last Edit: May 21, 2020, 04:44:01 pm by lelebass »

lelebass

  • New Member
  • *
  • Posts: 41
Re: SpeedButton Flat
« Reply #2 on: May 26, 2020, 10:13:45 am »
The same application renders differently with Sierra and Mojave. The same code compiled on Windows 10 gives the same result as Mojave.

After several tests, I can say that the situation is more complex than I initially thought. The behaviour in Mojave of the application compiled with 2.0.8 is not exactly the same as in Windows 10, but very similar and usable. 

Lazarus 2.0.8 Mojave - Correctly renders the button as flat (and trasparent), but does not highlight the button when the mouse is over
Lazarus 2.0.8 Sierra - Incorrect rendering of the button (missing transparency?)

Since the bug https://bugs.freepascal.org/view.php?id=35555 was reported and closed between last year May and June I tried to see what happens using Lazarus 2.0.0.

Lazarus 2.0.0 Mojave - Correctly renders the buttons as flat, does not highiligth the button on mouse over, but has an incorrect rendering when button is released. This happens with the application compiled and launched outside the IDE. If the application is launched inside the IDE with debugger everything is working as expected :o :o :o
Lazarus 2.0.0 Sierra - All correct.

Something definitely changed between Sierra and Mojave and I guess this has been addressed with a patch by Dmitry when closing bug 0035555. But I think the patch has introduced backwards compatibility problems.

I would like to help to try to fix this. I went trough the documentation:

https://wiki.lazarus.freepascal.org/Cocoa_Internals

I noticed that here:

https://wiki.lazarus.freepascal.org/Cocoa_Internals/Buttons

under TSpeedButton there is a note "This is not an actual control button, it's LCL-drawn button. todo: no themes API customdrawn controls used?".

Any hint on how to be helpful apart from reporting bugs and testing?

Ciao,
Daniele
« Last Edit: May 26, 2020, 03:57:02 pm by lelebass »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: SpeedButton Flat
« Reply #3 on: May 27, 2020, 01:50:05 am »
Something definitely changed between Sierra and Mojave and I guess this has been addressed with a patch by Dmitry when closing bug 0035555. But I think the patch has introduced backwards compatibility problems.
The first thing that comes to the mind is the default NSView transparency got changed.

There were some internal changes in rendering engine of Apple. They've switched from optional "drawing layers" to mandatory "drawing layers".

The item #35555 might not have been fixed at a time.
The report doesn't specify the particular version of macOS experiencing the issue.

I can tell you that Mojave was used for testing when the item was closed.

lelebass

  • New Member
  • *
  • Posts: 41
Re: SpeedButton Flat
« Reply #4 on: May 27, 2020, 04:08:00 pm »
In my tests I used the latest available versions of Mojave 10.14.6 and Sierra 10.12.6.

Ciao,
Daniele

lelebass

  • New Member
  • *
  • Posts: 41
Re: SpeedButton Flat
« Reply #5 on: June 08, 2020, 12:01:17 pm »
Dear skalogryz,
I installed latest Trunk SVN63326 and tested the simple application under Sierra and Mojave.

Sierra:

https://youtu.be/NY70p5DuA_w

Mojave:

https://youtu.be/quOKN_Ci6Aw

On both videos, from left to right, you can see the application compiled with Lazarus 2.0.0, 2.0.8 and Trunk. As you can see now the rendering under Sierra is OK. Thank you for fixing this!

I am still a bit puzzled by the fact that 2.0.0 was able to show the mouse-over status of the button while the most recent versions of Lazarus are not.

By the way, thank you again! 

Cheers,
Daniele

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: SpeedButton Flat
« Reply #6 on: June 09, 2020, 07:30:03 pm »
The themed drawing is changing between versions.

Overall theme drawing is some of a painful matter in Cocoa.

1. in 2.0.0. the fully custom theme drawing was used. It works fine in many ways, except it produces non-native results.

2. in 2.0.4 are more "native" ways of drawing was introduced (using deprecating NSCell APIs). However, there's a certain issue of configuring a NSCell object for "desired" drawing. (as the result are not known ahead). As a result the same configuration for NSCell gave different results on different macOS versions. (which is actually expected. But a different visual feedback is wanted)

2.1 besides NSCell API's there's "carbon-legacy" HITheme APIs. The term "legacy" shouldn't be taken as something negative. Apple did deprecate carbon, and most of it APIs did not move to 64-bit, yet HItheme APIs are available for 64-bit (and thus available for Cocoa).

The problem with using HITheme is uncertainty about its future. (i.e. Apple is introducing its on ARM processors for future Macs). So it might take an opportunity and remove HITheme as well.
Cells are also being deprecated.

So LCL has to move in the dark unknown and so such "side-effects" are possible.
Especially when Theme drawing is used a lot through LCL.
« Last Edit: June 09, 2020, 07:31:53 pm by skalogryz »

Clover

  • New Member
  • *
  • Posts: 46
Re: SpeedButton Flat
« Reply #7 on: September 02, 2020, 07:48:16 pm »
A hacky but effective way to restore the lost mouse-over feature on flat TSpeedButtons is to toggle the Flat attribute in an OnMouseEnter and OnMouseLeave event. It looks similar to the original effect. For example:

Code: Pascal  [Select][+][-]
  1. procedure TForm.SpeedBtnMouseEnter (Sender: TObject);
  2. begin
  3.   if Sender is TSpeedButton then
  4.     with Sender as TSpeedButton do
  5.       Flat := false;
  6. end;
  7.  
  8. procedure TForm.SpeedBtnMouseLeave (Sender: TObject);
  9. begin
  10.   if Sender is TSpeedButton then
  11.     with Sender as TSpeedButton do
  12.       Flat := true;
  13. end;

You can conditionally assign the two events to all your TSpeedButton components in Form.Create:

Code: Pascal  [Select][+][-]
  1. {$ifdef Darwin}
  2.   for i := 0 to ComponentCount-1 do
  3.     if Components[i] is TSpeedButton then with TSpeedButton(Components[i]) do
  4.     begin
  5.       OnMouseEnter := SpeedBtnMouseEnter;
  6.       OnMouseLeave := SpeedBtnMouseLeave;
  7.     end;
  8. {$endif}

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: SpeedButton Flat
« Reply #8 on: September 07, 2020, 10:06:57 am »
During the last days I made a lot of experiments with Speedbuttons concerning the properties flat and transparent:
https://forum.lazarus.freepascal.org/index.php/topic,51116.0.html
To restore the lost mouse-over feature (which is always apparent in Windows f.e.), I used the Down-property.
You can find some programs I uploaded within this thread.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

 

TinyPortal © 2005-2018