KiCad PCB EDA Suite
ui_common.cpp File Reference
#include <wx/wx.h>
#include <widgets/ui_common.h>
#include <algorithm>

Go to the source code of this file.

Macros

#define BADGE_SIZE   20
 
#define BADGE_FONT_SIZE   10
 

Functions

wxBitmap MakeBadge (SEVERITY aStyle, int aCount, wxWindow *aWindow, int aDepth)
 
SEVERITY SeverityFromString (const wxString &aSeverity)
 
wxString SeverityToString (const SEVERITY &aSeverity)
 

Macro Definition Documentation

◆ BADGE_FONT_SIZE

#define BADGE_FONT_SIZE   10

Definition at line 34 of file ui_common.cpp.

◆ BADGE_SIZE

#define BADGE_SIZE   20

Definition at line 33 of file ui_common.cpp.

Function Documentation

◆ MakeBadge()

wxBitmap MakeBadge ( SEVERITY  aStyle,
int  aCount,
wxWindow *  aWindow,
int  aDepth 
)

Definition at line 36 of file ui_common.cpp.

37 {
38  wxSize size( BADGE_SIZE, BADGE_SIZE );
39  wxBitmap bitmap( size );
40  wxBrush brush;
41  wxMemoryDC badgeDC;
42  wxColour badgeColour;
43  wxColour textColour;
44  wxColour backColour;
45  int fontSize = BADGE_FONT_SIZE;
46 
47  if( aCount > 99 )
48  fontSize--;
49 
50  badgeDC.SelectObject( bitmap );
51 
52  brush.SetStyle( wxBRUSHSTYLE_SOLID );
53 
54  backColour = aWindow->GetParent()->GetBackgroundColour();
55 
56  // Each level inside staticBoxes is darkened by 210
57  for( int i = 1; i < aDepth; ++i )
58  backColour = backColour.MakeDisabled( 210 );
59 
60  brush.SetColour( backColour );
61  badgeDC.SetBackground( brush );
62  badgeDC.Clear();
63 
64  if( aCount == 0 )
65  return bitmap;
66 
67  switch( aStyle )
68  {
69  case RPT_SEVERITY_ERROR:
70  badgeColour = *wxRED;
71  textColour = *wxWHITE;
72  break;
74  badgeColour = *wxYELLOW;
75  textColour = *wxBLACK;
76  break;
78  badgeColour = *wxGREEN;
79  textColour = *wxWHITE;
80  break;
82  case RPT_SEVERITY_INFO:
83  default:
84  badgeColour = *wxLIGHT_GREY;
85  textColour = *wxBLACK;
86  break;
87  }
88 
89  brush.SetStyle( wxBRUSHSTYLE_SOLID );
90  brush.SetColour( badgeColour );
91  badgeDC.SetBrush( brush );
92  badgeDC.SetPen( wxPen( badgeColour, 0 ) );
93  badgeDC.DrawCircle( size.x / 2 - 1, size.y / 2, ( std::max( size.x, size.y ) / 2 ) - 1 );
94 
95  wxFont font( fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD );
96  badgeDC.SetFont( font );
97 
98  wxString text = wxString::Format( wxT( "%d" ), aCount );
99  wxSize textExtent = badgeDC.GetTextExtent( text );
100 
101  badgeDC.SetTextForeground( textColour );
102  badgeDC.DrawText( text, size.x / 2 - textExtent.x / 2 - 1, size.y / 2 - textExtent.y / 2 );
103 
104  return bitmap;
105 }
#define BADGE_SIZE
Definition: ui_common.cpp:33
#define BADGE_FONT_SIZE
Definition: ui_common.cpp:34
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References BADGE_FONT_SIZE, BADGE_SIZE, Format(), RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, RPT_SEVERITY_EXCLUSION, RPT_SEVERITY_INFO, and RPT_SEVERITY_WARNING.

Referenced by WX_HTML_REPORT_PANEL::updateBadges(), DIALOG_DRC::updateDisplayedCounts(), and DIALOG_ERC::updateDisplayedCounts().

◆ SeverityFromString()

SEVERITY SeverityFromString ( const wxString &  aSeverity)

Definition at line 108 of file ui_common.cpp.

109 {
110  if( aSeverity == wxT( "warning" ) )
111  return RPT_SEVERITY_WARNING;
112  else if( aSeverity == wxT( "ignore" ) )
113  return RPT_SEVERITY_IGNORE;
114  else
115  return RPT_SEVERITY_ERROR;
116 }

References RPT_SEVERITY_ERROR, RPT_SEVERITY_IGNORE, and RPT_SEVERITY_WARNING.

Referenced by BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), and ERC_SETTINGS::ERC_SETTINGS().

◆ SeverityToString()

wxString SeverityToString ( const SEVERITY aSeverity)

Definition at line 119 of file ui_common.cpp.

120 {
121  if( aSeverity == RPT_SEVERITY_IGNORE )
122  return wxT( "ignore" );
123  else if( aSeverity == RPT_SEVERITY_WARNING )
124  return wxT( "warning" );
125  else
126  return wxT( "error" );
127 }

References RPT_SEVERITY_IGNORE, and RPT_SEVERITY_WARNING.

Referenced by BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), and ERC_SETTINGS::ERC_SETTINGS().