29#include <wx/mstream.h>
31#include <wx/menuitem.h>
32#include <wx/aui/auibar.h>
33#include <wx/dcclient.h>
34#include <wx/dcmemory.h>
38#include <unordered_map>
60 return bitmap == other.bitmap &&
scale == other.scale;
73 static const bool sz64 =
sizeof( uintptr_t ) == 8;
74 static const size_t mask = sz64 ? 0xF000000000000000uLL : 0xF0000000uL;
75 static const size_t offset = sz64 ? 60 : 28;
82 ( (uintptr_t)(
id.bitmap ) & ~mask ) |
83 ( ( (uintptr_t)(
id.
scale ) & 0xF ) << offset );
115 wxMemoryInputStream is( aBitmap->
png, aBitmap->
byteCount );
116 wxImage
image( is, wxBITMAP_TYPE_PNG );
117 wxBitmap bitmap(
image );
125 #if defined( __WXMSW__)
132 const int vert_size = aWindow->ConvertDialogToPixels( wxSize( 0, 8 ) ).y;
138 if( vert_size > 34 )
return 8;
139 else if( vert_size > 29 )
return 7;
140 else if( vert_size > 24 )
return 6;
148 int requested_scale =
Pgm().GetCommonSettings()->m_Appearance.icon_scale;
150 if( requested_scale > 0 )
151 return requested_scale;
195 return wxBitmap( aBitmap );
199 wxImage
image = aBitmap.ConvertToImage();
201 wxIMAGE_QUALITY_BILINEAR );
203 return wxBitmap(
image );
210 wxBitmap* bitmap =
new wxBitmap(
GetBitmapStore()->GetBitmap( aBitmap ) );
219 wxCHECK( aFrame !=
nullptr,
false );
224 wxSize image_size = aFrame->
GetCanvas()->GetClientSize();
227 wxBitmap bitmap( image_size.x, image_size.y );
230 memdc.SelectObject( bitmap );
231 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
232 memdc.SelectObject( wxNullBitmap );
234 wxImage
image = bitmap.ConvertToImage();
236 wxBitmapType type = wxBITMAP_TYPE_PNG;
237 switch( aBitmapType )
244 if( !
image.SaveFile( aFileName, type ) )
255 bool useImagesInMenus =
Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
257 wxItemKind menu_type = aMenu->GetKind();
259 if( useImagesInMenus && menu_type != wxITEM_CHECK && menu_type != wxITEM_RADIO )
261 aMenu->SetBitmap( aImage );
266wxMenuItem*
AddMenuItem( wxMenu* aMenu,
int aId,
const wxString& aText,
267 const wxBitmap& aImage, wxItemKind aType = wxITEM_NORMAL )
269 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
272 aMenu->Append( item );
278wxMenuItem*
AddMenuItem( wxMenu* aMenu,
int aId,
const wxString& aText,
279 const wxString& aHelpText,
const wxBitmap& aImage,
280 wxItemKind aType = wxITEM_NORMAL )
282 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
285 aMenu->Append( item );
292 const wxString& aText,
const wxBitmap& aImage )
294 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText );
295 item->SetSubMenu( aSubMenu );
298 aMenu->Append( item );
305 const wxString& aText,
const wxString& aHelpText,
306 const wxBitmap& aImage )
308 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText, aHelpText );
309 item->SetSubMenu( aSubMenu );
312 aMenu->Append( item );
wxBitmap * KiBitmapNew(BITMAPS aBitmap)
Allocate a wxBitmap on heap from a memory record, held in a BITMAPS.
static std::unique_ptr< BITMAP_STORE > s_BitmapStore
void ClearScaledBitmapCache()
Wipes out the scaled bitmap cache so that the icon theme can be changed.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
static std::mutex s_BitmapCacheMutex
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
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.
BITMAP_STORE * GetBitmapStore()
static std::unordered_map< SCALED_BITMAP_ID, wxBitmap > s_ScaledBitmapCache
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
static int get_scale_factor(wxWindow *aWindow)
bool SaveCanvasImageToFile(EDA_DRAW_FRAME *aFrame, const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
BITMAPS
A list of all bitmap identifiers.
Helper to retrieve bitmaps while handling icon themes and scaling.
wxBitmap GetBitmap(BITMAPS aBitmapId, int aHeight=-1)
Retrieves a bitmap from the given bitmap id.
wxBitmap GetBitmapScaled(BITMAPS aBitmapId, int aScaleFactor, int aHeight=-1)
Retrieves a bitmap from the given bitmap id, scaled to a given factor.
The base class for create windows for drawing purpose.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Base window classes and related definitions.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
PNG memory record (file in memory).
const unsigned char * png
bool operator==(SCALED_BITMAP_ID const &other) const noexcept
SCALED_BITMAP_ID argument_type
result_type operator()(argument_type const &id) const noexcept
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".