message: Implement generic version of macOS's template images
  Implement loading of template images in a similar way to how macOS does
  it, i.e. taking a black image and applying transparency (or inverting
  it for dark modes) automatically.
diff: #include <set>
  #include "icons.h"
  +
  +#include "colorscheme.h"
  #include "edapp.h"
  #include "hidpi.h"
  #include "utility.h"
  @@ -87,6 +89,26 @@ bool ShouldBeMirorredInRTL(const wxArtID& id, const wxArtClient& client)
  return mirror;
  }
  +void ProcessTemplateImage(wxImage& img, bool keepOpaque)
  +{
  + int size = img.GetWidth() * img.GetHeight();
  +
  + if (ColorScheme::GetAppMode() == ColorScheme::Dark)
  + {
  + auto rgb = img.GetData();
  + for (int i = 0; i < 3*size; ++i, ++rgb)
  + *rgb = 255 - *rgb;
  + }
  +
  + // Apply 50% transparency
  + if (!keepOpaque)
  + {
  + auto alpha = img.GetAlpha();
  + for (int i = 0; i < size; ++i, ++alpha)
  + *alpha /= 2;
  + }
  +}
  +
  } // anonymous namespace
  wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
  @@ -96,9 +118,12 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
  wxLogTrace("poedit.icons", "getting icon '%s'", id_.c_str());
  wxArtID id(id_);
  - const bool disabledVariant = id.Contains("@disabled");
  - if (disabledVariant)
  - id.Replace("@disabled", "");
  + #define CHECK_FOR_VARIANT(name) \
  + const bool name##Variant = id.Contains("@" #name); \
  + if (name##Variant) \
  + id.Replace("@" #name, "")
  + CHECK_FOR_VARIANT(disabled);
  + CHECK_FOR_VARIANT(opaque);
  // Silence warning about unused parameter in some of the builds
  (void)client;
  @@ -136,13 +161,21 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
  wxString icon;
  icon.Printf("%s/%s", iconsdir, id);
  wxLogTrace("poedit.icons", "loading from %s", icon);
  - wxImage img = LoadScaledBitmap(icon);
  + wxImage img;
  + if (ColorScheme::GetAppMode() == ColorScheme::Dark)
  + img = LoadScaledBitmap(icon + "Dark");
  + if (!img.IsOk())
  + img = LoadScaledBitmap(icon);
  +
  if (!img.IsOk())
  {
  wxLogTrace("poedit.icons", "failed to load icon '%s'", id);
  return wxNullBitmap;
  }
  + if (id.EndsWith("Template"))
  + ProcessTemplateImage(img, opaqueVariant);
  +
  if (disabledVariant)
  img = img.ConvertToDisabled();
  