View Issue Details

IDProjectCategoryView StatusLast Update
0021754LazarusLCLpublic2012-04-19 00:22
ReporterDavid JenkinsAssigned ToPaul Ishenin 
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version0.9.30.5 (SVN)Product Build 
Target VersionFixed in Version1.1 (SVN) 
Summary0021754: Add Overlay drawing to Image Lists
DescriptionWe'd like to match some Delphi functionality by adding TCustomImageList.FOverlayList, TCustomImageList.DrawOverlay(), and TCustomImageList.Overlay. And also checking for OverLays and drawing them in TCustomTreeVew.DoPaintNode.

Patches against rev 36681 attached
TagsNo tags attached.
Fixed in Revision36805
LazTarget-
WidgetsetCarbon
Attached Files
  • imglist.inc.patch (2,520 bytes)
    --- /Users/djenkins/laz-changes/14720/imglist.inc	2012-04-11 16:37:13.000000000 
    +++ /Users/djenkins/laz-changes/14720/imglist.inc.ss	2012-04-11 16:40:06.000000000 
    @@ -477,6 +477,7 @@
       while FChangeLinkList.Count>0 do
         UnregisterChanges(TChangeLink(FChangeLinkList[0]));
       FreeThenNil(FChangeLinkList);
    +  FreeThenNil(FOverlayList);
     end;
     
     {------------------------------------------------------------------------------
    @@ -519,6 +520,37 @@
                               BkColor, BlendColor, ADrawEffect, ADrawingStyle, AImageType);
     end;
     
    +procedure TCustomImageList.DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer;
    +  AOverlay: TOverlay; AEnabled: Boolean = True);
    +begin
    +  DrawOverlay(ACanvas, AX, AY, AIndex, AOverlay, EffectMap[AEnabled]);
    +end;
    +
    +procedure TCustomImageList.DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer;
    +  AOverlay: TOverlay; ADrawEffect: TGraphicsDrawEffect);
    +begin
    +  DrawOverlay(ACanvas, AX, AY, AIndex, AOverlay, DrawingStyle, ImageType, ADrawEffect);
    +end;
    +
    +procedure TCustomImageList.DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer;
    +  AOverlay: TOverlay; ADrawingStyle: TDrawingStyle; AImageType: TImageType;
    +  ADrawEffect: TGraphicsDrawEffect);
    +var OverlayIndex: Integer;
    +begin
    +  if (AIndex < 0) or (AIndex >= FCount) then Exit;
    +
    +  ReferenceNeeded;
    +  TWSCustomImageListClass(WidgetSetClass).Draw(Self, AIndex, ACanvas, Rect(AX, AY, FWidth, FHeight),
    +                          BkColor, BlendColor, ADrawEffect, ADrawingStyle, AImageType);
    +
    +  OverlayIndex := Integer(FOverlayList[AOverlay + 1]);
    +  if (OverlayIndex < 0) or (OverlayIndex >= FCount) then Exit;
    +
    +  TWSCustomImageListClass(WidgetSetClass).Draw(Self, OverlayIndex, ACanvas, Rect(AX, AY, FWidth, FHeight),
    +                          BkColor, BlendColor, ADrawEffect, ADrawingStyle, AImageType);
    +end;
    +
    +
     {------------------------------------------------------------------------------
       Method:  TCustomImageList.EndUpdate
       Params:  none
    @@ -733,6 +765,8 @@
     procedure TCustomImageList.Initialize;
     begin
       FChangeLinkList := TList.Create;
    +  FOverlayList := TList.Create;
    +  FOverlayList.Count := High(TOverlay) + 1;
       FAllocBy := 4;
       FAllocCount := 0;
       FBlendColor := clNone;
    @@ -1308,6 +1342,10 @@
         {$ELSE}
         Result:=false;
         {$ENDIF}
    +
    +procedure TCustomImageList.Overlay(AIndex: Integer; Overlay: TOverlay);
    +begin
    +  FOverlayList.Insert(Overlay + 1, Pointer(AIndex));
     end;
     
     {------------------------------------------------------------------------------
    
    imglist.inc.patch (2,520 bytes)
  • imglist.pp.patch (1,914 bytes)
    --- /Users/djenkins/laz-changes/14720/imglist.pp	2012-04-11 16:42:36.000000000 
    +++ /Users/djenkins/laz-changes/14720/imglist.pp.ss	2012-04-11 16:43:33.000000000 
    @@ -103,6 +103,7 @@
     
       TDrawingStyle = (dsFocus, dsSelected, dsNormal, dsTransparent);
       TImageType = (itImage, itMask);
    +  TOverlay = 0..20;
     
       TCustomImageList = class(TLCLReferenceComponent)
       private
    @@ -123,6 +124,7 @@
         FBkColor: TColor;
         FChanged: boolean;
         FUpdateCount: integer;
    +    FOverlayList: TList;
     
         procedure AllocData(ACount: Integer);
         function  GetReference: TWSCustomImageListReference;
    @@ -177,6 +179,10 @@
           AEnabled: Boolean = True); overload;
         procedure Draw(ACanvas: TCanvas; AX, AY, AIndex: Integer; ADrawingStyle: TDrawingStyle; AImageType: TImageType;
           ADrawEffect: TGraphicsDrawEffect); overload; virtual;
    +    procedure DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer; AOverlay: TOverlay; AEnabled: Boolean = True);
    +    procedure DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer; AOverlay: TOverlay; ADrawEffect: TGraphicsDrawEffect);
    +    procedure DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer; AOverlay: TOverlay; ADrawingStyle:
    +      TDrawingStyle; AImageType: TImageType; ADrawEffect: TGraphicsDrawEffect); virtual;
         procedure FillDescription(out ADesc: TRawImageDescription);
     
         procedure GetBitmap(Index: Integer; Image: TCustomBitmap); overload;
    @@ -193,6 +199,7 @@
         procedure InsertIcon(AIndex: Integer; AIcon: TCustomIcon);
         procedure InsertMasked(Index: Integer; AImage: TCustomBitmap; MaskColor: TColor);
         procedure Move(ACurIndex, ANewIndex: Integer);
    +    procedure Overlay(AIndex: Integer; Overlay: TOverlay);
         procedure Replace(AIndex: Integer; AImage, AMask: TCustomBitmap);
         procedure ReplaceMasked(Index: Integer; NewImage: TCustomBitmap; MaskColor: TColor);
         procedure RegisterChanges(Value: TChangeLink);
    
    imglist.pp.patch (1,914 bytes)
  • treeview.inc.patch (833 bytes)
    --- /Users/djenkins/laz-changes/14720/treeview.inc	2012-04-11 16:44:22.000000000 
    +++ /Users/djenkins/laz-changes/14720/treeview.inc.ss	2012-04-11 16:45:37.000000000 
    @@ -4884,8 +4884,12 @@
             ImgIndex := Node.SelectedIndex;
           end;
           if (ImgIndex >= 0) and (ImgIndex < Images.Count) then
    -        Images.Draw(Canvas, x + 1, (NodeRect.Top + NodeRect.Bottom - Images.Height) div 2,
    -            ImgIndex, Node.FNodeEffect);
    +      	if Node.OverlayIndex < 0 then
    +          Images.Draw(Canvas, x + 1, (NodeRect.Top + NodeRect.Bottom - Images.Height) div 2,
    +             ImgIndex, Node.FNodeEffect)
    +      	else
    +          Images.DrawOverlay(Canvas, x + 1, (NodeRect.Top + NodeRect.Bottom - Images.Height) div 2,
    +             ImgIndex, Node.OverlayIndex, Node.FNodeEffect);
           inc(x, Images.Width + 2);
         end;
     
    
    treeview.inc.patch (833 bytes)

Activities

2012-04-13 21:48

 

imglist.inc.patch (2,520 bytes)
--- /Users/djenkins/laz-changes/14720/imglist.inc	2012-04-11 16:37:13.000000000 
+++ /Users/djenkins/laz-changes/14720/imglist.inc.ss	2012-04-11 16:40:06.000000000 
@@ -477,6 +477,7 @@
   while FChangeLinkList.Count>0 do
     UnregisterChanges(TChangeLink(FChangeLinkList[0]));
   FreeThenNil(FChangeLinkList);
+  FreeThenNil(FOverlayList);
 end;
 
 {------------------------------------------------------------------------------
@@ -519,6 +520,37 @@
                           BkColor, BlendColor, ADrawEffect, ADrawingStyle, AImageType);
 end;
 
+procedure TCustomImageList.DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer;
+  AOverlay: TOverlay; AEnabled: Boolean = True);
+begin
+  DrawOverlay(ACanvas, AX, AY, AIndex, AOverlay, EffectMap[AEnabled]);
+end;
+
+procedure TCustomImageList.DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer;
+  AOverlay: TOverlay; ADrawEffect: TGraphicsDrawEffect);
+begin
+  DrawOverlay(ACanvas, AX, AY, AIndex, AOverlay, DrawingStyle, ImageType, ADrawEffect);
+end;
+
+procedure TCustomImageList.DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer;
+  AOverlay: TOverlay; ADrawingStyle: TDrawingStyle; AImageType: TImageType;
+  ADrawEffect: TGraphicsDrawEffect);
+var OverlayIndex: Integer;
+begin
+  if (AIndex < 0) or (AIndex >= FCount) then Exit;
+
+  ReferenceNeeded;
+  TWSCustomImageListClass(WidgetSetClass).Draw(Self, AIndex, ACanvas, Rect(AX, AY, FWidth, FHeight),
+                          BkColor, BlendColor, ADrawEffect, ADrawingStyle, AImageType);
+
+  OverlayIndex := Integer(FOverlayList[AOverlay + 1]);
+  if (OverlayIndex < 0) or (OverlayIndex >= FCount) then Exit;
+
+  TWSCustomImageListClass(WidgetSetClass).Draw(Self, OverlayIndex, ACanvas, Rect(AX, AY, FWidth, FHeight),
+                          BkColor, BlendColor, ADrawEffect, ADrawingStyle, AImageType);
+end;
+
+
 {------------------------------------------------------------------------------
   Method:  TCustomImageList.EndUpdate
   Params:  none
@@ -733,6 +765,8 @@
 procedure TCustomImageList.Initialize;
 begin
   FChangeLinkList := TList.Create;
+  FOverlayList := TList.Create;
+  FOverlayList.Count := High(TOverlay) + 1;
   FAllocBy := 4;
   FAllocCount := 0;
   FBlendColor := clNone;
@@ -1308,6 +1342,10 @@
     {$ELSE}
     Result:=false;
     {$ENDIF}
+
+procedure TCustomImageList.Overlay(AIndex: Integer; Overlay: TOverlay);
+begin
+  FOverlayList.Insert(Overlay + 1, Pointer(AIndex));
 end;
 
 {------------------------------------------------------------------------------
imglist.inc.patch (2,520 bytes)

2012-04-13 21:49

 

imglist.pp.patch (1,914 bytes)
--- /Users/djenkins/laz-changes/14720/imglist.pp	2012-04-11 16:42:36.000000000 
+++ /Users/djenkins/laz-changes/14720/imglist.pp.ss	2012-04-11 16:43:33.000000000 
@@ -103,6 +103,7 @@
 
   TDrawingStyle = (dsFocus, dsSelected, dsNormal, dsTransparent);
   TImageType = (itImage, itMask);
+  TOverlay = 0..20;
 
   TCustomImageList = class(TLCLReferenceComponent)
   private
@@ -123,6 +124,7 @@
     FBkColor: TColor;
     FChanged: boolean;
     FUpdateCount: integer;
+    FOverlayList: TList;
 
     procedure AllocData(ACount: Integer);
     function  GetReference: TWSCustomImageListReference;
@@ -177,6 +179,10 @@
       AEnabled: Boolean = True); overload;
     procedure Draw(ACanvas: TCanvas; AX, AY, AIndex: Integer; ADrawingStyle: TDrawingStyle; AImageType: TImageType;
       ADrawEffect: TGraphicsDrawEffect); overload; virtual;
+    procedure DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer; AOverlay: TOverlay; AEnabled: Boolean = True);
+    procedure DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer; AOverlay: TOverlay; ADrawEffect: TGraphicsDrawEffect);
+    procedure DrawOverlay(ACanvas: TCanvas; AX, AY, AIndex: Integer; AOverlay: TOverlay; ADrawingStyle:
+      TDrawingStyle; AImageType: TImageType; ADrawEffect: TGraphicsDrawEffect); virtual;
     procedure FillDescription(out ADesc: TRawImageDescription);
 
     procedure GetBitmap(Index: Integer; Image: TCustomBitmap); overload;
@@ -193,6 +199,7 @@
     procedure InsertIcon(AIndex: Integer; AIcon: TCustomIcon);
     procedure InsertMasked(Index: Integer; AImage: TCustomBitmap; MaskColor: TColor);
     procedure Move(ACurIndex, ANewIndex: Integer);
+    procedure Overlay(AIndex: Integer; Overlay: TOverlay);
     procedure Replace(AIndex: Integer; AImage, AMask: TCustomBitmap);
     procedure ReplaceMasked(Index: Integer; NewImage: TCustomBitmap; MaskColor: TColor);
     procedure RegisterChanges(Value: TChangeLink);
imglist.pp.patch (1,914 bytes)

2012-04-13 21:49

 

treeview.inc.patch (833 bytes)
--- /Users/djenkins/laz-changes/14720/treeview.inc	2012-04-11 16:44:22.000000000 
+++ /Users/djenkins/laz-changes/14720/treeview.inc.ss	2012-04-11 16:45:37.000000000 
@@ -4884,8 +4884,12 @@
         ImgIndex := Node.SelectedIndex;
       end;
       if (ImgIndex >= 0) and (ImgIndex < Images.Count) then
-        Images.Draw(Canvas, x + 1, (NodeRect.Top + NodeRect.Bottom - Images.Height) div 2,
-            ImgIndex, Node.FNodeEffect);
+      	if Node.OverlayIndex < 0 then
+          Images.Draw(Canvas, x + 1, (NodeRect.Top + NodeRect.Bottom - Images.Height) div 2,
+             ImgIndex, Node.FNodeEffect)
+      	else
+          Images.DrawOverlay(Canvas, x + 1, (NodeRect.Top + NodeRect.Bottom - Images.Height) div 2,
+             ImgIndex, Node.OverlayIndex, Node.FNodeEffect);
       inc(x, Images.Width + 2);
     end;
 
treeview.inc.patch (833 bytes)

Juha Manninen

2012-04-15 09:58

developer   ~0058608

Last edited: 2012-04-15 10:19

How to test this Overlay thing?

You should create proper patches. You can also include many files in one patch when they logically belong together. The paths in a patch should be relative to Lazarus src root dir.
While in Lazarus root dir:
 $ svn diff lcl/imglist.pp lcl/include/imglist.inc lcl/include/treeview.inc > overlay.patch

I am also happy with patches with git's format, in case you want to use git.

***

$ patch -p0 < ~/patch/imglist.inc.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- /Users/djenkins/laz-changes/14720/imglist.inc 2012-04-11 16:37:13.000000000
|+++ /Users/djenkins/laz-changes/14720/imglist.inc.ss 2012-04-11 16:40:06.000000000
--------------------------
File to patch:

Zeljan Rikalo

2012-04-15 10:26

developer   ~0058609

@Juha, you can delete path from imglist.inc.ss and leave only imglist.inc at that line and then apply it in directory where that file exists. It's bit incovinient, but works.

Paul Ishenin

2012-04-16 07:18

manager   ~0058640

I've reimplemented a bit your patch.

1. There is no need for TList if TOverlay is so small and fixed - it is enough to have an array.
2. When imagelist has a background color overlay will hide the main image. As result I passed clNone as background color of ovelay - hope this fix it.

Because of my changes you need to test them and close the issue if it works.

Issue History

Date Modified Username Field Change
2012-04-13 21:48 David Jenkins New Issue
2012-04-13 21:48 David Jenkins File Added: imglist.inc.patch
2012-04-13 21:48 David Jenkins Widgetset => Carbon
2012-04-13 21:49 David Jenkins File Added: imglist.pp.patch
2012-04-13 21:49 David Jenkins File Added: treeview.inc.patch
2012-04-15 09:58 Juha Manninen LazTarget => -
2012-04-15 09:58 Juha Manninen Note Added: 0058608
2012-04-15 09:58 Juha Manninen Status new => feedback
2012-04-15 10:19 Juha Manninen Note Edited: 0058608
2012-04-15 10:26 Zeljan Rikalo Note Added: 0058609
2012-04-16 07:18 Paul Ishenin Fixed in Revision => 36805
2012-04-16 07:18 Paul Ishenin Status feedback => resolved
2012-04-16 07:18 Paul Ishenin Fixed in Version => 1.1 (SVN)
2012-04-16 07:18 Paul Ishenin Resolution open => fixed
2012-04-16 07:18 Paul Ishenin Assigned To => Paul Ishenin
2012-04-16 07:18 Paul Ishenin Note Added: 0058640
2012-04-19 00:22 David Jenkins Status resolved => closed