Added: initial implementation for disabled drawing
This commit is contained in:
parent
86f3b26b31
commit
b65af473ce
@ -108,29 +108,45 @@ type
|
|||||||
private
|
private
|
||||||
FBackground: TColor;
|
FBackground: TColor;
|
||||||
FContainer: TX2GraphicContainer;
|
FContainer: TX2GraphicContainer;
|
||||||
|
FEnabled: Boolean;
|
||||||
FStretchMode: TX2GLStretchMode;
|
FStretchMode: TX2GLStretchMode;
|
||||||
|
FUpdateCount: Integer;
|
||||||
|
|
||||||
procedure SetBackground(const Value: TColor);
|
procedure SetBackground(const Value: TColor);
|
||||||
procedure SetContainer(const Value: TX2GraphicContainer);
|
procedure SetContainer(const Value: TX2GraphicContainer);
|
||||||
procedure SetStretchMode(const Value: TX2GLStretchMode);
|
procedure SetStretchMode(const Value: TX2GLStretchMode);
|
||||||
|
procedure SetEnabled(const Value: Boolean);
|
||||||
protected
|
protected
|
||||||
procedure DefineProperties(Filer: TFiler); override;
|
procedure DefineProperties(Filer: TFiler); override;
|
||||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||||
|
|
||||||
|
function DrawGraphic(const AIndex: Integer;
|
||||||
|
const ACanvas: TCanvas;
|
||||||
|
const AX, AY: Integer;
|
||||||
|
const AEnabled: Boolean = True): Boolean;
|
||||||
|
|
||||||
|
procedure DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
|
||||||
|
Style: Cardinal; Enabled: Boolean = True); override;
|
||||||
|
|
||||||
procedure CreateImage(const AIndex: Integer; var AImage, AMask: TBitmap); virtual;
|
procedure CreateImage(const AIndex: Integer; var AImage, AMask: TBitmap); virtual;
|
||||||
procedure AddImage(const AIndex: Integer); virtual;
|
procedure AddImage(const AIndex: Integer); virtual;
|
||||||
procedure UpdateImage(const AIndex: Integer); virtual;
|
procedure UpdateImage(const AIndex: Integer); virtual;
|
||||||
procedure DeleteImage(const AIndex: Integer); virtual;
|
procedure DeleteImage(const AIndex: Integer); virtual;
|
||||||
|
|
||||||
procedure RebuildImages(); virtual;
|
procedure RebuildImages(); virtual;
|
||||||
|
|
||||||
|
procedure BeginUpdate();
|
||||||
|
procedure EndUpdate();
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy(); override;
|
destructor Destroy(); override;
|
||||||
|
|
||||||
procedure Loaded(); override;
|
procedure Loaded(); override;
|
||||||
|
procedure Change(); override;
|
||||||
published
|
published
|
||||||
property Background: TColor read FBackground write SetBackground default clBtnFace;
|
property Background: TColor read FBackground write SetBackground default clBtnFace;
|
||||||
property Container: TX2GraphicContainer read FContainer write SetContainer;
|
property Container: TX2GraphicContainer read FContainer write SetContainer;
|
||||||
|
property Enabled: Boolean read FEnabled write SetEnabled;
|
||||||
property StretchMode: TX2GLStretchMode read FStretchMode write SetStretchMode default smCrop;
|
property StretchMode: TX2GLStretchMode read FStretchMode write SetStretchMode default smCrop;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -345,6 +361,14 @@ begin
|
|||||||
RebuildImages();
|
RebuildImages();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TX2GraphicList.Change;
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
if FUpdateCount = 0 then
|
||||||
|
RebuildImages();
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
destructor TX2GraphicList.Destroy;
|
destructor TX2GraphicList.Destroy;
|
||||||
begin
|
begin
|
||||||
@ -358,21 +382,16 @@ end;
|
|||||||
{========================= TX2GraphicList
|
{========================= TX2GraphicList
|
||||||
Graphics
|
Graphics
|
||||||
========================================}
|
========================================}
|
||||||
procedure TX2GraphicList.CreateImage;
|
function TX2GraphicList.DrawGraphic;
|
||||||
function DrawGraphic(const ADest: TCanvas; const AIndex: Integer): Boolean;
|
procedure InternalDrawGraphic(const ADest: TCanvas);
|
||||||
var
|
var
|
||||||
rDest: TRect;
|
rDest: TRect;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result := False;
|
|
||||||
if not Assigned(FContainer.Graphics[AIndex].Picture) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
with FContainer.Graphics[AIndex].Picture do
|
with FContainer.Graphics[AIndex].Picture do
|
||||||
begin
|
|
||||||
if (FStretchMode = smCrop) or
|
if (FStretchMode = smCrop) or
|
||||||
((Width <= Self.Width) and (Height <= Self.Height)) then
|
((Width <= Self.Width) and (Height <= Self.Height)) then
|
||||||
ADest.Draw(0, 0, Graphic)
|
ADest.Draw(AX, AY, Graphic)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
rDest := Rect(0, 0, Width, Height);
|
rDest := Rect(0, 0, Width, Height);
|
||||||
@ -386,9 +405,63 @@ procedure TX2GraphicList.CreateImage;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
bmpBackground: TBitmap;
|
||||||
|
bmpBlend: TBitmap;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
if not Assigned(FContainer) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if FContainer.Graphics[AIndex].Picture.Graphic.Empty then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if AEnabled then
|
||||||
|
// Enabled, simply draw the graphic
|
||||||
|
InternalDrawGraphic(ACanvas)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// Disabled, need to draw the image using 50% transparency. There's only
|
||||||
|
// one problem; not all TGraphic's support that, and neither is there a
|
||||||
|
// generic way of determining a pixel's transparency. So instead, we
|
||||||
|
// blend the background with a copy of the background with the graphic
|
||||||
|
// painted on it...
|
||||||
|
bmpBackground := TBitmap.Create();
|
||||||
|
bmpBlend := TBitmap.Create();
|
||||||
|
try
|
||||||
|
// Get background from canvas
|
||||||
|
with bmpBackground do
|
||||||
|
begin
|
||||||
|
Width := Self.Width;
|
||||||
|
Height := Self.Height;
|
||||||
|
PixelFormat := pf24bit;
|
||||||
|
Canvas.CopyRect(Rect(0, 0, Width, Height), ACanvas,
|
||||||
|
Rect(AX, AY, AX + Width, AY + Height));
|
||||||
|
end;
|
||||||
|
|
||||||
|
bmpBlend.Assign(bmpBackground);
|
||||||
|
InternalDrawGraphic(bmpBlend.Canvas);
|
||||||
|
|
||||||
|
// TODO Blend graphic with background
|
||||||
|
|
||||||
|
// TODO Copy blended graphic back
|
||||||
|
finally
|
||||||
|
FreeAndNil(bmpBlend);
|
||||||
|
FreeAndNil(bmpBackground);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TX2GraphicList.DoDraw;
|
||||||
|
begin
|
||||||
|
DrawGraphic(Index, Canvas, X, Y, Enabled);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TX2GraphicList.CreateImage;
|
||||||
function RGBTriple(const AColor: TColor): TRGBTriple;
|
function RGBTriple(const AColor: TColor): TRGBTriple;
|
||||||
var
|
var
|
||||||
cColor: Cardinal;
|
cColor: Cardinal;
|
||||||
@ -442,7 +515,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
Brush.Color := FBackground;
|
Brush.Color := FBackground;
|
||||||
FillRect(Rect(0, 0, Width, Height));
|
FillRect(Rect(0, 0, Width, Height));
|
||||||
bOk := DrawGraphic(Canvas, AIndex);
|
bOk := DrawGraphic(AIndex, Canvas, 0, 0, FEnabled);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -476,7 +549,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
Brush.Color := clBlack;
|
Brush.Color := clBlack;
|
||||||
FillRect(Rect(0, 0, Width, Height));
|
FillRect(Rect(0, 0, Width, Height));
|
||||||
DrawGraphic(Canvas, AIndex);
|
DrawGraphic(AIndex, Canvas, 0, 0, FEnabled);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -526,6 +599,8 @@ begin
|
|||||||
if csLoading in ComponentState then
|
if csLoading in ComponentState then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
BeginUpdate();
|
||||||
|
try
|
||||||
bmpImage := TBitmap.Create();
|
bmpImage := TBitmap.Create();
|
||||||
bmpMask := TBitmap.Create();
|
bmpMask := TBitmap.Create();
|
||||||
try
|
try
|
||||||
@ -540,6 +615,9 @@ begin
|
|||||||
FreeAndNil(bmpMask);
|
FreeAndNil(bmpMask);
|
||||||
FreeAndNil(bmpImage);
|
FreeAndNil(bmpImage);
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
EndUpdate();
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TX2GraphicList.UpdateImage;
|
procedure TX2GraphicList.UpdateImage;
|
||||||
@ -551,6 +629,8 @@ begin
|
|||||||
if csLoading in ComponentState then
|
if csLoading in ComponentState then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
BeginUpdate();
|
||||||
|
try
|
||||||
bmpImage := TBitmap.Create();
|
bmpImage := TBitmap.Create();
|
||||||
bmpMask := TBitmap.Create();
|
bmpMask := TBitmap.Create();
|
||||||
try
|
try
|
||||||
@ -560,11 +640,19 @@ begin
|
|||||||
FreeAndNil(bmpMask);
|
FreeAndNil(bmpMask);
|
||||||
FreeAndNil(bmpImage);
|
FreeAndNil(bmpImage);
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
EndUpdate();
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TX2GraphicList.DeleteImage;
|
procedure TX2GraphicList.DeleteImage;
|
||||||
begin
|
begin
|
||||||
|
BeginUpdate();
|
||||||
|
try
|
||||||
Delete(AIndex);
|
Delete(AIndex);
|
||||||
|
finally
|
||||||
|
EndUpdate();
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -577,6 +665,8 @@ begin
|
|||||||
(Width = 0) or (Height = 0) then
|
(Width = 0) or (Height = 0) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
BeginUpdate();
|
||||||
|
try
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
if not Assigned(FContainer) then
|
if not Assigned(FContainer) then
|
||||||
@ -584,6 +674,9 @@ begin
|
|||||||
|
|
||||||
for iIndex := 0 to FContainer.Graphics.Count - 1 do
|
for iIndex := 0 to FContainer.Graphics.Count - 1 do
|
||||||
AddImage(iIndex);
|
AddImage(iIndex);
|
||||||
|
finally
|
||||||
|
EndUpdate();
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -640,10 +733,28 @@ begin
|
|||||||
RebuildImages();
|
RebuildImages();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TX2GraphicList.SetEnabled;
|
||||||
|
begin
|
||||||
|
FEnabled := Value;
|
||||||
|
RebuildImages();
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TX2GraphicList.SetStretchMode;
|
procedure TX2GraphicList.SetStretchMode;
|
||||||
begin
|
begin
|
||||||
FStretchMode := Value;
|
FStretchMode := Value;
|
||||||
RebuildImages();
|
RebuildImages();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TX2GraphicList.BeginUpdate;
|
||||||
|
begin
|
||||||
|
Inc(FUpdateCount);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TX2GraphicList.EndUpdate;
|
||||||
|
begin
|
||||||
|
Assert(FUpdateCount > 0, 'EndUpdate without matching BeginUpdate!');
|
||||||
|
Dec(FUpdateCount);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user