KiCad PCB EDA Suite
bitmap_types.h File Reference
#include <wx/gdicmn.h>

Go to the source code of this file.

Functions

enum BITMAPS unsigned int BITMAP_STOREGetBitmapStore ()
 
wxBitmap KiBitmap (BITMAPS aBitmap)
 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...
 
void ClearScaledBitmapCache ()
 Wipes out the scaled bitmap cache so that the icon theme can be changed. More...
 
wxBitmap KiScaledBitmap (BITMAPS aBitmap, wxWindow *aWindow, int aHeight=-1)
 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...
 
int KiIconScale (wxWindow *aWindow)
 Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScaledSeparator. 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, wxBitmapType aBitmapType=wxBITMAP_TYPE_PNG)
 Save the current view as an image file. More...
 

Function Documentation

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

170 {
171  std::lock_guard<std::mutex> guard( s_BitmapCacheMutex );
172  s_ScaledBitmapCache.clear();
173 }
static std::unordered_map< SCALED_BITMAP_ID, wxBitmap > s_ScaledBitmapCache
Definition: bitmap.cpp:87
static std::mutex s_BitmapCacheMutex
Definition: bitmap.cpp:89

References s_BitmapCacheMutex, and s_ScaledBitmapCache.

Referenced by EDA_BASE_FRAME::ThemeChanged().

◆ GetBitmapStore()

enum BITMAPS unsigned int BITMAP_STORE* GetBitmapStore ( )
strong

Definition at line 92 of file bitmap.cpp.

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

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

Referenced by EDA_BASE_FRAME::CommonSettingsChanged(), EDA_BASE_FRAME::HandleSystemColorChange(), KiBitmap(), KiBitmapNew(), KiScaledBitmap(), and ACTION_PLUGINS::register_action().

◆ KiBitmap() [1/2]

wxBitmap KiBitmap ( BITMAPS  aBitmap)

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

Definition at line 104 of file bitmap.cpp.

105 {
106  return GetBitmapStore()->GetBitmap( aBitmap );
107 }
wxBitmap GetBitmap(BITMAPS aBitmapId, int aHeight=-1)
Retreives a bitmap from the given bitmap id.
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:92

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(), 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_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), 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_LOCKED_ITEMS_QUERY::DIALOG_LOCKED_ITEMS_QUERY(), 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_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), DIALOG_ANNOTATE::InitValues(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), PROJECT_TREE_PANE::onRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), SIM_PLOT_FRAME::onSimFinished(), SIM_PLOT_FRAME::onSimStarted(), PCB_CALCULATOR_FRAME::OnUpdateUI(), 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(), PROJECT_TREE::PROJECT_TREE(), 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_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(), SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_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(), TRANSLINE_IDENT::TRANSLINE_IDENT(), and PCB_CALCULATOR_FRAME::TranslineTypeSelection().

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

112 {
113  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
114  wxImage image( is, wxBITMAP_TYPE_PNG );
115  wxBitmap bitmap( image );
116 
117  return bitmap;
118 }
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 195 of file bitmap.cpp.

196 {
197  wxBitmap* bitmap = new wxBitmap( GetBitmapStore()->GetBitmap( aBitmap ) );
198 
199  return bitmap;
200 }
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:92

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

122 {
123  const int vert_size = aWindow->ConvertDialogToPixels( wxSize( 0, 8 ) ).y;
124 
125  // Autoscale won't exceed unity until the system has quite high resolution,
126  // because we don't want the icons to look obviously scaled on a system
127  // where it's easy to see it.
128 
129  if( vert_size > 34 ) return 8;
130  else if( vert_size > 29 ) return 7;
131  else if( vert_size > 24 ) return 6;
132  else return 4;
133 }

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 ( BITMAPS  aBitmap,
wxWindow *  aWindow,
int  aHeight = -1 
)

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

Definition at line 147 of file bitmap.cpp.

148 {
149  // Bitmap conversions are cached because they can be slow.
150  const int scale = get_scale_factor( aWindow );
151 
152  SCALED_BITMAP_ID id = { static_cast<BITMAPS>( aBitmap ), scale };
153 
154  std::lock_guard<std::mutex> guard( s_BitmapCacheMutex );
155  auto it = s_ScaledBitmapCache.find( id );
156 
157  if( it != s_ScaledBitmapCache.end() )
158  {
159  return it->second;
160  }
161  else
162  {
163  wxBitmap bitmap = GetBitmapStore()->GetBitmapScaled( aBitmap, scale, aHeight );
164  return s_ScaledBitmapCache.emplace( id, bitmap ).first->second;
165  }
166 }
wxBitmap GetBitmapScaled(BITMAPS aBitmapId, int aScaleFactor, int aHeight=-1)
Retrieves a bitmap from the given bitmap id, scaled to a given factor.
static std::unordered_map< SCALED_BITMAP_ID, wxBitmap > s_ScaledBitmapCache
Definition: bitmap.cpp:87
static int get_scale_factor(wxWindow *aWindow)
Definition: bitmap.cpp:136
const int scale
static std::mutex s_BitmapCacheMutex
Definition: bitmap.cpp:89
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:92

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

Referenced by ACTION_TOOLBAR::Add(), ACTION_TOOLBAR_PALETTE::AddAction(), 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(), SYMBOL_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER::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 176 of file bitmap.cpp.

177 {
178  const int scale = get_scale_factor( aWindow );
179 
180  if( scale == 4 )
181  {
182  return wxBitmap( aBitmap );
183  }
184  else
185  {
186  wxImage image = aBitmap.ConvertToImage();
187  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
188  wxIMAGE_QUALITY_BILINEAR );
189 
190  return wxBitmap( image );
191  }
192 }
static int get_scale_factor(wxWindow *aWindow)
Definition: bitmap.cpp:136
const int scale

References get_scale_factor(), image, 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 203 of file bitmap.cpp.

205 {
206  wxCHECK( aFrame != nullptr, false );
207 
208  bool retv = true;
209 
210  // Make a screen copy of the canvas:
211  wxSize image_size = aFrame->GetCanvas()->GetClientSize();
212 
213  wxClientDC dc( aFrame->GetCanvas() );
214  wxBitmap bitmap( image_size.x, image_size.y );
215  wxMemoryDC memdc;
216 
217  memdc.SelectObject( bitmap );
218  memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
219  memdc.SelectObject( wxNullBitmap );
220 
221  wxImage image = bitmap.ConvertToImage();
222 
223  if( !image.SaveFile( aFileName, aBitmapType ) )
224  retv = false;
225 
226  image.Destroy();
227  return retv;
228 }
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.

References EDA_DRAW_FRAME::GetCanvas(), and image.

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