Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TSVGIconImageList #114

Open
skamradt opened this issue Nov 24, 2023 · 7 comments
Open

Add support for TSVGIconImageList #114

skamradt opened this issue Nov 24, 2023 · 7 comments

Comments

@skamradt
Copy link

One of the SVG options that is available via GetIt in the more recent versions of Delphi contains the TSVGIconImageList. Using this list for SVG images mostly works, however the disabled drawing is broken, which is extremely visible if you use a dark theme. I made the following changes to TB2Common in the SpIsVirtualImageList procedure. The code change is towards the bottom of this procedure. I believe the patch file would need to be updated to include this change.

    // special case for TSVGIconImageList (also uses RTTI)
    else
      if (ImageList.ClassName = 'TSVGIconImageList') then begin
        if enabled then
          ImageList.Draw(ACanvas, ARect.Left, ARect.Top, ImageIndex)
        else
          begin
            RttiC := TRttiContext.Create;
            // Paint disabled
            RTTIC.GetType(ImageList.ClassType).GetMethod('PaintTo').Invoke(
              ImageList,[ACanvas,ImageIndex,ARect.Left,ARect.Top,ARect.Width,aRect.Height,False]);
          end;
      end
    else
   // end special case
    {$IFEND}
     // For older versions of Delphi

@pyscripter
Copy link

Strange. I use TSVGIconImageList and the disabled images painting looks fine without your patch.

image

@skamradt
Copy link
Author

it works fine if the colors (in your example) are white and your using a dark background. My source images are black and I am toggling between light and dark themes. So, on my almost black theme, when it falls back to the source color (which is black) and then draws that...which results in the following:
image
then with my change:
image

This also gives you control over how the disabled items draw by modifying the properties on the TSVGIconImageList for DisabledGreyScale (mine set to false) and DisabledOpacity (mine set to 50). I am setting FixedColor to match that of the theme clButtonText when I load a theme which simplifies having to have multiple sets of icons for my toolbar.

@pyscripter
Copy link

pyscripter commented Nov 24, 2023

My source images are black and I am toggling between light and dark themes.

The point with Svgs is that you can adjust the color to match the theme.

Here is how my toolbar looks on a light background:
image

and here is some code to do that every time the Vcl Style changes:

procedure TResourcesDataModule.UpdateImageCollections;

  procedure ProcessImageCollection(IC: TSVGIconImageCollection;
    FixedColor: TColor; AntiAliasColor: TColor = TColors.SysDefault);
  begin
    IC.SVGIconItems.BeginUpdate;
    try
      IC.FixedColor := SvgFixedColor(FixedColor);

      if AntiAliasColor <> TColors.SysDefault then
        IC.AntiAliasColor := StyleServices.GetSystemColor(AntiAliasColor);
    finally
      IC.SVGIconItems.EndUpdate;
    end;
  end;

var
  TextColor: TColor;
begin
  var Details := StyleServices.GetElementDetails(ttbButtonNormal);
  if not StyleServices.GetElementColor(Details, ecTextColor, TextColor) then
    TextColor := StyleServices.GetSystemColor(TColors.SysBtnText);

  ProcessImageCollection(icBrowserImages, TextColor);
  ProcessImageCollection(icCodeImages, TColors.SysWindowText, TColors.SysWindow);
  ProcessImageCollection(icGutterGlyphs, TextColor);
  ProcessImageCollection(icSVGImages, TextColor);
end;

@skamradt
Copy link
Author

skamradt commented Nov 24, 2023

Odd, I am performing pretty much the same changes to the image list:

PanelColor := ComputePanelColor; // slightly lighter on dark themes, darker on light themes
ToolbarColor := ColorBlendRGB(StyleServices.GetSystemColor(clBtnFace),PanelColor,0.5);
  :
TSVGIconImageList(lCtrl).FixedColor := StyleServices.GetSystemColor(clBtnText);
TSVGIconImageList(lCtrl).AntiAliasColor := ToolbarColor;

@pyscripter
Copy link

pyscripter commented Nov 24, 2023

What are your VirtualImageList options?
image

If your icons are white on a dark background, which apparently they are, then drawing with opacity should work.

@skamradt
Copy link
Author

skamradt commented Nov 24, 2023

I'm not using a virtual image list. I am using the TSVGIconImageList directly. This is on Delphi 12 (application is being updated from Delphi 10.3)

@pyscripter
Copy link

Which version of Delphi are you on?

I'm not using a virtual image list. I am using the TSVGIconImageList directly.

TSVGIconImageList is only for old versions of Delphi before Tokyo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants