KiCad PCB EDA Suite
msgpanel.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2011-2012 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef _MSGPANEL_H_
32 #define _MSGPANEL_H_
33 
34 
35 #include <gal/color4d.h>
36 
37 #include <wx/window.h>
38 
39 #include <vector>
40 
41 using KIGFX::COLOR4D;
42 
43 #define MSG_PANEL_DEFAULT_PAD 6
44 
45 
46 class EDA_MSG_PANEL;
47 
48 
54 {
55  int m_X;
56  int m_UpperY;
57  int m_LowerY;
58  wxString m_UpperText;
59  wxString m_LowerText;
61  int m_Pad;
62 
63  friend class EDA_MSG_PANEL;
64 
65 public:
66  MSG_PANEL_ITEM( const wxString& aUpperText, const wxString& aLowerText, COLOR4D aColor,
67  int aPad = MSG_PANEL_DEFAULT_PAD ) :
68  m_UpperText( aUpperText ),
69  m_LowerText( aLowerText ),
70  m_Color( aColor ),
71  m_Pad( aPad )
72  {
73  m_X = 0;
74  m_UpperY = 0;
75  m_LowerY = 0;
76  }
77 
79  m_Pad( MSG_PANEL_DEFAULT_PAD )
80 
81  {
82  m_X = 0;
83  m_UpperY = 0;
84  m_LowerY = 0;
85  m_Color = COLOR4D::UNSPECIFIED;
86  }
87 
88  void SetUpperText( const wxString& aUpperText ) { m_UpperText = aUpperText; }
89  const wxString& GetUpperText() const { return m_UpperText; }
90 
91  void SetLowerText( const wxString& aLowerText ) { m_LowerText = aLowerText; }
92  const wxString& GetLowerText() const { return m_LowerText; }
93 
94  void SetColor( COLOR4D aColor ) { m_Color = aColor; }
95  COLOR4D GetColor() const { return m_Color; }
96 
97  void SetPadding( int aPad ) { m_Pad = aPad; }
98  int GetPadding() const { return m_Pad; }
99 };
100 
101 
102 typedef std::vector<MSG_PANEL_ITEM> MSG_PANEL_ITEMS;
103 typedef MSG_PANEL_ITEMS::iterator MSG_PANEL_ITEMS_ITER;
104 typedef MSG_PANEL_ITEMS::const_iterator MSG_PANEL_ITEMS_CITER;
105 
106 
111 class EDA_MSG_PANEL : public wxPanel
112 {
113 protected:
115  int m_last_x;
116  wxSize m_fontSize;
117 
118  void showItem( wxDC& dc, const MSG_PANEL_ITEM& aItem );
119 
120  void erase( wxDC* DC );
121 
126  static wxSize computeFontSize();
127 
131  wxSize computeTextSize( const wxString& text ) const;
132 
133 public:
134  EDA_MSG_PANEL( wxWindow* aParent, int aId,
135  const wxPoint& aPosition, const wxSize& aSize,
136  long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr);
137  ~EDA_MSG_PANEL();
138 
144  static int GetRequiredHeight();
145 
146  void OnPaint( wxPaintEvent& aEvent );
147  void EraseMsgBox();
148 
159  void SetMessage( int aXPosition, const wxString& aUpperText,
160  const wxString& aLowerText, COLOR4D aColor );
161 
176  void AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
177  COLOR4D aColor, int aPad = 6 );
178 
186  void AppendMessage( const MSG_PANEL_ITEM& aMessageItem )
187  {
188  AppendMessage( aMessageItem.GetUpperText(), aMessageItem.GetLowerText(),
189  aMessageItem.GetColor(), aMessageItem.GetPadding() );
190  }
191 
192  DECLARE_EVENT_TABLE()
193 };
194 
195 
196 #endif // _MSGPANEL_H_
EDA_MSG_PANEL(wxWindow *aParent, int aId, const wxPoint &aPosition, const wxSize &aSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr)
Definition: msgpanel.cpp:39
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:197
wxSize computeTextSize(const wxString &text) const
Calculate the width and height of a text string using the system UI font.
Definition: msgpanel.cpp:78
COLOR4D m_Color
Definition: msgpanel.h:60
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:114
MSG_PANEL_ITEMS::const_iterator MSG_PANEL_ITEMS_CITER
Definition: msgpanel.h:104
const wxString & GetLowerText() const
Definition: msgpanel.h:92
wxString m_LowerText
Definition: msgpanel.h:59
class EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
MSG_PANEL_ITEMS::iterator MSG_PANEL_ITEMS_ITER
Definition: msgpanel.h:103
void AppendMessage(const MSG_PANEL_ITEM &aMessageItem)
Function AppendMessage appends aMessageItem to the message panel.
Definition: msgpanel.h:186
void OnPaint(wxPaintEvent &aEvent)
Definition: msgpanel.cpp:92
#define MSG_PANEL_DEFAULT_PAD
The default number of spaces between each text string.
Definition: msgpanel.h:43
wxSize m_fontSize
Definition: msgpanel.h:116
void SetColor(COLOR4D aColor)
Definition: msgpanel.h:94
void EraseMsgBox()
Definition: msgpanel.cpp:215
int m_last_x
the last used x coordinate
Definition: msgpanel.h:115
MSG_PANEL_ITEM(const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor, int aPad=MSG_PANEL_DEFAULT_PAD)
Definition: msgpanel.h:66
void SetMessage(int aXPosition, const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor)
Function SetMessage sets a message at aXPosition to aUpperText and aLowerText in the message panel...
Definition: msgpanel.cpp:145
void SetLowerText(const wxString &aLowerText)
Definition: msgpanel.h:91
COLOR4D GetColor() const
Definition: msgpanel.h:95
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor, int aPad=6)
Function AppendMessage appends a message to the message panel.
Definition: msgpanel.cpp:110
void erase(wxDC *DC)
Definition: msgpanel.cpp:223
void SetPadding(int aPad)
Definition: msgpanel.h:97
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
static wxSize computeFontSize()
Function getFontSize computes the height and width of a 'W' in the system font.
Definition: msgpanel.cpp:57
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
void SetUpperText(const wxString &aUpperText)
Definition: msgpanel.h:88
static int GetRequiredHeight()
Function GetRequiredHeight returns the required height (in pixels) of a EDA_MSG_PANEL.
Definition: msgpanel.cpp:71
int GetPadding() const
Definition: msgpanel.h:98
wxString m_UpperText
Definition: msgpanel.h:58
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
const wxString & GetUpperText() const
Definition: msgpanel.h:89