KiCad PCB EDA Suite
Loading...
Searching...
No Matches
msgpanel.cpp
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) 2004 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2021 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
26#include <widgets/msgpanel.h>
27
28#include <wx/dcscreen.h>
29#include <wx/dcclient.h>
30#include <wx/settings.h>
31#include <wx/toplevel.h>
32
33#include <widgets/ui_common.h>
34
35
36BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel )
37 EVT_PAINT( EDA_MSG_PANEL::OnPaint )
38END_EVENT_TABLE()
39
40
41EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition,
42 const wxSize& aSize, long style, const wxString &name ) :
43 wxPanel( aParent, aId, aPosition, aSize, style, name )
44{
45 SetFont( KIUI::GetStatusFont( this ) );
46 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
47
48 // informs wx not to paint the background itself as we will paint it later in erase()
49 SetBackgroundStyle( wxBG_STYLE_PAINT );
50
51 m_last_x = 0;
52
53 m_fontSize = GetTextExtent( wxT( "W" ) );
54}
55
56
58{
59}
60
61
62int EDA_MSG_PANEL::GetRequiredHeight( wxWindow* aWindow )
63{
64 wxSize fontSizeInPixels;
65 wxWindowDC dc( aWindow );
66
67 dc.SetFont( KIUI::GetControlFont( aWindow ) );
68 dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
69
70 // make space for two rows of text plus a number of pixels between them.
71 return 2 * fontSizeInPixels.y + 0;
72}
73
74
75void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
76{
77 wxPaintDC dc( this );
78
79 erase( &dc );
80
81 dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
82 dc.SetBackgroundMode( wxSOLID );
83 dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
84 dc.SetFont( KIUI::GetControlFont( this ) );
85
86 for( const MSG_PANEL_ITEM& item : m_Items )
87 showItem( dc, item );
88
89 aEvent.Skip();
90}
91
92
93void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
94 int aPadding )
95{
96 wxString text;
97 wxSize drawSize = GetClientSize();
98
99 text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
100 text.Append( ' ', aPadding );
101
102 MSG_PANEL_ITEM item;
103
104 /* Don't put the first message a window client position 0. Offset by
105 * one 'W' character width. */
106 if( m_last_x == 0 )
108
109 item.m_X = m_last_x;
110
111 item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
112 item.m_LowerY = drawSize.y - m_fontSize.y;
113
114 item.m_UpperText = aUpperText;
115 item.m_LowerText = aLowerText;
116 m_Items.push_back( item );
117 m_last_x += GetTextExtent( text ).x;
118
119 // Add an extra space between texts for a better look:
120 m_last_x += m_fontSize.x;
121
122 Refresh();
123}
124
125
126void EDA_MSG_PANEL::SetMessage( int aXPosition, const wxString& aUpperText,
127 const wxString& aLowerText )
128{
129 wxPoint pos;
130 wxSize drawSize = GetClientSize();
131
132 if( aXPosition >= 0 )
133 m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
134 else
135 pos.x = m_last_x;
136
137 MSG_PANEL_ITEM item;
138
139 item.m_X = pos.x;
140
141 item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
142 item.m_LowerY = drawSize.y - m_fontSize.y;
143
144 item.m_UpperText = aUpperText;
145 item.m_LowerText = aLowerText;
146
147 int ndx;
148
149 // update the vector, which is sorted by m_X
150 int limit = m_Items.size();
151
152 for( ndx = 0; ndx < limit; ++ndx )
153 {
154 // replace any item with same X
155 if( m_Items[ndx].m_X == item.m_X )
156 {
157 m_Items[ndx] = item;
158 break;
159 }
160
161 if( m_Items[ndx].m_X > item.m_X )
162 {
163 m_Items.insert( m_Items.begin() + ndx, item );
164 break;
165 }
166 }
167
168 if( ndx == limit ) // mutually exclusive with two above if tests
169 m_Items.push_back( item );
170
171 Refresh();
172}
173
174
175void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
176{
178
179 // Change the text to a disabled color when the window isn't active
180 wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
181
182 if( tlw && !tlw->IsActive() )
183 color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
184 else
185 color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
186
187 aDC.SetTextForeground( color.ToColour() );
188
189 if( !aItem.m_UpperText.IsEmpty() )
190 aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
191
192 if( !aItem.m_LowerText.IsEmpty() )
193 aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
194}
195
196
198{
199 m_Items.clear();
200 m_last_x = 0;
201 Refresh();
202}
203
204
205void EDA_MSG_PANEL::erase( wxDC* aDC )
206{
207 wxPen pen;
208 wxBrush brush;
209
210 wxSize size = GetClientSize();
211 wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
212
213 pen.SetColour( color );
214
215 brush.SetColour( color );
216 brush.SetStyle( wxBRUSHSTYLE_SOLID );
217
218 aDC->SetPen( pen );
219 aDC->SetBrush( brush );
220 aDC->DrawRectangle( 0, 0, size.x, size.y );
221}
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
A panel to display various information messages.
Definition: msgpanel.h:101
void SetMessage(int aXPosition, const wxString &aUpperText, const wxString &aLowerText)
Set a message at aXPosition to aUpperText and aLowerText in the message panel.
Definition: msgpanel.cpp:126
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition: msgpanel.cpp:93
int m_last_x
the last used x coordinate
Definition: msgpanel.h:168
void EraseMsgBox()
Definition: msgpanel.cpp:197
wxSize m_fontSize
Definition: msgpanel.h:169
static int GetRequiredHeight(wxWindow *aWindow)
Return the required height (in pixels) of a EDA_MSG_PANEL.
Definition: msgpanel.cpp:62
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:175
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:167
void OnPaint(wxPaintEvent &aEvent)
Definition: msgpanel.cpp:75
void erase(wxDC *DC)
Definition: msgpanel.cpp:205
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
wxString m_UpperText
Definition: msgpanel.h:91
wxString m_LowerText
Definition: msgpanel.h:92
Message panel definition file.
wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:127
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:157
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
Functions to provide common constants and other functions to assist in making a consistent UI.