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 ()
 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...
 

Static Protected Member Functions

static wxSize computeFontSize ()
 Compute the height and width of a 'W' in the system font. More...
 

Protected Attributes

MSG_PANEL_ITEMS m_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 103 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 44 of file msgpanel.cpp.

46  :
47  wxPanel( aParent, aId, aPosition, aSize, style, name )
48 {
49  SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
50  SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
51 
52  // informs wx not to paint the background itself as we will paint it later in erase()
53  SetBackgroundStyle( wxBG_STYLE_PAINT );
54 
55  m_last_x = 0;
56 
58 }
wxSize m_fontSize
Definition: msgpanel.h:176
int m_last_x
the last used x coordinate
Definition: msgpanel.h:175
const char * name
Definition: DXF_plotter.cpp:59
static wxSize computeFontSize()
Compute the height and width of a 'W' in the system font.
Definition: msgpanel.cpp:66

◆ ~EDA_MSG_PANEL()

EDA_MSG_PANEL::~EDA_MSG_PANEL ( )

Definition at line 61 of file msgpanel.cpp.

62 {
63 }

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 119 of file msgpanel.cpp.

121 {
122  wxString text;
123  wxSize drawSize = GetClientSize();
124 
125  text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
126  text.Append( ' ', aPadding );
127 
128  MSG_PANEL_ITEM item;
129 
130  /* Don't put the first message a window client position 0. Offset by
131  * one 'W' character width. */
132  if( m_last_x == 0 )
133  m_last_x = m_fontSize.x;
134 
135  item.m_X = m_last_x;
136 
137  item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
138  item.m_LowerY = drawSize.y - m_fontSize.y;
139 
140  item.m_UpperText = aUpperText;
141  item.m_LowerText = aLowerText;
142  m_Items.push_back( item );
143  m_last_x += computeTextSize( text ).x;
144 
145  // Add an extra space between texts for a better look:
146  m_last_x += m_fontSize.x;
147 
148  Refresh();
149 }
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:174
wxString m_LowerText
Definition: msgpanel.h:92
wxSize m_fontSize
Definition: msgpanel.h:176
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxSize computeTextSize(const wxString &text) const
Calculate the width and height of a text string using the system UI font.
Definition: msgpanel.cpp:87
int m_last_x
the last used x coordinate
Definition: msgpanel.h:175
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
wxString m_UpperText
Definition: msgpanel.h:91

References computeTextSize(), 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 151 of file msgpanel.h.

152  {
153  AppendMessage( aMessageItem.GetUpperText(), aMessageItem.GetLowerText(),
154  aMessageItem.GetPadding() );
155  }
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:119
int GetPadding() const
Definition: msgpanel.h:83

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

◆ computeFontSize()

wxSize EDA_MSG_PANEL::computeFontSize ( )
staticprotected

Compute the height and width of a 'W' in the system font.

Definition at line 66 of file msgpanel.cpp.

67 {
68  // Get size of the wxSYS_DEFAULT_GUI_FONT
69  wxSize fontSizeInPixels;
70 
71  wxScreenDC dc;
72 
73  dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
74  dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
75 
76  return fontSizeInPixels;
77 }

Referenced by GetRequiredHeight().

◆ 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.

Definition at line 87 of file msgpanel.cpp.

88 {
89  // Get size of the wxSYS_DEFAULT_GUI_FONT
90  wxSize textSizeInPixels;
91 
92  wxScreenDC dc;
93 
94  dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
95  dc.GetTextExtent( aText, &textSizeInPixels.x, &textSizeInPixels.y );
96 
97  return textSizeInPixels;
98 }

Referenced by AppendMessage().

◆ erase()

void EDA_MSG_PANEL::erase ( wxDC *  DC)
protected

Definition at line 231 of file msgpanel.cpp.

232 {
233  wxPen pen;
234  wxBrush brush;
235 
236  wxSize size = GetClientSize();
237  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
238 
239  pen.SetColour( color );
240 
241  brush.SetColour( color );
242  brush.SetStyle( wxBRUSHSTYLE_SOLID );
243 
244  aDC->SetPen( pen );
245  aDC->SetBrush( brush );
246  aDC->DrawRectangle( 0, 0, size.x, size.y );
247 }
int color
Definition: DXF_plotter.cpp:60

References color.

Referenced by OnPaint().

◆ EraseMsgBox()

void EDA_MSG_PANEL::EraseMsgBox ( )

Definition at line 223 of file msgpanel.cpp.

224 {
225  m_Items.clear();
226  m_last_x = 0;
227  Refresh();
228 }
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:174
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
int m_last_x
the last used x coordinate
Definition: msgpanel.h:175

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 ( )
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 80 of file msgpanel.cpp.

81 {
82  // make space for two rows of text plus a number of pixels between them.
83  return 2 * computeFontSize().y + 0;
84 }
static wxSize computeFontSize()
Compute the height and width of a 'W' in the system font.
Definition: msgpanel.cpp:66

References computeFontSize().

Referenced by EDA_DRAW_FRAME::EDA_DRAW_FRAME().

◆ OnPaint()

void EDA_MSG_PANEL::OnPaint ( wxPaintEvent &  aEvent)

Definition at line 101 of file msgpanel.cpp.

102 {
103  wxPaintDC dc( this );
104 
105  erase( &dc );
106 
107  dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
108  dc.SetBackgroundMode( wxSOLID );
109  dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
110  dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
111 
112  for( const MSG_PANEL_ITEM& item : m_Items )
113  showItem( dc, item );
114 
115  aEvent.Skip();
116 }
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:201
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:174
void erase(wxDC *DC)
Definition: msgpanel.cpp:231
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53

References erase(), 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 152 of file msgpanel.cpp.

154 {
155  wxPoint pos;
156  wxSize drawSize = GetClientSize();
157 
158  if( aXPosition >= 0 )
159  m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
160  else
161  pos.x = m_last_x;
162 
163  MSG_PANEL_ITEM item;
164 
165  item.m_X = pos.x;
166 
167  item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
168  item.m_LowerY = drawSize.y - m_fontSize.y;
169 
170  item.m_UpperText = aUpperText;
171  item.m_LowerText = aLowerText;
172 
173  int ndx;
174 
175  // update the vector, which is sorted by m_X
176  int limit = m_Items.size();
177 
178  for( ndx=0; ndx<limit; ++ndx )
179  {
180  // replace any item with same X
181  if( m_Items[ndx].m_X == item.m_X )
182  {
183  m_Items[ndx] = item;
184  break;
185  }
186 
187  if( m_Items[ndx].m_X > item.m_X )
188  {
189  m_Items.insert( m_Items.begin() + ndx, item );
190  break;
191  }
192  }
193 
194  if( ndx == limit ) // mutually exclusive with two above if tests
195  m_Items.push_back( item );
196 
197  Refresh();
198 }
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:174
wxString m_LowerText
Definition: msgpanel.h:92
wxSize m_fontSize
Definition: msgpanel.h:176
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
int m_last_x
the last used x coordinate
Definition: msgpanel.h:175
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 201 of file msgpanel.cpp.

202 {
203  COLOR4D color;
204 
205  // Change the text to a disabled color when the window isn't active
206  wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
207 
208  if( tlw && !tlw->IsActive() )
209  color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
210  else
211  color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
212 
213  aDC.SetTextForeground( color.ToColour() );
214 
215  if( !aItem.m_UpperText.IsEmpty() )
216  aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
217 
218  if( !aItem.m_LowerText.IsEmpty() )
219  aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
220 }
int color
Definition: DXF_plotter.cpp:60
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 176 of file msgpanel.h.

Referenced by AppendMessage(), and SetMessage().

◆ m_Items

MSG_PANEL_ITEMS EDA_MSG_PANEL::m_Items
protected

Definition at line 174 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 175 of file msgpanel.h.

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


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