Upgrade BITMAP_TOGGLE and GRID_BITMAP_TOGGLE to wxBitmapBundle
This commit is contained in:
parent
50fe585827
commit
06a4bdbf4c
|
@ -31,8 +31,9 @@
|
||||||
wxDEFINE_EVENT( TOGGLE_CHANGED, wxCommandEvent );
|
wxDEFINE_EVENT( TOGGLE_CHANGED, wxCommandEvent );
|
||||||
|
|
||||||
|
|
||||||
BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId, const wxBitmap& aCheckedBitmap,
|
BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId,
|
||||||
const wxBitmap& aUncheckedBitmap, bool aChecked ) :
|
const wxBitmapBundle& aCheckedBitmap,
|
||||||
|
const wxBitmapBundle& aUncheckedBitmap, bool aChecked ) :
|
||||||
wxPanel( aParent, aId ),
|
wxPanel( aParent, aId ),
|
||||||
m_checked( aChecked ),
|
m_checked( aChecked ),
|
||||||
m_unchecked_bitmap( aUncheckedBitmap ),
|
m_unchecked_bitmap( aUncheckedBitmap ),
|
||||||
|
@ -42,9 +43,9 @@ BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId, const wxBitmap&
|
||||||
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
SetSizer( sizer );
|
SetSizer( sizer );
|
||||||
|
|
||||||
const wxBitmap& bitmap = aChecked ? m_checked_bitmap : m_unchecked_bitmap;
|
const wxBitmapBundle& bundle = aChecked ? m_checked_bitmap : m_unchecked_bitmap;
|
||||||
|
|
||||||
m_bitmap = new wxStaticBitmap( this, aId, bitmap, wxDefaultPosition );
|
m_bitmap = new wxStaticBitmap( this, aId, bundle, wxDefaultPosition );
|
||||||
|
|
||||||
sizer->Add( m_bitmap, 0, 0 );
|
sizer->Add( m_bitmap, 0, 0 );
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
GRID_BITMAP_TOGGLE_RENDERER::GRID_BITMAP_TOGGLE_RENDERER( const wxBitmap& aCheckedBitmap,
|
GRID_BITMAP_TOGGLE_RENDERER::GRID_BITMAP_TOGGLE_RENDERER( const wxBitmapBundle& aCheckedBitmap,
|
||||||
const wxBitmap& aUncheckedBitmap ) :
|
const wxBitmapBundle& aUncheckedBitmap ) :
|
||||||
wxGridCellRenderer(),
|
wxGridCellRenderer(),
|
||||||
m_bitmapChecked( aCheckedBitmap ),
|
m_bitmapChecked( aCheckedBitmap ),
|
||||||
m_bitmapUnchecked( aUncheckedBitmap )
|
m_bitmapUnchecked( aUncheckedBitmap )
|
||||||
|
@ -48,10 +48,11 @@ void GRID_BITMAP_TOGGLE_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wx
|
||||||
wxGridCellRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected );
|
wxGridCellRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected );
|
||||||
|
|
||||||
bool checked = aGrid.GetCellValue( aRow, aCol ) == "1";
|
bool checked = aGrid.GetCellValue( aRow, aCol ) == "1";
|
||||||
const wxBitmap& bitmap = checked ? m_bitmapChecked : m_bitmapUnchecked;
|
const wxBitmapBundle& bundle = checked ? m_bitmapChecked : m_bitmapUnchecked;
|
||||||
|
wxBitmap bitmap = bundle.GetBitmapFor( &aGrid );
|
||||||
|
|
||||||
int x = std::max( 0, ( aRect.GetWidth() - m_bitmapChecked.GetWidth() ) / 2 );
|
int x = std::max( 0, ( aRect.GetWidth() - bitmap.GetWidth() ) / 2 );
|
||||||
int y = std::max( 0, ( aRect.GetHeight() - m_bitmapChecked.GetHeight() ) / 2 );
|
int y = std::max( 0, ( aRect.GetHeight() - bitmap.GetHeight() ) / 2 );
|
||||||
|
|
||||||
aDc.DrawBitmap( bitmap, aRect.GetTopLeft() + wxPoint( x, y ) );
|
aDc.DrawBitmap( bitmap, aRect.GetTopLeft() + wxPoint( x, y ) );
|
||||||
}
|
}
|
||||||
|
@ -60,5 +61,5 @@ void GRID_BITMAP_TOGGLE_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wx
|
||||||
wxSize GRID_BITMAP_TOGGLE_RENDERER::GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
|
wxSize GRID_BITMAP_TOGGLE_RENDERER::GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
|
||||||
int aRow, int aCol)
|
int aRow, int aCol)
|
||||||
{
|
{
|
||||||
return m_bitmapChecked.GetSize();
|
return m_bitmapChecked.GetPreferredBitmapSizeFor( &aGrid );
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#define _BITMAP_TOGGLE_H
|
#define _BITMAP_TOGGLE_H
|
||||||
|
|
||||||
#include <wx/statbmp.h>
|
#include <wx/statbmp.h>
|
||||||
|
#include <wx/bmpbndl.h>
|
||||||
#include <wx/panel.h>
|
#include <wx/panel.h>
|
||||||
|
|
||||||
#include <gal/color4d.h>
|
#include <gal/color4d.h>
|
||||||
|
@ -45,8 +46,8 @@ class BITMAP_TOGGLE : public wxPanel
|
||||||
public:
|
public:
|
||||||
BITMAP_TOGGLE() {}
|
BITMAP_TOGGLE() {}
|
||||||
|
|
||||||
BITMAP_TOGGLE( wxWindow* aParent, wxWindowID aId, const wxBitmap& aCheckedBitmap,
|
BITMAP_TOGGLE( wxWindow* aParent, wxWindowID aId, const wxBitmapBundle& aCheckedBitmap,
|
||||||
const wxBitmap& aUncheckedBitmap, bool aChecked = false );
|
const wxBitmapBundle& aUncheckedBitmap, bool aChecked = false );
|
||||||
|
|
||||||
///< Set the checkbox state
|
///< Set the checkbox state
|
||||||
void SetValue( bool aValue );
|
void SetValue( bool aValue );
|
||||||
|
@ -68,8 +69,8 @@ private:
|
||||||
bool m_checked;
|
bool m_checked;
|
||||||
|
|
||||||
wxStaticBitmap* m_bitmap;
|
wxStaticBitmap* m_bitmap;
|
||||||
wxBitmap m_unchecked_bitmap;
|
wxBitmapBundle m_unchecked_bitmap;
|
||||||
wxBitmap m_checked_bitmap;
|
wxBitmapBundle m_checked_bitmap;
|
||||||
|
|
||||||
wxLongLong m_debounce; // Timestamp for debouncing events
|
wxLongLong m_debounce; // Timestamp for debouncing events
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#ifndef KICAD_GRID_BITMAP_TOGGLE_H
|
#ifndef KICAD_GRID_BITMAP_TOGGLE_H
|
||||||
#define KICAD_GRID_BITMAP_TOGGLE_H
|
#define KICAD_GRID_BITMAP_TOGGLE_H
|
||||||
|
|
||||||
#include <wx/bitmap.h>
|
#include <wx/bmpbndl.h>
|
||||||
#include <wx/grid.h>
|
#include <wx/grid.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@
|
||||||
class GRID_BITMAP_TOGGLE_RENDERER : public wxGridCellRenderer
|
class GRID_BITMAP_TOGGLE_RENDERER : public wxGridCellRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GRID_BITMAP_TOGGLE_RENDERER( const wxBitmap& aCheckedBitmap,
|
GRID_BITMAP_TOGGLE_RENDERER( const wxBitmapBundle& aCheckedBitmap,
|
||||||
const wxBitmap& aUncheckedBitmap );
|
const wxBitmapBundle& aUncheckedBitmap );
|
||||||
|
|
||||||
~GRID_BITMAP_TOGGLE_RENDERER() {}
|
~GRID_BITMAP_TOGGLE_RENDERER() {}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ public:
|
||||||
int aRow, int aCol) override;
|
int aRow, int aCol) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxBitmap m_bitmapChecked;
|
wxBitmapBundle m_bitmapChecked;
|
||||||
|
|
||||||
wxBitmap m_bitmapUnchecked;
|
wxBitmapBundle m_bitmapUnchecked;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KICAD_GRID_BITMAP_TOGGLE_H
|
#endif // KICAD_GRID_BITMAP_TOGGLE_H
|
||||||
|
|
|
@ -523,8 +523,8 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::flipBoard );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::flipBoard );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
m_toggleGridRenderer = new GRID_BITMAP_TOGGLE_RENDERER( KiBitmap( BITMAPS::visibility ),
|
m_toggleGridRenderer = new GRID_BITMAP_TOGGLE_RENDERER(
|
||||||
KiBitmap( BITMAPS::visibility_off ) );
|
KiBitmapBundle( BITMAPS::visibility ), KiBitmapBundle( BITMAPS::visibility_off ) );
|
||||||
|
|
||||||
m_netsGrid->RegisterDataType( wxT( "bool" ), m_toggleGridRenderer, new wxGridCellBoolEditor );
|
m_netsGrid->RegisterDataType( wxT( "bool" ), m_toggleGridRenderer, new wxGridCellBoolEditor );
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo
|
||||||
wxSize size = ConvertDialogToPixels( SWATCH_SIZE_SMALL_DU );
|
wxSize size = ConvertDialogToPixels( SWATCH_SIZE_SMALL_DU );
|
||||||
m_netsGrid->SetColSize( NET_GRID_TABLE::COL_COLOR, size.x + cellPadding );
|
m_netsGrid->SetColSize( NET_GRID_TABLE::COL_COLOR, size.x + cellPadding );
|
||||||
|
|
||||||
size = KiBitmap( BITMAPS::visibility ).GetSize();
|
size = KiBitmapBundle( BITMAPS::visibility ).GetPreferredBitmapSizeFor( this );
|
||||||
m_netsGrid->SetColSize( NET_GRID_TABLE::COL_VISIBILITY, size.x + cellPadding );
|
m_netsGrid->SetColSize( NET_GRID_TABLE::COL_VISIBILITY, size.x + cellPadding );
|
||||||
|
|
||||||
m_netsGrid->SetDefaultCellFont( font );
|
m_netsGrid->SetDefaultCellFont( font );
|
||||||
|
@ -1554,10 +1554,9 @@ void APPEARANCE_CONTROLS::rebuildLayers()
|
||||||
swatch->SetToolTip( _( "Double click or middle click for color change, "
|
swatch->SetToolTip( _( "Double click or middle click for color change, "
|
||||||
"right click for menu" ) );
|
"right click for menu" ) );
|
||||||
|
|
||||||
BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE( panel, layer,
|
BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE(
|
||||||
KiBitmap( BITMAPS::visibility ),
|
panel, layer, KiBitmapBundle( BITMAPS::visibility ),
|
||||||
KiBitmap( BITMAPS::visibility_off ),
|
KiBitmapBundle( BITMAPS::visibility_off ), aSetting->visible );
|
||||||
aSetting->visible );
|
|
||||||
btn_visible->SetToolTip( _( "Show or hide this layer" ) );
|
btn_visible->SetToolTip( _( "Show or hide this layer" ) );
|
||||||
|
|
||||||
wxStaticText* label = new wxStaticText( panel, layer, aSetting->label );
|
wxStaticText* label = new wxStaticText( panel, layer, aSetting->label );
|
||||||
|
@ -2159,10 +2158,9 @@ void APPEARANCE_CONTROLS::rebuildObjects()
|
||||||
sizer->AddSpacer( swatchWidth );
|
sizer->AddSpacer( swatchWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE( m_windowObjects, layer,
|
BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE(
|
||||||
KiBitmap( BITMAPS::visibility ),
|
m_windowObjects, layer, KiBitmapBundle( BITMAPS::visibility ),
|
||||||
KiBitmap( BITMAPS::visibility_off ),
|
KiBitmapBundle( BITMAPS::visibility_off ), aSetting->visible );
|
||||||
aSetting->visible );
|
|
||||||
|
|
||||||
wxString tip;
|
wxString tip;
|
||||||
tip.Printf( _( "Show or hide %s" ), aSetting->label.Lower() );
|
tip.Printf( _( "Show or hide %s" ), aSetting->label.Lower() );
|
||||||
|
@ -2392,10 +2390,9 @@ void APPEARANCE_CONTROLS::rebuildNets()
|
||||||
if( isDefaultClass )
|
if( isDefaultClass )
|
||||||
setting->ctl_color->Hide();
|
setting->ctl_color->Hide();
|
||||||
|
|
||||||
setting->ctl_visibility = new BITMAP_TOGGLE( setting->ctl_panel, aId,
|
setting->ctl_visibility = new BITMAP_TOGGLE(
|
||||||
KiBitmap( BITMAPS::visibility ),
|
setting->ctl_panel, aId, KiBitmapBundle( BITMAPS::visibility ),
|
||||||
KiBitmap( BITMAPS::visibility_off ),
|
KiBitmapBundle( BITMAPS::visibility_off ), !hiddenClasses.count( name ) );
|
||||||
!hiddenClasses.count( name ) );
|
|
||||||
|
|
||||||
wxString tip;
|
wxString tip;
|
||||||
tip.Printf( _( "Show or hide ratsnest for nets in %s" ), name );
|
tip.Printf( _( "Show or hide ratsnest for nets in %s" ), name );
|
||||||
|
|
Loading…
Reference in New Issue