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>
#include <draw_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)
 Construct a wxBitmap from a memory record, held in a BITMAP_DEF. More...
 
int KiIconScale (wxWindow *aWindow)
 Return 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)
 Construct a wxBitmap from a memory record, scaling it if device DPI demands it. More...
 
wxBitmap KiScaledBitmap (const wxBitmap &aBitmap, EDA_BASE_FRAME *aWindow)
 Overload of the above function that takes another wxBitmap as a parameter. More...
 
void KiScaledSeparator (wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
 Add a separator to the given toolbar scaled the same way as KiScaledBitmap. More...
 
wxBitmap * KiBitmapNew (BITMAP_DEF aBitmap)
 Allocate a wxBitmap on heap from a memory record, held in a BITMAP_DEF. More...
 
bool SaveCanvasImageToFile (EDA_DRAW_FRAME *aFrame, const wxString &aFileName, wxBitmapType aBitmapType)
 Save the current view as an image file. 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 223 of file bitmap.cpp.

References PGM_BASE::CommonSettings(), KiBitmap(), Pgm(), and USE_ICONS_IN_MENUS_KEY.

Referenced by SCH_EDIT_FRAME::addJunctionMenuEntries(), 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(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), 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(), FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE(), LIB_EDIT_FRAME::locateItem(), SCH_EDIT_FRAME::LocateItem(), FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), TREE_PROJECT_FRAME::OnRight(), FOOTPRINT_EDIT_FRAME::OnRightClick(), EDA_3D_CANVAS::OnRightClick(), PL_EDITOR_FRAME::OnRightClick(), GERBVIEW_FRAME::OnRightClick(), SCH_EDIT_FRAME::OnRightClick(), LIB_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(), prepareToolsMenu(), prepareViewMenu(), LIB_VIEW_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU(), and SYMBOL_TREE_PANE::SYMBOL_TREE_PANE().

225 {
226  wxMenuItem* item;
227 
228  item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
229 
230  // Retrieve the global applicaton show icon option:
231  bool useImagesInMenus;
232  Pgm().CommonSettings()->Read( USE_ICONS_IN_MENUS_KEY, &useImagesInMenus );
233 
234  if( useImagesInMenus )
235  {
236  if( aType == wxITEM_CHECK || aType == wxITEM_RADIO )
237  {
238  #if defined( __WINDOWS__ )
239  item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
240  // A workaround to a strange bug on Windows, wx Widgets 3.0:
241  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
242  // unless we call SetFont
243  item->SetFont( *wxNORMAL_FONT );
244  #endif
245  }
246  else if( aType != wxITEM_RADIO )
247  {
248  item->SetBitmap( aImage );
249  }
250  }
251 
252  aMenu->Append( item );
253 
254  return item;
255 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:44
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 258 of file bitmap.cpp.

References PGM_BASE::CommonSettings(), KiBitmap(), Pgm(), and USE_ICONS_IN_MENUS_KEY.

261 {
262  wxMenuItem* item;
263 
264  item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
265 
266  // Retrieve the global applicaton show icon option:
267  bool useImagesInMenus;
268  Pgm().CommonSettings()->Read( USE_ICONS_IN_MENUS_KEY, &useImagesInMenus );
269 
270  if( useImagesInMenus )
271  {
272  if( aType == wxITEM_CHECK || aType == wxITEM_RADIO )
273  {
274  #if defined( __WINDOWS__ )
275  item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
276  // A workaround to a strange bug on Windows, wx Widgets 3.0:
277  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
278  // unless we call SetFont
279  item->SetFont( *wxNORMAL_FONT );
280  #endif
281  }
282  else if( aType != wxITEM_RADIO )
283  {
284  item->SetBitmap( aImage );
285  }
286  }
287 
288  aMenu->Append( item );
289 
290  return item;
291 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:44
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 294 of file bitmap.cpp.

References PGM_BASE::CommonSettings(), Pgm(), and USE_ICONS_IN_MENUS_KEY.

296 {
297  wxMenuItem* item;
298 
299  item = new wxMenuItem( aMenu, aId, aText );
300  item->SetSubMenu( aSubMenu );
301 
302  // Retrieve the global applicaton show icon option:
303  bool useImagesInMenus;
304  Pgm().CommonSettings()->Read( USE_ICONS_IN_MENUS_KEY, &useImagesInMenus );
305 
306  if( useImagesInMenus )
307  item->SetBitmap( aImage );
308 
309  aMenu->Append( item );
310 
311  return item;
312 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:44
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 315 of file bitmap.cpp.

References PGM_BASE::CommonSettings(), Pgm(), and USE_ICONS_IN_MENUS_KEY.

318 {
319  wxMenuItem* item;
320 
321  item = new wxMenuItem( aMenu, aId, aText, aHelpText );
322  item->SetSubMenu( aSubMenu );
323 
324  // Retrieve the global applicaton show icon option:
325  bool useImagesInMenus;
326  Pgm().CommonSettings()->Read( USE_ICONS_IN_MENUS_KEY, &useImagesInMenus );
327 
328  if( useImagesInMenus )
329  item->SetBitmap( aImage );
330 
331  aMenu->Append( item );
332 
333  return item;
334 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:44
static int get_scale_factor ( EDA_BASE_FRAME aWindow)
static

Definition at line 104 of file bitmap.cpp.

References PGM_BASE::CommonSettings(), ICON_SCALE_KEY, KiIconScale(), and Pgm().

Referenced by KiScaledBitmap(), and KiScaledSeparator().

105 {
106  int requested_scale;
107  Pgm().CommonSettings()->Read( ICON_SCALE_KEY, &requested_scale, 0 );
108 
109  if( requested_scale > 0 )
110  return requested_scale;
111  else
112  return KiIconScale( aWindow );
113 }
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:89
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
#define ICON_SCALE_KEY
Definition: pgm_base.h:45
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
wxBitmap KiBitmap ( BITMAP_DEF  aBitmap)

Construct a wxBitmap from a memory record, held in a BITMAP_DEF.

Definition at line 79 of file bitmap.cpp.

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

Referenced by SCH_EDIT_FRAME::addJunctionMenuEntries(), 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(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), GRID_CELL_ICON_TEXT_POPUP::Create(), 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_BOM::DIALOG_BOM(), DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS(), DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE(), DIALOG_DRC_CONTROL::DIALOG_DRC_CONTROL(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), DIALOG_EXIT::DIALOG_EXIT(), DIALOG_EXPORT_SVG::DIALOG_EXPORT_SVG(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), DIALOG_FOOTPRINT_BOARD_EDITOR::DIALOG_FOOTPRINT_BOARD_EDITOR(), DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), DIALOG_IMPORT_SETTINGS::DIALOG_IMPORT_SETTINGS(), DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_NETLIST::DIALOG_NETLIST(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), GRID_CELL_ICON_TEXT_RENDERER::Draw(), EDA_3D_VIEWER::EDA_3D_VIEWER(), EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL_RANGE(), EVT_UPDATE_UI(), EVT_UPDATE_UI_RANGE(), FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), GERBVIEW_FRAME::GERBVIEW_FRAME(), HIERARCHY_TREE::HIERARCHY_TREE(), DIALOG_PLOT::init_Dialog(), DIALOG_3D_VIEW_OPTIONS::initDialog(), DIALOG_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), PANEL_PREV_3D::initPanel(), DIALOG_ANNOTATE::InitValues(), KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME(), LIB_EDIT_FRAME::locateItem(), SCH_EDIT_FRAME::LocateItem(), FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnPageChanged(), TREE_PROJECT_FRAME::OnRight(), FOOTPRINT_EDIT_FRAME::OnRightClick(), EDA_3D_CANVAS::OnRightClick(), PL_EDITOR_FRAME::OnRightClick(), GERBVIEW_FRAME::OnRightClick(), SCH_EDIT_FRAME::OnRightClick(), LIB_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(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), 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(), prepareToolsMenu(), prepareViewMenu(), DIALOG_ERC::ReBuildMatrixPanel(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER::ReCreateMainToolbar(), LIB_VIEW_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), set_wxMenuIcon(), DIALOG_ERC::setDRCMatrixButtonState(), SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU(), SIM_PLOT_FRAME::SIM_PLOT_FRAME(), SYMBOL_TREE_PANE::SYMBOL_TREE_PANE(), TEXT_BUTTON_FILE_BROWSER::TEXT_BUTTON_FILE_BROWSER(), TEXT_BUTTON_FP_CHOOSER::TEXT_BUTTON_FP_CHOOSER(), TEXT_BUTTON_SYMBOL_CHOOSER::TEXT_BUTTON_SYMBOL_CHOOSER(), TEXT_BUTTON_URL::TEXT_BUTTON_URL(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), and TREEPROJECTFILES::TREEPROJECTFILES().

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

Allocate a wxBitmap on heap from a memory record, held in a BITMAP_DEF.

Returns
wxBitmap* - caller owns it.

Definition at line 185 of file bitmap.cpp.

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

Referenced by ABOUT_APP_INFO::CreateKiBitmap().

186 {
187  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
188  wxImage image( is, wxBITMAP_TYPE_PNG );
189  wxBitmap* bitmap = new wxBitmap( image );
190 
191  return bitmap;
192 }
const unsigned char * png
Definition: bitmap_types.h:45
int KiIconScale ( wxWindow *  aWindow)

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

Definition at line 89 of file bitmap.cpp.

Referenced by get_scale_factor(), PANEL_COMMON_SETTINGS::OnScaleAuto(), PCB_EDIT_FRAME::PrepareLayerIndicator(), and PANEL_COMMON_SETTINGS::TransferDataToWindow().

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

Construct 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 116 of file bitmap.cpp.

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

Referenced by PYTHON_ACTION_PLUGINS::deregister_action(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), 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().

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

Overload of the above function that takes another wxBitmap as a parameter.

Parameters
aBitmapbitmap definition
aWindowtarget window for scaling context

Definition at line 148 of file bitmap.cpp.

References get_scale_factor(), and SCALED_BITMAP_ID::scale.

149 {
150  const int scale = get_scale_factor( aWindow );
151 
152  if( scale == 4)
153  {
154  return wxBitmap( aBitmap );
155  }
156  else
157  {
158  wxImage image = aBitmap.ConvertToImage();
159  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
160  wxIMAGE_QUALITY_BILINEAR );
161 
162  return wxBitmap( image );
163  }
164 }
const int scale
static int get_scale_factor(EDA_BASE_FRAME *aWindow)
Definition: bitmap.cpp:104
void KiScaledSeparator ( wxAuiToolBar *  aToolbar,
EDA_BASE_FRAME aWindow 
)

Add a separator to the given toolbar scaled the same way as KiScaledBitmap.

Definition at line 167 of file bitmap.cpp.

References get_scale_factor(), and SCALED_BITMAP_ID::scale.

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

168 {
169  const int scale = get_scale_factor( aWindow );
170 
171  if( scale > 4 )
172  {
173  aToolbar->AddSpacer( 16 * ( scale - 4 ) / 4 );
174  }
175 
176  aToolbar->AddSeparator();
177 
178  if( scale > 4 )
179  {
180  aToolbar->AddSpacer( 16 * ( scale - 4 ) / 4 );
181  }
182 }
const int scale
static int get_scale_factor(EDA_BASE_FRAME *aWindow)
Definition: bitmap.cpp:104
bool SaveCanvasImageToFile ( EDA_DRAW_FRAME aFrame,
const wxString &  aFileName,
wxBitmapType  aBitmapType = wxBITMAP_TYPE_PNG 
)

Save the current view as an image file.

Parameters
aFrameThe current draw frame view to save.
aFileNameThe file name to save the image. This will overwrite an exisiting file.
aBitmapTypeThe type of bitmap create as defined by wxImage.
Returns
True if the file was successfully saved or false if the file failed to be saved.

Definition at line 195 of file bitmap.cpp.

References SCALED_BITMAP_ID::bitmap, and EDA_DRAW_FRAME::GetGalCanvas().

Referenced by DrawPageLayout(), and EDA_DRAW_FRAME::saveCanvasImageToFile().

197 {
198  wxCHECK( aFrame != nullptr, false );
199 
200  bool retv = true;
201 
202  // Make a screen copy of the canvas:
203  wxSize image_size = aFrame->GetGalCanvas()->GetClientSize();
204 
205  wxClientDC dc( aFrame->GetGalCanvas() );
206  wxBitmap bitmap( image_size.x, image_size.y );
207  wxMemoryDC memdc;
208 
209  memdc.SelectObject( bitmap );
210  memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
211  memdc.SelectObject( wxNullBitmap );
212 
213  wxImage image = bitmap.ConvertToImage();
214 
215  if( !image.SaveFile( aFileName, aBitmapType ) )
216  retv = false;
217 
218  image.Destroy();
219  return retv;
220 }
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928