kicad/common/msgpanel.cpp

192 lines
4.9 KiB
C++
Raw Normal View History

2007-10-03 19:45:32 +00:00
/******************************************************************/
/* msgpanel.cpp - fonctions des classes du type WinEDA_MsgPanel */
/******************************************************************/
2007-05-06 16:03:28 +00:00
#ifdef __GNUG__
#pragma implementation
#endif
#include "fctsys.h"
#include "wxstruct.h"
#include "common.h"
#include "colors.h"
2007-05-06 16:03:28 +00:00
/* table des evenements captes par un WinEDA_MsgPanel */
2007-10-03 19:45:32 +00:00
BEGIN_EVENT_TABLE( WinEDA_MsgPanel, wxPanel )
EVT_PAINT( WinEDA_MsgPanel::OnPaint )
2007-05-06 16:03:28 +00:00
END_EVENT_TABLE()
2007-10-03 19:45:32 +00:00
/***********************************************************/
/* Fonctions de base de WinEDA_MsgPanel: l'ecran de messages */
/***********************************************************/
2007-05-06 16:03:28 +00:00
2007-10-03 19:45:32 +00:00
WinEDA_MsgPanel::WinEDA_MsgPanel( WinEDA_DrawFrame* parent, int id,
const wxPoint& pos, const wxSize& size ) :
wxPanel( parent, id, pos, size )
2007-05-06 16:03:28 +00:00
{
2007-10-03 19:45:32 +00:00
m_Parent = parent;
SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
2008-03-31 13:46:00 +00:00
m_last_x = 0;
2007-05-06 16:03:28 +00:00
}
WinEDA_MsgPanel::~WinEDA_MsgPanel()
2007-05-06 16:03:28 +00:00
{
}
/*************************************************/
2007-10-03 19:45:32 +00:00
void WinEDA_MsgPanel::OnPaint( wxPaintEvent& event )
2007-05-06 16:03:28 +00:00
/*************************************************/
{
2007-10-03 19:45:32 +00:00
wxPaintDC dc( this );
2007-05-06 16:03:28 +00:00
2008-03-31 13:46:00 +00:00
erase( &dc );
2007-10-10 18:01:14 +00:00
dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
2007-10-10 18:01:14 +00:00
dc.SetBackgroundMode( wxSOLID );
dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
for( unsigned i=0; i<m_Items.size(); ++i )
showItem( dc, m_Items[i] );
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
event.Skip();
2007-05-06 16:03:28 +00:00
}
/*****************************************************************************/
2007-10-03 19:45:32 +00:00
void WinEDA_MsgPanel::Affiche_1_Parametre( int pos_X, const wxString& texte_H,
const wxString& texte_L, int color )
2007-05-06 16:03:28 +00:00
/*****************************************************************************/
2007-10-03 19:45:32 +00:00
2007-05-06 16:03:28 +00:00
/*
2007-10-03 19:45:32 +00:00
* Routine d'affichage d'un parametre.
* pos_X = cadrage horizontal
* si pos_X < 0 : la position horizontale est la derniere
* valeur demandee >= 0
* texte_H = texte a afficher en ligne superieure.
* si "", par d'affichage sur cette ligne
* texte_L = texte a afficher en ligne inferieure.
* si "", par d'affichage sur cette ligne
* color = couleur d'affichage
*/
2007-05-06 16:03:28 +00:00
{
2008-03-31 13:46:00 +00:00
wxPoint pos;
wxSize drawSize = GetClientSize();
2007-10-03 19:45:32 +00:00
2007-05-06 16:03:28 +00:00
2008-03-31 13:46:00 +00:00
// Get size of the font
wxSize fontSizeInPixels;
{
wxClientDC dc( this );
2007-10-03 19:45:32 +00:00
dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
2008-03-31 13:46:00 +00:00
dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
2007-10-03 19:45:32 +00:00
2008-03-31 13:46:00 +00:00
} // destroy wxClientDC ASAP
2007-10-03 19:45:32 +00:00
if( pos_X >= 0 )
{
2008-03-31 13:46:00 +00:00
m_last_x = pos.x = pos_X * (fontSizeInPixels.x + 2);
2007-10-03 19:45:32 +00:00
}
else
2008-03-31 13:46:00 +00:00
pos.x = m_last_x;
2007-10-03 19:45:32 +00:00
2007-10-10 18:01:14 +00:00
MsgItem item;
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
item.m_X = pos.x;
2008-03-31 13:46:00 +00:00
item.m_UpperY = (drawSize.y / 2) - fontSizeInPixels.y;
item.m_LowerY = drawSize.y - fontSizeInPixels.y;
2007-10-10 18:01:14 +00:00
item.m_UpperText = texte_H;
item.m_LowerText = texte_L;
item.m_Color = color;
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
int ndx;
2008-03-31 13:46:00 +00:00
// update the vector, which is sorted by m_X
2007-10-10 18:01:14 +00:00
int limit = m_Items.size();
for( ndx=0; ndx<limit; ++ndx )
2007-10-03 19:45:32 +00:00
{
2007-10-10 18:01:14 +00:00
// replace any item with same X
if( m_Items[ndx].m_X == item.m_X )
{
m_Items[ndx] = item;
break;
}
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
if( m_Items[ndx].m_X > item.m_X )
{
m_Items.insert( m_Items.begin()+ndx, item );
break;
}
2007-10-03 19:45:32 +00:00
}
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
if( ndx==limit ) // mutually exclusive with two above if tests
2007-10-03 19:45:32 +00:00
{
2007-10-10 18:01:14 +00:00
m_Items.push_back( item );
}
2008-03-31 13:46:00 +00:00
Refresh();
2007-10-10 18:01:14 +00:00
}
void WinEDA_MsgPanel::showItem( wxDC& dc, const MsgItem& aItem )
2007-10-10 18:01:14 +00:00
{
int color = aItem.m_Color;
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
if( color >= 0 )
{
color &= MASKCOLOR;
2008-03-31 13:46:00 +00:00
dc.SetTextForeground( wxColour( ColorRefs[color].m_Red,
2007-10-10 18:01:14 +00:00
ColorRefs[color].m_Green,
ColorRefs[color].m_Blue ) );
}
if( !aItem.m_UpperText.IsEmpty() )
{
dc.DrawText( aItem.m_UpperText.GetData(), aItem.m_X, aItem.m_UpperY );
}
2008-03-31 13:46:00 +00:00
2007-10-10 18:01:14 +00:00
if( !aItem.m_LowerText.IsEmpty() )
{
dc.DrawText( aItem.m_LowerText.GetData(), aItem.m_X, aItem.m_LowerY );
2007-10-03 19:45:32 +00:00
}
2007-05-06 16:03:28 +00:00
}
2007-10-03 19:45:32 +00:00
2007-05-06 16:03:28 +00:00
/****************************************/
void WinEDA_MsgPanel::EraseMsgBox()
2007-05-06 16:03:28 +00:00
/****************************************/
{
2008-03-31 13:46:00 +00:00
m_Items.clear();
m_last_x = 0;
Refresh();
2007-05-06 16:03:28 +00:00
}
/*******************************************/
2008-03-31 13:46:00 +00:00
void WinEDA_MsgPanel::erase( wxDC* DC )
2007-05-06 16:03:28 +00:00
/*******************************************/
{
2007-10-03 19:45:32 +00:00
wxPen pen;
wxBrush brush;
2008-03-31 13:46:00 +00:00
wxSize size = GetClientSize();
wxColor color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
2008-03-31 13:46:00 +00:00
2007-10-03 19:45:32 +00:00
pen.SetColour( color );
2008-03-31 13:46:00 +00:00
2007-10-03 19:45:32 +00:00
brush.SetColour( color );
brush.SetStyle( wxSOLID );
2008-03-31 13:46:00 +00:00
2007-10-03 19:45:32 +00:00
DC->SetPen( pen );
DC->SetBrush( brush );
DC->DrawRectangle( 0, 0, size.x, size.y );
2007-05-06 16:03:28 +00:00
}