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_SIZE( EDA_MSG_PANEL::OnSize )
42 EVT_PAINT( EDA_MSG_PANEL::OnPaint )
43END_EVENT_TABLE()
44
45
46EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition,
47 const wxSize& aSize, long style, const wxString &name ) :
48 wxPanel( aParent, aId, aPosition, aSize, style, name )
49{
50 SetFont( KIUI::GetStatusFont( this ) );
51 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
52
53 // informs wx not to paint the background itself as we will paint it later in erase()
54 SetBackgroundStyle( wxBG_STYLE_PAINT );
55
56 m_last_x = 0;
57
59
60 InvalidateBestSize();
61}
62
63
67
68
70{
71 wxFont font = KIUI::GetControlFont( this );
72 GetTextExtent( wxT( "W" ), &m_fontSize.x, &m_fontSize.y, 0, 0, &font );
73}
74
75
77{
78 return wxSize( wxDefaultCoord, 2 * m_fontSize.y + 0 );
79}
80
81
83{
84 return wxPanel::DoGetBestClientSize();
85}
86
87
88void EDA_MSG_PANEL::OnDPIChanged( wxDPIChangedEvent& aEvent )
89{
91 InvalidateBestSize();
92
93 aEvent.Skip();
94}
95
96
98{
99 m_last_x = 0;
100
101 for( MSG_PANEL_ITEM& item : m_Items )
102 updateItemPos( item );
103}
104
105
106void EDA_MSG_PANEL::OnSize( wxSizeEvent& aEvent )
107{
108 rebuildItems();
109}
110
111
112void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
113{
114 wxPaintDC dc( this );
115
116 erase( &dc );
117
118 dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
119 dc.SetBackgroundMode( wxSOLID );
120 dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
121 dc.SetFont( KIUI::GetControlFont( this ) );
122
123 for( const MSG_PANEL_ITEM& item : m_Items )
124 showItem( dc, item );
125
126 aEvent.Skip();
127}
128
129
131{
132 wxString text;
133 wxString upperText = item.GetUpperText();
134 wxString lowerText = item.GetLowerText();
135 wxSize drawSize = GetClientSize();
136
137 text = ( upperText.Len() > lowerText.Len() ) ? upperText : lowerText;
138 text.Append( ' ', item.GetPadding() );
139
140 /* Don't put the first message a window client position 0. Offset by
141 * one 'W' character width. */
142 if( m_last_x == 0 )
144
145 item.m_X = m_last_x;
146
147 item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
148 item.m_LowerY = drawSize.y - m_fontSize.y;
149
150 m_last_x += GetTextExtent( text ).x;
151
152 // Add an extra space between texts for a better look:
153 m_last_x += m_fontSize.x;
154}
155
156
157void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText, int aPadding )
158{
159 MSG_PANEL_ITEM item;
160
161 item.m_UpperText = aUpperText;
162 item.m_LowerText = aLowerText;
163
164 updateItemPos( item );
165 m_Items.push_back( item );
166
167 Refresh();
168}
169
170
171void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
172{
173 COLOR4D color;
174
175 // Change the text to a disabled color when the window isn't active
176 wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
177
178 if( tlw && !tlw->IsActive() )
179 color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
180 else
181 color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
182
183 aDC.SetTextForeground( color.ToColour() );
184
185 if( !aItem.m_UpperText.IsEmpty() )
186 aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
187
188 if( !aItem.m_LowerText.IsEmpty() )
189 aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
190}
191
192
194{
195 m_Items.clear();
196 m_last_x = 0;
197 Refresh();
198}
199
200
201void EDA_MSG_PANEL::erase( wxDC* aDC )
202{
203 wxPen pen;
204 wxBrush brush;
205
206 wxSize size = GetClientSize();
207 wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
208
209 pen.SetColour( color );
210
211 brush.SetColour( color );
212 brush.SetStyle( wxBRUSHSTYLE_SOLID );
213
214 aDC->SetPen( pen );
215 aDC->SetBrush( brush );
216 aDC->DrawRectangle( 0, 0, size.x, size.y );
217}
218
219
220std::optional<wxString> GetMsgPanelDisplayUuid( const KIID& aKiid )
221{
222 const static int showUuids = ADVANCED_CFG::GetCfg().m_MsgPanelShowUuids;
223 std::optional<wxString> uuid;
224
225 if( showUuids > 0 )
226 {
227 uuid = aKiid.AsString();
228
229 if( showUuids == 2 )
230 uuid = uuid->SubString( 0, 7 );
231 }
232
233 return uuid;
234}
const char * name
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 AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition msgpanel.cpp:157
void OnDPIChanged(wxDPIChangedEvent &aEvent)
Definition msgpanel.cpp:88
wxSize DoGetBestSize() const override
Definition msgpanel.cpp:76
void updateFontSize()
Definition msgpanel.cpp:69
int m_last_x
the last used x coordinate
Definition msgpanel.h:157
EDA_MSG_PANEL(wxWindow *aParent, int aId, const wxPoint &aPosition, const wxSize &aSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr)
Definition msgpanel.cpp:46
void EraseMsgBox()
Definition msgpanel.cpp:193
void updateItemPos(MSG_PANEL_ITEM &aItem)
Definition msgpanel.cpp:130
wxSize m_fontSize
Definition msgpanel.h:158
void rebuildItems()
Definition msgpanel.cpp:97
wxSize DoGetBestClientSize() const override
Definition msgpanel.cpp:82
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition msgpanel.cpp:171
std::vector< MSG_PANEL_ITEM > m_Items
Definition msgpanel.h:156
void OnPaint(wxPaintEvent &aEvent)
Definition msgpanel.cpp:112
void erase(wxDC *DC)
Definition msgpanel.cpp:201
void OnSize(wxSizeEvent &aEvent)
Definition msgpanel.cpp:106
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
wxColour ToColour() const
Definition color4d.cpp:225
Definition kiid.h:49
wxString AsString() const
Definition kiid.cpp:246
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:54
const wxString & GetUpperText() const
Definition msgpanel.h:77
const wxString & GetLowerText() const
Definition msgpanel.h:80
int GetPadding() const
Definition msgpanel.h:83
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:220
Message panel definition file.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
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.