Fix formatting from simulator X/Y zoom changes

This commit is contained in:
ecorm 2024-01-29 23:59:12 -04:00 committed by Jeff Young
parent 16de0a666c
commit 4dcd1fb8e2
6 changed files with 84 additions and 98 deletions

View File

@ -1366,15 +1366,14 @@ EVT_MENU( mpID_ZOOM_UNDO, mpWindow::onZoomUndo )
EVT_MENU( mpID_ZOOM_REDO, mpWindow::onZoomRedo )
END_EVENT_TABLE()
mpWindow::mpWindow() :
mpWindow( DelegatingContructorTag() )
mpWindow::mpWindow() : mpWindow( DelegatingContructorTag() )
{
initializeGraphicsContext();
}
mpWindow::mpWindow( wxWindow* parent, wxWindowID id ) :
mpWindow( DelegatingContructorTag(),
parent, id, wxDefaultPosition, wxDefaultSize, 0, wxT( "mathplot" ) )
mpWindow( DelegatingContructorTag(), parent, id, wxDefaultPosition, wxDefaultSize, 0,
wxT( "mathplot" ) )
{
m_popmenu.Append( mpID_ZOOM_UNDO, _( "Undo Last Zoom" ), _( "Return zoom to level prior to last zoom action" ) );
m_popmenu.Append( mpID_ZOOM_REDO, _( "Redo Last Zoom" ), _( "Return zoom to level prior to last zoom undo" ) );
@ -1618,9 +1617,8 @@ void mpWindow::Fit()
// JL
void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax,
const wxCoord* printSizeX, const wxCoord* printSizeY,
wxOrientation directions )
void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax, const wxCoord* printSizeX,
const wxCoord* printSizeY, wxOrientation directions )
{
const bool isPrinting = printSizeX != nullptr && printSizeY != nullptr;
@ -1661,19 +1659,19 @@ void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax,
// Adjust scale so that desired X/Y span plus extra gap fits in the plot area
double desiredSpanX = xMax - xMin;
double desiredSpanY = yMax - yMin;
double newScaleX = (desiredSpanX != 0) ? double(plotScreenWidth) / desiredSpanX : 1;
double newScaleY = (desiredSpanY != 0) ? double(plotScreenHeight) / desiredSpanY : 1;
double newScaleX = ( desiredSpanX != 0 ) ? double( plotScreenWidth ) / desiredSpanX : 1;
double newScaleY = ( desiredSpanY != 0 ) ? double( plotScreenHeight ) / desiredSpanY : 1;
// Adjust corner coordinates:
// Upstream's aspect lock code has been removed, so no need to account for centering.
double newPosX = xMin - (m_marginLeft / newScaleX);
double newPosY = yMax + (m_marginTop / newScaleY);
double newPosX = xMin - ( m_marginLeft / newScaleX );
double newPosY = yMax + ( m_marginTop / newScaleY );
// Commit above changes to member variables only if enabled for their respective dimension.
if( ((directions & wxHORIZONTAL) != 0) || isPrinting )
if( ( ( directions & wxHORIZONTAL ) != 0 ) || isPrinting )
{
// Don't commit the passed desired bounds when printing
if (!isPrinting)
if( !isPrinting )
{
m_desiredXmin = newDesiredXmin;
m_desiredXmax = newDesiredXmax;
@ -1684,10 +1682,10 @@ void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax,
m_posX = newPosX;
}
if( ((directions & wxVERTICAL) != 0) || isPrinting )
if( ( ( directions & wxVERTICAL ) != 0 ) || isPrinting )
{
// Don't commit the passed desired bounds when printing
if (!isPrinting)
if( !isPrinting )
{
m_desiredYmin = newDesiredYmin;
m_desiredYmax = newDesiredYmax;
@ -1715,7 +1713,7 @@ void mpWindow::AdjustLimitedView( wxOrientation directions )
// The m_desired* members are expressed in plot coordinates.
// They should be clamped against their respective m_minX, m_maxX, m_minY, m_maxY limits.
if( (directions & wxHORIZONTAL) != 0 )
if( ( directions & wxHORIZONTAL ) != 0 )
{
if( m_desiredXmin < m_minX )
{
@ -1734,7 +1732,7 @@ void mpWindow::AdjustLimitedView( wxOrientation directions )
}
}
if( (directions & wxVERTICAL) != 0 )
if( ( directions & wxVERTICAL ) != 0 )
{
if( m_desiredYmin < m_minY )
{
@ -1798,10 +1796,9 @@ void mpWindow::ZoomOut( const wxPoint& centerPoint )
}
void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor,
wxOrientation directions )
void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions )
{
if (zoomFactor == 0)
if( zoomFactor == 0 )
zoomFactor = 1.0;
DoZoom( centerPoint, 1.0 / zoomFactor, directions );
}
@ -2082,8 +2079,7 @@ void mpWindow::OnPaint( wxPaintEvent& WXUNUSED( event ) )
paintDC.Blit( 0, 0, m_scrX, m_scrY, targetDC, 0, 0 );
}
void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor,
wxOrientation directions )
void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions )
{
if( m_yLocked )
{
@ -2092,8 +2088,8 @@ void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor,
directions = wxHORIZONTAL;
}
const bool horizontally = (directions & wxHORIZONTAL) != 0;
const bool vertically = (directions & wxVERTICAL) != 0;
const bool horizontally = ( directions & wxHORIZONTAL ) != 0;
const bool vertically = ( directions & wxVERTICAL ) != 0;
pushZoomUndo( { m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax } );
@ -2102,8 +2098,8 @@ void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor,
if( c == wxDefaultPosition )
{
GetClientSize( &m_scrX, &m_scrY );
c.x = (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft;
c.y = (m_scrY - m_marginTop - m_marginBottom) / 2 + m_marginTop;
c.x = ( m_scrX - m_marginLeft - m_marginRight ) / 2 + m_marginLeft;
c.y = ( m_scrY - m_marginTop - m_marginBottom ) / 2 + m_marginTop;
}
else
{
@ -2115,14 +2111,14 @@ void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor,
// Zoom in/out:
const double MAX_SCALE = 1e6;
const double newScaleX = horizontally ? (m_scaleX * zoomFactor) : m_scaleX;
const double newScaleY = vertically ? (m_scaleY * zoomFactor) : m_scaleY;
const double newScaleX = horizontally ? ( m_scaleX * zoomFactor ) : m_scaleX;
const double newScaleY = vertically ? ( m_scaleY * zoomFactor ) : m_scaleY;
// Baaaaad things happen when you zoom in too much..
if( newScaleX > MAX_SCALE || newScaleY > MAX_SCALE )
return;
if ( horizontally )
if( horizontally )
{
// Transform the clicked X point to layer coordinates:
const double prior_layer_x = p2x( c.x );
@ -2135,7 +2131,7 @@ void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor,
RecomputeDesiredX( m_desiredXmin, m_desiredXmax );
}
if ( vertically )
if( vertically )
{
// Transform the clicked Y point to layer coordinates:
const double prior_layer_y = p2y( c.y );
@ -2150,7 +2146,7 @@ void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor,
AdjustLimitedView( directions );
if (zoomFactor < 1.0)
if( zoomFactor < 1.0 )
{
// These additional checks are needed because AdjustLimitedView only adjusts the position
// and not the scale.
@ -2170,7 +2166,7 @@ void mpWindow::RecomputeDesiredX( double& min, double& max )
{
const int plotScreenWidth = m_scrX - m_marginLeft - m_marginRight;
const double plotSpanX = plotScreenWidth / m_scaleX;
const double desiredSpanX = plotSpanX / ( 2*m_leftRightPlotGapFactor + 1 );
const double desiredSpanX = plotSpanX / ( 2 * m_leftRightPlotGapFactor + 1 );
const double xGap = desiredSpanX * m_leftRightPlotGapFactor;
min = m_posX + ( m_marginLeft / m_scaleX ) + xGap;
max = m_desiredXmin + desiredSpanX;
@ -2181,9 +2177,9 @@ void mpWindow::RecomputeDesiredY( double& min, double& max )
{
const int plotScreenHeight = m_scrY - m_marginTop - m_marginBottom;
const double plotSpanY = plotScreenHeight / m_scaleY;
const double desiredSpanY = plotSpanY / ( 2*m_topBottomPlotGapFactor + 1 );
const double desiredSpanY = plotSpanY / ( 2 * m_topBottomPlotGapFactor + 1 );
const double yGap = desiredSpanY * m_topBottomPlotGapFactor;
max = m_posY - ( m_marginTop / m_scaleY) - yGap;
max = m_posY - ( m_marginTop / m_scaleY ) - yGap;
min = m_desiredYmax - desiredSpanY;
}
@ -2200,15 +2196,15 @@ wxOrientation mpWindow::ViewNeedsRefitting( wxOrientation directions ) const
wxOrientation result = {};
if ( (directions & wxHORIZONTAL) != 0 )
if( ( directions & wxHORIZONTAL ) != 0 )
{
if ( ( m_desiredXmax > m_maxX + xGap ) || ( m_desiredXmin < m_minX - xGap ) )
if( ( m_desiredXmax > m_maxX + xGap ) || ( m_desiredXmin < m_minX - xGap ) )
result = static_cast<wxOrientation>( result | wxHORIZONTAL );
}
if ( (directions & wxVERTICAL) != 0 )
if( ( directions & wxVERTICAL ) != 0 )
{
if ( ( m_desiredYmax > m_maxY + yGap ) || ( m_desiredYmin < m_minY - yGap ) )
if( ( m_desiredYmax > m_maxY + yGap ) || ( m_desiredYmin < m_minY - yGap ) )
result = static_cast<wxOrientation>( result | wxVERTICAL );
}
@ -2223,10 +2219,9 @@ void mpWindow::PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction ac
const double changeUnitsY = change / m_scaleY;
const wxPoint clickPt( event.GetX(), event.GetY() );
switch (action)
switch( action )
{
case MouseWheelAction::NONE:
break;
case MouseWheelAction::NONE: break;
case MouseWheelAction::PAN_LEFT_RIGHT:
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
@ -2270,8 +2265,7 @@ void mpWindow::PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction ac
ZoomOut( clickPt, zoomIncrementalFactor, wxVERTICAL );
break;
default:
break;
default: break;
}
}

View File

@ -551,37 +551,31 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
m_params.emplace_back( new PARAM_ENUM<SIM_MOUSE_WHEEL_ACTION>(
"simulator.mouse_wheel_actions.vertical_unmodified",
&m_Simulator.preferences.mouse_wheel_actions.vertical_unmodified,
SIM_MOUSE_WHEEL_ACTION::ZOOM,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM, SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY ) );
m_params.emplace_back( new PARAM_ENUM<SIM_MOUSE_WHEEL_ACTION>(
"simulator.mouse_wheel_actions.vertical_with_ctrl",
&m_Simulator.preferences.mouse_wheel_actions.vertical_with_ctrl,
SIM_MOUSE_WHEEL_ACTION::PAN_LEFT_RIGHT,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::PAN_LEFT_RIGHT, SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY ) );
m_params.emplace_back( new PARAM_ENUM<SIM_MOUSE_WHEEL_ACTION>(
"simulator.mouse_wheel_actions.vertical_with_shift",
&m_Simulator.preferences.mouse_wheel_actions.vertical_with_shift,
SIM_MOUSE_WHEEL_ACTION::PAN_UP_DOWN,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY) );
SIM_MOUSE_WHEEL_ACTION::PAN_UP_DOWN, SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY ) );
m_params.emplace_back( new PARAM_ENUM<SIM_MOUSE_WHEEL_ACTION>(
"simulator.mouse_wheel_actions.vertical_with_alt",
&m_Simulator.preferences.mouse_wheel_actions.vertical_with_alt,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY) );
SIM_MOUSE_WHEEL_ACTION::NONE, SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY ) );
m_params.emplace_back( new PARAM_ENUM<SIM_MOUSE_WHEEL_ACTION>(
"simulator.mouse_wheel_actions.horizontal",
&m_Simulator.preferences.mouse_wheel_actions.horizontal,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY) );
&m_Simulator.preferences.mouse_wheel_actions.horizontal, SIM_MOUSE_WHEEL_ACTION::NONE,
SIM_MOUSE_WHEEL_ACTION::NONE, SIM_MOUSE_WHEEL_ACTION::ZOOM_VERTICALLY ) );
m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_h",
&m_SymChooserPanel.sash_pos_h, -1 ) );

View File

@ -197,8 +197,7 @@ public:
void ApplyPreferences( const SIM_PREFERENCES& aPrefs ) override
{
m_plotWin->SetMouseWheelActions(
convertMouseWheelActions( aPrefs.mouse_wheel_actions ) );
m_plotWin->SetMouseWheelActions( convertMouseWheelActions( aPrefs.mouse_wheel_actions ) );
}
wxString GetLabelX() const
@ -366,10 +365,10 @@ public:
private:
static mpWindow::MouseWheelActionSet
convertMouseWheelActions(const SIM_MOUSE_WHEEL_ACTION_SET& s)
convertMouseWheelActions( const SIM_MOUSE_WHEEL_ACTION_SET& s )
{
static_assert( static_cast<unsigned>(mpWindow::MouseWheelAction::COUNT) ==
static_cast<unsigned>(SIM_MOUSE_WHEEL_ACTION::COUNT),
static_assert( static_cast<unsigned>( mpWindow::MouseWheelAction::COUNT )
== static_cast<unsigned>( SIM_MOUSE_WHEEL_ACTION::COUNT ),
"mpWindow::MouseWheelAction enum must match SIM_MOUSE_WHEEL_ACTION" );
using A = mpWindow::MouseWheelAction;

View File

@ -637,7 +637,7 @@ void SIMULATOR_FRAME_UI::ApplyPreferences( const SIM_PREFERENCES& aPrefs )
m_preferences = aPrefs;
const std::size_t pageCount = m_plotNotebook->GetPageCount();
for( std::size_t i = 0; i<pageCount; ++i )
for( std::size_t i = 0; i < pageCount; ++i )
{
wxWindow* page = m_plotNotebook->GetPage( i );
auto simTab = dynamic_cast<SIM_TAB*>( page );

View File

@ -1101,7 +1101,7 @@ public:
void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
/** Set the pan/zoom actions corresponding to mousewheel/trackpad events. */
void SetMouseWheelActions( const MouseWheelActionSet& s ) {m_mouseWheelActions = s;}
void SetMouseWheelActions( const MouseWheelActionSet& s ) { m_mouseWheelActions = s; }
/** Set view to fit global bounding box of all plot layers and refresh display.
* Scale and position will be set to show all attached mpLayers.
@ -1124,8 +1124,7 @@ public:
* position on the screen after the zoom (by default, the center of the mpWindow).
*/
void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
void ZoomIn( const wxPoint& centerPoint, double zoomFactor,
wxOrientation directions = wxBOTH );
void ZoomIn( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions = wxBOTH );
/** Zoom out current view and refresh display
* @param centerPoint The point (pixel coordinates) that will stay in the same