Recangle program rewritten so it became more accurate on a screen

This commit is contained in:
Vladimir Ur 2011-04-12 21:21:22 +04:00
parent 668bdfa695
commit bf44999a6c
1 changed files with 17 additions and 77 deletions

View File

@ -1336,92 +1336,32 @@ void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
int aWidth, int aColor, wxPenStyle aStyle ) int aWidth, int aColor, wxPenStyle aStyle )
{ {
if( x1 > x2 )
EXCHG( x1, x2 );
if( y1 > y2 )
EXCHG( y1, y2 );
if( aClipBox )
{
int xmin = aClipBox->GetX();
int ymin = aClipBox->GetY();
int xmax = aClipBox->GetRight();
int ymax = aClipBox->GetBottom();
if( x1 > xmax )
return;
if( x2 < xmin )
return;
if( y1 > ymax )
return;
if( y2 < ymin )
return;
}
wxPoint points[5];
points[0] = wxPoint(x1, y1);
points[1] = wxPoint(x1, y2);
points[2] = wxPoint(x2, y2);
points[3] = wxPoint(x2, y1);
points[4] = points[0];
GRSetColorPen( aDC, aColor, aWidth, aStyle ); GRSetColorPen( aDC, aColor, aWidth, aStyle );
GRSetBrush( aDC, BLACK );
if( ( x1 == x2 ) || ( y1 == y2 ) ) ClipAndDrawFilledPoly(aClipBox, aDC, points, 5); // polygon approach is more accurate
aDC->DrawLine( x1, y1, x2, y2 );
else
{
GRSetBrush( aDC, BLACK );
aDC->DrawRectangle( x1, y1, x2 - x1, y2 - y1 );
}
} }
void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int Color, int BgColor ) int width, int Color, int BgColor )
{ {
if( x1 > x2 )
EXCHG( x1, x2 );
if( y1 > y2 ) wxPoint points[5];
EXCHG( y1, y2 ); points[0] = wxPoint(x1, y1);
points[1] = wxPoint(x1, y2);
if( ClipBox ) points[2] = wxPoint(x2, y2);
{ points[3] = wxPoint(x2, y1);
int xmin = ClipBox->GetX(); points[4] = points[0];
int ymin = ClipBox->GetY(); GRSetBrush( DC, BgColor, FILLED );
int xmax = ClipBox->GetRight(); GRSetColorPen( DC, BgColor, width );
int ymax = ClipBox->GetBottom(); ClipAndDrawFilledPoly(ClipBox, DC, points, 5); // polygon approach is more accurate
if( x1 > xmax )
return;
if( x2 < xmin )
return;
if( y1 > ymax )
return;
if( y2 < ymin )
return;
// Clipping coordinates
if( x1 < xmin )
x1 = xmin - 1;
if( y1 < ymin )
y1 = ymin - 1;
if( x2 > xmax )
x2 = xmax + 1;
if( y2 > ymax )
y2 = ymax + 1;
}
GRSetColorPen( DC, Color, width );
if( ( x1 == x2 ) || ( y1 == y2 ) )
DC->DrawLine( x1, y1, x2, y2 );
else
{
GRSetBrush( DC, BgColor, FILLED );
DC->DrawRectangle( x1, y1, x2 - x1, y2 - y1 );
}
} }