diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index eb9936d45f..1ca7f7ed63 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -223,6 +223,7 @@ set( COMMON_WIDGET_SRCS widgets/layer_box_selector.cpp widgets/lib_tree.cpp widgets/mathplot.cpp + widgets/number_badge.cpp widgets/paged_dialog.cpp widgets/progress_reporter.cpp widgets/split_button.cpp diff --git a/common/dialogs/wx_html_report_panel.cpp b/common/dialogs/wx_html_report_panel.cpp index be67fe88d5..d82210c470 100644 --- a/common/dialogs/wx_html_report_panel.cpp +++ b/common/dialogs/wx_html_report_panel.cpp @@ -28,10 +28,10 @@ #include #include -WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL( wxWindow* parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, +WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL( wxWindow* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, long style ) : WX_HTML_REPORT_PANEL_BASE( parent, id, pos, size, style ), m_reporter( this ), @@ -135,10 +135,10 @@ void WX_HTML_REPORT_PANEL::scrollToBottom() void WX_HTML_REPORT_PANEL::updateBadges() { int count = Count(RPT_SEVERITY_ERROR ); - m_errorsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_ERROR, count, m_errorsBadge, 2 ) ); + m_errorsBadge->UpdateNumber( count, RPT_SEVERITY_ERROR ); count = Count(RPT_SEVERITY_WARNING ); - m_warningsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_WARNING, count, m_warningsBadge, 2 ) ); + m_warningsBadge->UpdateNumber( count, RPT_SEVERITY_WARNING ); } diff --git a/common/dialogs/wx_html_report_panel_base.cpp b/common/dialogs/wx_html_report_panel_base.cpp index 7b56fa70f6..42f2e6bad3 100644 --- a/common/dialogs/wx_html_report_panel_base.cpp +++ b/common/dialogs/wx_html_report_panel_base.cpp @@ -42,18 +42,14 @@ WX_HTML_REPORT_PANEL_BASE::WX_HTML_REPORT_PANEL_BASE( wxWindow* parent, wxWindow m_checkBoxShowErrors = new wxCheckBox( m_box->GetStaticBox(), wxID_ANY, _("Errors"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerBottom->Add( m_checkBoxShowErrors, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); - m_errorsBadge = new wxStaticBitmap( m_box->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - m_errorsBadge->SetMinSize( wxSize( 20,20 ) ); - - bSizerBottom->Add( m_errorsBadge, 0, wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL, 4 ); + m_errorsBadge = new NUMBER_BADGE( m_box->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSizerBottom->Add( m_errorsBadge, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 4 ); m_checkBoxShowWarnings = new wxCheckBox( m_box->GetStaticBox(), wxID_ANY, _("Warnings"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerBottom->Add( m_checkBoxShowWarnings, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); - m_warningsBadge = new wxStaticBitmap( m_box->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - m_warningsBadge->SetMinSize( wxSize( 20,20 ) ); - - bSizerBottom->Add( m_warningsBadge, 0, wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL, 4 ); + m_warningsBadge = new NUMBER_BADGE( m_box->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSizerBottom->Add( m_warningsBadge, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 4 ); m_checkBoxShowActions = new wxCheckBox( m_box->GetStaticBox(), wxID_ANY, _("Actions"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerBottom->Add( m_checkBoxShowActions, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); diff --git a/common/dialogs/wx_html_report_panel_base.fbp b/common/dialogs/wx_html_report_panel_base.fbp index 80569ac082..210d2cadda 100644 --- a/common/dialogs/wx_html_report_panel_base.fbp +++ b/common/dialogs/wx_html_report_panel_base.fbp @@ -344,9 +344,9 @@ 4 - wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP 0 - + 1 1 1 @@ -357,13 +357,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -375,12 +377,13 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 0 - 20,20 + 1 m_errorsBadge 1 @@ -390,9 +393,10 @@ 1 Resizable + 1 - ; forward_declare + ; ; forward_declare 0 @@ -467,9 +471,9 @@ 4 - wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP 0 - + 1 1 1 @@ -480,13 +484,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -498,12 +504,13 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 0 - 20,20 + 1 m_warningsBadge 1 @@ -513,9 +520,10 @@ 1 Resizable + 1 - ; forward_declare + ; ; forward_declare 0 diff --git a/common/dialogs/wx_html_report_panel_base.h b/common/dialogs/wx_html_report_panel_base.h index e5a45b210a..25c3f8b901 100644 --- a/common/dialogs/wx_html_report_panel_base.h +++ b/common/dialogs/wx_html_report_panel_base.h @@ -18,10 +18,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -44,9 +44,9 @@ class WX_HTML_REPORT_PANEL_BASE : public wxPanel wxStaticText* m_staticTextShow; wxCheckBox* m_checkBoxShowAll; wxCheckBox* m_checkBoxShowErrors; - wxStaticBitmap* m_errorsBadge; + NUMBER_BADGE* m_errorsBadge; wxCheckBox* m_checkBoxShowWarnings; - wxStaticBitmap* m_warningsBadge; + NUMBER_BADGE* m_warningsBadge; wxCheckBox* m_checkBoxShowActions; wxCheckBox* m_checkBoxShowInfos; wxButton* m_btnSaveReportToFile; diff --git a/common/widgets/number_badge.cpp b/common/widgets/number_badge.cpp new file mode 100644 index 0000000000..bd51472ead --- /dev/null +++ b/common/widgets/number_badge.cpp @@ -0,0 +1,164 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include + + +NUMBER_BADGE::NUMBER_BADGE( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, + const wxSize& aSize, int aStyles ) : + wxPanel( aParent, aId, aPos, aSize, aStyles ), + m_textSize( 10 ), + m_maxNumber( 1000 ), + m_currentNumber( 0 ), + m_showBadge( false ) +{ + computeSize(); + Bind( wxEVT_PAINT, &NUMBER_BADGE::onPaint, this ); +} + + +void NUMBER_BADGE::UpdateNumber( int aNumber, SEVERITY aSeverity ) +{ + m_showBadge = true; + m_currentNumber = aNumber; + + // Choose the colors of the badge rectangle and font + if( aNumber < 0 ) + { + m_showBadge = false; + } + else if( aNumber == 0 ) + { + if( aSeverity == RPT_SEVERITY_ERROR || aSeverity == RPT_SEVERITY_WARNING ) + { + m_badgeColour = KIGFX::COLOR4D( GREEN ).ToColour(); + m_textColour = *wxWHITE; + } + else + { + m_showBadge = false; + } + } + else + { + switch( aSeverity ) + { + case RPT_SEVERITY_ERROR: + m_badgeColour = *wxRED; + m_textColour = *wxWHITE; + break; + + case RPT_SEVERITY_WARNING: + m_badgeColour = *wxYELLOW; + m_textColour = *wxBLACK; + break; + + case RPT_SEVERITY_ACTION: + m_badgeColour = KIGFX::COLOR4D( GREEN ).ToColour(); + m_textColour = *wxWHITE; + break; + + case RPT_SEVERITY_EXCLUSION: + case RPT_SEVERITY_INFO: + default: + m_badgeColour = *wxLIGHT_GREY; + m_textColour = *wxBLACK; + break; + } + } + + // Force the badge UI to refresh so the new number and color is displayed + Refresh(); +} + + +void NUMBER_BADGE::SetMaximumNumber( int aMax ) +{ + m_maxNumber = aMax; + computeSize(); +} + + +void NUMBER_BADGE::SetTextSize( int aSize ) +{ + m_textSize = aSize; + computeSize(); +} + + +void NUMBER_BADGE::computeSize() +{ + wxClientDC dc( this ); + + wxString test = wxString::Format( wxT( "%d" ), m_maxNumber ); + int len = test.length(); + + // Determine the size using the string "-999+" where the - on the front is for spacing from + // the start of the rectangle so the number isn't close to the curved edge. + test = "-"; + test.Pad( len, '9' ); + test += "+"; + + dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); + + SetMinSize( dc.GetTextExtent( test ) ); +} + + +void NUMBER_BADGE::onPaint( wxPaintEvent& aEvt ) +{ + // The drawing rectangle + wxSize clientSize = GetSize(); + wxPaintDC dc( this ); + wxString text; + wxBrush brush; + + // Give the badge a transparent background to show the panel underneath + dc.SetBackground( *wxTRANSPARENT_BRUSH ); + dc.Clear(); + + // We always draw a transparent background, but only draw the badge when it is needed + if( !m_showBadge ) + return; + + // The rectangle the color is drawn in needs to be shrunk by 1px on each axis because for some reason it seems + // to be padded out by 1px and is cutoff otherwise. + wxRect rect( wxPoint( 0, 0 ), clientSize - wxSize( 1, 1 ) ); + + brush.SetStyle( wxBRUSHSTYLE_SOLID ); + brush.SetColour( m_badgeColour ); + dc.SetBrush( brush ); + dc.SetPen( wxPen( m_badgeColour, 0 ) ); + dc.DrawRoundedRectangle( rect, rect.height / 2 ); + + // Cap the number displayed and add the "+" to the end if required + if( m_currentNumber > m_maxNumber ) + text = wxString::Format( wxT( "%d+" ), m_maxNumber ); + else + text = wxString::Format( wxT( "%d" ), m_currentNumber ); + + dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); + dc.SetTextForeground( m_textColour ); + dc.DrawLabel( text, wxRect( wxPoint( 0, 0 ), clientSize ), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL ); +} diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index 25cd8d22de..0bea072f75 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -30,97 +30,6 @@ int KIUI::GetStdMargin() } -#define BADGE_SIZE 24 -#define BADGE_FONT_SIZE 10 - -wxBitmap MakeBadge( SEVERITY aStyle, int aCount, wxWindow* aWindow, int aDepth ) -{ - wxSize size( BADGE_SIZE, BADGE_SIZE ); - wxBitmap bitmap( size ); - wxBrush brush; - wxMemoryDC badgeDC; - wxColour badgeColour; - wxColour textColour; - wxColour backColour; - int fontSize = BADGE_FONT_SIZE; - - if( aCount > 99 ) - fontSize--; - - badgeDC.SelectObject( bitmap ); - - brush.SetStyle( wxBRUSHSTYLE_SOLID ); - - backColour = aWindow->GetParent()->GetBackgroundColour(); - - // Each level inside staticBoxes is darkened by 215 - for( int i = 1; i < aDepth; ++i ) - backColour = backColour.MakeDisabled( 215 ); - - brush.SetColour( backColour ); - badgeDC.SetBackground( brush ); - badgeDC.Clear(); - - if( aCount < 0 ) - { - return bitmap; - } - else if( aCount == 0 ) - { - if( aStyle == RPT_SEVERITY_ERROR || aStyle == RPT_SEVERITY_WARNING ) - { - badgeColour = KIGFX::COLOR4D( GREEN ).ToColour(); - textColour = *wxWHITE; - } - else - { - return bitmap; - } - } - else - { - switch( aStyle ) - { - case RPT_SEVERITY_ERROR: - badgeColour = *wxRED; - textColour = *wxWHITE; - break; - case RPT_SEVERITY_WARNING: - badgeColour = *wxYELLOW; - textColour = *wxBLACK; - break; - case RPT_SEVERITY_ACTION: - badgeColour = KIGFX::COLOR4D( GREEN ).ToColour(); - textColour = *wxWHITE; - break; - case RPT_SEVERITY_EXCLUSION: - case RPT_SEVERITY_INFO: - default: - badgeColour = *wxLIGHT_GREY; - textColour = *wxBLACK; - break; - } - } - - brush.SetStyle( wxBRUSHSTYLE_SOLID ); - brush.SetColour( badgeColour ); - badgeDC.SetBrush( brush ); - badgeDC.SetPen( wxPen( badgeColour, 0 ) ); - badgeDC.DrawCircle( size.x / 2 - 1, size.y / 2, ( std::max( size.x, size.y ) / 2 ) - 1 ); - - wxFont font( fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ); - badgeDC.SetFont( font ); - - wxString text = wxString::Format( wxT( "%d" ), aCount ); - wxSize textExtent = badgeDC.GetTextExtent( text ); - - badgeDC.SetTextForeground( textColour ); - badgeDC.DrawText( text, size.x / 2 - textExtent.x / 2 - 1, size.y / 2 - textExtent.y / 2 ); - - return bitmap; -} - - SEVERITY SeverityFromString( const wxString& aSeverity ) { if( aSeverity == wxT( "warning" ) ) diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 400e191abe..8faf05afe4 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -81,6 +81,10 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) : m_sdbSizer1OK->SetDefault(); + m_errorsBadge->SetMaximumNumber( 999 ); + m_warningsBadge->SetMaximumNumber( 999 ); + m_exclusionsBadge->SetMaximumNumber( 999 ); + if( m_parent->CheckAnnotate( NULL_REPORTER::GetInstance(), false ) ) { wxHyperlinkCtrl* button = new wxHyperlinkCtrl( m_infoBar, wxID_ANY, @@ -167,9 +171,9 @@ void DIALOG_ERC::updateDisplayedCounts() numWarnings = -1; } - m_errorsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_ERROR, numErrors, m_errorsBadge ) ); - m_warningsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_WARNING, numWarnings, m_warningsBadge ) ); - m_exclusionsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_EXCLUSION, numExcluded, m_exclusionsBadge ) ); + m_errorsBadge->UpdateNumber( numErrors, RPT_SEVERITY_ERROR ); + m_warningsBadge->UpdateNumber( numWarnings, RPT_SEVERITY_WARNING ); + m_exclusionsBadge->UpdateNumber( numExcluded, RPT_SEVERITY_EXCLUSION ); } diff --git a/eeschema/dialogs/dialog_erc_base.cpp b/eeschema/dialogs/dialog_erc_base.cpp index 67296ce4ec..a99778b235 100644 --- a/eeschema/dialogs/dialog_erc_base.cpp +++ b/eeschema/dialogs/dialog_erc_base.cpp @@ -74,24 +74,20 @@ DIALOG_ERC_BASE::DIALOG_ERC_BASE( wxWindow* parent, wxWindowID id, const wxStrin m_showErrors = new wxCheckBox( this, wxID_ANY, _("Errors"), wxDefaultPosition, wxDefaultSize, 0 ); bSeveritySizer->Add( m_showErrors, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_errorsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - m_errorsBadge->SetMinSize( wxSize( 20,20 ) ); - - bSeveritySizer->Add( m_errorsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 ); + m_errorsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSeveritySizer->Add( m_errorsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 ); m_showWarnings = new wxCheckBox( this, wxID_ANY, _("Warnings"), wxDefaultPosition, wxDefaultSize, 0 ); bSeveritySizer->Add( m_showWarnings, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_warningsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - m_warningsBadge->SetMinSize( wxSize( 20,20 ) ); - - bSeveritySizer->Add( m_warningsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 ); + m_warningsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSeveritySizer->Add( m_warningsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 ); m_showExclusions = new wxCheckBox( this, wxID_ANY, _("Exclusions"), wxDefaultPosition, wxDefaultSize, 0 ); bSeveritySizer->Add( m_showExclusions, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_exclusionsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - bSeveritySizer->Add( m_exclusionsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 ); + m_exclusionsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSeveritySizer->Add( m_exclusionsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 ); bSeveritySizer->Add( 0, 0, 1, wxEXPAND, 5 ); diff --git a/eeschema/dialogs/dialog_erc_base.fbp b/eeschema/dialogs/dialog_erc_base.fbp index f2070ca45a..1526e53812 100644 --- a/eeschema/dialogs/dialog_erc_base.fbp +++ b/eeschema/dialogs/dialog_erc_base.fbp @@ -406,7 +406,7 @@ 5 wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 0 - + bSeveritySizer wxHORIZONTAL @@ -612,11 +612,11 @@ OnSeverity - + 25 - wxRIGHT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 - + 1 1 1 @@ -627,13 +627,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -645,12 +647,13 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 0 - 20,20 + 1 m_errorsBadge 1 @@ -660,6 +663,7 @@ 1 Resizable + 1 ; ; forward_declare @@ -735,11 +739,11 @@ OnSeverity - + 25 - wxRIGHT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 - + 1 1 1 @@ -750,13 +754,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -768,12 +774,13 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 0 - 20,20 + 1 m_warningsBadge 1 @@ -783,6 +790,7 @@ 1 Resizable + 1 ; ; forward_declare @@ -858,11 +866,11 @@ OnSeverity - + 25 - wxRIGHT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 - + 1 1 1 @@ -873,13 +881,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -891,6 +901,7 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 @@ -906,6 +917,7 @@ 1 Resizable + 1 ; ; forward_declare diff --git a/eeschema/dialogs/dialog_erc_base.h b/eeschema/dialogs/dialog_erc_base.h index 08f85a79af..78fc9bf1c6 100644 --- a/eeschema/dialogs/dialog_erc_base.h +++ b/eeschema/dialogs/dialog_erc_base.h @@ -30,7 +30,7 @@ class WX_INFOBAR; #include #include #include -#include +#include #include #include #include @@ -56,11 +56,11 @@ class DIALOG_ERC_BASE : public DIALOG_SHIM wxStaticText* m_showLabel; wxCheckBox* m_showAll; wxCheckBox* m_showErrors; - wxStaticBitmap* m_errorsBadge; + NUMBER_BADGE* m_errorsBadge; wxCheckBox* m_showWarnings; - wxStaticBitmap* m_warningsBadge; + NUMBER_BADGE* m_warningsBadge; wxCheckBox* m_showExclusions; - wxStaticBitmap* m_exclusionsBadge; + NUMBER_BADGE* m_exclusionsBadge; wxButton* m_saveReport; wxStaticLine* m_staticline1; wxBoxSizer* m_buttonsSizer; diff --git a/include/widgets/number_badge.h b/include/widgets/number_badge.h new file mode 100644 index 0000000000..2b433f1fa3 --- /dev/null +++ b/include/widgets/number_badge.h @@ -0,0 +1,95 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef NUMBER_BADGE_H_ +#define NUMBER_BADGE_H_ + +#include +#include + +/** + * A simple UI element that puts a number on top of a colored rounded rectangle with a fill + * color that shows the severity of the reports the number is counting (e.g. green, yellow, red). + * This badge will also automatically truncate the displayed number to the set maximum and display + * "+" at the end to represent it is truncated. + */ +class NUMBER_BADGE : public wxPanel +{ +public: + /** + * Create a number badge with 10pt font and a maximum number of 1000. + */ + NUMBER_BADGE( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, + const wxSize& aSize, int aStyles ); + + /** + * Update the number displayed on the badge. + * + * Severity to badge color mapping: + * - RPT_SEVERITY_ERROR = red badge + * - RPT_SEVERITY_WARNING = yellow badge + * - RPT_SEVERITY_ACTION = green badge + * - RPT_SEVERITY_EXCLUSION = light grey badge + * - RPT_SEVERITY_INFO = light grey badge + * + * @param aNumber is the new number to display. + * @param aSeverity is the new severity of the badge. + */ + void UpdateNumber( int aNumber, SEVERITY aSeverity ); + + /** + * Set the maximum number to be shown on the badge. Any numbers greater than this + * will be displayed as the maximum number followed by "+". + * + * @param aMax is the maximum number + */ + void SetMaximumNumber( int aMax ); + + /** + * Set the text size to use on the badge. + * + * @param aSize is the text size (in pt) to use on the badge + */ + void SetTextSize( int aSize ); + +protected: + /** + * Helper function to compute the size of the badge + */ + void computeSize(); + + /** + * Handler that actually paints the badge and the text. + */ + void onPaint( wxPaintEvent& aEvt ); + + int m_textSize; // The text size to use + int m_maxNumber; // The maximum number allowed to be shown on the badge + + int m_currentNumber; // The current number to display + bool m_showBadge; // If true, displays the actual badge otherwise it is invisible + wxColour m_badgeColour; // The color of the badge + wxColour m_textColour; // The color of the text on the badge +}; + +#endif diff --git a/include/widgets/ui_common.h b/include/widgets/ui_common.h index 64a4a4e9d3..73410b1ac3 100644 --- a/include/widgets/ui_common.h +++ b/include/widgets/ui_common.h @@ -28,8 +28,6 @@ #include -class wxWindow; - namespace KIUI { @@ -53,13 +51,8 @@ enum SEVERITY { RPT_SEVERITY_IGNORE = 0x20 }; -wxBitmap MakeBadge( SEVERITY aStyle, int aCount, wxWindow* aWindow, int aDepth = 1 ); - SEVERITY SeverityFromString( const wxString& aSeverity ); wxString SeverityToString( const SEVERITY& aSeverity ); - - - #endif // UI_COMMON_H diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index 019c7fcfb0..9b005a84a3 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,10 @@ DIALOG_DRC::DIALOG_DRC( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent ) : m_sdbSizerOK->SetDefault(); + m_errorsBadge->SetMaximumNumber( 999 ); + m_warningsBadge->SetMaximumNumber( 999 ); + m_exclusionsBadge->SetMaximumNumber( 999 ); + initValues(); syncCheckboxes(); @@ -859,7 +864,7 @@ void DIALOG_DRC::updateDisplayedCounts() numWarnings = -1; } - m_errorsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_ERROR, numErrors, m_errorsBadge ) ); - m_warningsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_WARNING, numWarnings, m_warningsBadge ) ); - m_exclusionsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_EXCLUSION, numExcluded, m_exclusionsBadge ) ); + m_errorsBadge->UpdateNumber( numErrors, RPT_SEVERITY_ERROR ); + m_warningsBadge->UpdateNumber( numWarnings, RPT_SEVERITY_WARNING ); + m_exclusionsBadge->UpdateNumber( numExcluded, RPT_SEVERITY_EXCLUSION ); } diff --git a/pcbnew/dialogs/dialog_drc_base.cpp b/pcbnew/dialogs/dialog_drc_base.cpp index 5c76cf4b81..4cd7f169d4 100644 --- a/pcbnew/dialogs/dialog_drc_base.cpp +++ b/pcbnew/dialogs/dialog_drc_base.cpp @@ -62,8 +62,8 @@ DIALOG_DRC_BASE::DIALOG_DRC_BASE( wxWindow* parent, wxWindowID id, const wxStrin wxBoxSizer* bSizer10; bSizer10 = new wxBoxSizer( wxVERTICAL ); - m_messages = new WX_HTML_REPORT_BOX( m_panelMessages, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); - bSizer10->Add( m_messages, 1, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, 5 ); + m_messages = new WX_HTML_REPORT_BOX( m_panelMessages, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); + bSizer10->Add( m_messages, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* bGaugeMargins; bGaugeMargins = new wxBoxSizer( wxVERTICAL ); @@ -162,24 +162,20 @@ DIALOG_DRC_BASE::DIALOG_DRC_BASE( wxWindow* parent, wxWindowID id, const wxStrin m_showErrors = new wxCheckBox( this, wxID_ANY, _("Errors"), wxDefaultPosition, wxDefaultSize, 0 ); bSeveritySizer->Add( m_showErrors, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_errorsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - m_errorsBadge->SetMinSize( wxSize( 20,20 ) ); - - bSeveritySizer->Add( m_errorsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 ); + m_errorsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSeveritySizer->Add( m_errorsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 ); m_showWarnings = new wxCheckBox( this, wxID_ANY, _("Warnings"), wxDefaultPosition, wxDefaultSize, 0 ); bSeveritySizer->Add( m_showWarnings, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_warningsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - m_warningsBadge->SetMinSize( wxSize( 20,20 ) ); - - bSeveritySizer->Add( m_warningsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 ); + m_warningsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSeveritySizer->Add( m_warningsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 ); m_showExclusions = new wxCheckBox( this, wxID_ANY, _("Exclusions"), wxDefaultPosition, wxDefaultSize, 0 ); bSeveritySizer->Add( m_showExclusions, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_exclusionsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - bSeveritySizer->Add( m_exclusionsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 ); + m_exclusionsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSeveritySizer->Add( m_exclusionsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 ); bSeveritySizer->Add( 5, 0, 1, wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/dialog_drc_base.fbp b/pcbnew/dialogs/dialog_drc_base.fbp index 6d934a7162..9890066088 100644 --- a/pcbnew/dialogs/dialog_drc_base.fbp +++ b/pcbnew/dialogs/dialog_drc_base.fbp @@ -1344,9 +1344,9 @@ 25 - wxRIGHT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 - + 1 1 1 @@ -1357,13 +1357,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -1375,12 +1377,13 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 0 - 20,20 + 1 m_errorsBadge 1 @@ -1390,6 +1393,7 @@ 1 Resizable + 1 ; ; forward_declare @@ -1467,9 +1471,9 @@ 25 - wxRIGHT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 - + 1 1 1 @@ -1480,13 +1484,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -1498,12 +1504,13 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 0 - 20,20 + 1 m_warningsBadge 1 @@ -1513,6 +1520,7 @@ 1 Resizable + 1 ; ; forward_declare @@ -1590,9 +1598,9 @@ 25 - wxRIGHT|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxRIGHT 0 - + 1 1 1 @@ -1603,13 +1611,15 @@ - 1 0 + NUMBER_BADGE 1 + 1 + 0 Dock 0 @@ -1621,6 +1631,7 @@ 0 0 wxID_ANY + #include <widgets/number_badge.h> 0 @@ -1636,6 +1647,7 @@ 1 Resizable + 1 ; ; forward_declare diff --git a/pcbnew/dialogs/dialog_drc_base.h b/pcbnew/dialogs/dialog_drc_base.h index 3efcba8abb..e7960360f7 100644 --- a/pcbnew/dialogs/dialog_drc_base.h +++ b/pcbnew/dialogs/dialog_drc_base.h @@ -30,7 +30,7 @@ class WX_HTML_REPORT_BOX; #include #include #include -#include +#include #include #include #include @@ -68,11 +68,11 @@ class DIALOG_DRC_BASE : public DIALOG_SHIM wxStaticText* m_showLabel; wxCheckBox* m_showAll; wxCheckBox* m_showErrors; - wxStaticBitmap* m_errorsBadge; + NUMBER_BADGE* m_errorsBadge; wxCheckBox* m_showWarnings; - wxStaticBitmap* m_warningsBadge; + NUMBER_BADGE* m_warningsBadge; wxCheckBox* m_showExclusions; - wxStaticBitmap* m_exclusionsBadge; + NUMBER_BADGE* m_exclusionsBadge; wxButton* m_saveReport; wxStaticLine* m_staticline1; wxBoxSizer* m_sizerButtons;