Fade Treenode; equivalent for TreeView_SetItem w' TVIS_CUT ? lazarus / 31-LCL ---------------------------------------------------------------------- d7_2_laz · 2021-06-28 08:14 Win x64. I assume the macro TreeView_SetItem won't have any effect on the non-Windows LCL Treeview, but what could be the equivalent measure for to temporarely fade a tree node? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // Delphi:procedure FadeTreeNode(Handle: hWnd; ANode: TTreeNode);//var  Item: tagTVITEM;  //  won't compile with Lazarusvar  Item: tagTVITEMA;  //  or tagTVIITEMW ?begin    with Item do begin          mask := TVIF_STATE;          //hItem := ANode.ItemId;  // Lazarus doesn't know the property ItemId          stateMask := TVIS_CUT;        state := stateMask and DWORD(-1);     end;     TreeView_SetItem(Handle, Item);   // won't compile when using tagTVIITEMWend; ---------------------------------------------------------------------- d7_2_laz · 2021-07-02 09:42 Hello Jamie, thanks! You say, for a cutted node not to indicate visually that it is in a cutted state  (ie. by a faded icon appearance), but to remove it (maybe interimswise) really from the tree? ---------------------------------------------------------------------- d7_2_laz · 2021-07-03 09:13 Hm, whatever this property does (other than to set the flag nsCut), probably (as of a quick test) it does not affect the visualizaion of the node's icon. The appearance of the node's icon does not change when changing the property. The use case is twofold: first, to indicate visually (dimmed node icon with less brightness) that a node is candidate to be moved / reinserted at a subsequent Paste, which will move objects and the belonging node from A to B. And oftenly the technique is used by file managers for to indicate hidden objects (ie. see hidden files or folders in the Windows Explorer: the nodes are faded). Why TVIS_CUT is oftenly used for Window's treeview is described here (it related to VB, but this does not matter): https://www.vbforums.com/showthread.php?851257-RESOLVED-How-to-get- quot-hidden-quot-versions-of-file-folder-icons I think it's not possible to do something similar with the LCL treeview (rather than to use a seüarate dedicated set of icons, of course). But i'm not sure though i simply missed something. ---------------------------------------------------------------------- d7_2_laz · 2021-07-03 14:24 Jamie, thanks for conversation! Yes, there are ways around, but being more or less complicated. For the "hidden files and folders" thing (items, that are comparatively durable) i actually do a preparation of the icon as retrieved from the system, changing the brightness of the icon/bitmap before storing it in the imagelist. A complication here will arise by the builtin overlays (ie. link overlay) that better should be excluded from the fading (would look ugly otherwise).  -- Solved. The node cut effect thing i'm ignoring for the moment. It's not so important that i would like to have the tree nodes ownerdrawn instead of the imagelist means only for that. But of course it would be nice to have the capability one day, because it think it belongs to the Gui habits at least on Windows (don't know how it behaves on other OSses). That's the reason why i did ask, if there's an already known code around. If not, fine anyway; if yes, would be nice to know for future usage ... On Linux, Mac ... a visual fading / any visual indication of cutted nodes is not common? ---------------------------------------------------------------------- d7_2_laz · 2021-07-04 17:16 Hello Jamie, i'll add a screenshot below, showing two faded nodes, two faded nodes having the complication that there are overlay images inside (link overlays) and two "normal" icons as retrieved via SHGetFileInfoW. For the case that the file items are hidden (->  FileInfo.dwAttributes and SFGAO_HIDDEN) i query if there are also an overlay   //  -> bHasOverlay := (FileInfo.dwAttributes and SFGAO_LINK) <> 0;): If hidden, i transfer the icon to a TPicture.Bitmap and call a procedure that i found somewhere on the net as:           BlendBitmap(myPicture.Bitmap, BmpBlended, clWhite, 50, bgColor, bHasOverlay);           Node.ImageIndex := Self.Images.Add(BmpBlended, nil); I know that there are several ways to do, but i tried that one. With two minor somehow hackish adaptions. - the black portion of the bitmapp background needed to be removed, because an subsequent ImageList_ReplaceIcon was not enough - the position and size of an overlay image (if any) better would be determined programatically. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure BlendBitmap(Source :TBitmap; Dest :TBitmap; BlendColor :TColor; BlendValue: Byte; bgColor: TColor; bExcludeOverlay: Boolean);var   X, Y,  R, G, B,  PR, PG, PB :Integer; blColor :LongInt;      scColor :TColor; Percent :Single; tmpBitmap :TBitmap;      bExcludeThis: Boolean;begin  if BlendValue > 100 then    BlendValue := 100;  tmpBitmap := TBitmap.Create;  try    tmpBitmap.Assign(Source);    Percent := BlendValue/100;     blColor := ColorToRGB(BlendColor);    R := (blColor and $000000FF);        // Red    G := (blColor and $0000FF00) shr 8;  // Green    B := (blColor and $00FF0000) shr 16; // Blue    for X := 0 to tmpBitmap.Width -1 do        for Y := 0 to tmpBitmap.Height -1 do begin        scColor := tmpBitmap.Canvas.Pixels[X, Y];        if scColor = clBlack then    // !!!  Hack!  Black background to be removed           scColor := bgColor;  // background color instead of black        PR := (scColor and $000000FF);          // % Red        PG := ((scColor and $0000FF00) shr 8);  // % Green        PB := ((scColor and $00FF0000) shr 16); // % Blu        PR := Trunc(R +((PR -R) *Percent));        PG := Trunc(G +((PG -G) *Percent));        PB := Trunc(B +((PB -B) *Percent));        // Hack! Exclude an overlay region (if any) from the pixel manipulation        bExcludeThis := bExcludeOverlay And Not ((X > 8) or  (Y < 8));  // is hardcoded. Better: determine the value before        if  Not bExcludeThis then            tmpBitmap.Canvas.Pixels[X, Y] := RGB(PR ,PG, PB);       end;    Dest.Assign(tmpBitmap);   // Kopiert die temporäre Bitmap an das Ziel  finally    tmpBitmap.Free;  end;end; Side noted, for the cut effect, ie. at keystroke Ctrl-X. I thought, hm, in treeview.inc there is the node state nsCut. Wouldn't it be possible to use a different "FNode.FNodeEffect" at drawing, eg. gdeDisabled instead of gdeNormal? Around line 5417: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           if Node.GetCut = True then               ImageRes.Draw(Canvas, x + 1, NodeRect.Top + (NodeRect.Bottom - NodeRect.Top - ImageRes.Height) div 2,                    ImgIndex, gdeDisabled)            else             ImageRes.Draw(Canvas, x + 1, NodeRect.Top + (NodeRect.Bottom - NodeRect.Top - ImageRes.Height) div 2,                   ImgIndex, Node.FNodeEffect); but this quick 5-minute-test ws not successul. Screenshot "hidden files or folders": ---------------------------------------------------------------------- d7_2_laz · 2021-07-04 19:05 Thanks for the tip Jamie! Although i have no clue about TRawImage now, i'll keep an eye on to improve. Especially in this app i'm very sensitive about speed and performance, but so far not so much in this special regard "hidden files and folders" .... because the occurance is rare (there aren't so much), and so the routine is called rarely. Much effort and thoughts for such a little thing ....  but, hm, nobody likes the idea to loose even small features he had already used for years, with a fingersnip (TreeView_SetItem, with tvis_cut) ---------------------------------------------------------------------- d7_2_laz · 2021-07-05 11:03 Jamie, just for interest: i measured "BlendBitmap" by GetTickCount and it did run approx. 1,6 ms per16x16-pixel icon. Then i measured "FadeIn"  -  fading example using TLazIntfImage from https://wiki.lazarus.freepascal.org/Developing_with_Graphics#Working_w ith_TLazIntfImage.2C_TRawImage_and_TLazCanvas just for test, without much further adaptions. It took approx. 2 to 4,6 ms fpr the same icon(s). ---------------------------------------------------------------------- d7_2_laz · 2021-07-05 13:15 Tested another procedure found here: https://www.lazarusforum.de/viewtopic.php?t=7104 It looks promising: Loop with 100 test calls of "BlendBitmap"   --> approx. 140 ms for the 100 calls Loop with 100 test calls of "Brightness"      --> approx. 16 ms for the 100 calls  (!!) Measured in the ide (slower than starting the executable directly). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //uses LCLType, IntfGraphics, fpImage, math;procedure Brightness(SourceBitmap, DestBitmap: TBitMap; Offset: integer);var  SrcIntfImg, TempIntfImg: TLazIntfImage;  ImgHandle, ImgMaskHandle: HBitmap;     px, py: integer; CurColor: TFPColor;begin  Offset:=Offset * $FF;  SrcIntfImg := TLazIntfImage.Create(0, 0);  SrcIntfImg.LoadFromBitmap(SourceBitmap.Handle, SourceBitmap.MaskHandle);  TempIntfImg := TLazIntfImage.Create(0, 0);  TempIntfImg.DataDescription := GetDescriptionFromDevice(0);  TempIntfImg.SetSize(SrcIntfImg.Width,SrcIntfImg.Height);  for py := 0 to SrcIntfImg.Height - 1 do  begin    for px := 0 to SrcIntfImg.Width - 1 do begin       CurColor := SrcIntfImg.Colors[px, py];       CurColor.red := EnsureRange(CurColor.red + Offset,0,$FFFF);       CurColor.green := EnsureRange(CurColor.green + Offset,0,$FFFF);       CurColor.blue := EnsureRange(CurColor.blue + Offset,0,$FFFF);       TempIntfImg.Colors[px, py] := CurColor;    end;  end;  TempIntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle, False);  DestBitmap.Handle := ImgHandle;  DestBitmap.MaskHandle := ImgMaskHandle;  SrcIntfImg.Free;  TempIntfImg.Free;end; Brightness(icopict.Bitmap, BmpBlended, 50);   // values between -255 and +255 ---------------------------------------------------------------------- d7_2_laz · 2021-07-05 14:51 Ok, ten times faster than the original, but i was not quite happy< with the colors itself, too yellow ... Also, still open: black background / transparency problem, and the overlay area still not preserved. I ended up by using the alpha channel and doing the following modification, that comes quite close to the original as inspirated by TreeView_SetItem  / TVIS_CUT: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //uses LCLType, IntfGraphics, fpImage, math;procedure Brightness(SourceBitmap, DestBitmap: TBitMap; Offset: integer; bgColor: TColor; bExcludeOverlay: Boolean);var  SrcIntfImg, TempIntfImg: TLazIntfImage;  ImgHandle, ImgMaskHandle: HBitmap;     px, py: integer; CurColor, CurColorOrig: TFPColor;     bExcludeThis: Boolean; ovllim: Integer;begin  Offset:=Offset * $FF;  SrcIntfImg := TLazIntfImage.Create(0, 0);  SrcIntfImg.LoadFromBitmap(SourceBitmap.Handle, SourceBitmap.MaskHandle);  TempIntfImg := TLazIntfImage.Create(0, 0);  TempIntfImg.DataDescription := GetDescriptionFromDevice(0);  TempIntfImg.SetSize(SrcIntfImg.Width,SrcIntfImg.Height);  ovllim := SourceBitmap.Height - 8;  for py := 0 to SrcIntfImg.Height - 1 do  begin    for px := 0 to SrcIntfImg.Width - 1 do begin       CurColor := SrcIntfImg.Colors[px, py];       CurColorOrig := CurColor;       CurColor.red := EnsureRange(CurColor.red + Offset,0,$FFFF);       CurColor.green := EnsureRange(CurColor.green + Offset,0,$FFFF);       CurColor.blue := EnsureRange(CurColor.blue + Offset,0,$FFFF);       CurColor.Alpha := 32564;       bExcludeThis := bExcludeOverlay And Not ((px > ovllim) or  (py < ovllim));       if CurColorOrig = TColorToFPColor(clBlack) then          CurColor := TColorToFPColor(bgColor);       if bExcludeThis then          CurColor := CurColorOrig;       TempIntfImg.Colors[px, py] := CurColor;    end;  end;  TempIntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle, False);  DestBitmap.Handle := ImgHandle;  DestBitmap.MaskHandle := ImgMaskHandle;  SrcIntfImg.Free;  TempIntfImg.Free;end;....Brightness(icopict.Bitmap, BmpBlended, 0, bgColor, bHasOverlay);   // values between -255 and +255Node.ImageIndex := Self.Images.Add(BmpBlended, nil);