Tell wx that we really want a transparent background

Try more options for telling wxWidgets that we want the area
to have a transparent background. Also, fix some spacing issues.

Fixes https://gitlab.com/kicad/code/kicad/issues/4842
This commit is contained in:
Ian McInerney 2020-07-08 16:27:53 +01:00
parent 4c383c51fa
commit 37ce9fb847
3 changed files with 35 additions and 19 deletions

View File

@ -69,6 +69,8 @@ void WX_ANGLE_TEXT::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
dc.SetFont( GetFont() );
dc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ) );
dc.SetTextBackground( wxTransparentColor );
dc.SetBackgroundMode( wxTRANSPARENT );
dc.SetBackground( *wxTRANSPARENT_BRUSH );
wxSize size = dc.GetTextExtent( m_label );
EDA_RECT rect( wxPoint( 0, 0 ), size );
@ -80,6 +82,15 @@ void WX_ANGLE_TEXT::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
EDA_RECT WX_ANGLE_TEXT::GetBoundingBox( wxWindow* aWindow, const wxString& aLabel, double aAngle )
{
wxSize size = WX_ANGLE_TEXT::GetTextSize( aWindow, aLabel );
EDA_RECT rect( wxPoint( 0, 0 ), size );
return rect.GetBoundingBoxRotated( rect.GetPosition(), aAngle );
}
wxSize WX_ANGLE_TEXT::GetTextSize( wxWindow* aWindow, const wxString& aLabel )
{
// Create the font used for the text
wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
@ -89,8 +100,5 @@ EDA_RECT WX_ANGLE_TEXT::GetBoundingBox( wxWindow* aWindow, const wxString& aLabe
wxClientDC dc( aWindow );
dc.SetFont( font );
wxSize size = dc.GetTextExtent( aLabel );
EDA_RECT rect( wxPoint( 0, 0 ), size );
return rect.GetBoundingBoxRotated( rect.GetPosition(), aAngle );
return dc.GetTextExtent( aLabel );
}

View File

@ -44,6 +44,15 @@ public:
*/
static EDA_RECT GetBoundingBox( wxWindow* aWindow, const wxString& aLabel, double aAngle );
/**
* Get the height and width of the unrotated text string that is created for this control.
* This will include any modifications done to the font.
*
* @param aWindow is the wxWindow the text will go on
* @param aLabel is the text string
*/
static wxSize GetTextSize( wxWindow* aWindow, const wxString& aLabel );
protected:
void OnEraseBackground( wxEraseEvent& WXUNUSED( aEvent ) );
void OnPaint( wxPaintEvent& WXUNUSED( aEvent ) );

View File

@ -76,23 +76,22 @@ void PANEL_SETUP_PINMAP::OnResetMatrixClick( wxCommandEvent& aEvent )
void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
{
// Try to know the size of bitmap button used in drc matrix
wxBitmapButton * dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( ercerr_xpm ) );
wxSize bitmap_size = dummy->GetSize();
wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( ercerr_xpm ) );
wxSize bmapSize = dummy->GetSize();
delete dummy;
wxPoint pos;
// Get the current text size using a dummy text.
wxStaticText* text = new wxStaticText( m_matrixPanel, -1, CommentERC_V[0], pos );
EDA_RECT bbox = WX_ANGLE_TEXT::GetBoundingBox( m_matrixPanel, CommentERC_V[0], 450 );
// Get the text size for the angled text
EDA_RECT bbox = WX_ANGLE_TEXT::GetBoundingBox( m_matrixPanel, CommentERC_V[0], 450 );
wxSize txtSize = WX_ANGLE_TEXT::GetTextSize( m_matrixPanel, CommentERC_V[0] );
int text_height = text->GetRect().GetHeight();
bitmap_size.y = std::max( bitmap_size.y, text_height );
delete text;
bmapSize.y = std::max( bmapSize.y, txtSize.y );
// compute the Y pos interval:
pos.y = bbox.GetHeight();
wxStaticText* text;
if( !m_initialized )
{
std::vector<wxStaticText*> labels;
@ -100,9 +99,9 @@ void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
// Print row labels
for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
{
int y = pos.y + (ii * bitmap_size.y);
int y = pos.y + (ii * bmapSize.y);
text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii],
wxPoint( 5, y + ( bitmap_size.y / 2 ) - ( text_height / 2 ) ) );
wxPoint( 5, y + ( bmapSize.y / 2 ) - ( txtSize.y / 2 ) ) );
labels.push_back( text );
int x = text->GetRect().GetRight();
@ -124,20 +123,20 @@ void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
{
int y = pos.y + (ii * bitmap_size.y);
int y = pos.y + (ii * bmapSize.y);
for( int jj = 0; jj <= ii; jj++ )
{
// Add column labels (only once)
PIN_ERROR diag = m_schematic->ErcSettings().GetPinMapValue( ii, jj );
int x = pos.x + ( jj * ( bitmap_size.x + 4 ) );
int x = pos.x + ( jj * ( bmapSize.x + 4 ) );
if( ( ii == jj ) && !m_initialized )
{
wxPoint txtpos;
txtpos.x = x + ( bitmap_size.x / 2 );
txtpos.y = y - text_height;
txtpos.x = x + ( bmapSize.x / 2 );
txtpos.y = y - txtSize.y;
new WX_ANGLE_TEXT( m_matrixPanel, wxID_ANY, CommentERC_V[ii], txtpos, 450 );
}