mbColorLib: Fix painting of transparent background

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5467 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-12-13 09:59:28 +00:00
parent 060a6d39bd
commit 5795461441
6 changed files with 66 additions and 36 deletions

View File

@@ -52,7 +52,7 @@ type
procedure CreateWnd; override;
procedure Resize; override;
procedure Paint; override;
procedure PaintParentBack; override;
// procedure PaintParentBack; override;
procedure WMSetFocus(var Message: {$IFDEF FPC}TLMSetFocus{$ELSE}TWMSetFocus{$ENDIF});
message {$IFDEF FPC}LM_SETFOCUS{$ELSE}WM_SETFOCUS{$ENDIF};
procedure DoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
@@ -109,8 +109,8 @@ uses
constructor THSLColorPicker.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle - [csAcceptsControls] + [csOpaque];
DoubleBuffered := true;
// ControlStyle := ControlStyle - [csAcceptsControls] + [csOpaque];
//DoubleBuffered := true;
PBack := TBitmap.Create;
PBack.PixelFormat := pf32bit;
{$IFDEF DELPHI_7_UP} {$IFDEF DELPHI}
@@ -323,7 +323,7 @@ function THSLColorPicker.GetManual:boolean;
begin
Result := FHSPicker.Manual or FLPicker.Manual;
end;
(*
procedure THSLColorPicker.PaintParentBack;
begin
if PBack = nil then
@@ -333,13 +333,20 @@ begin
end;
PBack.Width := Width;
PBack.Height := Height;
PaintParentBack(PBack);
if Color = clDefault then begin
PBack.Transparent := true;
PBack.TransparentColor := clForm;
PBack.Canvas.Brush.Color := clForm;
end else
PBack.Canvas.Brush.Color := Color;
PBack.Canvas.FillRect(0, 0, Width, Height);
// PaintParentBack(PBack);
end;
*)
procedure THSLColorPicker.Resize;
begin
inherited;
PaintParentBack;
// PaintParentBack(Canvas);
if (FHSPicker = nil) or (FLPicker = nil) then
exit;
@@ -354,12 +361,12 @@ end;
procedure THSLColorPicker.CreateWnd;
begin
inherited;
PaintParentBack;
// PaintParentBack;
end;
procedure THSLColorPicker.Paint;
begin
PaintParentBack;
PaintParentBack(Canvas);
Canvas.Draw(0, 0, PBack);
end;

View File

@@ -295,24 +295,28 @@ var
XOffs, YOffs, Count: Integer;
dColor: Single;
OffScreen: TBitmap;
{$IFDEF DELPHI_7_UP}
{$IFDEF DELPHI_7_UP} {$IFDEF DELPHI}
MemDC: HDC;
OldBMP: HBITMAP;
{$ENDIF}
{$ENDIF} {$ENDIF}
begin
OffScreen := TBitmap.Create;
try
OffScreen.PixelFormat := pf32bit;
// OffScreen.PixelFormat := pf32bit;
OffScreen.Width := Width;
OffScreen.Height := FColorCombRect.Bottom - FColorCombRect.Top + FBWCombRect.Bottom - FBWCombRect.Top;
//Parent background
{$IFDEF FPC}
if Color = clDefault then
begin
Offscreen.Transparent := true;
Offscreen.TransparentColor := clForm;
Offscreen.Canvas.Brush.Color := clForm
else
end else
{$ENDIF}
OffScreen.Canvas.Brush.Color := Color;
OffScreen.Canvas.FillRect(OffScreen.Canvas.ClipRect);
{$IFDEF DELPHI_7_UP}{$IFDEF DELPHI}
if ParentBackground then
with ThemeServices do
@@ -325,6 +329,7 @@ begin
if MemDC <> 0 then DeleteDC(MemDC);
end;
{$ENDIF}{$ENDIF}
with OffScreen.Canvas do
begin
Pen.Style := psClear;
@@ -454,7 +459,7 @@ end;
procedure THexaColorPicker.Paint;
begin
PaintParentBack;
PaintParentBack; //(Canvas);
if FColorCombs = nil then
CalculateCombLayout;
DrawCombControls;

View File

@@ -52,7 +52,7 @@ type
procedure DoChange;
procedure DoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Paint; override;
procedure PaintParentBack; override;
// procedure PaintParentBack; override;
procedure Resize; override;
procedure WMSetFocus(var Message: {$IFDEF FPC}TLMSetFocus{$ELSE}TWMSetFocus{$ENDIF});
message {$IFDEF FPC}LM_SETFOCUS{$ELSE}WM_SETFOCUS{$ENDIF};
@@ -329,7 +329,7 @@ end;
procedure TSLHColorPicker.Resize;
begin
inherited;
PaintParentBack;
// PaintParentBack;
if (FSLPicker = nil) or (FHPicker = nil) then
exit;
@@ -340,7 +340,7 @@ begin
FHPicker.Left := Width - FHPicker.Width;
FHPicker.Height := Height;
end;
{
procedure TSLHColorPicker.PaintParentBack;
begin
if PBack = nil then
@@ -351,12 +351,12 @@ begin
PBack.Width := Width;
PBack.Height := Height;
PaintParentBack(PBack);
end;
end; }
procedure TSLHColorPicker.Paint;
begin
PaintParentBack;
Canvas.Draw(0, 0, PBack);
PaintParentBack(Canvas);
// Canvas.Draw(0, 0, PBack);
end;
procedure TSLHColorPicker.CreateWnd;

View File

@@ -45,12 +45,12 @@ type
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
{$ELSE}
procedure CMParentColorChanged(var Message: TLMessage); message CM_PARENTCOLORCHANGED;
procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
// procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetDefaultColor(const DefaultColorType: TDefaultColorType): TColor; override;
// function GetDefaultColor(const DefaultColorType: TDefaultColorType): TColor; override;
published
property ParentColor default true;
end;
@@ -95,11 +95,11 @@ procedure TmbBasicPicker.CreateGradient;
begin
// to be implemented by descendants
end;
{
function TmbBasicPicker.GetDefaultColor(const DefaultColorType: TDefaultColorType): TColor;
begin
result := inherited GetDefaultColor(DefaultColorType);
end;
end; }
function TmbBasicPicker.GetGradientColor(AValue: Integer): TColor;
begin
@@ -170,13 +170,19 @@ end;
procedure TmbBasicPicker.PaintParentBack(ABitmap: TBitmap);
begin
ABitmap.Width := Width;
ABitmap.Height := Height;
{$IFNDEF DELPHI}
if Color = clDefault then
ABitmap.Canvas.Brush.Color := GetDefaultColor(dctBrush)
else
if Color = clDefault then begin
ABitmap.Transparent := true;
ABitmap.TransparentColor := clForm;
ABitmap.Canvas.Brush.Color := clForm; //GetDefaultColor(dctBrush)
end else
{$ENDIF}
ABitmap.Canvas.Brush.Color := Color;
ABitmap.Canvas.FillRect(ABitmap.Canvas.ClipRect);
Canvas.Draw(0, 0, ABitmap);
{$IFDEF DELPHI_7_UP}{$IFDEF DELPHI}
if ParentBackground then
with ThemeServices do
@@ -197,7 +203,11 @@ var
begin
Offscreen := TBitmap.Create;
try
Offscreen.PixelFormat := pf32bit;
// Offscreen.PixelFormat := pf32bit;
if Color = clDefault then begin
Offscreen.Transparent := true;
Offscreen.TransparentColor := GetDefaultColor(dctBrush);
end;
Offscreen.Width := Width;
Offscreen.Height := Height;
PaintParentBack(Offscreen);
@@ -244,13 +254,13 @@ begin
Result := true;
end;
(* !!!!!!!!!!!!!!!!!
procedure TmbBasicPicker.WMEraseBkgnd(
var Message: {$IFDEF DELPHI}TWMEraseBkgnd{$ELSE}TLMEraseBkgnd{$ENDIF} );
begin
inherited;
// Message.Result := 1;
end;
end; *)
end.

View File

@@ -348,7 +348,7 @@ begin
if Selected then
Brush.Color := clHighlight
else
Brush.Color := Color; //clBtnFace;
Brush.Color := Color;
FillRect(R);
MoveTo(R.Left, R.Bottom - 1);
LineTo(R.Right, R.Bottom - 1);
@@ -427,13 +427,15 @@ begin
Font.Style := [fsBold];
if Selected then
begin
Brush.Color := clHighlightText;
//Brush.Color := clHighlightText;
Pen.Color := clHighlightText;
Font.Color := clHighlightText;
end
else
begin
Brush.Color := clWindowText;
//Brush.Color := clWindowText;
Pen.Color := clWindowText;
Font.Color := clWindowText;
end;
TR := Rect(R.Left + 48, R.Top + (48 - TextHeight(itemText)) div 2, R.Right - 15, R.Bottom);
if Assigned(FDraw) then FDraw(Self, Index, Canvas.Font, itemText, Selected);

View File

@@ -56,7 +56,6 @@ type
FBevelOuter: TBevelCut;
FBevelWidth: TBevelWidth;
FBorderStyle: TBorderStyle;
procedure SetBevelInner(Value: TBevelCut);
procedure SetBevelOuter(Value: TBevelCut);
procedure SetBevelWidth(Value: TBevelWidth);
@@ -77,8 +76,10 @@ type
FPickRect: TRect;
FLayout: TTrackBarLayout;
FLimit: integer;
FBack: TBitmap;
procedure CreateGradient; override;
procedure Paint; override;
// procedure PaintParentBack;
procedure DrawFrames; dynamic;
procedure Resize; override;
procedure CreateWnd; override;
@@ -191,7 +192,7 @@ const
constructor TmbTrackBarPicker.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle - [csAcceptsControls] + [csOpaque];
//ControlStyle := ControlStyle - [csAcceptsControls]; // + [csOpaque]; // !!!!!!!!
DoubleBuffered := true;
{$IFDEF DELPHI_7_UP} {$IFDEF DELPHI}
ParentBackground := true;
@@ -200,10 +201,14 @@ begin
Height := 22;
TabStop := true;
ParentShowHint := true;
FBack := TBitmap.Create;
FGradientWidth := 256;
FGradientHeight := 12;
FGradientBmp := TBitmap.Create;
FGradientBmp.PixelFormat := pf32bit;
mx := 0;
my := 0;
FIncrement := 1;
@@ -232,6 +237,7 @@ end;
destructor TmbTrackbarPicker.Destroy;
begin
FGradientBmp.Free;
FBack.Free;
inherited;
end;
@@ -385,7 +391,7 @@ end;
procedure TmbTrackBarPicker.Paint;
begin
CalcPickRect;
PaintParentBack;
PaintParentBack(Canvas);
FArrowPos := GetArrowPos;
Execute(TBA_Paint);
if FBorderStyle <> bsNone then