kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #28009
[Request for Tests] Experimental icon options in Kicad
I recently had a look at the feasibility of enabling/disabling icons in menus and changing icons
size, depending on the monitor size in pixels.
I cannot fully test myself the result of large pixels (looks bad on my monitor), but is is intended
to be used only for HDPI monitors.
This is only a feasibility test.
Currently, it allows (from kicad manager only, preferences menu) to enable/disable icons in menus
and set icons sizes, for the full Kicad applications.
After changing an option, you have to quit and restart Kicad, to take in account the icon settings.
I need to know:
* If the look of large icons is good with HDPI monitors (standards icons are just scaled)
* If it is useful with monitors having only a vertical size of 800 pixels (choose "small icons")
* If HDPI monitors are correctly detected (the Kicad/preferences/Icons Options shows in HDPI
SysScale menu the scaling factor returned by wxWidgets for the monitor in use to display the Kicad
manger.
* If it makes sense to have an option to enable/disable icons in menus at run time, especially for
OSX users.
Attached the patch to test this experimental feature.
Thanks.
--
Jean-Pierre CHARRAS
common/bitmap.cpp | 147 +++++++++++++++++++++++++++++++++++++++++++++++-
common/pgm_base.cpp | 67 ++++++++++++++++++++++
include/id.h | 10 ++++
include/menus_helpers.h | 115 ++++---------------------------------
include/pgm_base.h | 23 ++++++++
kicad/kicad.h | 7 +++
kicad/mainframe.cpp | 47 ++++++++++++++++
kicad/menubar.cpp | 7 +++
8 files changed, 315 insertions(+), 108 deletions(-)
diff --git a/common/bitmap.cpp b/common/bitmap.cpp
index 25cb8ad..de50842 100644
--- a/common/bitmap.cpp
+++ b/common/bitmap.cpp
@@ -26,20 +26,161 @@
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/mstream.h>
+#include <wx/menu.h>
+#include <wx/menuitem.h>
+#include <common.h>
#include <bitmaps.h>
-
+#include <pgm_base.h>
wxBitmap KiBitmap( BITMAP_DEF aBitmap )
{
wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
+ wxImage image( is, wxBITMAP_TYPE_PNG );
+
+ // Retrieve the global applicaton icon scale factor:
+ double iconsScale = Pgm().GetIconsScale();
+
+ if( iconsScale < 0 ) // Means use HDPI sys setting
+ iconsScale = -iconsScale;
- return wxBitmap( wxImage( is, wxBITMAP_TYPE_PNG, -1 ), -1 );
+ if( iconsScale != 1.0 )
+ {
+ int w = KiROUND( image.GetWidth() * iconsScale );
+ int h = KiROUND( image.GetHeight() * iconsScale );
+ // image.Rescale( w, h, wxIMAGE_QUALITY_HIGH );
+ image.Rescale( w, h );
+ }
+
+ wxBitmap bitmap( image );
+
+ return bitmap;
}
+
wxBitmap* KiBitmapNew( BITMAP_DEF aBitmap )
{
wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
+ wxImage image( is, wxBITMAP_TYPE_PNG );
- return new wxBitmap( wxImage( is, wxBITMAP_TYPE_PNG, -1 ), -1 );
+ // Retrieve the global applicaton icon scale factor:
+ double iconsScale = Pgm().GetIconsScale();
+
+ if( iconsScale < 0 ) // Means use HDPI sys setting
+ iconsScale = -iconsScale;
+
+ if( iconsScale != 1.0 )
+ {
+ int w = KiROUND( image.GetWidth() * iconsScale );
+ int h = KiROUND( image.GetHeight() * iconsScale );
+ // image.Rescale( w, h, wxIMAGE_QUALITY_HIGH );
+ image.Rescale( w, h );
+ }
+
+ wxBitmap* bitmap = new wxBitmap( image );
+
+ return bitmap;
}
+
+wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
+ const wxBitmap& aImage, wxItemKind aType = wxITEM_NORMAL )
+{
+ wxMenuItem* item;
+
+ item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
+
+ // Retrieve the global applicaton show icon option:
+ bool useImagesInMenus = Pgm().GetUseIconsInMenus();
+
+ if( useImagesInMenus )
+ {
+ if( aType == wxITEM_CHECK )
+ {
+ #if defined( __WINDOWS__ )
+ item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
+ // A workaround to a strange bug on Windows, wx Widgets 3.0:
+ // size of bitmaps is not taken in account for wxITEM_CHECK menu
+ // unless we call SetFont
+ item->SetFont(*wxNORMAL_FONT);
+ #endif
+ }
+ else
+ item->SetBitmap( aImage );
+ }
+
+ aMenu->Append( item );
+
+ return item;
+}
+
+wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
+ const wxString& aHelpText, const wxBitmap& aImage,
+ wxItemKind aType = wxITEM_NORMAL )
+{
+ wxMenuItem* item;
+
+ item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
+
+ // Retrieve the global applicaton show icon option:
+ bool useImagesInMenus = Pgm().GetUseIconsInMenus();
+
+ if( useImagesInMenus )
+ {
+ if( aType == wxITEM_CHECK )
+ {
+ #if defined( __WINDOWS__ )
+ item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
+ // A workaround to a strange bug on Windows, wx Widgets 3.0:
+ // size of bitmaps is not taken in account for wxITEM_CHECK menu
+ // unless we call SetFont
+ item->SetFont(*wxNORMAL_FONT);
+ #endif
+ }
+ else
+ item->SetBitmap( aImage );
+ }
+
+ aMenu->Append( item );
+
+ return item;
+}
+
+wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
+ const wxString& aText, const wxBitmap& aImage )
+{
+ wxMenuItem* item;
+
+ item = new wxMenuItem( aMenu, aId, aText );
+ item->SetSubMenu( aSubMenu );
+
+ // Retrieve the global applicaton show icon option:
+ bool useImagesInMenus = Pgm().GetUseIconsInMenus();
+
+ if( useImagesInMenus )
+ item->SetBitmap( aImage );
+
+ aMenu->Append( item );
+
+ return item;
+};
+
+
+wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
+ const wxString& aText, const wxString& aHelpText,
+ const wxBitmap& aImage )
+{
+ wxMenuItem* item;
+
+ item = new wxMenuItem( aMenu, aId, aText, aHelpText );
+ item->SetSubMenu( aSubMenu );
+
+ // Retrieve the global applicaton show icon option:
+ bool useImagesInMenus = Pgm().GetUseIconsInMenus();
+
+ if( useImagesInMenus )
+ item->SetBitmap( aImage );
+
+ aMenu->Append( item );
+
+ return item;
+};
diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp
index ce26c2b..8722d92 100644
--- a/common/pgm_base.cpp
+++ b/common/pgm_base.cpp
@@ -63,6 +63,10 @@ static const wxChar languageCfgKey[] = wxT( "LanguageID" );
static const wxChar pathEnvVariables[] = wxT( "EnvironmentVariables" );
static const wxChar showEnvVarWarningDialog[] = wxT( "ShowEnvVarWarningDialog" );
static const wxChar traceEnvVars[] = wxT( "KIENVVARS" );
+///< enable/disable icons in menus
+static const wxChar entryUseIconsInMenus[] = wxT( "UseIconsInMenus" );
+///< Scaling factor for icons
+static const wxChar entryIconsScale[] = wxT( "IconsScale" );
/**
@@ -585,6 +589,8 @@ void PGM_BASE::loadCommonSettings()
m_help_size.y = 400;
m_common_settings->Read( showEnvVarWarningDialog, &m_show_env_var_dialog );
+ m_common_settings->Read( entryUseIconsInMenus, &m_useIconsInMenus, true );
+ m_common_settings->Read( entryIconsScale, &m_iconsScale, 1.0 );
m_editor_name = m_common_settings->Read( wxT( "Editor" ) );
@@ -626,6 +632,9 @@ void PGM_BASE::SaveCommonSettings()
m_common_settings->Write( workingDirKey, cur_dir );
m_common_settings->Write( showEnvVarWarningDialog, m_show_env_var_dialog );
+ m_common_settings->Write( entryUseIconsInMenus, m_useIconsInMenus );
+ m_common_settings->Write( entryIconsScale, m_iconsScale );
+
// Save the local environment variables.
m_common_settings->SetPath( pathEnvVariables );
@@ -902,3 +911,61 @@ void PGM_BASE::ConfigurePaths( wxWindow* aParent )
SetLocalEnvVariables( dlg_envvars.GetEnvVarMap() );
}
+
+
+void PGM_BASE::AddMenuIconsOptions( wxMenu* MasterMenu, wxWindow* aWin )
+{
+ wxMenu* menu = NULL;
+ wxMenuItem* item = MasterMenu->FindItem( ID_KICAD_SELECT_ICONS_OPTIONS );
+
+ if( item ) // This menu exists, do nothing
+ return;
+
+ menu = new wxMenu;
+
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICONS_IN_MENUS,
+ _( "Icons in Menus" ), wxEmptyString,
+ wxITEM_CHECK ) );
+ menu->Check( ID_KICAD_SELECT_ICONS_IN_MENUS, m_useIconsInMenus );
+
+ menu->AppendSeparator();
+
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICON_SMALL,
+ _( "Small Icons x 0.8" ), wxEmptyString,
+ wxITEM_RADIO ) );
+ menu->Check( ID_KICAD_SELECT_ICON_SMALL, m_iconsScale < 1.0 );
+
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICON_DEFAULT,
+ _( "Default Size" ), wxEmptyString,
+ wxITEM_RADIO ) );
+ menu->Check( ID_KICAD_SELECT_ICON_DEFAULT, m_iconsScale == 1.0 );
+
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICON_SIZE1,
+ _( "Bigger Icons x 1.5" ), wxEmptyString,
+ wxITEM_RADIO ) );
+ menu->Check( ID_KICAD_SELECT_ICON_SIZE1, m_iconsScale == 1.5 );
+
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICON_SIZE2,
+ _( "Medium Icons x 1.8" ), wxEmptyString,
+ wxITEM_RADIO ) );
+ menu->Check( ID_KICAD_SELECT_ICON_SIZE2, m_iconsScale == 1.8 );
+
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICON_SIZE3,
+ _( "Large Icons x 2" ), wxEmptyString,
+ wxITEM_RADIO ) );
+ menu->Check( ID_KICAD_SELECT_ICON_SIZE3, m_iconsScale == 2.0 );
+
+ double sc_content = aWin->GetContentScaleFactor();
+ wxString txt;
+ txt.Printf( _( "HDPI SysScale %f" ), sc_content );
+ menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICON_HDPI_SYSVALUE,
+ txt, wxEmptyString,
+ wxITEM_RADIO ) );
+ menu->Check( ID_KICAD_SELECT_ICON_HDPI_SYSVALUE, m_iconsScale == -sc_content );
+
+ AddMenuItem( MasterMenu, menu,
+ ID_KICAD_SELECT_ICONS_OPTIONS,
+ _( "Icons Options" ),
+ _( "Select show icons in menus and icons sizes" ),
+ KiBitmap( hammer_xpm ) );
+}
diff --git a/include/id.h b/include/id.h
index c27dc5a..0a52344 100644
--- a/include/id.h
+++ b/include/id.h
@@ -147,6 +147,16 @@ enum main_id
ID_LANGUAGE_LITHUANIAN,
ID_LANGUAGE_CHOICE_END,
+ ID_KICAD_SELECT_ICONS_OPTIONS,
+ ID_KICAD_SELECT_ICONS_IN_MENUS,
+ ID_KICAD_SELECT_ICON_SMALL,
+ ID_KICAD_SELECT_ICON_DEFAULT,
+ ID_KICAD_SELECT_ICON_SIZE1,
+ ID_KICAD_SELECT_ICON_SIZE2,
+ ID_KICAD_SELECT_ICON_SIZE3,
+ ID_KICAD_SELECT_ICON_HDPI_SYSVALUE,
+ ID_KICAD_SELECT_ICON_OPTIONS_END,
+
ID_SET_REPEAT_OPTION,
// Popup Menu (mouse Right button) (id consecutifs)
diff --git a/include/menus_helpers.h b/include/menus_helpers.h
index ace6be5..a3d377a 100644
--- a/include/menus_helpers.h
+++ b/include/menus_helpers.h
@@ -33,20 +33,9 @@
#include <wx/menu.h>
#include <wx/menuitem.h>
-
#include <bitmaps.h>
-/**
- * SET_BITMAP is a macro used to add a bitmap to a menu item.
- * @note Do not use with checked menu items.
- * @param aImage is the image to add the menu item.
- */
-#if !defined( USE_IMAGES_IN_MENUS )
-# define SET_BITMAP( aImage )
-#else
-# define SET_BITMAP( aImage ) item->SetBitmap( aImage )
-#endif
/**
* Function AddMenuItem
@@ -60,35 +49,8 @@
* @param aType is the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
* @return a pointer to the new created wxMenuItem
*/
-static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
- int aId,
- const wxString& aText,
- const wxBitmap& aImage,
- wxItemKind aType = wxITEM_NORMAL )
-{
- wxMenuItem* item;
-
- item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
-
- if( aType == wxITEM_CHECK )
- {
-#if defined( USE_IMAGES_IN_MENUS ) && defined( __WINDOWS__ )
- item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
- // A workaround to a strange bug on Windows, wx Widgets 3.0:
- // size of bitmaps is not taken in account for wxITEM_CHECK menu
- // unless we call SetFont
- item->SetFont(*wxNORMAL_FONT);
-#endif
- }
- else
- {
- SET_BITMAP( aImage );
- }
-
- aMenu->Append( item );
-
- return item;
-}
+wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
+ const wxBitmap& aImage, wxItemKind aType = wxITEM_NORMAL );
/**
@@ -104,36 +66,9 @@ static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
* @param aType is the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
* @return a pointer to the new created wxMenuItem
*/
-static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
- int aId,
- const wxString& aText,
- const wxString& aHelpText,
- const wxBitmap& aImage,
- wxItemKind aType = wxITEM_NORMAL )
-{
- wxMenuItem* item;
-
- item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
-
- if( aType == wxITEM_CHECK )
- {
-#if defined( USE_IMAGES_IN_MENUS ) && defined( __WINDOWS__ )
- item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
- // A workaround to a strange bug on Windows, wx Widgets 3.0:
- // size of bitmaps is not taken in account for wxITEM_CHECK menu
- // unless we call SetFont
- item->SetFont(*wxNORMAL_FONT);
-#endif
- }
- else
- {
- SET_BITMAP( aImage );
- }
-
- aMenu->Append( item );
-
- return item;
-}
+wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
+ const wxString& aHelpText, const wxBitmap& aImage,
+ wxItemKind aType = wxITEM_NORMAL );
/**
@@ -148,23 +83,8 @@ static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
* @param aImage is the icon to add to the new menu item.
* @return a pointer to the new created wxMenuItem
*/
-static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
- wxMenu* aSubMenu,
- int aId,
- const wxString& aText,
- const wxBitmap& aImage )
-{
- wxMenuItem* item;
-
- item = new wxMenuItem( aMenu, aId, aText );
- item->SetSubMenu( aSubMenu );
-
- SET_BITMAP( aImage );
-
- aMenu->Append( item );
-
- return item;
-};
+wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
+ const wxString& aText, const wxBitmap& aImage );
/**
@@ -180,23 +100,8 @@ static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
* @param aImage is the icon to add to the new menu item.
* @return a pointer to the new created wxMenuItem
*/
-static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
- wxMenu* aSubMenu,
- int aId,
- const wxString& aText,
- const wxString& aHelpText,
- const wxBitmap& aImage )
-{
- wxMenuItem* item;
-
- item = new wxMenuItem( aMenu, aId, aText, aHelpText );
- item->SetSubMenu( aSubMenu );
-
- SET_BITMAP( aImage );
-
- aMenu->Append( item );
-
- return item;
-};
+wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
+ const wxString& aText, const wxString& aHelpText,
+ const wxBitmap& aImage );
#endif // MENUS_HELPERS_H_
diff --git a/include/pgm_base.h b/include/pgm_base.h
index 271f4f7..3106d02 100644
--- a/include/pgm_base.h
+++ b/include/pgm_base.h
@@ -217,6 +217,16 @@ public:
VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
/**
+ * Function AddMenuIconsOptions
+ * creates a menu list for icons in menu and icon sizes choice,
+ * and add it as submenu to \a MasterMenu.
+ *
+ * @param MasterMenu The main menu. The sub menu list will be accessible from the menu
+ * item with id ID_KICAD_SELECT_ICONS_OPTIONS
+ */
+ VTBL_ENTRY void AddMenuIconsOptions( wxMenu* MasterMenu, wxWindow* aWin );
+
+ /**
* Function SetLanguageIdentifier
* sets in .m_language_id member the wxWidgets language identifier Id from
* the KiCad menu id (internal menu identifier).
@@ -320,6 +330,14 @@ public:
*/
void SaveCommonSettings();
+ /// Scaling factor for menus and tool icons
+ void SetIconsScale( double aValue ) { m_iconsScale = aValue; }
+ double GetIconsScale() { return m_iconsScale; }
+ /// True to use menu icons
+ void SetUseIconsInMenus( bool aUseIcons ) { m_useIconsInMenus = aUseIcons; }
+ bool GetUseIconsInMenus() { return m_useIconsInMenus; }
+
+
protected:
/**
@@ -350,6 +368,11 @@ protected:
/// true to use the selected PDF browser, if exists, or false to use the default
bool m_use_system_pdf_browser;
+ /// Scaling factor for menus and tool icons
+ double m_iconsScale;
+ /// True to use menu icons
+ bool m_useIconsInMenus;
+
/// Trap all changes in here, simplifies debugging
void setLanguageId( int aId ) { m_language_id = aId; }
diff --git a/kicad/kicad.h b/kicad/kicad.h
index c430875..45e1761 100644
--- a/kicad/kicad.h
+++ b/kicad/kicad.h
@@ -146,6 +146,13 @@ public:
void OnSize( wxSizeEvent& event );
/**
+ * Function OnChangeIconSize
+ * Selects the current incon size in Kicad
+ * (the default for toolbars/menus is 26x26 pixels).
+ */
+ void OnChangeIconSize( wxCommandEvent& event );
+
+ /**
* Function OnLoadProject
* loads an exiting or creates a new project (.pro) file.
*/
diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp
index fdf5ecd..3bef1d3 100644
--- a/kicad/mainframe.cpp
+++ b/kicad/mainframe.cpp
@@ -438,6 +438,52 @@ void KICAD_MANAGER_FRAME::OnRunPcbFpEditor( wxCommandEvent& event )
}
+void KICAD_MANAGER_FRAME::OnChangeIconSize( wxCommandEvent& event )
+{
+ if( event.GetId() == ID_KICAD_SELECT_ICONS_IN_MENUS )
+ {
+ Pgm().SetUseIconsInMenus( event.IsChecked() );
+ }
+ else
+ {
+ double iconScale;
+
+ switch( event.GetId() )
+ {
+ case ID_KICAD_SELECT_ICON_SMALL:
+ iconScale = 0.8;
+ break;
+
+ default:
+ case ID_KICAD_SELECT_ICON_DEFAULT:
+ iconScale = 1.0;
+ break;
+
+ case ID_KICAD_SELECT_ICON_SIZE1:
+ iconScale = 1.5;
+ break;
+
+ case ID_KICAD_SELECT_ICON_SIZE2:
+ iconScale = 1.8;
+ break;
+
+ case ID_KICAD_SELECT_ICON_SIZE3:
+ iconScale = 2.0;
+ break;
+
+ case ID_KICAD_SELECT_ICON_HDPI_SYSVALUE:
+ // Stores the negative value as marker for HDPI sys value
+ iconScale = -GetContentScaleFactor();
+ break;
+ }
+
+ Pgm().SetIconsScale( iconScale );
+ }
+
+ ReCreateMenuBar();
+}
+
+
void KICAD_MANAGER_FRAME::OnRunBitmapConverter( wxCommandEvent& event )
{
Execute( this, BITMAPCONVERTER_EXE );
@@ -544,6 +590,7 @@ void KICAD_MANAGER_FRAME::PrintPrjInfo()
PrintMsg( msg );
}
+
void KICAD_MANAGER_FRAME::Process_Config( wxCommandEvent& event )
{
int id = event.GetId();
diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp
index 7b247ee..80babb0 100644
--- a/kicad/menubar.cpp
+++ b/kicad/menubar.cpp
@@ -105,6 +105,9 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
EVT_BUTTON( ID_TO_PL_EDITOR, KICAD_MANAGER_FRAME::OnRunPageLayoutEditor )
EVT_MENU( ID_TO_PL_EDITOR, KICAD_MANAGER_FRAME::OnRunPageLayoutEditor )
+ EVT_MENU_RANGE( ID_KICAD_SELECT_ICONS_OPTIONS, ID_KICAD_SELECT_ICON_OPTIONS_END,
+ KICAD_MANAGER_FRAME::OnChangeIconSize )
+
EVT_UPDATE_UI( ID_SELECT_DEFAULT_PDF_BROWSER, KICAD_MANAGER_FRAME::OnUpdateDefaultPdfBrowser )
EVT_UPDATE_UI( ID_SELECT_PREFERED_PDF_BROWSER,
KICAD_MANAGER_FRAME::OnUpdatePreferredPdfBrowser )
@@ -361,6 +364,10 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
preferencesMenu->AppendSeparator();
Pgm().AddMenuLanguageList( preferencesMenu );
+ // Icons options submenu
+ preferencesMenu->AppendSeparator();
+ Pgm().AddMenuIconsOptions( preferencesMenu, this );
+
// Menu Tools:
wxMenu* toolsMenu = new wxMenu;
Follow ups