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_DPI_CHANGED( EDA_MSG_PANEL::OnDPIChanged )
38 EVT_PAINT( EDA_MSG_PANEL::OnPaint )
39END_EVENT_TABLE()
40
41
42EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition,
43 const wxSize& aSize, long style, const wxString &name ) :
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 updateFontSize();
55
56 InvalidateBestSize();
57}
58
59
61{
62}
63
64
66{
67 wxFont font = KIUI::GetControlFont( this );
68 GetTextExtent( wxT( "W" ), &m_fontSize.x, &m_fontSize.y, 0, 0, &font );
69}
70
71
73{
74 return wxSize( wxDefaultCoord, 2 * m_fontSize.y + 0 );
75}
76
77
79{
80 return wxPanel::DoGetBestClientSize();
81}
82
83
84void EDA_MSG_PANEL::OnDPIChanged( wxDPIChangedEvent& aEvent )
85{
87 InvalidateBestSize();
88
89 aEvent.Skip();
90}
91
92
93void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
94{
95 wxPaintDC dc( this );
96
97 erase( &dc );
98
99 dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
100 dc.SetBackgroundMode( wxSOLID );
101 dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
102 dc.SetFont( KIUI::GetControlFont( this ) );
103
104 for( const MSG_PANEL_ITEM& item : m_Items )
105 showItem( dc, item );
106
107 aEvent.Skip();
108}
109
110
111void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
112 int aPadding )
113{
114 wxString text;
115 wxSize drawSize = GetClientSize();
116
117 text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
118 text.Append( ' ', aPadding );
119
120 MSG_PANEL_ITEM item;
121
122 /* Don't put the first message a window client position 0. Offset by
123 * one 'W' character width. */
124 if( m_last_x == 0 )
126
127 item.m_X = m_last_x;
128
129 item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
130 item.m_LowerY = drawSize.y - m_fontSize.y;
131
132 item.m_UpperText = aUpperText;
133 item.m_LowerText = aLowerText;
134 m_Items.push_back( item );
135 m_last_x += GetTextExtent( text ).x;
136
137 // Add an extra space between texts for a better look:
138 m_last_x += m_fontSize.x;
139
140 Refresh();
141}
142
143
144void EDA_MSG_PANEL::SetMessage( int aXPosition, const wxString& aUpperText,
145 const wxString& aLowerText )
146{
147 wxPoint pos;
148 wxSize drawSize = GetClientSize();
149
150 if( aXPosition >= 0 )
151 m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
152 else
153 pos.x = m_last_x;
154
155 MSG_PANEL_ITEM item;
156
157 item.m_X = pos.x;
158
159 item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
160 item.m_LowerY = drawSize.y - m_fontSize.y;
161
162 item.m_UpperText = aUpperText;
163 item.m_LowerText = aLowerText;
164
165 int ndx;
166
167 // update the vector, which is sorted by m_X
168 int limit = m_Items.size();
169
170 for( ndx = 0; ndx < limit; ++ndx )
171 {
172 // replace any item with same X
173 if( m_Items[ndx].m_X == item.m_X )
174 {
175 m_Items[ndx] = item;
176 break;
177 }
178
179 if( m_Items[ndx].m_X > item.m_X )
180 {
181 m_Items.insert( m_Items.begin() + ndx, item );
182 break;
183 }
184 }
185
186 if( ndx == limit ) // mutually exclusive with two above if tests
187 m_Items.push_back( item );
188
189 Refresh();
190}
191
192
193void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
194{
196
197 // Change the text to a disabled color when the window isn't active
198 wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
199
200 if( tlw && !tlw->IsActive() )
201 color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
202 else
203 color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
204
205 aDC.SetTextForeground( color.ToColour() );
206
207 if( !aItem.m_UpperText.IsEmpty() )
208 aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
209
210 if( !aItem.m_LowerText.IsEmpty() )
211 aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
212}
213
214
216{
217 m_Items.clear();
218 m_last_x = 0;
219 Refresh();
220}
221
222
223void EDA_MSG_PANEL::erase( wxDC* aDC )
224{
225 wxPen pen;
226 wxBrush brush;
227
228 wxSize size = GetClientSize();
229 wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
230
231 pen.SetColour( color );
232
233 brush.SetColour( color );
234 brush.SetStyle( wxBRUSHSTYLE_SOLID );
235
236 aDC->SetPen( pen );
237 aDC->SetBrush( brush );
238 aDC->DrawRectangle( 0, 0, size.x, size.y );
239}
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:144
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition: msgpanel.cpp:111
void OnDPIChanged(wxDPIChangedEvent &aEvent)
Definition: msgpanel.cpp:84
wxSize DoGetBestSize() const override
Definition: msgpanel.cpp:72
void updateFontSize()
Definition: msgpanel.cpp:65
int m_last_x
the last used x coordinate
Definition: msgpanel.h:162
void EraseMsgBox()
Definition: msgpanel.cpp:215
wxSize m_fontSize
Definition: msgpanel.h:163
wxSize DoGetBestClientSize() const override
Definition: msgpanel.cpp:78
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:193
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:161
void OnPaint(wxPaintEvent &aEvent)
Definition: msgpanel.cpp:93
void erase(wxDC *DC)
Definition: msgpanel.cpp:223
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.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:130
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:160
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.