about summary refs log tree commit diff stats
path: root/src/icons.cpp
blob: 87ba0377e791192c20cabcf2e3ca2d00dfa08448 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "icons.h"

#include "global.h"

const wxBitmap* IconCache::GetIcon(const std::string& filename, wxSize size) {
  std::tuple<std::string, int, int> key = {filename, size.x, size.y};

  if (!icons_.count(key)) {
    icons_[key] =
        wxBitmap(wxImage(GetAbsolutePath(filename).c_str(),
                         wxBITMAP_TYPE_PNG)
                     .Scale(size.x, size.y));
  }

  return &icons_.at(key);
}

static IconCache* ICON_CACHE_INSTANCE = nullptr;

void SetTheIconCache(IconCache* instance) { ICON_CACHE_INSTANCE = instance; }

IconCache& GetTheIconCache() { return *ICON_CACHE_INSTANCE; }