KiCad PCB EDA Suite
bitmap_types.h File Reference
#include <config.h>

Go to the source code of this file.

Classes

struct  BITMAP_OPAQUE
 PNG memory record (file in memory). More...
 

Macros

#define EXTERN_BITMAP(x)   extern const BITMAP_OPAQUE x[1];
 

Typedefs

typedef const BITMAP_OPAQUEBITMAP_DEF
 a BITMAP_DEF is really a const pointer to an opaque structure. More...
 

Functions

wxBitmap KiBitmap (BITMAP_DEF aBitmap)
 Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF. More...
 
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...
 
int KiIconScale (wxWindow *aWindow)
 Function KiIconScale Returns the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScaledSeparator. More...
 
wxBitmap * KiBitmapNew (BITMAP_DEF aBitmap)
 Function KiBitmapNew allocates a wxBitmap on heap from a memory record, held in a BITMAP_DEF. More...
 

Macro Definition Documentation

#define EXTERN_BITMAP (   x)    extern const BITMAP_OPAQUE x[1];

Definition at line 49 of file bitmap_types.h.

Typedef Documentation

typedef const BITMAP_OPAQUE* BITMAP_DEF

a BITMAP_DEF is really a const pointer to an opaque structure.

So you should never need to use 'const' with it.

Definition at line 54 of file bitmap_types.h.

Function Documentation

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 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_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_VIEW_FRAME::LIB_VIEW_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(), 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(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), 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(), 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(), 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_FP_CHOOSER::TEXT_BUTTON_FP_CHOOSER(), TEXT_BUTTON_URL::TEXT_BUTTON_URL(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), 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 165 of file bitmap.cpp.

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

Referenced by ABOUT_APP_INFO::CreateKiBitmap().

166 {
167  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
168  wxImage image( is, wxBITMAP_TYPE_PNG );
169  wxBitmap* bitmap = new wxBitmap( image );
170 
171  return bitmap;
172 }
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(), PANEL_COMMON_SETTINGS::OnScaleAuto(), PCB_EDIT_FRAME::PrepareLayerIndicator(), and PANEL_COMMON_SETTINGS::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 115 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(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::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().

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

Function KiScaledSeparator Adds a separator to the given toolbar scaled the same way as KiScaledBitmap.

Definition at line 147 of file bitmap.cpp.

References get_scale_factor(), and SCALED_BITMAP_ID::scale.

Referenced by FOOTPRINT_EDIT_FRAME::ReCreateAuxiliaryToolbar(), GERBVIEW_FRAME::ReCreateAuxiliaryToolbar(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::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().

148 {
149  const int scale = get_scale_factor( aWindow );
150 
151  if( scale > 4 )
152  {
153  aToolbar->AddSpacer( 16 * ( scale - 4 ) / 4 );
154  }
155 
156  aToolbar->AddSeparator();
157 
158  if( scale > 4 )
159  {
160  aToolbar->AddSpacer( 16 * ( scale - 4 ) / 4 );
161  }
162 }
const int scale
static int get_scale_factor(EDA_BASE_FRAME *aWindow)
Definition: bitmap.cpp:103