Commit fb9e1ea0 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Make drawframe.cpp's StatusBar use field widths which are dynamically determined

base on expected text and current window font.

Expand the virtual world to 2.14 meters in the nanometer build of PCBNEW.
This seems to be holding up for now.
parent 86e04b4f
...@@ -135,6 +135,21 @@ void SetLocaleTo_Default() ...@@ -135,6 +135,21 @@ void SetLocaleTo_Default()
} }
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow )
{
wxCoord width;
wxCoord height;
{
wxClientDC dc( aWindow );
dc.SetFont( aWindow->GetFont() );
dc.GetTextExtent( aSingleLine, &width, &height );
}
return wxSize( width, height );
}
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString ) bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
{ {
wxWindow* window = aCtrl->GetParent(); wxWindow* window = aCtrl->GetParent();
...@@ -150,21 +165,13 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString ) ...@@ -150,21 +165,13 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
aString = &ctrlText; aString = &ctrlText;
} }
wxCoord width; wxSize textz = GetTextSize( *aString, window );
wxCoord height; wxSize ctrlz = aCtrl->GetSize();
{
wxClientDC dc( window );
dc.SetFont( aCtrl->GetFont() );
dc.GetTextExtent( *aString, &width, &height );
}
wxSize size = aCtrl->GetSize();
if( size.GetWidth() < width + 10 ) if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
{ {
size.SetWidth( width + 10 ); ctrlz.SetWidth( textz.GetWidth() + 10 );
aCtrl->SetSizeHints( size ); aCtrl->SetSizeHints( ctrlz );
return true; return true;
} }
......
...@@ -88,8 +88,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& ti ...@@ -88,8 +88,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& ti
const wxPoint& pos, const wxSize& size, long style ) : const wxPoint& pos, const wxSize& size, long style ) :
EDA_BASE_FRAME( father, idtype, title, pos, size, style ) EDA_BASE_FRAME( father, idtype, title, pos, size, style )
{ {
wxSize minsize;
m_drawToolBar = NULL; m_drawToolBar = NULL;
m_optionsToolBar = NULL; m_optionsToolBar = NULL;
m_gridSelectBox = NULL; m_gridSelectBox = NULL;
...@@ -110,27 +108,43 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& ti ...@@ -110,27 +108,43 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& ti
m_GridColor = DARKGRAY; // Grid color m_GridColor = DARKGRAY; // Grid color
m_snapToGrid = true; m_snapToGrid = true;
// Internal units per inch: = 1000 for schema, = 10000 for PCB //#define ZOOM_DISPLAY_SIZE 60
minsize.x = 470; //#define COORD_DISPLAY_SIZE 165
minsize.y = 350 + m_MsgFrameHeight; //#define DELTA_DISPLAY_SIZE 245
//#define UNITS_DISPLAY_SIZE 65
// Pane sizes for status bar.
// @todo these should be sized based on typical text content, like
// "dx -10.123 -10.123 dy -10.123 -10.123" using the system font which is
// in play on a particular platform, and should not be constants.
// Please do not reduce these constant values, and please use dynamic
// system font specific sizing in the future.
#define ZOOM_DISPLAY_SIZE 60
#define COORD_DISPLAY_SIZE 165
#define DELTA_DISPLAY_SIZE 245
#define UNITS_DISPLAY_SIZE 65
#define FUNCTION_DISPLAY_SIZE 110 #define FUNCTION_DISPLAY_SIZE 110
static const int dims[6] = { -1, ZOOM_DISPLAY_SIZE,
COORD_DISPLAY_SIZE, DELTA_DISPLAY_SIZE,
UNITS_DISPLAY_SIZE, FUNCTION_DISPLAY_SIZE };
CreateStatusBar( 6 ); CreateStatusBar( 6 );
SetStatusWidths( 6, dims );
// set the size of the status bar subwindows:
wxWindow* stsbar = GetStatusBar();
int dims[] = {
// balance of status bar on far left is set to a default or whatever is left over.
-1,
// When using GetTextSize() remember the width of '1' is not the same
// as the width of '0' unless the font is fixed width, and it usually won't be.
// zoom:
GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
// cursor coords
GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
// delta distances
GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
// units display, Inches is bigger than mm
GetTextSize( wxT( "Inches" ), stsbar ).x + 10,
FUNCTION_DISPLAY_SIZE,
};
SetStatusWidths( DIM( dims ), dims );
// Create child subwindows. // Create child subwindows.
GetClientSize( &m_FrameSize.x, &m_FrameSize.y ); GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
...@@ -660,10 +674,12 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosi ...@@ -660,10 +674,12 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosi
return true; return true;
} }
#define SAFETY_MARGIN 100
// see comment in classpcb.cpp near line 66 // See comment in classpcb.cpp near line 66
static const double MAX_AXIS = 1518500251 - SAFETY_MARGIN; //static const double MAX_AXIS = 1518500251;
// However I am not seeing a problem with this size yet:
static const double MAX_AXIS = INT_MAX - 100;
#define VIRT_MIN (-MAX_AXIS/2.0) ///< min X or Y coordinate in virtual space #define VIRT_MIN (-MAX_AXIS/2.0) ///< min X or Y coordinate in virtual space
#define VIRT_MAX (MAX_AXIS/2.0) ///< max X or Y coordinate in virtual space #define VIRT_MAX (MAX_AXIS/2.0) ///< max X or Y coordinate in virtual space
......
...@@ -525,6 +525,13 @@ private: ...@@ -525,6 +525,13 @@ private:
}; };
/**
* Function GetTextSize
* returns the size of @a aSingleLine of text when it is rendered in @a aWindow
* using whatever font is currently set in that window.
*/
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
/** /**
* Function EnsureTextCtrlWidth * Function EnsureTextCtrlWidth
* sets the minimum pixel width on a text control in order to make a text * sets the minimum pixel width on a text control in order to make a text
......
...@@ -568,6 +568,15 @@ void PCB_BASE_FRAME::UpdateStatusBar() ...@@ -568,6 +568,15 @@ void PCB_BASE_FRAME::UpdateStatusBar()
wxString formatter; wxString formatter;
switch( g_UserUnit ) switch( g_UserUnit )
{ {
#if defined( USE_PCBNEW_NANOMETRE )
case INCHES:
formatter = wxT( "Ro %.6f Th %.1f" );
break;
case MILLIMETRES:
formatter = wxT( "Ro %.6f Th %.1f" );
break;
#else
case INCHES: case INCHES:
formatter = wxT( "Ro %.4f Th %.1f" ); formatter = wxT( "Ro %.4f Th %.1f" );
break; break;
...@@ -575,6 +584,7 @@ void PCB_BASE_FRAME::UpdateStatusBar() ...@@ -575,6 +584,7 @@ void PCB_BASE_FRAME::UpdateStatusBar()
case MILLIMETRES: case MILLIMETRES:
formatter = wxT( "Ro %.3f Th %.1f" ); formatter = wxT( "Ro %.3f Th %.1f" );
break; break;
#endif
case UNSCALED_UNITS: case UNSCALED_UNITS:
formatter = wxT( "Ro %f Th %f" ); formatter = wxT( "Ro %f Th %f" );
...@@ -601,6 +611,17 @@ void PCB_BASE_FRAME::UpdateStatusBar() ...@@ -601,6 +611,17 @@ void PCB_BASE_FRAME::UpdateStatusBar()
switch( g_UserUnit ) switch( g_UserUnit )
{ {
#if defined( USE_PCBNEW_NANOMETRES )
case INCHES:
absformatter = wxT( "X %.6f Y %.6f" );
locformatter = wxT( "dx %.6f dy %.6f d %.6f" );
break;
case MILLIMETRES:
absformatter = wxT( "X %.6f Y %.6f" );
locformatter = wxT( "dx %.6f dy %.6f d %.6f" );
break;
#else
case INCHES: case INCHES:
absformatter = wxT( "X %.4f Y %.4f" ); absformatter = wxT( "X %.4f Y %.4f" );
locformatter = wxT( "dx %.4f dy %.4f d %.4f" ); locformatter = wxT( "dx %.4f dy %.4f d %.4f" );
...@@ -610,6 +631,7 @@ void PCB_BASE_FRAME::UpdateStatusBar() ...@@ -610,6 +631,7 @@ void PCB_BASE_FRAME::UpdateStatusBar()
absformatter = wxT( "X %.3f Y %.3f" ); absformatter = wxT( "X %.3f Y %.3f" );
locformatter = wxT( "dx %.3f dy %.3f d %.3f" ); locformatter = wxT( "dx %.3f dy %.3f d %.3f" );
break; break;
#endif
case UNSCALED_UNITS: case UNSCALED_UNITS:
absformatter = wxT( "X %f Y %f" ); absformatter = wxT( "X %f Y %f" );
......
...@@ -62,7 +62,6 @@ static const double pcbZoomList[] = ...@@ -62,7 +62,6 @@ static const double pcbZoomList[] =
ZOOM_FACTOR( 300.0 ), ZOOM_FACTOR( 300.0 ),
/* /*
The largest distance that wx can support is INT_MAX, since it represents The largest distance that wx can support is INT_MAX, since it represents
distance often in a wxCoord or wxSize. As a scalar, a distance is always distance often in a wxCoord or wxSize. As a scalar, a distance is always
positive. On most machines which run KiCad, int is 32 bits and INT_MAX is positive. On most machines which run KiCad, int is 32 bits and INT_MAX is
...@@ -148,10 +147,8 @@ static GRID_TYPE pcbGridList[] = ...@@ -148,10 +147,8 @@ static GRID_TYPE pcbGridList[] =
PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
BASE_SCREEN( SCREEN_T ) BASE_SCREEN( SCREEN_T )
{ {
wxSize displayz = wxGetDisplaySize(); // D(wxSize displayz = wxGetDisplaySize();)
// D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
for( unsigned i = 0; i < DIM( pcbZoomList ); ++i ) for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
m_ZoomList.push_back( pcbZoomList[i] ); m_ZoomList.push_back( pcbZoomList[i] );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment