diff --git a/lcl/graphtype.pp b/lcl/graphtype.pp index 9ea663dcc3..e50f45f430 100644 --- a/lcl/graphtype.pp +++ b/lcl/graphtype.pp @@ -47,7 +47,8 @@ type gdeNormal, // no effect gdeDisabled, // grayed image gdeHighlighted, // a bit highlighted image - gdeShadowed // a bit shadowed image + gdeShadowed, // a bit shadowed image + gde1Bit // 1 Bit image (for non-XP windows buttons) ); //------------------------------------------------------------------------------ @@ -1413,15 +1414,42 @@ end; procedure TRawImage.PerformEffect(const ADrawEffect: TGraphicsDrawEffect; CreateNewData: Boolean); + + function CheckDescription: Boolean; + begin + Result := + (Description.Format = ricfRGBA) and + (Description.PaletteColorCount = 0) and + (Description.MaskBitsPerPixel = 0) and + (Description.Depth = 32) and + (Description.BitOrder = riboBitsInOrder) and + (Description.ByteOrder = riboMSBFirst) and + (Description.LineOrder = riloTopToBottom) and + (Description.BitsPerPixel = 32) and + (Description.RedPrec = 8) and + (Description.RedShift = 8) and + (Description.GreenPrec = 8) and + (Description.GreenShift = 16) and + (Description.BluePrec = 8) and + (Description.BlueShift = 24) and + (Description.AlphaPrec = 8) and + (Description.AlphaShift = 0); + end; + const GlowShadow = 48; ColorMultiplier = (256 - GlowShadow) / 256; +// 1 Bit color weights. Total weight = 1000 + R_Weight = 222; + G_Weight = 707; + B_Weight = 071; + H_Threshold = $D5; // threshold of highlight ($D5 is value from experiments. $80 is standard) + var AData: PRGBAQuad; P: Pointer; i, j: integer; begin - // TODO: add check here for Description. Only RGBA data can be processed here. if CreateNewData then begin GetMem(AData, DataSize); @@ -1433,6 +1461,12 @@ begin P := Data; AData := P; end; + + // check here for Description. Only RGBA data can be processed here. + if not CheckDescription then + Exit; + + case ADrawEffect of gdeNormal: ; gdeDisabled: @@ -1477,6 +1511,29 @@ begin inc(AData); end; end; + gde1Bit: + begin + for i := 0 to Description.Height - 1 do + for j := 0 to Description.Width - 1 do + begin + with AData^ do + begin + // color should be either black or none + Alpha := ord + ( + ((R_Weight * Red + G_Weight * Green + B_Weight * Blue) < H_Threshold * 1000) and + (Alpha >= $80) + ) * $FF; + if Alpha = $FF then + begin + Red := 00; + Green := 00; + Blue := 00; + end; + end; + inc(AData); + end; + end; end; Data := P; end; diff --git a/lcl/interfaces/win32/win32wsbuttons.pp b/lcl/interfaces/win32/win32wsbuttons.pp index 4438570f94..41bd6bd3ff 100644 --- a/lcl/interfaces/win32/win32wsbuttons.pp +++ b/lcl/interfaces/win32/win32wsbuttons.pp @@ -187,14 +187,17 @@ var if (srcWidth <> 0) and (srcHeight <> 0) then begin + TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(AState, AIndex, AEffect); if themesActive then begin // non-themed winapi wants white/other as background/picture-disabled colors // themed winapi draws bitmap-as, with transparency defined by bitbtn.brush color SetBkColor(hdcNewBitmap, ColorToRGB(BitBtn.Brush.Color)); SetTextColor(hdcNewBitmap, GetSysColor(COLOR_BTNSHADOW)); - end; - TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(AState, AIndex, AEffect); + end + else + if AEffect = gdeDisabled then + AEffect := gde1Bit; TWin32WSCustomImageList.DrawToDC(TBitBtnAceess(BitBtn).FButtonGlyph.Images, AIndex, hdcNewBitmap, Rect(XDestBitmap, YDestBitmap, glyphWidth, glyphHeight),