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.
......@@ -38,6 +38,13 @@
*/
/* Definitions for enabling and disabling debugging features in gr_basic.cpp.
* Please remember to set these back to 0 before making SVN commits.
*/
#define DEBUG_DUMP_CLIP_ERROR_COORDS 0 // Set to 1 to dump clip algorithm errors.
#define DEBUG_DUMP_CLIP_COORDS 0 // Set to 1 to dump clipped coordinates.
// For draw mode = XOR GR_XOR or GR_NXOR by background color
int g_XorMode = GR_NXOR;
......@@ -138,8 +145,6 @@ int GRMapY( int y )
#define WHEN_INSIDE
#if defined( USE_WX_ZOOM )
/**
* Test if any part of a line falls within the bounds of a rectangle.
*
......@@ -153,56 +158,224 @@ int GRMapY( int y )
*
* @return - False if any part of the line lies within the rectangle.
*/
static bool clipLine( EDA_Rect* aClipBox, int x1, int y1, int x2, int y2 )
static bool clipLine( EDA_Rect* aClipBox, int& x1, int& y1, int& x2, int& y2 )
{
if( aClipBox->Inside( x1, y1 ) || aClipBox->Inside( x2, y2 ) )
if( aClipBox->Inside( x1, y1 ) && aClipBox->Inside( x2, y2 ) )
return false;
int ax1, ay1, ax2, ay2;
wxRect rect =*aClipBox;
ax1 = rect.GetBottomLeft().x;
ay1 = rect.GetBottomLeft().y;
ax2 = rect.GetTopLeft().x;
ay2 = rect.GetTopLeft().y;
wxRect rect = *aClipBox;
int minX = rect.GetLeft();
int maxX = rect.GetRight();
int minY = rect.GetTop();
int maxY = rect.GetBottom();
int clippedX, clippedY;
#if DEBUG_DUMP_CLIP_COORDS
int tmpX1, tmpY1, tmpX2, tmpY2;
tmpX1 = x1;
tmpY1 = y1;
tmpX2 = x2;
tmpY2 = y2;
#endif
/* Left clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, ax1, ay1, ax2, ay2 ) )
if( aClipBox->Inside( x1, y1 ) )
{
if( x1 == x2 ) /* Vertical line, clip Y. */
{
if( y2 < minY )
{
y2 = minY;
return false;
}
if( y2 > maxY )
{
y2 = maxY;
return false;
}
}
else if( y1 == y2 ) /* Horizontal line, clip X. */
{
if( x2 < minX )
{
x2 = minX;
return false;
}
ax1 = rect.GetTopRight().x;
ay1 = rect.GetTopRight().y;
if( x2 > maxX )
{
x2 = maxX;
return false;
}
}
/* If we're here, it's a diagonal line. */
/* Top clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, ax1, ay1, ax2, ay2 ) )
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, minY, minX, maxY,
&clippedX, &clippedY ) /* Left */
|| TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, minY, maxX, minY,
&clippedX, &clippedY ) /* Top */
|| TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, maxX, minY, maxX, maxY,
&clippedX, &clippedY ) /* Right */
|| TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, maxY, maxX, maxY,
&clippedX, &clippedY ) ) /* Bottom */
{
if( x2 != clippedX )
x2 = clippedX;
if( y2 != clippedY )
y2 = clippedY;
return false;
}
ax2 = rect.GetBottomRight().x;
ay2 = rect.GetBottomRight().y;
/* If we're here, something has gone terribly wrong. */
#if DEBUG_DUMP_CLIP_ERROR_COORDS
wxLogDebug( wxT( "Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY, x1, y1, x2, y2 );
#endif
return false;
}
else if( aClipBox->Inside( x2, y2 ) )
{
if( x1 == x2 ) /* Vertical line, clip Y. */
{
if( y2 < minY )
{
y2 = minY;
return false;
}
/* Right clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, ax1, ay1, ax2, ay2 ) )
if( y2 > maxY )
{
y2 = maxY;
return false;
}
}
else if( y1 == y2 ) /* Horizontal line, clip X. */
{
if( x2 < minX )
{
x2 = minX;
return false;
}
ax1 = rect.GetBottomLeft().x;
ay1 = rect.GetBottomLeft().y;
if( x2 > maxX )
{
x2 = maxX;
return false;
}
}
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, minY, minX, maxY,
&clippedX, &clippedY ) /* Left */
|| TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, minY, maxX, minY,
&clippedX, &clippedY ) /* Top */
|| TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, maxX, minY, maxX, maxY,
&clippedX, &clippedY ) /* Right */
|| TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, maxY, maxX, maxY,
&clippedX, &clippedY ) ) /* Bottom */
{
if( x1 != clippedX )
x1 = clippedX;
if( y1 != clippedY )
y1 = clippedY;
return false;
}
/* If we're here, something has gone terribly wrong. */
#if DEBUG_DUMP_CLIP_ERROR_COORDS
wxLogDebug( wxT( "Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY, x1, y1, x2, y2 );
#endif
return false;
}
else
{
int* intersectX;
int* intersectY;
int intersectX1, intersectY1, intersectX2, intersectY2;
bool haveFirstPoint = false;
intersectX = &intersectX1;
intersectY = &intersectY1;
/* Left clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, minY, minX, maxY,
intersectX, intersectY ) )
{
intersectX = &intersectX2;
intersectY = &intersectY2;
haveFirstPoint = true;
}
/* Top clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, minY, maxX, minY,
intersectX, intersectY ) )
{
intersectX = &intersectX2;
intersectY = &intersectY2;
if( haveFirstPoint )
{
x1 = intersectX1;
y1 = intersectY1;
x2 = intersectX2;
y2 = intersectY2;
return false;
}
haveFirstPoint = true;
}
/* Right clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, maxX, minY, maxX, maxY,
intersectX, intersectY ) )
{
intersectX = &intersectX2;
intersectY = &intersectY2;
if( haveFirstPoint )
{
x1 = intersectX1;
y1 = intersectY1;
x2 = intersectX2;
y2 = intersectY2;
return false;
}
haveFirstPoint = true;
}
/* Bottom clip rectangle line. */
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, ax1, ay1, ax2, ay2 ) )
if( TestForIntersectionOfStraightLineSegments( x1, y1, x2, y2, minX, maxY, maxX, maxY,
intersectX, intersectY ) )
{
intersectX = &intersectX2;
intersectY = &intersectY2;
if( haveFirstPoint )
{
x1 = intersectX1;
y1 = intersectY1;
x2 = intersectX2;
y2 = intersectY2;
return false;
}
}
/* If we're here and only one line of the clip box has been intersected,
* something has gone terribly wrong. */
#if DEBUG_DUMP_CLIP_ERROR_COORDS
if( haveFirstPoint )
wxLogDebug( wxT( "Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY, x1, y1, x2, y2 );
#endif
}
/* Set this to one to verify that diagonal lines get clipped properly. */
#if 0
#if DEBUG_DUMP_CLIP_COORDS
if( !( x1 == x2 || y1 == y2 ) )
wxLogDebug( wxT( "Clipped line (%d,%d):(%d,%d) from rectangle (%d,%d,%d,%d)" ),
x1, y1, x2, y2, rect.x, rect.y, rect.x + rect.width, rect.y + rect.height );
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY );
#endif
return true;
}
#else
/**
* Function clip_line
* @return bool - true when WHEN_OUTSIDE fires, else false.
......@@ -306,8 +479,6 @@ static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 )
return false;
}
#endif
static void WinClipAndDrawLine( EDA_Rect* ClipBox, wxDC* DC,
int x1, int y1, int x2, int y2,
......
......@@ -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