KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <wx/bmpbndl.h>
27
28#include <bitmaps/bitmap_info.h>
29#include <kicommon.h>
30
31class ASSET_ARCHIVE;
32class wxImage;
33
34
35namespace std
36{
37 template<> struct KICOMMON_API hash<std::pair<BITMAPS, int>>
38 {
39 size_t operator()( const std::pair<BITMAPS, int>& aPair ) const;
40 };
41}
42
47{
48public:
50
51 ~BITMAP_STORE() = default;
52
58 wxBitmap GetBitmap( BITMAPS aBitmapId, int aHeight = -1 );
59
64 wxBitmapBundle GetBitmapBundle( BITMAPS aBitmapId );
65
71 wxBitmapBundle GetDisabledBitmapBundle( BITMAPS aBitmapId );
72
87 wxBitmap GetBitmapScaled( BITMAPS aBitmapId, int aScaleFactor, int aHeight = -1 );
88
93 void ThemeChanged();
94
95 bool IsDarkTheme() const { return m_theme == wxT( "dark" ); }
96
97private:
98
99 wxImage getImage( BITMAPS aBitmapId, int aHeight = -1 );
100
101 const wxString& bitmapName( BITMAPS aBitmapId, int aHeight = -1 );
102
103 wxString computeBitmapName( BITMAPS aBitmapId, int aHeight = -1 );
104
105 void buildBitmapInfoCache();
106
107 std::unique_ptr<ASSET_ARCHIVE> m_archive;
108
109 std::unordered_map<std::pair<BITMAPS, int>, wxString> m_bitmapNameCache;
110
111 std::unordered_map<BITMAPS, std::vector<BITMAP_INFO>> m_bitmapInfoCache;
112
113 wxString m_theme;
114};
115
116#endif // KICAD_BITMAP_STORE_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
An asset archive represents a file containing data assets that are loaded from disk and then cached i...
Definition: asset_archive.h:37
Helper to retrieve bitmaps while handling icon themes and scaling.
Definition: bitmap_store.h:47
~BITMAP_STORE()=default
bool IsDarkTheme() const
Definition: bitmap_store.h:95
std::unordered_map< BITMAPS, std::vector< BITMAP_INFO > > m_bitmapInfoCache
Definition: bitmap_store.h:111
std::unique_ptr< ASSET_ARCHIVE > m_archive
Definition: bitmap_store.h:107
std::unordered_map< std::pair< BITMAPS, int >, wxString > m_bitmapNameCache
Definition: bitmap_store.h:109
wxString m_theme
Definition: bitmap_store.h:113
#define KICOMMON_API
Definition: kicommon.h:28
STL namespace.