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 The 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 <advanced_config.h>
34#include <kiid.h>
35
36#include <widgets/ui_common.h>
37
38
39BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel )
40 EVT_DPI_CHANGED( EDA_MSG_PANEL::OnDPIChanged )
41 EVT_PAINT( EDA_MSG_PANEL::OnPaint )
42END_EVENT_TABLE()
43
44
45EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition,
46 const wxSize& aSize, long style, const wxString &name ) :
47 wxPanel( aParent, aId, aPosition, aSize, style, name )
48{
49 SetFont( KIUI::GetStatusFont( this ) );
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
57 updateFontSize();
58
59 InvalidateBestSize();
60}
61
62
64{
65}
66
67
69{
70 wxFont font = KIUI::GetControlFont( this );
71 GetTextExtent( wxT( "W" ), &m_fontSize.x, &m_fontSize.y, 0, 0, &font );
72}
73
74
76{
77 return wxSize( wxDefaultCoord, 2 * m_fontSize.y + 0 );
78}
79
80
82{
83 return wxPanel::DoGetBestClientSize();
84}
85
86
87void EDA_MSG_PANEL::OnDPIChanged( wxDPIChangedEvent& aEvent )
88{
90 InvalidateBestSize();
91
92 aEvent.Skip();
93}
94
95
96void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
97{
98 wxPaintDC dc( this );
99
100 erase( &dc );
101
102 dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
103 dc.SetBackgroundMode( wxSOLID );
104 dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
105 dc.SetFont( KIUI::GetControlFont( this ) );
106
107 for( const MSG_PANEL_ITEM& item : m_Items )
108 showItem( dc, item );
109
110 aEvent.Skip();
111}
112
113
114void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
115 int aPadding )
116{
117 wxString text;
118 wxSize drawSize = GetClientSize();
119
120 text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
121 text.Append( ' ', aPadding );
122
123 MSG_PANEL_ITEM item;
124
125 /* Don't put the first message a window client position 0. Offset by
126 * one 'W' character width. */
127 if( m_last_x == 0 )
129
130 item.m_X = m_last_x;
131
132 item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
133 item.m_LowerY = drawSize.y - m_fontSize.y;
134
135 item.m_UpperText = aUpperText;
136 item.m_LowerText = aLowerText;
137 m_Items.push_back( item );
138 m_last_x += GetTextExtent( text ).x;
139
140 // Add an extra space between texts for a better look:
141 m_last_x += m_fontSize.x;
142
143 Refresh();
144}
145
146
147void EDA_MSG_PANEL::SetMessage( int aXPosition, const wxString& aUpperText,
148 const wxString& aLowerText )
149{
150 wxPoint pos;
151 wxSize drawSize = GetClientSize();
152
153 if( aXPosition >= 0 )
154 m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
155 else
156 pos.x = m_last_x;
157
158 MSG_PANEL_ITEM item;
159
160 item.m_X = pos.x;
161
162 item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
163 item.m_LowerY = drawSize.y - m_fontSize.y;
164
165 item.m_UpperText = aUpperText;
166 item.m_LowerText = aLowerText;
167
168 int ndx;
169
170 // update the vector, which is sorted by m_X
171 int limit = m_Items.size();
172
173 for( ndx = 0; ndx < limit; ++ndx )
174 {
175 // replace any item with same X
176 if( m_Items[ndx].m_X == item.m_X )
177 {
178 m_Items[ndx] = item;
179 break;
180 }
181
182 if( m_Items[ndx].m_X > item.m_X )
183 {
184 m_Items.insert( m_Items.begin() + ndx, item );
185 break;
186 }
187 }
188
189 if( ndx == limit ) // mutually exclusive with two above if tests
190 m_Items.push_back( item );
191
192 Refresh();
193}
194
195
196void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
197{
199
200 // Change the text to a disabled color when the window isn't active
201 wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
202
203 if( tlw && !tlw->IsActive() )
204 color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
205 else
206 color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
207
208 aDC.SetTextForeground( color.ToColour() );
209
210 if( !aItem.m_UpperText.IsEmpty() )
211 aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
212
213 if( !aItem.m_LowerText.IsEmpty() )
214 aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
215}
216
217
219{
220 m_Items.clear();
221 m_last_x = 0;
222 Refresh();
223}
224
225
226void EDA_MSG_PANEL::erase( wxDC* aDC )
227{
228 wxPen pen;
229 wxBrush brush;
230
231 wxSize size = GetClientSize();
232 wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
233
234 pen.SetColour( color );
235
236 brush.SetColour( color );
237 brush.SetStyle( wxBRUSHSTYLE_SOLID );
238
239 aDC->SetPen( pen );
240 aDC->SetBrush( brush );
241 aDC->DrawRectangle( 0, 0, size.x, size.y );
242}
243
244
245std::optional<wxString> GetMsgPanelDisplayUuid( const KIID& aKiid )
246{
247 const static int showUuids = ADVANCED_CFG::GetCfg().m_MsgPanelShowUuids;
248 std::optional<wxString> uuid;
249
250 if( showUuids > 0 )
251 {
252 uuid = aKiid.AsString();
253
254 if( showUuids == 2 )
255 uuid = uuid->SubString( 0, 7 );
256 }
257
258 return uuid;
259}
int color
Definition: DXF_plotter.cpp:60
const char * name
Definition: DXF_plotter.cpp:59
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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:147
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition: msgpanel.cpp:114
void OnDPIChanged(wxDPIChangedEvent &aEvent)
Definition: msgpanel.cpp:87
wxSize DoGetBestSize() const override
Definition: msgpanel.cpp:75
void updateFontSize()
Definition: msgpanel.cpp:68
int m_last_x
the last used x coordinate
Definition: msgpanel.h:162
void EraseMsgBox()
Definition: msgpanel.cpp:218
wxSize m_fontSize
Definition: msgpanel.h:163
wxSize DoGetBestClientSize() const override
Definition: msgpanel.cpp:81
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:196
std::vector< MSG_PANEL_ITEM > m_Items
Definition: msgpanel.h:161
void OnPaint(wxPaintEvent &aEvent)
Definition: msgpanel.cpp:96
void erase(wxDC *DC)
Definition: msgpanel.cpp:226
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:246
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
int m_MsgPanelShowUuids
Show UUIDs of items in the message panel.
std::optional< wxString > GetMsgPanelDisplayUuid(const KIID &aKiid)
Get a formatted UUID string for display in the message panel, according to the current advanced confi...
Definition: msgpanel.cpp:245
Message panel definition file.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:131
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:161
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.