~cern-kicad/kicad/kicad-pns-tom

« back to all changes in this revision

Viewing changes to common/gr_basic.cpp

  • Committer: Maciej Suminski
  • Date: 2013-08-02 13:57:24 UTC
  • mfrom: (4024.1.238 kicad)
  • mto: This revision was merged to the branch mainline in revision 4221.
  • Revision ID: maciej.suminski@cern.ch-20130802135724-gix6orezshkukodv
Upstream merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <wx/graphics.h>
16
16
 
17
17
static const bool FILLED = true;
 
18
static const bool NOT_FILLED = false;
18
19
 
19
20
/* Important Note:
20
21
 * These drawing functions  clip draw item before send these items to wxDC draw
50
51
EDA_COLOR_T g_DrawBgColor = WHITE;
51
52
 
52
53
 
53
 
#define USE_CLIP_FILLED_POLYGONS
54
 
 
55
 
#ifdef USE_CLIP_FILLED_POLYGONS
56
 
static void ClipAndDrawFilledPoly( EDA_RECT * ClipBox, wxDC * DC, wxPoint Points[], int n );
57
 
#endif
 
54
static void ClipAndDrawPoly( EDA_RECT * ClipBox, wxDC * DC, wxPoint Points[],
 
55
                             int n );
58
56
 
59
57
/* These functions are used by corresponding functions
60
58
 * ( GRSCircle is called by GRCircle for instance) after mapping coordinates
857
855
/*
858
856
 * Draw a new polyline and fill it if Fill, in screen space.
859
857
 */
860
 
static void GRSPoly( EDA_RECT* ClipBox,
861
 
                     wxDC*     DC,
862
 
                     int       n,
863
 
                     wxPoint   Points[],
864
 
                     bool      Fill,
865
 
                     int       width,
866
 
                     EDA_COLOR_T       Color,
867
 
                     EDA_COLOR_T       BgColor )
 
858
static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, wxPoint Points[],
 
859
                     bool      Fill, int width,
 
860
                     EDA_COLOR_T Color, EDA_COLOR_T BgColor )
868
861
{
869
862
    if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
870
863
        return;
878
871
 
879
872
        /* clip before send the filled polygon to wxDC, because under linux
880
873
         * (GTK?) polygons having large coordinates are incorrectly drawn
 
874
         * (integer overflow in coordinates, I am guessing)
881
875
         */
882
 
#ifdef USE_CLIP_FILLED_POLYGONS
883
 
        ClipAndDrawFilledPoly( ClipBox, DC, Points, n );
884
 
#else
885
 
        DC->DrawPolygon( n, Points );  // does not work very well under linux
886
 
#endif
 
876
        ClipAndDrawPoly( ClipBox, DC, Points, n );
887
877
    }
888
878
    else
889
879
    {
903
893
/*
904
894
 * Draw a new closed polyline and fill it if Fill, in screen space.
905
895
 */
906
 
static void GRSClosedPoly( EDA_RECT* ClipBox,
907
 
                           wxDC*     DC,
908
 
                           int       aPointCount,
909
 
                           wxPoint   aPoints[],
910
 
                           bool      Fill,
911
 
                           int       width,
912
 
                           EDA_COLOR_T       Color,
913
 
                           EDA_COLOR_T       BgColor )
 
896
static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC,
 
897
                           int       aPointCount, wxPoint aPoints[],
 
898
                           bool      aFill, int aWidth,
 
899
                           EDA_COLOR_T       aColor,
 
900
                           EDA_COLOR_T       aBgColor )
914
901
{
915
 
    if( !IsGRSPolyDrawable( ClipBox, aPointCount, aPoints ) )
 
902
    if( !IsGRSPolyDrawable( aClipBox, aPointCount, aPoints ) )
916
903
        return;
917
904
 
918
 
    GRSetColorPen( DC, Color, width );
 
905
    GRSetColorPen( aDC, aColor, aWidth );
919
906
 
920
 
    if( Fill && ( aPointCount > 2 ) )
 
907
    if( aFill && ( aPointCount > 2 ) )
921
908
    {
922
909
        GRLastMoveToX = aPoints[aPointCount - 1].x;
923
910
        GRLastMoveToY = aPoints[aPointCount - 1].y;
924
 
        GRSetBrush( DC, BgColor, FILLED );
925
 
#ifdef USE_CLIP_FILLED_POLYGONS
926
 
        ClipAndDrawFilledPoly( ClipBox, DC, aPoints, aPointCount );
927
 
#else
928
 
        DC->DrawPolygon( aPointCount, aPoints );  // does not work very well under linux
929
 
#endif
 
911
        GRSetBrush( aDC, aBgColor, FILLED );
 
912
        ClipAndDrawPoly( aClipBox, aDC, aPoints, aPointCount );
930
913
    }
931
914
    else
932
915
    {
933
 
        GRSetBrush( DC, BgColor );
934
 
        DC->DrawLines( aPointCount, aPoints );
 
916
        GRSetBrush( aDC, aBgColor );
 
917
        aDC->DrawLines( aPointCount, aPoints );
935
918
 
 
919
        int lastpt = aPointCount - 1;
936
920
        /* Close the polygon. */
937
 
        if( aPoints[aPointCount - 1] != aPoints[0] )
 
921
        if( aPoints[lastpt] != aPoints[0] )
938
922
        {
939
 
            GRLine( ClipBox,
940
 
                    DC,
941
 
                    aPoints[0].x,
942
 
                    aPoints[0].y,
943
 
                    aPoints[aPointCount - 1].x,
944
 
                    aPoints[aPointCount - 1].y,
945
 
                    width,
946
 
                    Color );
 
923
            GRLine( aClipBox, aDC, aPoints[0].x, aPoints[0].y,
 
924
                    aPoints[lastpt].x, aPoints[lastpt].y,
 
925
                    aWidth, aColor );
947
926
        }
948
927
    }
949
928
}
1153
1132
 
1154
1133
 
1155
1134
void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y,
1156
 
                  double StAngle, double EndAngle, int r, 
 
1135
                  double StAngle, double EndAngle, int r,
1157
1136
                  EDA_COLOR_T Color, EDA_COLOR_T BgColor )
1158
1137
{
1159
1138
    GRFilledArc( ClipBox, DC, x, y, StAngle, EndAngle, r, 0, Color, BgColor );
1322
1301
void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
1323
1302
              int aWidth, EDA_COLOR_T aColor, wxPenStyle aStyle )
1324
1303
{
1325
 
 
1326
1304
    wxPoint points[5];
1327
1305
    points[0] = wxPoint(x1, y1);
1328
1306
    points[1] = wxPoint(x1, y2);
1329
1307
    points[2] = wxPoint(x2, y2);
1330
1308
    points[3] = wxPoint(x2, y1);
1331
1309
    points[4] = points[0];
1332
 
    GRSetColorPen( aDC, aColor, aWidth, aStyle );
1333
 
    GRSetBrush( aDC, BLACK );
1334
 
    if( aClipBox )
1335
 
    {
1336
 
        EDA_RECT clipbox(*aClipBox);
1337
 
        clipbox.Inflate(aWidth);
1338
 
        ClipAndDrawFilledPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
1339
 
    }
1340
 
    else
1341
 
        ClipAndDrawFilledPoly(aClipBox, aDC, points, 5);
 
1310
    GRSClosedPoly( aClipBox, aDC, 5, points, NOT_FILLED, aWidth,
 
1311
                           aColor, aColor );
1342
1312
}
1343
1313
 
1344
1314
 
1345
1315
void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
1346
1316
                    int aWidth, EDA_COLOR_T aColor, EDA_COLOR_T aBgColor )
1347
1317
{
1348
 
 
1349
1318
    wxPoint points[5];
1350
1319
    points[0] = wxPoint(x1, y1);
1351
1320
    points[1] = wxPoint(x1, y2);
1354
1323
    points[4] = points[0];
1355
1324
    GRSetBrush( aDC, aBgColor, FILLED );
1356
1325
    GRSetColorPen( aDC, aBgColor, aWidth );
 
1326
 
1357
1327
    if( aClipBox && (aWidth > 0) )
1358
1328
    {
1359
1329
        EDA_RECT clipbox(*aClipBox);
1360
1330
        clipbox.Inflate(aWidth);
1361
 
        ClipAndDrawFilledPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
 
1331
        ClipAndDrawPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
1362
1332
    }
1363
1333
    else
1364
 
        ClipAndDrawFilledPoly(aClipBox, aDC, points, 5);
 
1334
        ClipAndDrawPoly(aClipBox, aDC, points, 5 );
1365
1335
}
1366
1336
 
1367
 
 
1368
 
#ifdef USE_CLIP_FILLED_POLYGONS
1369
 
 
1370
1337
/**
1371
 
 * Function ClipAndDrawFilledPoly
 
1338
 * Function ClipAndDrawPoly
1372
1339
 *  Used to clip a polygon and draw it as Filled Polygon
1373
1340
 *  uses the Sutherland and Hodgman algo to clip the given poly against a
1374
1341
 *  rectangle.  This rectangle is the drawing area this is useful under
1382
1349
 */
1383
1350
#include <SutherlandHodgmanClipPoly.h>
1384
1351
 
1385
 
void ClipAndDrawFilledPoly( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPoints[], int n )
 
1352
void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPoints[], int n )
1386
1353
{
1387
1354
    if( aClipBox == NULL )
1388
1355
    {
1417
1384
}
1418
1385
 
1419
1386
 
1420
 
#endif
1421
 
 
1422
 
 
1423
1387
void GRBezier( EDA_RECT* ClipBox,
1424
1388
               wxDC*     DC,
1425
1389
               int       x1,
1561
1525
    return candidate;
1562
1526
}
1563
1527
 
1564
 
void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y, 
 
1528
void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y,
1565
1529
                   int aSize, EDA_COLOR_T aColor )
1566
1530
{
1567
1531
        int anchor_size = aDC->DeviceToLogicalXRel( aSize );