Recent

Author Topic: Translucent form and opaque roundrect  (Read 481 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1913
    • Lazarus and Free Pascal italian community
Translucent form and opaque roundrect
« on: June 14, 2019, 08:57:04 am »
Hi guys, I want to understand how to draw an opaque roundrect on a translucent form. I did some tests, but by making the form translucent even the roundrect that I draw in the form2 paint event becomes translucent. Try my test and press the button on the first form. You will understand what I mean.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: Translucent form and opaque roundrect
« Reply #1 on: June 14, 2019, 10:57:36 am »
On windows you can use:
SetLayeredWindowAttributes(Handle, clFuchsia, 180, LWA_COLORKEY or LWA_ALPHA);

See attached project.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

xinyiman

  • Hero Member
  • *****
  • Posts: 1913
    • Lazarus and Free Pascal italian community
Re: Translucent form and opaque roundrect
« Reply #2 on: June 14, 2019, 11:03:58 am »
On windows you can use:
SetLayeredWindowAttributes(Handle, clFuchsia, 180, LWA_COLORKEY or LWA_ALPHA);

See attached project.

Thanks but your solution isn't cross-platform. Run only windows system.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: Translucent form and opaque roundrect
« Reply #3 on: June 14, 2019, 11:21:19 am »
Yes, right.

Mybe someone can add a ColorKey property to TForm and uses system specific functions to set it.

There should be a Unix/OSX pendant.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

xinyiman

  • Hero Member
  • *****
  • Posts: 1913
    • Lazarus and Free Pascal italian community
Re: Translucent form and opaque roundrect
« Reply #4 on: June 14, 2019, 11:52:46 am »
sorry but don't understand
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: Translucent form and opaque roundrect
« Reply #5 on: June 14, 2019, 12:15:41 pm »
We need a new property for TForm like AlphaBlend and AlphaBlendValue: ColorKey.

AlphaBlend and AlphaBlendValue are set in the Windows widgetset by SetLayeredWindowAttributes.
SetLayeredWindowAttributes can also set the ColorKey. So for Windows widgetset there is a solution.

For other widgetsets there must be an equivalent function to set the ColorKey.

If we know them we can add ColorKey property to TForm and will have a cross platform solution!
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

xinyiman

  • Hero Member
  • *****
  • Posts: 1913
    • Lazarus and Free Pascal italian community
Re: Translucent form and opaque roundrect
« Reply #6 on: June 14, 2019, 12:24:16 pm »
AlphaBlend and AlphaBlendValue run correctly on mac but all form and components get transparent value. For me necessity is important form with transparency and component (like a button or image) not.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: Translucent form and opaque roundrect
« Reply #7 on: June 14, 2019, 01:37:57 pm »
So my solution doesn't work either.

Have a look here: https://stackoverflow.com/questions/4928215/changing-alpha-of-window-background-not-the-whole-window

But LCL can't set alpha value of window background color.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)