KiCad PCB EDA Suite
bitmap.cpp File Reference
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/mstream.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
#include <wx/aui/auibar.h>
#include <cstdint>
#include <mutex>
#include <unordered_map>
#include <common.h>
#include <bitmaps.h>
#include <pgm_base.h>
#include <eda_base_frame.h>

Go to the source code of this file.

Classes

struct  SCALED_BITMAP_ID
 
struct  std::hash< SCALED_BITMAP_ID >
 

Namespaces

 std
 

Template specialization to enable wxStrings for certain containers (e.g. unordered_map)


 

Functions

wxBitmap KiBitmap (BITMAP_DEF aBitmap)
 Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF. More...
 
int KiIconScale (wxWindow *aWindow)
 Function KiIconScale Returns the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScaledSeparator. More...
 
static int get_scale_factor (EDA_BASE_FRAME *aWindow)
 
wxBitmap KiScaledBitmap (BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
 Function KiScaledBitmap Constructs a wxBitmap from a memory record, scaling it if device DPI demands it. More...
 
void KiScaledSeparator (wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
 Function KiScaledSeparator Adds a separator to the given toolbar scaled the same way as KiScaledBitmap. More...
 
wxBitmap * KiBitmapNew (BITMAP_DEF aBitmap)
 Function KiBitmapNew allocates a wxBitmap on heap from a memory record, held in a BITMAP_DEF. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, int aId, const wxString &aText, const wxString &aHelpText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, wxMenu *aSubMenu, int aId, const wxString &aText, const wxBitmap &aImage)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aSubMenu in aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, wxMenu *aSubMenu, int aId, const wxString &aText, const wxString &aHelpText, const wxBitmap &aImage)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aSubMenu in aMenu. More...
 

Function Documentation

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage,
wxItemKind  aType = wxITEM_NORMAL 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aMenu.

Parameters
aMenuis the menu to add the new item.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aImageis the icon to add to the new menu item.
aTypeis the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
Returns
a pointer to the new created wxMenuItem

Definition at line 174 of file bitmap.cpp.

References PGM_BASE::GetUseIconsInMenus(), KiBitmap(), and Pgm().

Referenced by AddHotkeyConfigMenu(), SCH_EDIT_FRAME::addJunctionMenuEntries(), EDA_BASE_FRAME::AddMenuIconsOptions(), PGM_BASE::AddMenuLanguageList(), AddMenusForBitmap(), AddMenusForBlock(), AddMenusForBus(), AddMenusForBusEntry(), AddMenusForComponent(), AddMenusForComponentField(), AddMenusForEditComponent(), AddMenusForGLabel(), AddMenusForHierchicalSheet(), AddMenusForHLabel(), AddMenusForLabel(), AddMenusForMarkers(), AddMenusForPin(), AddMenusForSheetPin(), AddMenusForText(), AddMenusForWire(), EDA_DRAW_FRAME::AddMenuZoomAndGrid(), AddNewItemsCommand(), PCB_LAYER_WIDGET::AddRightClickMenuItems(), CMP_TREE_PANE::CMP_TREE_PANE(), EDA_3D_VIEWER::CreateMenuBar(), PCB_EDIT_FRAME::createPopUpBlockMenu(), PCB_EDIT_FRAME::createPopUpMenuForFootprints(), PCB_EDIT_FRAME::createPopUpMenuForFpPads(), PCB_EDIT_FRAME::createPopUpMenuForFpTexts(), PCB_EDIT_FRAME::createPopUpMenuForMarkers(), PCB_EDIT_FRAME::createPopUpMenuForTexts(), PCB_EDIT_FRAME::createPopupMenuForTracks(), PCB_EDIT_FRAME::createPopUpMenuForZones(), PYTHON_ACTION_PLUGINS::deregister_action(), LIB_EDIT_FRAME::locateItem(), SCH_EDIT_FRAME::LocateItem(), FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay(), TREE_PROJECT_FRAME::OnRight(), FOOTPRINT_EDIT_FRAME::OnRightClick(), EDA_3D_CANVAS::OnRightClick(), PL_EDITOR_FRAME::OnRightClick(), GERBVIEW_FRAME::OnRightClick(), LIB_EDIT_FRAME::OnRightClick(), SCH_EDIT_FRAME::OnRightClick(), PCB_EDIT_FRAME::OnRightClick(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), PL_EDITOR_FRAME::OnTreeRightClick(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), prepareEditMenu(), prepareExportMenu(), prepareFilesMenu(), prepareHelpMenu(), prepareInspectMenu(), prepareLibraryMenu(), preparePlaceMenu(), preparePreferencesMenu(), prepareRouteMenu(), prepareSetupMenu(), prepareToolsMenu(), prepareViewMenu(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), and SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU().

176 {
177  wxMenuItem* item;
178 
179  item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
180 
181  // Retrieve the global applicaton show icon option:
182  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
183 
184  if( useImagesInMenus )
185  {
186  if( aType == wxITEM_CHECK || aType == wxITEM_RADIO )
187  {
188  #if defined( __WINDOWS__ )
189  item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
190  // A workaround to a strange bug on Windows, wx Widgets 3.0:
191  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
192  // unless we call SetFont
193  item->SetFont( *wxNORMAL_FONT );
194  #endif
195  }
196  else if( aType != wxITEM_RADIO )
197  {
198  item->SetBitmap( aImage );
199  }
200  }
201 
202  aMenu->Append( item );
203 
204  return item;
205 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
bool GetUseIconsInMenus()
Definition: pgm_base.h:328
wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage,
wxItemKind  aType = wxITEM_NORMAL 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aMenu.

Parameters
aMenuis the menu to add the new item.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aHelpTextis the help message string for the new menu item.
aImageis the icon to add to the new menu item.
aTypeis the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
Returns
a pointer to the new created wxMenuItem

Definition at line 208 of file bitmap.cpp.

References PGM_BASE::GetUseIconsInMenus(), KiBitmap(), and Pgm().

211 {
212  wxMenuItem* item;
213 
214  item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
215 
216  // Retrieve the global applicaton show icon option:
217  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
218 
219  if( useImagesInMenus )
220  {
221  if( aType == wxITEM_CHECK || aType == wxITEM_RADIO )
222  {
223  #if defined( __WINDOWS__ )
224  item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
225  // A workaround to a strange bug on Windows, wx Widgets 3.0:
226  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
227  // unless we call SetFont
228  item->SetFont( *wxNORMAL_FONT );
229  #endif
230  }
231  else if( aType != wxITEM_RADIO )
232  {
233  item->SetBitmap( aImage );
234  }
235  }
236 
237  aMenu->Append( item );
238 
239  return item;
240 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
bool GetUseIconsInMenus()
Definition: pgm_base.h:328
wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aSubMenu in aMenu.

Parameters
aMenuis the menu to add the new submenu item.
aSubMenuis the submenu to add the new menu.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aImageis the icon to add to the new menu item.
Returns
a pointer to the new created wxMenuItem

Definition at line 243 of file bitmap.cpp.

References PGM_BASE::GetUseIconsInMenus(), and Pgm().

245 {
246  wxMenuItem* item;
247 
248  item = new wxMenuItem( aMenu, aId, aText );
249  item->SetSubMenu( aSubMenu );
250 
251  // Retrieve the global applicaton show icon option:
252  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
253 
254  if( useImagesInMenus )
255  item->SetBitmap( aImage );
256 
257  aMenu->Append( item );
258 
259  return item;
260 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
bool GetUseIconsInMenus()
Definition: pgm_base.h:328
wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aSubMenu in aMenu.

Parameters
aMenuis the menu to add the new submenu item.
aSubMenuis the submenu to add the new menu.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aHelpTextis the help message string for the new menu item.
aImageis the icon to add to the new menu item.
Returns
a pointer to the new created wxMenuItem

Definition at line 263 of file bitmap.cpp.

References PGM_BASE::GetUseIconsInMenus(), and Pgm().

266 {
267  wxMenuItem* item;
268 
269  item = new wxMenuItem( aMenu, aId, aText, aHelpText );
270  item->SetSubMenu( aSubMenu );
271 
272  // Retrieve the global applicaton show icon option:
273  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
274 
275  if( useImagesInMenus )
276  item->SetBitmap( aImage );
277 
278  aMenu->Append( item );
279 
280  return item;
281 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
bool GetUseIconsInMenus()
Definition: pgm_base.h:328
static int get_scale_factor ( EDA_BASE_FRAME aWindow)
static

Definition at line 103 of file bitmap.cpp.

References EDA_BASE_FRAME::GetIconScale(), and KiIconScale().

Referenced by KiScaledBitmap(), and KiScaledSeparator().

104 {
105  const int requested_scale = aWindow->GetIconScale();
106 
107  if( requested_scale > 0 )
108  return requested_scale;
109  else
110  return KiIconScale( aWindow );
111 }
int KiIconScale(wxWindow *aWindow)
Function KiIconScale Returns the automatic scale factor that would be used for a given window by KiSc...
Definition: bitmap.cpp:88
virtual int GetIconScale()
Function GetIconScale.
wxBitmap KiBitmap ( BITMAP_DEF  aBitmap)

Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.

Definition at line 78 of file bitmap.cpp.

References SCALED_BITMAP_ID::bitmap, BITMAP_OPAQUE::byteCount, and BITMAP_OPAQUE::png.

Referenced by AddHotkeyConfigMenu(), SCH_EDIT_FRAME::addJunctionMenuEntries(), EDA_BASE_FRAME::AddMenuIconsOptions(), AddMenuItem(), PGM_BASE::AddMenuLanguageList(), AddMenusForBitmap(), AddMenusForBlock(), AddMenusForBus(), AddMenusForBusEntry(), AddMenusForComponent(), AddMenusForComponentField(), AddMenusForEditComponent(), AddMenusForGLabel(), AddMenusForHierchicalSheet(), AddMenusForHLabel(), AddMenusForLabel(), AddMenusForMarkers(), AddMenusForPin(), AddMenusForSheetPin(), AddMenusForText(), AddMenusForWire(), EDA_DRAW_FRAME::AddMenuZoomAndGrid(), AddNewItemsCommand(), PCB_LAYER_WIDGET::AddRightClickMenuItems(), CMP_TREE_PANE::CMP_TREE_PANE(), LAUNCHER_PANEL::CreateCommandToolbar(), EDA_3D_VIEWER::CreateMenuBar(), PCB_EDIT_FRAME::createPopUpBlockMenu(), PCB_EDIT_FRAME::createPopUpMenuForFootprints(), PCB_EDIT_FRAME::createPopUpMenuForFpPads(), PCB_EDIT_FRAME::createPopUpMenuForFpTexts(), PCB_EDIT_FRAME::createPopUpMenuForMarkers(), PCB_EDIT_FRAME::createPopUpMenuForTexts(), PCB_EDIT_FRAME::createPopupMenuForTracks(), PCB_EDIT_FRAME::createPopUpMenuForZones(), DIALOG_ABOUT::createStaticBitmap(), CVPCB_MAINFRAME::CVPCB_MAINFRAME(), PYTHON_ACTION_PLUGINS::deregister_action(), DIALOG_ABOUT::DIALOG_ABOUT(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC(), DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB(), DIALOG_EXIT::DIALOG_EXIT(), DIALOG_FOOTPRINT_BOARD_EDITOR::DIALOG_FOOTPRINT_BOARD_EDITOR(), DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR(), DIALOG_NETLIST::DIALOG_NETLIST(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::DIALOG_PNS_LENGTH_TUNING_SETTINGS(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), EDA_3D_VIEWER::EDA_3D_VIEWER(), EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL(), EVT_UPDATE_UI(), EVT_UPDATE_UI_RANGE(), GERBVIEW_FRAME::GERBVIEW_FRAME(), DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetValue(), DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetValue(), HIERARCHY_TREE::HIERARCHY_TREE(), DIALOG_EXCHANGE_FOOTPRINTS::init(), DIALOG_PLOT::init_Dialog(), DIALOG_3D_VIEW_OPTIONS::initDialog(), DIALOG_COPPER_ZONE::initDialog(), DIALOG_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), DIALOG_PLOT_SCHEMATIC::initDlg(), PANEL_PREV_3D::initPanel(), DIALOG_ANNOTATE::InitValues(), DIALOG_PAD_PROPERTIES::initValues(), KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME(), LIB_EDIT_FRAME::LIB_EDIT_FRAME(), LIB_VIEW_FRAME::LIB_VIEW_FRAME(), LIB_EDIT_FRAME::locateItem(), SCH_EDIT_FRAME::LocateItem(), FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay(), WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnPageChanged(), WIZARD_FPLIB_TABLE::OnPageChanged(), TREE_PROJECT_FRAME::OnRight(), FOOTPRINT_EDIT_FRAME::OnRightClick(), EDA_3D_CANVAS::OnRightClick(), PL_EDITOR_FRAME::OnRightClick(), GERBVIEW_FRAME::OnRightClick(), LIB_EDIT_FRAME::OnRightClick(), SCH_EDIT_FRAME::OnRightClick(), PCB_EDIT_FRAME::OnRightClick(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), SIM_PLOT_FRAME::onSimFinished(), SIM_PLOT_FRAME::onSimStarted(), PL_EDITOR_FRAME::OnTreeRightClick(), PCB_EDIT_FRAME::PCB_EDIT_FRAME(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), PinShapeComboBox::PinShapeComboBox(), PinTypeComboBox::PinTypeComboBox(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), prepareEditMenu(), prepareExportMenu(), prepareFilesMenu(), prepareHelpMenu(), prepareInspectMenu(), prepareLibraryMenu(), preparePlaceMenu(), preparePreferencesMenu(), prepareRouteMenu(), prepareSetupMenu(), prepareToolsMenu(), prepareViewMenu(), DIALOG_ERC::ReBuildMatrixPanel(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER::ReCreateMainToolbar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), set_wxMenuIcon(), DIALOG_ERC::setDRCMatrixButtonState(), DIALOG_LIB_EDIT_PIN::SetOrientationList(), SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU(), SIM_PLOT_FRAME::SIM_PLOT_FRAME(), and TREEPROJECTFILES::TREEPROJECTFILES().

79 {
80  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
81  wxImage image( is, wxBITMAP_TYPE_PNG );
82  wxBitmap bitmap( image );
83 
84  return bitmap;
85 }
const unsigned char * png
Definition: bitmap_types.h:43
wxBitmap* KiBitmapNew ( BITMAP_DEF  aBitmap)

Function KiBitmapNew allocates a wxBitmap on heap from a memory record, held in a BITMAP_DEF.

Returns
wxBitmap* - caller owns it.

Definition at line 164 of file bitmap.cpp.

References SCALED_BITMAP_ID::bitmap, BITMAP_OPAQUE::byteCount, and BITMAP_OPAQUE::png.

Referenced by ABOUT_APP_INFO::CreateKiBitmap().

165 {
166  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
167  wxImage image( is, wxBITMAP_TYPE_PNG );
168  wxBitmap* bitmap = new wxBitmap( image );
169 
170  return bitmap;
171 }
const unsigned char * png
Definition: bitmap_types.h:43
int KiIconScale ( wxWindow *  aWindow)

Function KiIconScale Returns the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScaledSeparator.

Definition at line 88 of file bitmap.cpp.

Referenced by get_scale_factor(), DIALOG_GENERALOPTIONS::init(), DIALOG_DISPLAY_OPTIONS::OnOKBUttonClick(), DIALOG_GENERALOPTIONS::OnScaleAuto(), DIALOG_DISPLAY_OPTIONS::OnScaleAuto(), DIALOG_EESCHEMA_OPTIONS::OnScaleAuto(), DIALOG_LIBEDIT_OPTIONS::OnScaleAuto(), PCB_EDIT_FRAME::PrepareLayerIndicator(), DIALOG_EESCHEMA_OPTIONS::TransferDataToWindow(), and DIALOG_LIBEDIT_OPTIONS::TransferDataToWindow().

89 {
90  const int vert_size = aWindow->ConvertDialogToPixels( wxSize( 0, 8 ) ).y;
91 
92  // Autoscale won't exceed unity until the system has quite high resolution,
93  // because we don't want the icons to look obviously scaled on a system
94  // where it's easy to see it.
95 
96  if( vert_size > 34 ) return 8;
97  else if( vert_size > 29 ) return 7;
98  else if( vert_size > 24 ) return 6;
99  else return 4;
100 }
wxBitmap KiScaledBitmap ( BITMAP_DEF  aBitmap,
EDA_BASE_FRAME aWindow 
)

Function KiScaledBitmap Constructs a wxBitmap from a memory record, scaling it if device DPI demands it.

Internally this may use caching to avoid scaling the same image twice. If caching is used, it's guaranteed threadsafe.

Parameters
aBitmapbitmap definition
aWindowtarget window for scaling context

Definition at line 114 of file bitmap.cpp.

References BITMAP_OPAQUE::byteCount, get_scale_factor(), BITMAP_OPAQUE::png, and SCALED_BITMAP_ID::scale.

Referenced by PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), LIB_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), GERBVIEW_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), LIB_EDIT_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

115 {
116  // Bitmap conversions are cached because they can be slow.
117  static std::unordered_map<SCALED_BITMAP_ID, wxBitmap> bitmap_cache;
118  static std::mutex bitmap_cache_mutex;
119  const int scale = get_scale_factor( aWindow );
120 
121  SCALED_BITMAP_ID id = { aBitmap, scale };
122 
123  std::lock_guard<std::mutex> guard( bitmap_cache_mutex );
124  auto it = bitmap_cache.find( id );
125 
126  if( it != bitmap_cache.end() )
127  {
128  return it->second;
129  }
130  else
131  {
132  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
133  wxImage image( is, wxBITMAP_TYPE_PNG );
134 
135  // Bilinear seems to genuinely look better for these line-drawing icons
136  // than bicubic, despite claims in the wx documentation that bicubic is
137  // "highest quality". I don't recommend changing this. Bicubic looks
138  // blurry and makes me want an eye exam.
139  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
140  wxIMAGE_QUALITY_BILINEAR );
141  return bitmap_cache.emplace( id, wxBitmap( image ) ).first->second;
142  }
143 }
const unsigned char * png
Definition: bitmap_types.h:43
const int scale
static int get_scale_factor(EDA_BASE_FRAME *aWindow)
Definition: bitmap.cpp:103
void KiScaledSeparator ( wxAuiToolBar *  aToolbar,
EDA_BASE_FRAME aWindow 
)