mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-29 15:29:18 +02:00
* Fixed imageindex when assigning icons (#11650)
* Fixed (un)sharing of images with incompatible share type (#11641) * Added AssignImage to TIcon so a bitmap can be assigned to the current image. Format and dimention need to be the same git-svn-id: trunk@16020 -
This commit is contained in:
parent
d6717344a2
commit
7bad1d6307
@ -1186,6 +1186,7 @@ type
|
|||||||
procedure LoadFromIntfImage(IntfImage: TLazIntfImage);
|
procedure LoadFromIntfImage(IntfImage: TLazIntfImage);
|
||||||
procedure SaveToStream(AStream: TStream); override;
|
procedure SaveToStream(AStream: TStream); override;
|
||||||
procedure GetSupportedSourceMimeTypes(List: TStrings); override;
|
procedure GetSupportedSourceMimeTypes(List: TStrings); override;
|
||||||
|
procedure GetSize(out AWidth, AHeight: Integer);
|
||||||
procedure Mask(ATransparentColor: TColor);
|
procedure Mask(ATransparentColor: TColor);
|
||||||
procedure SetHandles(ABitmap, AMask: HBITMAP); virtual; abstract; // called when handles are set by user
|
procedure SetHandles(ABitmap, AMask: HBITMAP); virtual; abstract; // called when handles are set by user
|
||||||
function ReleaseBitmapHandle: HBITMAP;
|
function ReleaseBitmapHandle: HBITMAP;
|
||||||
@ -1204,9 +1205,6 @@ type
|
|||||||
write SetTransparentColor default clDefault;
|
write SetTransparentColor default clDefault;
|
||||||
property TransparentMode: TTransparentMode read FTransparentMode
|
property TransparentMode: TTransparentMode read FTransparentMode
|
||||||
write SetTransparentMode default tmAuto;
|
write SetTransparentMode default tmAuto;
|
||||||
{$IFDEF DebugBitmap}
|
|
||||||
DebugEnabled: boolean;
|
|
||||||
{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TSharedCustomBitmap = class(TSharedRasterImage)
|
TSharedCustomBitmap = class(TSharedRasterImage)
|
||||||
|
@ -272,9 +272,10 @@ procedure TCustomIcon.Assign(Source: TPersistent);
|
|||||||
begin
|
begin
|
||||||
if Source is TCustomIcon
|
if Source is TCustomIcon
|
||||||
then begin
|
then begin
|
||||||
FCurrent := TCustomIcon(Source).Current;
|
FCurrent := -1;
|
||||||
end
|
end;
|
||||||
else if Source is TRasterImage
|
|
||||||
|
if Source is TRasterImage
|
||||||
then begin
|
then begin
|
||||||
Clear;
|
Clear;
|
||||||
|
|
||||||
@ -286,6 +287,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
inherited Assign(Source);
|
inherited Assign(Source);
|
||||||
|
|
||||||
|
if Source is TCustomIcon
|
||||||
|
then begin
|
||||||
|
FCurrent := TCustomIcon(Source).Current;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomIcon.AssignImage(ASource: TRasterImage);
|
procedure TCustomIcon.AssignImage(ASource: TRasterImage);
|
||||||
|
@ -640,6 +640,10 @@ begin
|
|||||||
if AImage = nil then Exit;
|
if AImage = nil then Exit;
|
||||||
|
|
||||||
// Paul: dont optimize. We need to call HandleNeeded before checking of maskhandle
|
// Paul: dont optimize. We need to call HandleNeeded before checking of maskhandle
|
||||||
|
// mwe: we should use MaskHandle without checking, but since TRasterImage only
|
||||||
|
// has a Transparent property and no Masked property, masks would also get
|
||||||
|
// generated for alpha images. Therefore we re rely now on the fact that a
|
||||||
|
// "native" mask handle is generated when a bitmaphandle is created.
|
||||||
img := AImage.Handle;
|
img := AImage.Handle;
|
||||||
if AMask = nil
|
if AMask = nil
|
||||||
then begin
|
then begin
|
||||||
|
@ -19,9 +19,32 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
procedure TRasterImage.Assign(Source: TPersistent);
|
procedure TRasterImage.Assign(Source: TPersistent);
|
||||||
|
procedure CopyMask(AMask: HBITMAP);
|
||||||
|
var
|
||||||
|
RI: TRawImage;
|
||||||
|
msk, dummy: HBITMAP;
|
||||||
|
begin
|
||||||
|
// we need a winapi.CopyImage here (would make things easier)
|
||||||
|
// in theory, it should not matter if a HBITMAP was created as bitmap or as mask
|
||||||
|
// since there is a description problem in gtk, create both (we cannot create mask only)
|
||||||
|
// todo: fix gtk
|
||||||
|
if not RawImage_FromBitmap(RI, AMask, AMask) then Exit;
|
||||||
|
msk := 0;
|
||||||
|
dummy := 0;
|
||||||
|
RawImage_CreateBitmaps(RI, dummy, msk {, True});
|
||||||
|
RI.FreeData;
|
||||||
|
DeleteObject(dummy);
|
||||||
|
|
||||||
|
if BitmapHandleAllocated
|
||||||
|
then UpdateHandles(BitmapHandle, msk)
|
||||||
|
else UpdateHandles(0, msk);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
SrcImage: TRasterImage absolute Source;
|
SrcImage: TRasterImage absolute Source;
|
||||||
SrcFPImage: TFPCustomImage absolute Source;
|
SrcFPImage: TFPCustomImage absolute Source;
|
||||||
|
SrcRawImage, DstRawImage: PRawImage;
|
||||||
IntfImage: TLazIntfImage;
|
IntfImage: TLazIntfImage;
|
||||||
ImgHandle,ImgMaskHandle: HBitmap;
|
ImgHandle,ImgMaskHandle: HBitmap;
|
||||||
begin
|
begin
|
||||||
@ -29,7 +52,13 @@ begin
|
|||||||
|
|
||||||
if Source is TRasterImage
|
if Source is TRasterImage
|
||||||
then begin
|
then begin
|
||||||
// TRasterImage can share image data
|
if MaskHandleAllocated
|
||||||
|
then begin
|
||||||
|
// Clear mask first mask
|
||||||
|
if BitmapHandleAllocated
|
||||||
|
then UpdateHandles(BitmapHandle, 0)
|
||||||
|
else UpdateHandles(0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
FTransparent := SrcImage.Transparent;
|
FTransparent := SrcImage.Transparent;
|
||||||
FTransparentMode := SrcImage.TransparentMode;
|
FTransparentMode := SrcImage.TransparentMode;
|
||||||
@ -43,20 +72,40 @@ begin
|
|||||||
FreeCanvasContext;
|
FreeCanvasContext;
|
||||||
// release old FImage
|
// release old FImage
|
||||||
FSharedImage.Release;
|
FSharedImage.Release;
|
||||||
|
|
||||||
|
// We only can share images of the same type ...
|
||||||
|
if CanShareImage(SrcImage.GetSharedImageClass)
|
||||||
|
then begin
|
||||||
// share FImage with assigned graphic
|
// share FImage with assigned graphic
|
||||||
FSharedImage := SrcImage.FSharedImage;
|
FSharedImage := SrcImage.FSharedImage;
|
||||||
FSharedImage.Reference;
|
FSharedImage.Reference;
|
||||||
|
|
||||||
// We only can share images of the same type and when neither we or source is updating
|
// when updating, unshare
|
||||||
// Since we "share" it first, the unshare code will create a copy
|
// Since we "share" it first, the unshare code will create a copy
|
||||||
if (FUpdateCount > 0)
|
if (FUpdateCount > 0)
|
||||||
or (SrcImage.FUpdateCount > 0)
|
or (SrcImage.FUpdateCount > 0)
|
||||||
or not CanShareImage(SrcImage.GetSharedImageClass)
|
|
||||||
then begin
|
then begin
|
||||||
UnshareImage(True);
|
UnshareImage(True);
|
||||||
FreeSaveStream;
|
FreeSaveStream;
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
// not sharable, create rawimage copy
|
||||||
|
FSharedImage := GetSharedImageClass.Create;
|
||||||
|
FSharedImage.Reference;
|
||||||
|
|
||||||
|
// copy raw image
|
||||||
|
SrcRawImage := SrcImage.GetRawImagePtr;
|
||||||
|
DstRawImage := GetRawImagePtr;
|
||||||
|
if (SrcRawImage <> nil) and (DstRawImage <> nil)
|
||||||
|
then with SrcRawImage^ do
|
||||||
|
ExtractRect(Rect(0, 0, Description.Width, Description.Height), DstRawImage^);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if SrcImage.MaskHandleAllocated
|
||||||
|
then CopyMask(SrcImage.MaskHandle);
|
||||||
|
|
||||||
|
|
||||||
if FUpdateCount = 0
|
if FUpdateCount = 0
|
||||||
then Changed(Self);
|
then Changed(Self);
|
||||||
@ -697,6 +746,24 @@ begin
|
|||||||
Result := TSharedRasterImage;
|
Result := TSharedRasterImage;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TRasterImage.GetSize(out AWidth, AHeight: Integer);
|
||||||
|
var
|
||||||
|
Desc: PRawImageDescription;
|
||||||
|
begin
|
||||||
|
Desc := GetRawImageDescriptionPtr;
|
||||||
|
if (Desc = nil) or (Desc^.Format = ricfNone)
|
||||||
|
then begin
|
||||||
|
AWidth := 0;
|
||||||
|
AHeight := 0;
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
AWidth := Desc^.Width;
|
||||||
|
AHeight := Desc^.Height;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procedure TRasterImage.ReadData(Stream: TStream);
|
procedure TRasterImage.ReadData(Stream: TStream);
|
||||||
function GetImageClass: TRasterImageClass;
|
function GetImageClass: TRasterImageClass;
|
||||||
const
|
const
|
||||||
|
Loading…
Reference in New Issue
Block a user