Programming => LCL => Topic started by: d-_-b on August 15, 2019, 12:49:18 am
Title: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: d-_-b on August 15, 2019, 12:49:18 am
Hi,
Someone in irc reported an issue with the mbColorLib TmbDeskPickerButton returning the wrong color on Windows. Eg, you select black(0) and it returns 65793(RGB: 010101).
I debugged the problem and realised `TScreenForm` with a `AlphaBlendValue := 1` affects the `ScreenWin.GetDesktopColor` (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/mbColorLib/ScreenWin.pas#l54) method.
Setting `TScreenForm.AlphaBlendValue := 0` does not work because this "hide" the window so no selection can take place. Also calling `TScreenForm.Hide`, then `GetDesktopColor`, and then `TScreenForm.Show` creates a lot of flickering on screen.
So I then decided to rename `ScreenWin.GetDesktopColor` (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/mbColorLib/ScreenWin.pas#l54) to `ScreenWin.GetScreenColor` and add a private method to `TScreenForm` as follow and that seems to do the trick:
Have a look at a visual demo of the problem and my solution linked to a TCheckBox to enable/disable the bug. (https://imgur.com/a/Y0p9Yb1)
You will see on the first selection the black return as 010101(due to TScreenForm) and the second selection as 000000 because I change AlphaBlendValue := 0 as suggested.
Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: wp on August 15, 2019, 12:29:10 pm
Applied your fix, thank you. In addition, I use a temporary bitmap now which seems to be essential for Linux qt because otherwise the colorpicker always reports white (25,255,255) there. Please test.
Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: d-_-b on August 19, 2019, 04:41:35 pm
wp thanks for the quick fix! The user tested and seems happy.
I have another suggestion, when I look at the code to show the form (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/mbColorLib/ScreenWin.pas#l127) I saw it only takes the primary screen width and height into account. Should that not be changed to: