KiCad PCB EDA Suite
EDA_MSG_PANEL Class Reference

A panel to display various information messages. More...

#include <msgpanel.h>

Inheritance diagram for EDA_MSG_PANEL:

Public Member Functions

 EDA_MSG_PANEL (wxWindow *aParent, int aId, const wxPoint &aPosition, const wxSize &aSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr)
 
 ~EDA_MSG_PANEL ()
 
void OnPaint (wxPaintEvent &aEvent)
 
void EraseMsgBox ()
 
void SetMessage (int aXPosition, const wxString &aUpperText, const wxString &aLowerText)
 Set a message at aXPosition to aUpperText and aLowerText in the message panel. More...
 
void AppendMessage (const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
 Append a message to the message panel. More...
 
void AppendMessage (const MSG_PANEL_ITEM &aMessageItem)
 Append aMessageItem to the message panel. More...
 

Static Public Member Functions

static int GetRequiredHeight (wxWindow *aWindow)
 Return the required height (in pixels) of a EDA_MSG_PANEL. More...
 

Protected Member Functions

void showItem (wxDC &dc, const MSG_PANEL_ITEM &aItem)
 
void erase (wxDC *DC)
 
wxSize computeTextSize (const wxString &text) const
 Calculate the width and height of a text string using the system UI font. More...
 

Protected Attributes

std::vector< MSG_PANEL_ITEMm_Items
 
int m_last_x
 the last used x coordinate More...
 
wxSize m_fontSize
 

Detailed Description

A panel to display various information messages.

Definition at line 100 of file msgpanel.h.

Constructor & Destructor Documentation

◆ EDA_MSG_PANEL()

EDA_MSG_PANEL::EDA_MSG_PANEL ( wxWindow *  aParent,
int  aId,
const wxPoint &  aPosition,
const wxSize &  aSize,
long  style = wxTAB_TRAVERSAL,
const wxString &  name = wxPanelNameStr 
)

Definition at line 41 of file msgpanel.cpp.

43  :
44  wxPanel( aParent, aId, aPosition, aSize, style, name )
45 {
46  SetFont( KIUI::GetStatusFont( this ) );
47  SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
48 
49  // informs wx not to paint the background itself as we will paint it later in erase()
50  SetBackgroundStyle( wxBG_STYLE_PAINT );
51 
52  m_last_x = 0;
53 
54  m_fontSize = GetTextExtent( wxT( "W" ) );
55 }
wxSize m_fontSize
Definition: msgpanel.h:169
int m_last_x
the last used x coordinate
Definition: msgpanel.h:168
wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:132
const char * name
Definition: DXF_plotter.cpp:56

References KIUI::GetStatusFont().

◆ ~EDA_MSG_PANEL()

EDA_MSG_PANEL::~EDA_MSG_PANEL ( )

Definition at line 58 of file msgpanel.cpp.

59 {
60 }

Member Function Documentation

◆ AppendMessage() [1/2]

void EDA_MSG_PANEL::AppendMessage ( const wxString &  aUpperText,
const wxString &  aLowerText,
int  aPadding = 6 
)

Append a message to the message panel.

This method automatically adjusts for the width of the text string. Making consecutive calls to AppendMessage will append each message to the right of the last message. This message is not compatible with Affiche_1_Parametre.

Parameters
aUpperTextThe message upper text.
aLowerTextThe message lower text.
aPaddingNumber of spaces to pad between messages (default = 4).

Definition at line 94 of file msgpanel.cpp.

96 {
97  wxString text;
98  wxSize drawSize = GetClientSize();
99 
100  text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
101  text.Append( ' ', aPadding );
102 
103  MSG_PANEL_ITEM item;
104 
105  /* Don't put the first message a window client position 0. Offset by
106  * one 'W' character width. */
107  if( m_last_x == 0 )
108  m_last_x = m_fontSize.x;
109 
110  item.m_X = m_last_x;
111 
112  item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
113  item.m_LowerY = drawSize.y - m_fontSize.y;
114 
115  item.m_UpperText = aUpperText;
116  item.m_LowerText = aLowerText;
117  m_Items.push_back( item );
118  m_last_x += GetTextExtent( text ).x;
119 
120  // Add an extra space between texts for a better look:
121  m_last_x += m_fontSize.x;
122 
123  Refresh();
124 }
wxString m_LowerText
Definition: msgpanel.h:92
wxSize m_fontSize
Definition: msgpanel.h:169
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:167
int m_last_x
the last used x coordinate
Definition: msgpanel.h:168
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
wxString m_UpperText
Definition: msgpanel.h:91

References m_fontSize, m_Items, m_last_x, MSG_PANEL_ITEM::m_LowerText, MSG_PANEL_ITEM::m_LowerY, MSG_PANEL_ITEM::m_UpperText, MSG_PANEL_ITEM::m_UpperY, MSG_PANEL_ITEM::m_X, Refresh(), and text.

Referenced by AppendMessage(), EDA_DRAW_FRAME::AppendMsgPanel(), and EDA_DRAW_FRAME::SetMsgPanel().

◆ AppendMessage() [2/2]

void EDA_MSG_PANEL::AppendMessage ( const MSG_PANEL_ITEM aMessageItem)
inline

Append aMessageItem to the message panel.

Parameters
aMessageItemis a reference to an MSG_PANEL_ITEM containing the message to append to the panel.

Definition at line 148 of file msgpanel.h.

149  {
150  AppendMessage( aMessageItem.GetUpperText(), aMessageItem.GetLowerText(),
151  aMessageItem.GetPadding() );
152  }
const wxString & GetLowerText() const
Definition: msgpanel.h:80
const wxString & GetUpperText() const
Definition: msgpanel.h:77
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition: msgpanel.cpp:94
int GetPadding() const
Definition: msgpanel.h:83

References AppendMessage(), MSG_PANEL_ITEM::GetLowerText(), MSG_PANEL_ITEM::GetPadding(), and MSG_PANEL_ITEM::GetUpperText().

◆ computeTextSize()

wxSize EDA_MSG_PANEL::computeTextSize ( const wxString &  text) const
protected

Calculate the width and height of a text string using the system UI font.

◆ erase()

void EDA_MSG_PANEL::erase ( wxDC *  DC)
protected

Definition at line 206 of file msgpanel.cpp.

207 {
208  wxPen pen;
209  wxBrush brush;
210 
211  wxSize size = GetClientSize();
212  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
213 
214  pen.SetColour( color );
215 
216  brush.SetColour( color );
217  brush.SetStyle( wxBRUSHSTYLE_SOLID );
218 
219  aDC->SetPen( pen );
220  aDC->SetBrush( brush );
221  aDC->DrawRectangle( 0, 0, size.x, size.y );
222 }
int color
Definition: DXF_plotter.cpp:57

References color.

Referenced by OnPaint().

◆ EraseMsgBox()

void EDA_MSG_PANEL::EraseMsgBox ( )

Definition at line 198 of file msgpanel.cpp.

199 {
200  m_Items.clear();
201  m_last_x = 0;
202  Refresh();
203 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:167
int m_last_x
the last used x coordinate
Definition: msgpanel.h:168

References m_Items, m_last_x, and Refresh().

Referenced by EDA_DRAW_FRAME::ClearMsgPanel(), EDA_DRAW_FRAME::EraseMsgBox(), and EDA_DRAW_FRAME::SetMsgPanel().

◆ GetRequiredHeight()

int EDA_MSG_PANEL::GetRequiredHeight ( wxWindow *  aWindow)
static

Return the required height (in pixels) of a EDA_MSG_PANEL.

This takes into consideration the system gui font, wxSYS_DEFAULT_GUI_FONT.

Definition at line 63 of file msgpanel.cpp.

64 {
65  wxSize fontSizeInPixels;
66  wxScreenDC dc;
67 
68  dc.SetFont( KIUI::GetControlFont( aWindow ) );
69  dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
70 
71  // make space for two rows of text plus a number of pixels between them.
72  return 2 * fontSizeInPixels.y + 0;
73 }
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:150

References KIUI::GetControlFont().

Referenced by EDA_DRAW_FRAME::EDA_DRAW_FRAME().

◆ OnPaint()

void EDA_MSG_PANEL::OnPaint ( wxPaintEvent &  aEvent)

Definition at line 76 of file msgpanel.cpp.

77 {
78  wxPaintDC dc( this );
79 
80  erase( &dc );
81 
82  dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
83  dc.SetBackgroundMode( wxSOLID );
84  dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
85  dc.SetFont( KIUI::GetControlFont( this ) );
86 
87  for( const MSG_PANEL_ITEM& item : m_Items )
88  showItem( dc, item );
89 
90  aEvent.Skip();
91 }
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:176
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:150
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:167
void erase(wxDC *DC)
Definition: msgpanel.cpp:206
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53

References erase(), KIUI::GetControlFont(), m_Items, and showItem().

◆ SetMessage()

void EDA_MSG_PANEL::SetMessage ( int  aXPosition,
const wxString &  aUpperText,
const wxString &  aLowerText 
)

Set a message at aXPosition to aUpperText and aLowerText in the message panel.

Parameters
aXPositionThe horizontal position to display the message or less than zero to set the message using the last message position.
aUpperTextThe text to be displayed in top line.
aLowerTextThe text to be displayed in bottom line.

Definition at line 127 of file msgpanel.cpp.

129 {
130  wxPoint pos;
131  wxSize drawSize = GetClientSize();
132 
133  if( aXPosition >= 0 )
134  m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
135  else
136  pos.x = m_last_x;
137 
138  MSG_PANEL_ITEM item;
139 
140  item.m_X = pos.x;
141 
142  item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
143  item.m_LowerY = drawSize.y - m_fontSize.y;
144 
145  item.m_UpperText = aUpperText;
146  item.m_LowerText = aLowerText;
147 
148  int ndx;
149 
150  // update the vector, which is sorted by m_X
151  int limit = m_Items.size();
152 
153  for( ndx=0; ndx<limit; ++ndx )
154  {
155  // replace any item with same X
156  if( m_Items[ndx].m_X == item.m_X )
157  {
158  m_Items[ndx] = item;
159  break;
160  }
161 
162  if( m_Items[ndx].m_X > item.m_X )
163  {
164  m_Items.insert( m_Items.begin() + ndx, item );
165  break;
166  }
167  }
168 
169  if( ndx == limit ) // mutually exclusive with two above if tests
170  m_Items.push_back( item );
171 
172  Refresh();
173 }
wxString m_LowerText
Definition: msgpanel.h:92
wxSize m_fontSize
Definition: msgpanel.h:169
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:167
int m_last_x
the last used x coordinate
Definition: msgpanel.h:168
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
wxString m_UpperText
Definition: msgpanel.h:91

References m_fontSize, m_Items, m_last_x, MSG_PANEL_ITEM::m_LowerText, MSG_PANEL_ITEM::m_LowerY, MSG_PANEL_ITEM::m_UpperText, MSG_PANEL_ITEM::m_UpperY, MSG_PANEL_ITEM::m_X, and Refresh().

◆ showItem()

void EDA_MSG_PANEL::showItem ( wxDC &  dc,
const MSG_PANEL_ITEM aItem 
)
protected

Definition at line 176 of file msgpanel.cpp.

177 {
178  COLOR4D color;
179 
180  // Change the text to a disabled color when the window isn't active
181  wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
182 
183  if( tlw && !tlw->IsActive() )
184  color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
185  else
186  color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
187 
188  aDC.SetTextForeground( color.ToColour() );
189 
190  if( !aItem.m_UpperText.IsEmpty() )
191  aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
192 
193  if( !aItem.m_LowerText.IsEmpty() )
194  aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
195 }
int color
Definition: DXF_plotter.cpp:57
wxString m_LowerText
Definition: msgpanel.h:92
wxString m_UpperText
Definition: msgpanel.h:91
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References color, MSG_PANEL_ITEM::m_LowerText, MSG_PANEL_ITEM::m_LowerY, MSG_PANEL_ITEM::m_UpperText, MSG_PANEL_ITEM::m_UpperY, and MSG_PANEL_ITEM::m_X.

Referenced by OnPaint().

Member Data Documentation

◆ m_fontSize

wxSize EDA_MSG_PANEL::m_fontSize
protected

Definition at line 169 of file msgpanel.h.

Referenced by AppendMessage(), and SetMessage().

◆ m_Items

std::vector<MSG_PANEL_ITEM> EDA_MSG_PANEL::m_Items
protected

Definition at line 167 of file msgpanel.h.

Referenced by AppendMessage(), EraseMsgBox(), OnPaint(), and SetMessage().

◆ m_last_x

int EDA_MSG_PANEL::m_last_x
protected

the last used x coordinate

Definition at line 168 of file msgpanel.h.

Referenced by AppendMessage(), EraseMsgBox(), and SetMessage().


The documentation for this class was generated from the following files: