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
28class ASSET_ARCHIVE;
29class wxImage;
30
31
32namespace 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{
45public:
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
81private:
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
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
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:36
Helper to retrieve bitmaps while handling icon themes and scaling.
Definition: bitmap_store.h:44
wxString computeBitmapName(BITMAPS aBitmapId, int aHeight=-1)
~BITMAP_STORE()=default
bool IsDarkTheme() const
Definition: bitmap_store.h:79
void buildBitmapInfoCache()
std::unordered_map< BITMAPS, std::vector< BITMAP_INFO > > m_bitmapInfoCache
Definition: bitmap_store.h:95
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
std::unique_ptr< ASSET_ARCHIVE > m_archive
Definition: bitmap_store.h:91
std::unordered_map< std::pair< BITMAPS, int >, wxString > m_bitmapNameCache
Definition: bitmap_store.h:93
const wxString & bitmapName(BITMAPS aBitmapId, int aHeight=-1)
wxBitmap GetBitmap(BITMAPS aBitmapId, int aHeight=-1)
Retrieves a bitmap from the given bitmap id.
wxString m_theme
Definition: bitmap_store.h:97
wxBitmap GetBitmapScaled(BITMAPS aBitmapId, int aScaleFactor, int aHeight=-1)
Retrieves a bitmap from the given bitmap id, scaled to a given factor.
wxImage getImage(BITMAPS aBitmapId, int aHeight=-1)
Definition: bitmap.cpp:64