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 <wx/dc.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <cstdint>
#include <mutex>
#include <unordered_map>
#include <bitmaps.h>
#include <pgm_base.h>
#include <eda_base_frame.h>
#include <eda_draw_frame.h>
#include <settings/common_settings.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 (wxWindow *aWindow)
 
wxBitmap KiScaledBitmap (BITMAP_DEF aBitmap, wxWindow *aWindow)
 Construct a wxBitmap from a memory record, scaling it if device DPI demands it. More...
 
wxBitmap KiScaledBitmap (const wxBitmap &aBitmap, wxWindow *aWindow)
 Overload of the above function that takes another wxBitmap as a parameter. 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...
 
void AddBitmapToMenuItem (wxMenuItem *aMenu, const wxBitmap &aImage)
 Add a bitmap to a menuitem. 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

◆ AddBitmapToMenuItem()

void AddBitmapToMenuItem ( wxMenuItem *  aMenu,
const wxBitmap &  aImage 
)

Add a bitmap to a menuitem.

Parameters
aMenuis the menuitem.
aImageis the icon to add to aMenu. It is added only if use images in menus config option allows it. For wxITEM_CHECK or wxITEM_RADIO menuitems, the bitmap is added only on Windows, other platforms do not support it

Definition at line 207 of file bitmap.cpp.

208 {
209  // Retrieve the global applicaton show icon option:
210  bool useImagesInMenus = Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
211 
212  wxItemKind menu_type = aMenu->GetKind();
213 
214  if( useImagesInMenus )
215  {
216  if( menu_type == wxITEM_CHECK || menu_type == wxITEM_RADIO )
217  {
218  #if defined( __WINDOWS__ )
219  aMenu->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
220  // A workaround to a strange bug on Windows, wx Widgets 3.0:
221  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
222  // unless we call SetFont
223  aMenu->SetFont( *wxNORMAL_FONT );
224  #endif
225  }
226  else if( menu_type != wxITEM_RADIO )
227  {
228  aMenu->SetBitmap( aImage );
229  }
230  }
231 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
const BITMAP_OPAQUE checked_ok_xpm[1]
Definition: checked_ok.cpp:51

References checked_ok_xpm, KiBitmap(), and Pgm().

Referenced by ACTION_MENU::Add(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), AddMenuItem(), ACTION_MENU::appendCopy(), ACTION_MENU::DisplayTitle(), CONDITIONAL_MENU::Evaluate(), and SIM_PLOT_FRAME::setIconsForMenuItems().

◆ AddMenuItem() [1/4]

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

236 {
237  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
238  AddBitmapToMenuItem( item, aImage );
239 
240  aMenu->Append( item );
241 
242  return item;
243 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207

References AddBitmapToMenuItem().

Referenced by GERBER_LAYER_WIDGET::AddRightClickMenuItems(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), TREE_PROJECT_FRAME::OnRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), APPEARANCE_CONTROLS::rebuildLayerContextMenu(), PANEL_COLOR_SETTINGS::ShowColorContextMenu(), and SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU().

◆ AddMenuItem() [2/4]

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

249 {
250  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
251  AddBitmapToMenuItem( item, aImage );
252 
253  aMenu->Append( item );
254 
255  return item;
256 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207

References AddBitmapToMenuItem().

◆ AddMenuItem() [3/4]

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

261 {
262  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText );
263  item->SetSubMenu( aSubMenu );
264  AddBitmapToMenuItem( item, aImage );
265 
266  aMenu->Append( item );
267 
268  return item;
269 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207

References AddBitmapToMenuItem().

◆ AddMenuItem() [4/4]

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

275 {
276  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText );
277  item->SetSubMenu( aSubMenu );
278  AddBitmapToMenuItem( item, aImage );
279 
280  aMenu->Append( item );
281 
282  return item;
283 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207

References AddBitmapToMenuItem().

◆ get_scale_factor()

static int get_scale_factor ( wxWindow *  aWindow)
static

Definition at line 107 of file bitmap.cpp.

108 {
109  int requested_scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
110 
111  if( requested_scale > 0 )
112  return requested_scale;
113  else
114  return KiIconScale( aWindow );
115 }
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:92
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102

References KiIconScale(), and Pgm().

Referenced by KiScaledBitmap().

◆ KiBitmap()

wxBitmap KiBitmap ( BITMAP_DEF  aBitmap)

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

Definition at line 82 of file bitmap.cpp.

83 {
84  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
85  wxImage image( is, wxBITMAP_TYPE_PNG );
86  wxBitmap bitmap( image );
87 
88  return bitmap;
89 }
const unsigned char * png
Definition: bitmap_def.h:31

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

Referenced by ACTION_MENU::Add(), AddBitmapToMenuItem(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), BM2CMP_FRAME::BM2CMP_FRAME(), WX_COLLAPSIBLE_PANE_HEADER::Create(), GRID_CELL_ICON_TEXT_POPUP::Create(), DIALOG_ABOUT::createStaticBitmap(), CVPCB_MAINFRAME::CVPCB_MAINFRAME(), DIALOG_ABOUT::DIALOG_ABOUT(), DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE(), DIALOG_BOM::DIALOG_BOM(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS(), DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE(), DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), DIALOG_EXPORT_SVG::DIALOG_EXPORT_SVG(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR(), DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), DIALOG_GROUP_PROPERTIES::DIALOG_GROUP_PROPERTIES(), DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX(), DIALOG_IMPORT_SETTINGS::DIALOG_IMPORT_SETTINGS(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_MIGRATE_SETTINGS::DIALOG_MIGRATE_SETTINGS(), DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR(), DIALOG_NETLIST::DIALOG_NETLIST(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES(), DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC(), DIALOG_SCH_IMPORT_SETTINGS::DIALOG_SCH_IMPORT_SETTINGS(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES(), DIALOG_UNUSED_PAD_LAYERS::DIALOG_UNUSED_PAD_LAYERS(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), ACTION_MENU::DisplayTitle(), GRID_CELL_ICON_TEXT_RENDERER::Draw(), CONDITIONAL_MENU::Evaluate(), EVT_GRID_CMD_CELL_CHANGED(), EVT_MENU_RANGE(), EVT_TOOL_RANGE(), EVT_UPDATE_UI_RANGE(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), GERBVIEW_FRAME::GERBVIEW_FRAME(), GRID_CELL_ICON_TEXT_RENDERER::GetBestSize(), HIERARCHY_TREE::HIERARCHY_TREE(), DIALOG_EDIT_ONE_FIELD::init(), DIALOG_PLOT::init_Dialog(), DIALOG_3D_VIEW_OPTIONS::initDialog(), DIALOG_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), DIALOG_ANNOTATE::InitValues(), LIB_VIEW_FRAME::LIB_VIEW_FRAME(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), TREE_PROJECT_FRAME::OnRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), SIM_PLOT_FRAME::onSimFinished(), SIM_PLOT_FRAME::onSimStarted(), 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_PREV_3D::PANEL_PREV_3D(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PANEL_SETUP_RULES::PANEL_SETUP_RULES(), PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES(), PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME(), PinShapeComboBox::PinShapeComboBox(), PinTypeComboBox::PinTypeComboBox(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), APPEARANCE_CONTROLS::rebuildLayerContextMenu(), APPEARANCE_CONTROLS::rebuildLayers(), PANEL_SETUP_PINMAP::reBuildMatrixPanel(), APPEARANCE_CONTROLS::rebuildNets(), APPEARANCE_CONTROLS::rebuildObjects(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::SCH_EDIT_FRAME(), PANEL_SETUP_PINMAP::setDRCMatrixButtonState(), SIM_PLOT_FRAME::setIconsForMenuItems(), PANEL_FP_EDITOR_DEFAULTS::Show(), PANEL_SETUP_FEATURE_CONSTRAINTS::Show(), DIALOG_PAD_PROPERTIES::Show(), PANEL_COLOR_SETTINGS::ShowColorContextMenu(), SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU(), SIM_PLOT_FRAME::SIM_PLOT_FRAME(), SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME(), DIALOG_UNUSED_PAD_LAYERS::syncImages(), 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(), BM2CMP_FRAME::ToggleAspectRatioLock(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), and TREEPROJECTFILES::TREEPROJECTFILES().

◆ KiBitmapNew()

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

170 {
171  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
172  wxImage image( is, wxBITMAP_TYPE_PNG );
173  wxBitmap* bitmap = new wxBitmap( image );
174 
175  return bitmap;
176 }
const unsigned char * png
Definition: bitmap_def.h:31

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

Referenced by ABOUT_APP_INFO::CreateKiBitmap().

◆ KiIconScale()

int KiIconScale ( wxWindow *  aWindow)

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

Definition at line 92 of file bitmap.cpp.

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

Referenced by ACTION_TOOLBAR::AddScaledSeparator(), PANEL_COMMON_SETTINGS::applySettingsToPanel(), get_scale_factor(), PANEL_COMMON_SETTINGS::OnIconScaleAuto(), and PCB_EDIT_FRAME::PrepareLayerIndicator().

◆ KiScaledBitmap() [1/2]

wxBitmap KiScaledBitmap ( BITMAP_DEF  aBitmap,
wxWindow *  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 118 of file bitmap.cpp.

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

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

Referenced by ACTION_TOOLBAR::Add(), ACTION_TOOLBAR_PALETTE::AddAction(), ACTION_TOOLBAR::AddButton(), ACTION_TOOLBAR::AddGroup(), ACTION_TOOLBAR::doSelectAction(), PANEL_SETUP_BOARD_STACKUP::PANEL_SETUP_BOARD_STACKUP(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), KICAD_MANAGER_FRAME::RecreateLauncher(), EDA_3D_VIEWER::ReCreateMainToolbar(), and SYMBOL_EDIT_FRAME::ReCreateVToolbar().

◆ KiScaledBitmap() [2/2]

wxBitmap KiScaledBitmap ( const wxBitmap &  aBitmap,
wxWindow *  aWindow 
)

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

Parameters
aBitmapbitmap definition
aWindowtarget window for scaling context

Definition at line 150 of file bitmap.cpp.

151 {
152  const int scale = get_scale_factor( aWindow );
153 
154  if( scale == 4)
155  {
156  return wxBitmap( aBitmap );
157  }
158  else
159  {
160  wxImage image = aBitmap.ConvertToImage();
161  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
162  wxIMAGE_QUALITY_BILINEAR );
163 
164  return wxBitmap( image );
165  }
166 }
static int get_scale_factor(wxWindow *aWindow)
Definition: bitmap.cpp:107
const int scale

References get_scale_factor(), and scale.

◆ SaveCanvasImageToFile()

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

181 {
182  wxCHECK( aFrame != nullptr, false );
183 
184  bool retv = true;
185 
186  // Make a screen copy of the canvas:
187  wxSize image_size = aFrame->GetCanvas()->GetClientSize();
188 
189  wxClientDC dc( aFrame->GetCanvas() );
190  wxBitmap bitmap( image_size.x, image_size.y );
191  wxMemoryDC memdc;
192 
193  memdc.SelectObject( bitmap );
194  memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
195  memdc.SelectObject( wxNullBitmap );
196 
197  wxImage image = bitmap.ConvertToImage();
198 
199  if( !image.SaveFile( aFileName, aBitmapType ) )
200  retv = false;
201 
202  image.Destroy();
203  return retv;
204 }
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.

References EDA_DRAW_FRAME::GetCanvas().

Referenced by LIB_CONTROL::ExportView(), and FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng().