KiCad PCB EDA Suite
bitmap.cpp File Reference
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/gdicmn.h>
#include <wx/mstream.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
#include <wx/aui/auibar.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <cstdint>
#include <mutex>
#include <unordered_map>
#include <asset_archive.h>
#include <bitmaps.h>
#include <bitmap_store.h>
#include <bitmaps/bitmap_opaque.h>
#include <pgm_base.h>
#include <eda_base_frame.h>
#include <eda_draw_frame.h>
#include <paths.h>
#include <kiplatform/ui.h>

Go to the source code of this file.

Classes

struct  SCALED_BITMAP_ID
 
struct  std::hash< SCALED_BITMAP_ID >
 

Namespaces

namespace  std
 

Functions

BITMAP_STOREGetBitmapStore ()
 
wxBitmap KiBitmap (BITMAPS aBitmap, int aHeightTag)
 Construct a wxBitmap from an image identifier Returns the image from the active theme if the image has multiple theme variants. More...
 
wxBitmap KiBitmap (const BITMAP_OPAQUE *aBitmap)
 Compatibility shim for pcb_calculator until its images are pulled into the PNG pipeline. 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 (BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
 Construct a wxBitmap from a memory record, scaling it if device DPI demands it. More...
 
void ClearScaledBitmapCache ()
 Wipes out the scaled bitmap cache so that the icon theme can be changed. More...
 
wxBitmap KiScaledBitmap (const wxBitmap &aBitmap, wxWindow *aWindow)
 Overload of the above function that takes another wxBitmap as a parameter. More...
 
wxBitmap * KiBitmapNew (BITMAPS aBitmap)
 Allocate a wxBitmap on heap from a memory record, held in a BITMAPS. More...
 
bool SaveCanvasImageToFile (EDA_DRAW_FRAME *aFrame, const wxString &aFileName, BITMAP_TYPE 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)
 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)
 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)
 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)
 Create and insert a menu item with an icon and a help message string into aSubMenu in aMenu. More...
 

Variables

static std::unique_ptr< BITMAP_STOREs_BitmapStore
 
static std::unordered_map< SCALED_BITMAP_ID, wxBitmap > s_ScaledBitmapCache
 
static std::mutex s_BitmapCacheMutex
 

Function Documentation

◆ AddBitmapToMenuItem()

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

Add a bitmap to a menuitem.

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

Parameters
aMenuis the menuitem.
aImageis the icon to add to aMenu.

Definition at line 252 of file bitmap.cpp.

253{
254 // Retrieve the global application show icon option:
255 bool useImagesInMenus = Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
256
257 wxItemKind menu_type = aMenu->GetKind();
258
259 if( useImagesInMenus && menu_type != wxITEM_CHECK && menu_type != wxITEM_RADIO )
260 {
261 aMenu->SetBitmap( aImage );
262 }
263}
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References Pgm().

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

◆ AddMenuItem() [1/4]

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

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

268{
269 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
270 AddBitmapToMenuItem( item, aImage );
271
272 aMenu->Append( item );
273
274 return item;
275}
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:252

References AddBitmapToMenuItem().

Referenced by GERBER_LAYER_WIDGET::AddRightClickMenuItems(), PCB_EDIT_FRAME::buildActionPluginMenus(), PROJECT_TREE_PANE::onRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), APPEARANCE_CONTROLS::rebuildLayerContextMenu(), and PANEL_COLOR_SETTINGS::ShowColorContextMenu().

◆ AddMenuItem() [2/4]

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

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

281{
282 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
283 AddBitmapToMenuItem( item, aImage );
284
285 aMenu->Append( item );
286
287 return item;
288}

References AddBitmapToMenuItem().

◆ AddMenuItem() [3/4]

wxMenuItem * AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage 
)

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

293{
294 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText );
295 item->SetSubMenu( aSubMenu );
296 AddBitmapToMenuItem( item, aImage );
297
298 aMenu->Append( item );
299
300 return item;
301}

References AddBitmapToMenuItem().

◆ AddMenuItem() [4/4]

wxMenuItem * AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage 
)

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

307{
308 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText );
309 item->SetSubMenu( aSubMenu );
310 AddBitmapToMenuItem( item, aImage );
311
312 aMenu->Append( item );
313
314 return item;
315}

References AddBitmapToMenuItem().

◆ ClearScaledBitmapCache()

void ClearScaledBitmapCache ( )

Wipes out the scaled bitmap cache so that the icon theme can be changed.

TODO: move scaling system into BITMAP_STORE so this global doesn't need to exist

Definition at line 182 of file bitmap.cpp.

183{
184 std::lock_guard<std::mutex> guard( s_BitmapCacheMutex );
185 s_ScaledBitmapCache.clear();
186}
static std::mutex s_BitmapCacheMutex
Definition: bitmap.cpp:91
static std::unordered_map< SCALED_BITMAP_ID, wxBitmap > s_ScaledBitmapCache
Definition: bitmap.cpp:89

References s_BitmapCacheMutex, and s_ScaledBitmapCache.

Referenced by EDA_BASE_FRAME::ThemeChanged().

◆ get_scale_factor()

static int get_scale_factor ( wxWindow *  aWindow)
static

Definition at line 146 of file bitmap.cpp.

147{
148 int requested_scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
149
150 if( requested_scale > 0 )
151 return requested_scale;
152 else
153 return KiIconScale( aWindow );
154}
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:123

References KiIconScale(), and Pgm().

Referenced by KiScaledBitmap().

◆ GetBitmapStore()

BITMAP_STORE * GetBitmapStore ( )

Definition at line 94 of file bitmap.cpp.

95{
96 if( !s_BitmapStore )
97 {
98 wxFileName path( PATHS::GetStockDataPath() + wxT( "/resources" ), wxT( "images.zip" ) );
99 s_BitmapStore = std::make_unique<BITMAP_STORE>();
100 }
101
102 return s_BitmapStore.get();
103}
static std::unique_ptr< BITMAP_STORE > s_BitmapStore
Definition: bitmap.cpp:51
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:150

References PATHS::GetStockDataPath(), path, and s_BitmapStore.

Referenced by EDA_BASE_FRAME::CommonSettingsChanged(), EDA_BASE_FRAME::HandleSystemColorChange(), KiBitmap(), KiBitmapNew(), KiScaledBitmap(), ACTION_TOOLBAR::onThemeChanged(), PANEL_KICAD_LAUNCHER::onThemeChanged(), PROJECT_TREE_PANE::onThemeChanged(), PCB_CALCULATOR_FRAME::onThemeChanged(), and ACTION_PLUGINS::register_action().

◆ KiBitmap() [1/2]

wxBitmap KiBitmap ( BITMAPS  aBitmap,
int  aHeightTag = -1 
)

Construct a wxBitmap from an image identifier Returns the image from the active theme if the image has multiple theme variants.

Parameters
aBitmapis from the BITMAPS enum in bitmaps_list.h
aHeightTagis the requested height tag for multi-res bitmaps (-1 for any)

Definition at line 106 of file bitmap.cpp.

107{
108 return GetBitmapStore()->GetBitmap( aBitmap, aHeightTag );
109}
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:94
wxBitmap GetBitmap(BITMAPS aBitmapId, int aHeight=-1)
Retrieves a bitmap from the given bitmap id.

References BITMAP_STORE::GetBitmap(), and GetBitmapStore().

Referenced by ACTION_MENU::Add(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), BM2CMP_FRAME::BM2CMP_FRAME(), PCB_EDIT_FRAME::buildActionPluginMenus(), 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_DIMENSION_PROPERTIES::DIALOG_DIMENSION_PROPERTIES(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), DIALOG_EXPORT_SVG::DIALOG_EXPORT_SVG(), DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES(), DIALOG_GROUP_PROPERTIES::DIALOG_GROUP_PROPERTIES(), DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX(), DIALOG_IMPORT_NETLIST::DIALOG_IMPORT_NETLIST(), DIALOG_IMPORT_SETTINGS::DIALOG_IMPORT_SETTINGS(), DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SHAPE_PROPERTIES::DIALOG_LIB_SHAPE_PROPERTIES(), DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_LIB_TEXT_PROPERTIES::DIALOG_LIB_TEXT_PROPERTIES(), DIALOG_LIB_TEXTBOX_PROPERTIES::DIALOG_LIB_TEXTBOX_PROPERTIES(), DIALOG_LINE_PROPERTIES::DIALOG_LINE_PROPERTIES(), DIALOG_LOCKED_ITEMS_QUERY::DIALOG_LOCKED_ITEMS_QUERY(), DIALOG_MANAGE_REPOSITORIES::DIALOG_MANAGE_REPOSITORIES(), DIALOG_MIGRATE_SETTINGS::DIALOG_MIGRATE_SETTINGS(), DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS(), DIALOG_PCM::DIALOG_PCM(), DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES(), DIALOG_PLOT::DIALOG_PLOT(), DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC(), DIALOG_SCH_IMPORT_SETTINGS::DIALOG_SCH_IMPORT_SETTINGS(), DIALOG_SHAPE_PROPERTIES::DIALOG_SHAPE_PROPERTIES(), DIALOG_SHEET_PIN_PROPERTIES::DIALOG_SHEET_PIN_PROPERTIES(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), DIALOG_SIM_MODEL< T_symbol, T_field >::DIALOG_SIM_MODEL(), DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES(), DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES(), DIALOG_UNUSED_PAD_LAYERS::DIALOG_UNUSED_PAD_LAYERS(), DIALOG_USER_DEFINED_SIGNALS::DIALOG_USER_DEFINED_SIGNALS(), DIALOG_WIRE_BUS_PROPERTIES::DIALOG_WIRE_BUS_PROPERTIES(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), ACTION_MENU::DisplayTitle(), BM2CMP_FRAME::doReCreateMenuBar(), GRID_CELL_ICON_TEXT_RENDERER::Draw(), EDA_REORDERABLE_LIST_DIALOG::EDA_REORDERABLE_LIST_DIALOG(), CONDITIONAL_MENU::Evaluate(), EVT_GRID_CMD_CELL_CHANGED(), EVT_MENU_RANGE(), EVT_TOOL_RANGE(), EVT_UPDATE_UI_RANGE(), NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages(), NL_SCHEMATIC_PLUGIN_IMPL::exportCommandsAndImages(), NL_PCBNEW_PLUGIN_IMPL::exportCommandsAndImages(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), GERBVIEW_FRAME::GERBVIEW_FRAME(), GRID_CELL_ICON_TEXT_RENDERER::GetBestSize(), HIERARCHY_PANE::HIERARCHY_PANE(), DIALOG_FIELD_PROPERTIES::init(), DIALOG_PLOT::init_Dialog(), DIALOG_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), DIALOG_ANNOTATE::InitValues(), PANEL_EESCHEMA_ANNOTATION_OPTIONS::loadEEschemaSettings(), PROJECT_TREE::LoadIcons(), PROJECT_TREE_PANE::onRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(), PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS(), PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), PANEL_REGULATOR::PANEL_REGULATOR(), PANEL_RF_ATTENUATORS::PANEL_RF_ATTENUATORS(), PANEL_SETUP_BUSES::PANEL_SETUP_BUSES(), 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_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES(), PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES(), PANEL_TRANSLINE::PANEL_TRANSLINE(), PANEL_VIA_SIZE::PANEL_VIA_SIZE(), PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME(), PinShapeComboBox::PinShapeComboBox(), PinTypeComboBox::PinTypeComboBox(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), PROPERTIES_FRAME::PROPERTIES_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(), DIALOG_PAD_PROPERTIES::Show(), PANEL_FP_EDITOR_DEFAULTS::Show(), PANEL_SETUP_CONSTRAINTS::Show(), PANEL_COLOR_SETTINGS::ShowColorContextMenu(), SIMULATOR_FRAME::SIMULATOR_FRAME(), SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME(), SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME(), TEARDROP_DIALOG::TEARDROP_DIALOG(), 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(), PANEL_COLOR_CODE::ThemeChanged(), PANEL_REGULATOR::ThemeChanged(), PANEL_RF_ATTENUATORS::ThemeChanged(), PANEL_TRANSLINE::ThemeChanged(), PANEL_VIA_SIZE::ThemeChanged(), PANEL_COLOR_CODE::ToleranceSelection(), PANEL_RF_ATTENUATORS::TransfAttenuatorDataToPanel(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), PANEL_TRANSLINE::TranslineTypeSelection(), TUNER_SLIDER::TUNER_SLIDER(), DIALOG_UNUSED_PAD_LAYERS::updateImage(), and PANEL_RF_ATTENUATORS::UpdateUI().

◆ KiBitmap() [2/2]

wxBitmap KiBitmap ( const BITMAP_OPAQUE aBitmap)

Compatibility shim for pcb_calculator until its images are pulled into the PNG pipeline.

Definition at line 113 of file bitmap.cpp.

114{
115 wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
116 wxImage image( is, wxBITMAP_TYPE_PNG );
117 wxBitmap bitmap( image );
118
119 return bitmap;
120}
const unsigned char * png
Definition: bitmap_opaque.h:27

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

◆ KiBitmapNew()

wxBitmap * KiBitmapNew ( BITMAPS  aBitmap)

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

Parameters
aBitmapis from the BITMAPS enum in bitmaps_list.h
Returns
wxBitmap* - caller owns it.

Definition at line 208 of file bitmap.cpp.

209{
210 wxBitmap* bitmap = new wxBitmap( GetBitmapStore()->GetBitmap( aBitmap ) );
211
212 return bitmap;
213}

References GetBitmapStore().

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

124{
125 #if defined( __WXMSW__) && wxCHECK_VERSION( 3, 1, 6 )
126 // Basically don't try and scale within kicad and let wx do its thing
127 // with wx introducing bitmap bundles, it will auto scale automatically with dpi
128 // the issue is, none of the scaling factors have any tie to system scaling
129 // this means wx is actually going to scale again causing even more distorted icons
130 return 4;
131 #else
132 const int vert_size = aWindow->ConvertDialogToPixels( wxSize( 0, 8 ) ).y;
133
134 // Autoscale won't exceed unity until the system has quite high resolution,
135 // because we don't want the icons to look obviously scaled on a system
136 // where it's easy to see it.
137
138 if( vert_size > 34 ) return 8;
139 else if( vert_size > 29 ) return 7;
140 else if( vert_size > 24 ) return 6;
141 else return 4;
142 #endif
143}

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

◆ KiScaledBitmap() [1/2]

wxBitmap KiScaledBitmap ( BITMAPS  aBitmap,
wxWindow *  aWindow,
int  aHeight = -1,
bool  aQuantized = false 
)

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
aBitmapis from the BITMAPS enum in bitmaps_list.h
aWindowtarget window for scaling context
aHeightis the requested image height for the source bitmap, or -1 for any height
aQuantizedif true scaling will be rounded to integers (2X, 3X, etc.).

Definition at line 157 of file bitmap.cpp.

158{
159 // Bitmap conversions are cached because they can be slow.
160 int scale = get_scale_factor( aWindow );
161
162 if( aQuantized )
163 scale = KiROUND( (double) scale / 4.0 ) * 4;
164
165 SCALED_BITMAP_ID id = { static_cast<BITMAPS>( aBitmap ), scale };
166
167 std::lock_guard<std::mutex> guard( s_BitmapCacheMutex );
168 auto it = s_ScaledBitmapCache.find( id );
169
170 if( it != s_ScaledBitmapCache.end() )
171 {
172 return it->second;
173 }
174 else
175 {
176 wxBitmap bitmap = GetBitmapStore()->GetBitmapScaled( aBitmap, scale, aHeight );
177 return s_ScaledBitmapCache.emplace( id, bitmap ).first->second;
178 }
179}
static int get_scale_factor(wxWindow *aWindow)
Definition: bitmap.cpp:146
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
wxBitmap GetBitmapScaled(BITMAPS aBitmapId, int aScaleFactor, int aHeight=-1)
Retrieves a bitmap from the given bitmap id, scaled to a given factor.
const int scale
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References get_scale_factor(), BITMAP_STORE::GetBitmapScaled(), GetBitmapStore(), KiROUND(), s_BitmapCacheMutex, s_ScaledBitmapCache, and scale.

Referenced by ACTION_TOOLBAR::Add(), ACTION_TOOLBAR_PALETTE::AddAction(), PCB_EDIT_FRAME::AddActionPluginTools(), ACTION_TOOLBAR::AddButton(), ACTION_TOOLBAR::AddGroup(), PANEL_KICAD_LAUNCHER::CreateLaunchers(), ACTION_TOOLBAR::doSelectAction(), PANEL_SETUP_BOARD_STACKUP::PANEL_SETUP_BOARD_STACKUP(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), SYMBOL_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER_FRAME::ReCreateMainToolbar(), and ACTION_TOOLBAR::RefreshBitmaps().

◆ KiScaledBitmap() [2/2]

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

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

Parameters
aBitmapis the source bitmap to scale
aWindowtarget window for scaling context

Definition at line 189 of file bitmap.cpp.

190{
191 const int scale = get_scale_factor( aWindow );
192
193 if( scale == 4 )
194 {
195 return wxBitmap( aBitmap );
196 }
197 else
198 {
199 wxImage image = aBitmap.ConvertToImage();
200 image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
201 wxIMAGE_QUALITY_BILINEAR );
202
203 return wxBitmap( image );
204 }
205}

References get_scale_factor(), image, and scale.

◆ SaveCanvasImageToFile()

bool SaveCanvasImageToFile ( EDA_DRAW_FRAME aFrame,
const wxString &  aFileName,
BITMAP_TYPE  aBitmapType = BITMAP_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 existing 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 216 of file bitmap.cpp.

218{
219 wxCHECK( aFrame != nullptr, false );
220
221 bool retv = true;
222
223 // Make a screen copy of the canvas:
224 wxSize image_size = aFrame->GetCanvas()->GetClientSize();
225
226 wxClientDC dc( aFrame->GetCanvas() );
227 wxBitmap bitmap( image_size.x, image_size.y );
228 wxMemoryDC memdc;
229
230 memdc.SelectObject( bitmap );
231 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
232 memdc.SelectObject( wxNullBitmap );
233
234 wxImage image = bitmap.ConvertToImage();
235
236 wxBitmapType type = wxBITMAP_TYPE_PNG;
237 switch( aBitmapType )
238 {
239 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
240 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
241 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
242 }
243
244 if( !image.SaveFile( aFileName, type ) )
245 retv = false;
246
247 image.Destroy();
248 return retv;
249}
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.

References BMP, EDA_DRAW_FRAME::GetCanvas(), image, JPG, and PNG.

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

Variable Documentation

◆ s_BitmapCacheMutex

std::mutex s_BitmapCacheMutex
static

Definition at line 91 of file bitmap.cpp.

Referenced by ClearScaledBitmapCache(), and KiScaledBitmap().

◆ s_BitmapStore

std::unique_ptr<BITMAP_STORE> s_BitmapStore
static

Definition at line 51 of file bitmap.cpp.

Referenced by GetBitmapStore().

◆ s_ScaledBitmapCache

std::unordered_map<SCALED_BITMAP_ID, wxBitmap> s_ScaledBitmapCache
static

Definition at line 89 of file bitmap.cpp.

Referenced by ClearScaledBitmapCache(), and KiScaledBitmap().