Merge branch 'DisabledDrawEffectStyle' into 'main'

LazUtils: Added DisabledDrawEffectStyle to control disabled image appearance

See merge request freepascal.org/lazarus/lazarus!298
This commit is contained in:
Maxim Ganetsky 2024-06-12 23:02:09 +00:00
commit 9f98ea7602
2 changed files with 37 additions and 3 deletions

View File

@ -268,6 +268,7 @@ function RawImageQueryFlagsToString(AFlags: TRawImageQueryFlags): string;
var
MissingBits: array[0..15] of array[0..7] of word;
DisabledDrawEffectStyle: (ddesGrayscale, ddesDarken, ddesLighten) = ddesGrayscale;
implementation
@ -1651,6 +1652,7 @@ var
AData: PRGBAQuad;
P: Pointer;
i, j: integer;
Gray: Byte;
begin
// check here for Description. Only RGBA data can be processed here.
if not CheckDescription then
@ -1676,9 +1678,21 @@ begin
begin
with AData^ do
begin
Red := (Red + Green + Blue) div 3;
Green := Red;
Blue := Red;
Gray := (Red + Green + Blue) div 3;
// Apply existing alpha and reduce visibility by a further 66%
if DisabledDrawEffectStyle = ddesLighten then
begin
Alpha := Byte((Integer(Gray) * Alpha) div 768);
Gray := $FF;
end
else if DisabledDrawEffectStyle = ddesDarken then
begin
Alpha := Byte((Integer($FF - Gray) * Alpha) div 768);
Gray := $00;
end;
Red := Gray;
Green := Gray;
Blue := Gray;
end;
inc(AData);
end;

View File

@ -1317,6 +1317,26 @@ boundaries.
<seealso/>
</element>
<element name="DisabledDrawEffectStyle">
<short>Controls the appearance of disabled images.</short>
<descr>
<p>
This variable controls how <link id="TRawImage.PerformEffect"/>
represents <link id="TGraphicsDrawEffect.gdeDisabled">gdeDisabled</link>.
Applications should set it based on the background color for their
interfaces.
</p>
</descr>
</element>
<element name="DisabledDrawEffectStyle.ddesGrayscale">
<short>Convert RGB values to grayscale.</short>
</element>
<element name="DisabledDrawEffectStyle.ddesDarken">
<short>Convert to black with alpha representing grayscale.</short>
</element>
<element name="DisabledDrawEffectStyle.ddesLighten">
<short>Convert to white with alpha representing grayscale.</short>
</element>
</module>
<!-- GraphType -->
</package>