KiCad PCB EDA Suite
bitmap_store.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KICAD_BITMAP_STORE_H
21 #define KICAD_BITMAP_STORE_H
22 
23 #include <memory>
24 #include <unordered_map>
25 
26 #include <bitmaps/bitmap_info.h>
27 
28 class ASSET_ARCHIVE;
29 class wxImage;
30 
31 
32 namespace std
33 {
34  template<> struct hash<std::pair<BITMAPS, int>>
35  {
36  size_t operator()( const std::pair<BITMAPS, int>& aPair ) const;
37  };
38 }
39 
44 {
45 public:
46  BITMAP_STORE();
47 
48  ~BITMAP_STORE() = default;
49 
55  wxBitmap GetBitmap( BITMAPS aBitmapId, int aHeight = -1 );
56 
71  wxBitmap GetBitmapScaled( BITMAPS aBitmapId, int aScaleFactor, int aHeight = -1 );
72 
77  void ThemeChanged();
78 
79  bool IsDarkTheme() const { return m_theme == wxT( "dark" ); }
80 
81 private:
82 
83  wxImage getImage( BITMAPS aBitmapId, int aHeight = -1 );
84 
85  const wxString& bitmapName( BITMAPS aBitmapId, int aHeight = -1 );
86 
87  wxString computeBitmapName( BITMAPS aBitmapId, int aHeight = -1 );
88 
89  void buildBitmapInfoCache();
90 
91  std::unique_ptr<ASSET_ARCHIVE> m_archive;
92 
93  std::unordered_map<std::pair<BITMAPS, int>, wxString> m_bitmapNameCache;
94 
95  std::unordered_map<BITMAPS, std::vector<BITMAP_INFO>> m_bitmapInfoCache;
96 
97  wxString m_theme;
98 };
99 
100 #endif // KICAD_BITMAP_STORE_H
void buildBitmapInfoCache()
wxBitmap GetBitmapScaled(BITMAPS aBitmapId, int aScaleFactor, int aHeight=-1)
Retrieves a bitmap from the given bitmap id, scaled to a given factor.
An asset archive represents a file containing data assets that are loaded from disk and then cached i...
Definition: asset_archive.h:35
Helper to retrieve bitmaps while handling icon themes and scaling.
Definition: bitmap_store.h:43
std::unordered_map< std::pair< BITMAPS, int >, wxString > m_bitmapNameCache
Definition: bitmap_store.h:93
Definition: bitmap.cpp:64
bool IsDarkTheme() const
Definition: bitmap_store.h:79
wxString computeBitmapName(BITMAPS aBitmapId, int aHeight=-1)
wxString m_theme
Definition: bitmap_store.h:97
std::unordered_map< BITMAPS, std::vector< BITMAP_INFO > > m_bitmapInfoCache
Definition: bitmap_store.h:95
wxImage getImage(BITMAPS aBitmapId, int aHeight=-1)
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
~BITMAP_STORE()=default
wxBitmap GetBitmap(BITMAPS aBitmapId, int aHeight=-1)
Retrieves a bitmap from the given bitmap id.
std::unique_ptr< ASSET_ARCHIVE > m_archive
Definition: bitmap_store.h:91
const wxString & bitmapName(BITMAPS aBitmapId, int aHeight=-1)