Commit aab2f8a7 authored by stambaughw's avatar stambaughw

USE_WX_ZOOM clean up and other minor improvements.

* Make USE_WX_ZOOM clipping routine actually clip rather than just test
  if line needs drawn.
* Clean up as many USE_WX_ZOOM #ifdefs as possible.
* Minor coordinate rounding improvements.
* Minor scrolling and panning improvements.
* Remove unused KicadGraphicContext object code.
parent 1da3a164
......@@ -22,6 +22,12 @@
#include <wx/fontdlg.h>
/* Definitions for enabling and disabling extra debugging output. Please
* remember to set these to 0 before committing changes to SVN.
*/
#define DEBUG_DUMP_SCROLLBAR_SETTINGS 0 // Set to 1 to print scroll bar settings.
/* Configuration entry names. */
static const wxString CursorShapeEntryKeyword( wxT( "CursorShape" ) );
static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) );
......@@ -446,6 +452,7 @@ void WinEDA_DrawFrame::AdjustScrollBars()
int unitsX, unitsY, posX, posY;
wxSize drawingSize, clientSize;
BASE_SCREEN* screen = GetBaseScreen();
bool noRefresh = true;
if( screen == NULL || DrawPanel == NULL )
return;
......@@ -457,30 +464,27 @@ void WinEDA_DrawFrame::AdjustScrollBars()
// client area at the current zoom level.
clientSize = DrawPanel->GetClientSize();
#ifdef USE_WX_ZOOM
INSTALL_DC( dc, DrawPanel );
clientSize.x = dc.DeviceToLogicalXRel( clientSize.x );
clientSize.y = dc.DeviceToLogicalYRel( clientSize.y );
#else
screen->Unscale( clientSize );
#endif
double scalar = screen->GetScalingFactor();
clientSize.x = wxRound( (double) clientSize.x / scalar );
clientSize.y = wxRound( (double) clientSize.y / scalar );
/* Adjust drawing size when zooming way out to prevent centering around
* cursor problems. */
if( clientSize.x > drawingSize.x || clientSize.y > drawingSize.y )
drawingSize = clientSize;
drawingSize += clientSize / 2;
drawingSize.x += wxRound( (double) clientSize.x / 2.0 );
drawingSize.y += wxRound( (double) clientSize.y / 2.0 );
if( screen->m_Center )
{
screen->m_DrawOrg.x = -drawingSize.x / 2;
screen->m_DrawOrg.y = -drawingSize.y / 2;
screen->m_DrawOrg.x = -wxRound( (double) drawingSize.x / 2.0 );
screen->m_DrawOrg.y = -wxRound( (double) drawingSize.y / 2.0 );
}
else
{
screen->m_DrawOrg.x = -clientSize.x / 2;
screen->m_DrawOrg.y = -clientSize.y / 2;
screen->m_DrawOrg.x = -wxRound( (double) clientSize.x / 2.0 );
screen->m_DrawOrg.y = -wxRound( (double) clientSize.y / 2.0 );
}
/* Always set scrollbar pixels per unit to 1 unless you want the zoom
......@@ -492,41 +496,32 @@ void WinEDA_DrawFrame::AdjustScrollBars()
screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1;
// Calculate the number of scroll bar units for the given zoom level. */
#ifdef USE_WX_ZOOM
unitsX = dc.LogicalToDeviceXRel( drawingSize.x );
unitsY = dc.LogicalToDeviceYRel( drawingSize.y );
#else
unitsX = screen->Scale( drawingSize.x );
unitsY = screen->Scale( drawingSize.y );
#endif
unitsX = wxRound( (double) drawingSize.x * scalar );
unitsY = wxRound( (double) drawingSize.y * scalar );
// Calculate the position, place the cursor at the center of screen.
posX = screen->m_Curseur.x - screen->m_DrawOrg.x;
posY = screen->m_Curseur.y - screen->m_DrawOrg.y;
posX -= clientSize.x / 2;
posY -= clientSize.y / 2;
posX -= wxRound( (double) clientSize.x / 2.0 );
posY -= wxRound( (double) clientSize.y / 2.0 );
if( posX <= 0 )
if( posX < 0 )
posX = 0;
if( posY <= 0 )
if( posY < 0 )
posY = 0;
#ifdef USE_WX_ZOOM
posX = dc.LogicalToDeviceXRel( posX );
posY = dc.LogicalToDeviceYRel( posY );
#else
posX = screen->Scale( posX );
posY = screen->Scale( posY );
#endif
posX = wxRound( (double) posX * scalar );
posY = wxRound( (double) posY * scalar );
screen->m_ScrollbarPos = wxPoint( posX, posY );
screen->m_ScrollbarNumber = wxSize( unitsX, unitsY );
#if 0
#if DEBUG_DUMP_SCROLLBAR_SETTINGS
wxLogDebug( wxT( "SetScrollbars(%d, %d, %d, %d, %d, %d)" ),
m_ScrollPixelsPerUnitX, m_ScrollPixelsPerUnitY,
unitsX, unitsY, posX, posY );
screen->m_ScrollPixelsPerUnitX, screen->m_ScrollPixelsPerUnitY,
screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y,
screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y );
#endif
DrawPanel->SetScrollbars( screen->m_ScrollPixelsPerUnitX,
......@@ -534,7 +529,7 @@ void WinEDA_DrawFrame::AdjustScrollBars()
screen->m_ScrollbarNumber.x,
screen->m_ScrollbarNumber.y,
screen->m_ScrollbarPos.x,
screen->m_ScrollbarPos.y, TRUE );
screen->m_ScrollbarPos.y, noRefresh );
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -54,11 +54,11 @@ void WinEDA_DrawFrame::PutOnGrid( wxPoint* coord )
if( !GetBaseScreen()->m_UserGridIsON )
{
int tmp = wxRound( coord->x / grid_size.x );
coord->x = wxRound( tmp * grid_size.x );
int tmp = wxRound( (double) coord->x / grid_size.x );
coord->x = wxRound( (double) tmp * grid_size.x );
tmp = wxRound( coord->y / grid_size.y );
coord->y = wxRound( tmp * grid_size.y );
tmp = wxRound( (double) coord->y / grid_size.y );
coord->y = wxRound( (double) tmp * grid_size.y );
}
}
......
......@@ -211,6 +211,7 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )
wxRealPoint delta;
int flagcurseur = 0;
wxPoint curpos, oldpos;
double scalar = GetScreen()->GetScalingFactor();
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this );
......@@ -219,13 +220,8 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )
delta = GetScreen()->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( wxRound( delta.x ) );
delta.y = DC->LogicalToDeviceYRel( wxRound( delta.y ) );
Mouse = DrawPanel->CalcUnscrolledPosition( Mouse );
#else
GetScreen()->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x <= 0 )
delta.x = 1;
......
......@@ -216,13 +216,13 @@ SCH_ITEM* WinEDA_SchematicFrame::SchematicGeneralLocateAndDisplay(
}
void WinEDA_SchematicFrame::GeneralControle( wxDC* DC,
wxPoint MousePositionInPixels )
void WinEDA_SchematicFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels )
{
wxRealPoint delta;
SCH_SCREEN* screen = GetScreen();
wxPoint curpos, oldpos;
int hotkey = 0;
double scalar = screen->GetScalingFactor();
ActiveScreen = screen;
......@@ -231,13 +231,8 @@ void WinEDA_SchematicFrame::GeneralControle( wxDC* DC,
delta = screen->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( wxRound( delta.x ) );
delta.y = DC->LogicalToDeviceYRel( wxRound( delta.y ) );
MousePositionInPixels = DrawPanel->CalcUnscrolledPosition( MousePositionInPixels );
#else
screen->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x <= 0 )
delta.x = 1;
......@@ -317,13 +312,13 @@ void WinEDA_SchematicFrame::GeneralControle( wxDC* DC,
}
void WinEDA_LibeditFrame::GeneralControle( wxDC* DC,
wxPoint MousePositionInPixels )
void WinEDA_LibeditFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels )
{
wxRealPoint delta;
SCH_SCREEN* screen = GetScreen();
wxPoint curpos, oldpos;
int hotkey = 0;
double scalar = screen->GetScalingFactor();
ActiveScreen = screen;
......@@ -332,13 +327,8 @@ void WinEDA_LibeditFrame::GeneralControle( wxDC* DC,
delta = screen->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( wxRound( delta.x ) );
delta.y = DC->LogicalToDeviceYRel( wxRound( delta.y ) );
MousePositionInPixels = DrawPanel->CalcUnscrolledPosition( MousePositionInPixels );
#else
screen->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x <= 0 )
delta.x = 1;
......@@ -417,13 +407,13 @@ void WinEDA_LibeditFrame::GeneralControle( wxDC* DC,
}
void WinEDA_ViewlibFrame::GeneralControle( wxDC* DC,
wxPoint MousePositionInPixels )
void WinEDA_ViewlibFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels )
{
wxRealPoint delta;
SCH_SCREEN* screen = GetScreen();
wxPoint curpos, oldpos;
int hotkey = 0;
double scalar = screen->GetScalingFactor();
ActiveScreen = screen;
......@@ -432,13 +422,8 @@ void WinEDA_ViewlibFrame::GeneralControle( wxDC* DC,
delta = screen->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( wxRound( delta.x ) );
delta.y = DC->LogicalToDeviceYRel( wxRound( delta.y ) );
MousePositionInPixels = DrawPanel->CalcUnscrolledPosition( MousePositionInPixels );
#else
screen->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x <= 0 )
delta.x = 1;
......
......@@ -38,18 +38,15 @@ void WinEDA_GerberFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
return;
}
double scalar = GetScreen()->GetScalingFactor();
curpos = DrawPanel->CursorRealPosition( Mouse );
oldpos = GetScreen()->m_Curseur;
delta = GetScreen()->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( delta.x );
delta.y = DC->LogicalToDeviceYRel( delta.y );
Mouse = DrawPanel->CalcUnscrolledPosition( Mouse );
#else
GetScreen()->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x == 0 )
delta.x = 1;
......
......@@ -25,15 +25,6 @@
#include <wx/dcgraph.h>
#endif
// Helper class to handle the client Device Context
class KicadGraphicContext : public wxClientDC
{
public:
KicadGraphicContext( WinEDA_DrawPanel * aDrawPanel );
~KicadGraphicContext();
};
// Macro used to declare a device context in kicad:
#if USE_WX_GRAPHICS_CONTEXT && USE_WX_ZOOM
#define INSTALL_DC(name,parent) \
......
......@@ -258,18 +258,15 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
SetTitle( GetScreen()->m_FileName );
}
double scalar = GetScreen()->GetScalingFactor();
curpos = DrawPanel->CursorRealPosition( Mouse );
oldpos = GetScreen()->m_Curseur;
delta = GetScreen()->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( delta.x );
delta.y = DC->LogicalToDeviceYRel( delta.y );
Mouse = DrawPanel->CalcUnscrolledPosition( Mouse );
#else
GetScreen()->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x <= 0 )
delta.x = 1;
......
......@@ -451,18 +451,15 @@ void WinEDA_ModuleEditFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
return;
}
double scalar = GetScreen()->GetScalingFactor();
curpos = DrawPanel->CursorRealPosition( Mouse );
oldpos = GetScreen()->m_Curseur;
delta = GetScreen()->GetGridSize();
#ifdef USE_WX_ZOOM
delta.x = DC->LogicalToDeviceXRel( wxRound( delta.x ) );
delta.y = DC->LogicalToDeviceYRel( wxRound( delta.y ) );
Mouse = DrawPanel->CalcUnscrolledPosition( Mouse );
#else
GetScreen()->Scale( delta );
#endif
delta.x *= scalar;
delta.y *= scalar;
if( delta.x == 0 )
delta.x = 1;
......
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