~ubuntu-branches/ubuntu/karmic/xpuzzles/karmic

« back to all changes in this revision

Viewing changes to xoct/Oct.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-22 16:29:42 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050822162942-tdtf178zkpd3xxdg
Tags: 7.1.3-1ubuntu1
Update {build-,}depends for xorg -> mesa transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#
6
6
###
7
7
#
8
 
#  Copyright (c) 1994 - 2004    David Albert Bagley, bagleyd@tux.org
 
8
#  Copyright (c) 1994 - 2005    David Albert Bagley, bagleyd@tux.org
9
9
#
10
10
#                   All Rights Reserved
11
11
#
695
695
        return (j - 1);
696
696
}
697
697
 
698
 
static      RTT
699
 
ToRTT(int position)
 
698
static void
 
699
ToRTT(int position, RTT * rtt)
700
700
{
701
 
        RTT         rtt;
702
 
 
703
 
        rtt.row = Sqrt(position);
 
701
        rtt->row = Sqrt(position);
704
702
        /* Passing row so there is no sqrt calculation again */
705
 
        rtt.trbl = (position - rtt.row * rtt.row) / 2;
706
 
        rtt.tlbr = (rtt.row * rtt.row + 2 * rtt.row - position) / 2;
707
 
        return rtt;
 
703
        rtt->trbl = (position - rtt->row * rtt->row) / 2;
 
704
        rtt->tlbr = (rtt->row * rtt->row + 2 * rtt->row - position) / 2;
708
705
}
709
706
 
710
707
static int
728
725
                Boolean origin)
729
726
{
730
727
        /* CoordModePrevious -> CoordModeOrigin */
731
 
        POINT      *temp = NULL;
732
 
        int         pt;
 
728
        POINT *temp = NULL;
 
729
        int pt;
733
730
 
734
731
        if (!origin) {
735
732
                if (!(temp = (POINT *) malloc(sizeof (POINT) * n))) {
765
762
DrawOrientLine(OctWidget w, int orient, int face, int side, int dx, int dy,
766
763
                GC borderGC)
767
764
{
768
 
        int         x_1 = 0, x_2 = 0, y_1 = 0, y_2 = 0;
769
 
        int         temp1 = w->oct.facetLength + 1;
770
 
        int         temp2 = w->oct.facetLength / 2 + 1;
771
 
        int         temp3 = w->oct.orientLineLength / 3;
 
765
        int x_1 = 0, x_2 = 0, y_1 = 0, y_2 = 0;
 
766
        int temp1 = w->oct.facetLength + 1;
 
767
        int temp2 = w->oct.facetLength / 2 + 1;
 
768
        int temp3 = w->oct.orientLineLength / 3;
772
769
 
773
770
        /* clock positions */
774
771
        switch ((side == face) ? orient : (orient + MAXORIENT / 2) % MAXORIENT) {
856
853
static void
857
854
DrawTriangle(OctWidget w, int face, int position, int offset)
858
855
{
859
 
        GC          faceGC, borderGC;
860
 
        int         dx = 0, dy = 0;
861
 
        int         side, row = Sqrt(position);
862
 
        int         base = row * row;
863
 
        int         g = position - base;
864
 
        int         s = g % 2;
865
 
        int         pos = row * (w->oct.facetLength + w->oct.delta);
866
 
        int         orient, view, faceOnView;
 
856
        GC faceGC, borderGC;
 
857
        int dx = 0, dy = 0;
 
858
        int side, row = Sqrt(position);
 
859
        int base = row * row;
 
860
        int g = position - base;
 
861
        int s = g % 2;
 
862
        int pos = row * (w->oct.facetLength + w->oct.delta);
 
863
        int orient, view, faceOnView;
867
864
 
868
865
        view = (face / MAXSIDES == UP) ? DOWN : UP;
869
866
        faceOnView = face - MAXSIDES * (!view);
948
945
        }
949
946
        POLYGON(w, faceGC, borderGC, triangleList[side], 3, False);
950
947
        if (w->oct.mono) {
951
 
                int         letterX, letterY;
952
 
                char        buf[2];
 
948
                int letterX, letterY;
 
949
                char buf[2];
953
950
 
954
951
                buf[0] =
955
952
#ifdef WINVER
971
968
        }
972
969
        if (w->oct.orient)
973
970
                DrawOrientLine(w, w->oct.facetLoc[face][position].rotation, faceOnView,
974
 
                               side, dx, dy, borderGC);
 
971
                        side, dx, dy, borderGC);
975
972
}
976
973
 
977
974
void
978
975
DrawAllPieces(OctWidget w)
979
976
{
980
 
        int         position, face;
 
977
        int position, face;
981
978
 
982
979
        for (face = 0; face < MAXFACES; face++)
983
980
                for (position = 0; position < w->oct.sizeSize; position++)
995
992
static void
996
993
DrawFrame(OctWidget w, Boolean focus)
997
994
{
998
 
        int         startx, starty, lengthx, lengthy, longlength;
 
995
        int startx, starty, lengthx, lengthy, longlength;
999
996
 
1000
997
        GC gc = (focus) ? w->oct.frameGC : w->oct.borderGC;
1001
998
        startx = 1 + w->oct.puzzleOffset.x;
1052
1049
static void
1053
1050
RotateFace(OctWidget w, int view, int side, int direction)
1054
1051
{
1055
 
        int         g, square, s;
1056
 
        int         i = 0, j = 0, k, i_1, j_1, k_1, position;
 
1052
        int g, square, s;
 
1053
        int i = 0, j = 0, k, i_1, j_1, k_1, position;
1057
1054
 
1058
1055
        /* Read Face */
1059
1056
        k = -1;
1060
1057
        square = 0;
1061
1058
        for (g = 0; g < w->oct.sizeSize; g++) {
1062
 
                /* This is the old algorithm, its now more efficient
1063
 
                   k = Sqrt(g);
1064
 
                   j = (g - k * k) / 2;
1065
 
                   i = ((k + 1) * (k + 1) - g - 1) / 2; */
 
1059
#if 0
 
1060
                /* This is the old algorithm, its now more efficient */
 
1061
                k = Sqrt(g);
 
1062
                j = (g - k * k) / 2;
 
1063
                i = ((k + 1) * (k + 1) - g - 1) / 2;
 
1064
#endif
1066
1065
                if (square <= g) {
1067
1066
                        k++;
1068
1067
                        square = (k + 1) * (k + 1);
1105
1104
static void
1106
1105
ReadRTT(OctWidget w, int view, int side, int dir, int h, int len, int orient)
1107
1106
{
1108
 
        int         f, g, s;
1109
 
        int         base = h * h;
 
1107
        int f, g, s;
 
1108
        int base = h * h;
1110
1109
 
1111
1110
        if (!(dir % 2) || dir > COORD)
1112
1111
                for (g = 0; g < len; g++)
1137
1136
static void
1138
1137
RotateRTT(OctWidget w, int rotate, int len, int orient)
1139
1138
{
1140
 
        int         g;
 
1139
        int g;
1141
1140
 
1142
1141
        for (g = 0; g < len; g++)
1143
1142
                w->oct.rowLoc[orient][g].rotation =
1147
1146
static void
1148
1147
ReverseRTT(OctWidget w, int len, int orient)
1149
1148
{
1150
 
        int         g;
1151
 
        OctLoc      temp;
 
1149
        int g;
 
1150
        OctLoc temp;
1152
1151
 
1153
1152
        for (g = 0; g < (len - 1) / 2; g++) {
1154
1153
                temp = w->oct.rowLoc[orient][len - 1 - g];
1160
1159
static void
1161
1160
WriteRTT(OctWidget w, int view, int side, int dir, int h, int len, int orient)
1162
1161
{
1163
 
        int         f, g, s;
1164
 
        int         base = h * h;
 
1162
        int f, g, s;
 
1163
        int base = h * h;
1165
1164
 
1166
1165
        if (!(dir % 2) || dir > COORD) {        /* CW || CCW */
1167
1166
                for (g = 0; g < len; g++) {
1197
1196
static void
1198
1197
MovePieces(OctWidget w, int face, RTT rtt, int direction, int style)
1199
1198
{
1200
 
        int         view, side, orient, newView, rotate, g, h, len;
1201
 
        int         newSide, oldSide, newDirection, bound, l = 0;
 
1199
        int view, side, orient, newView, rotate, g, h, len;
 
1200
        int newSide, oldSide, newDirection, bound, l = 0;
1202
1201
 
1203
1202
        view = face / MAXSIDES;
1204
1203
        side = face % MAXSIDES;
1210
1209
                        rtt.row = rtt.trbl = rtt.tlbr = 0;
1211
1210
                }
1212
1211
                if ((!rtt.row && !(direction % 2)) ||
1213
 
                    (!rtt.trbl && (direction % 2) && !((side + direction / 2) % 2)) ||
1214
 
                    (!rtt.tlbr && (direction % 2) && ((side + direction / 2) % 2)))
 
1212
                                (!rtt.trbl && (direction % 2) &&
 
1213
                                !((side + direction / 2) % 2)) ||
 
1214
                                (!rtt.tlbr && (direction % 2) &&
 
1215
                                ((side + direction / 2) % 2)))
1215
1216
                        RotateFace(w, view, rowToRotate[side][direction].face,
1216
 
                                   rowToRotate[side][direction].rotation);
 
1217
                                rowToRotate[side][direction].rotation);
1217
1218
                if ((rtt.row == w->oct.size - 1 && !(direction % 2)) ||
1218
 
                    (rtt.trbl == w->oct.size - 1 && (direction % 2) &&
1219
 
                     !((side + direction / 2) % 2)) ||
1220
 
                    (rtt.tlbr == w->oct.size - 1 && (direction % 2) &&
1221
 
                     (side + direction / 2) % 2))
 
1219
                                (rtt.trbl == w->oct.size - 1 &&
 
1220
                                (direction % 2) &&
 
1221
                                !((side + direction / 2) % 2)) ||
 
1222
                                (rtt.tlbr == w->oct.size - 1 &&
 
1223
                                (direction % 2) &&
 
1224
                                (side + direction / 2) % 2))
1222
1225
                        RotateFace(w, !view, rowToRotate[MAXSIDES + side][direction].face,
1223
 
                           rowToRotate[MAXSIDES + side][direction].rotation);
 
1226
                                rowToRotate[MAXSIDES + side][direction].rotation);
1224
1227
                if (!(direction % 2))
1225
1228
                        h = rtt.row;
1226
1229
                else if ((direction / 2 + side) % 2)
1277
1280
                        h = rtt.trbl;
1278
1281
 
1279
1282
                if (w->oct.sticky &&
1280
 
                    !((direction > TL && h == w->oct.size - 1) ||
1281
 
                      (direction <= TL && !h))) {
 
1283
                                !((direction > TL && h == w->oct.size - 1) ||
 
1284
                                (direction <= TL && !h))) {
1282
1285
                        l = 0;
1283
1286
                        h = (direction <= TL);
1284
1287
                        bound = TRUE;
1304
1307
                                                        ((direction + 6) % MAXFACES) : ((direction + 2) % MAXFACES);
1305
1308
                                                if (side % 2)
1306
1309
                                                        rotate = (((newDirection - direction) / 2 + MAXSIDES) %
1307
 
                                                                  MAXSIDES == 1) ? 4 : MAXORIENT - 4;
 
1310
                                                                MAXSIDES == 1) ? 4 : MAXORIENT - 4;
1308
1311
                                                else
1309
1312
                                                        rotate = (((newDirection - direction) / 2 + MAXSIDES) %
1310
 
                                                                  MAXSIDES == 1) ? 2 : MAXORIENT - 2;
 
1313
                                                                MAXSIDES == 1) ? 2 : MAXORIENT - 2;
1311
1314
                                        } else {        /* Next is on same view */
1312
1315
                                                newView = view;
1313
1316
                                                newSide = MAXSIDES - side - 1;
1335
1338
                        }
1336
1339
                        l++;
1337
1340
                        if (w->oct.sticky &&
1338
 
                            !((direction > TL && h == w->oct.size - 1) ||
1339
 
                              (direction <= TL && !h)))
 
1341
                                        !((direction > TL && h == w->oct.size - 1) ||
 
1342
                                        (direction <= TL && !h)))
1340
1343
                                h++;
1341
1344
                        else
1342
1345
                                g++;
1343
1346
                } while ((bound && l < w->oct.size - 1) ||
1344
 
                         (((direction > TL && h == w->oct.size - 1) ||
1345
 
                           (direction <= TL && !h)) && g < 2 && !bound));
 
1347
                                (((direction > TL && h == w->oct.size - 1) ||
 
1348
                                (direction <= TL && !h)) && g < 2 && !bound));
1346
1349
        }
1347
1350
}
1348
1351
 
1349
1352
static void
1350
1353
MoveControlCb(OctWidget w, int face, int direction, int style)
1351
1354
{
1352
 
        int         i, j;
1353
 
        RTT         rtt;
 
1355
        int i, j;
 
1356
        RTT rtt;
1354
1357
 
1355
1358
        if (w->oct.sticky) {
1356
1359
                if (style == PERIOD3)
1381
1384
                                                rtt.tlbr = j;
1382
1385
                                                MovePieces(w,
1383
1386
                                                                (!(face / MAXSIDES)) * MAXSIDES + ((face % 2) ?
1384
 
                                                                                                   (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
 
1387
                                                                                                (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
1385
1388
                                                                (direction == CW) ? CCW : CW, style);
1386
1389
                                        } else {
1387
1390
                                                j = i + 1;
1390
1393
                                                rtt.tlbr = j;
1391
1394
                                                MovePieces(w,
1392
1395
                                                                (!(face / MAXSIDES)) * MAXSIDES + ((face % 2) ?
1393
 
                                                                                                   (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
 
1396
                                                                                                (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
1394
1397
                                                                ((direction / 2) % 2) ? (direction + 2) % MAXFACES :
1395
1398
                                                                (direction + 6) % MAXFACES, style);
1396
1399
                                        }
1420
1423
                                                rtt.tlbr = j;
1421
1424
                                                MovePieces(w,
1422
1425
                                                                (!(face / MAXSIDES)) * MAXSIDES + ((face % 2) ?
1423
 
                                                                                                   (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
 
1426
                                                                                                (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
1424
1427
                                                                (direction == CW) ? CCW : CW, style);
1425
1428
                                        } else {
1426
1429
                                                j = i - w->oct.size + 1;
1429
1432
                                                rtt.tlbr = j;
1430
1433
                                                MovePieces(w,
1431
1434
                                                                (!(face / MAXSIDES)) * MAXSIDES + ((face % 2) ?
1432
 
                                                                                                   (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
 
1435
                                                                                                (face + MAXSIDES / 2) % MAXSIDES : face % MAXSIDES), rtt,
1433
1436
                                                                ((direction / 2) % 2) ? (direction + 2) % MAXFACES :
1434
1437
                                                                (direction + 6) % MAXFACES, style);
1435
1438
                                        }
1445
1448
        if (control)
1446
1449
                MoveControlCb(w, face, direction, style);
1447
1450
        else {
1448
 
                MovePieces(w, face, ToRTT(position), direction, style);
 
1451
                RTT rtt;
 
1452
 
 
1453
                ToRTT(position, &rtt);
 
1454
                MovePieces(w, face, rtt, direction, style);
1449
1455
                SetOct(w, OCT_MOVED);
1450
1456
        }
1451
1457
        PutMove(face, position, direction, style, control);
1452
1458
}
1453
1459
 
1454
 
static      Boolean
 
1460
static Boolean
1455
1461
SelectPieces(OctWidget w, int x, int y, int *face, RTT * rtt)
1456
1462
{
1457
 
        int         view;
 
1463
        int view;
1458
1464
 
1459
1465
        x -= w->oct.puzzleOffset.x;
1460
1466
        y -= w->oct.puzzleOffset.y;
1467
1473
        } else
1468
1474
                view = UP;
1469
1475
        if (x <= 0 || y <= 0 ||
1470
 
            x >= w->oct.faceLength + w->oct.delta ||
1471
 
            y >= w->oct.faceLength + w->oct.delta)
 
1476
                        x >= w->oct.faceLength + w->oct.delta ||
 
1477
                        y >= w->oct.faceLength + w->oct.delta)
1472
1478
                return False;
1473
1479
        else if (x + y > w->oct.faceLength) {
1474
1480
                if (x > y)
1487
1493
        }
1488
1494
        rtt->row = 0;
1489
1495
        while ((x <= (w->oct.size - (rtt->row + 1)) *
1490
 
                (w->oct.facetLength + w->oct.delta) ||
1491
 
                x >= w->oct.viewMiddle + (rtt->row + 1) *
1492
 
                (w->oct.facetLength + w->oct.delta) + 1 ||
1493
 
                y <= (w->oct.size - (rtt->row + 1)) *
1494
 
                (w->oct.facetLength + w->oct.delta) ||
1495
 
                y >= w->oct.viewMiddle + (rtt->row + 1) *
1496
 
                (w->oct.facetLength + w->oct.delta) + 1) &&
1497
 
               rtt->row < w->oct.size)
 
1496
                        (w->oct.facetLength + w->oct.delta) ||
 
1497
                        x >= w->oct.viewMiddle + (rtt->row + 1) *
 
1498
                        (w->oct.facetLength + w->oct.delta) + 1 ||
 
1499
                        y <= (w->oct.size - (rtt->row + 1)) *
 
1500
                        (w->oct.facetLength + w->oct.delta) ||
 
1501
                        y >= w->oct.viewMiddle + (rtt->row + 1) *
 
1502
                        (w->oct.facetLength + w->oct.delta) + 1) &&
 
1503
                        rtt->row < w->oct.size)
1498
1504
                rtt->row++;
1499
1505
        rtt->trbl = 0;
1500
1506
        while ((x + y) / 2 <= (w->oct.size - (rtt->trbl + 1)) *
1501
 
               (w->oct.facetLength + w->oct.delta) + 2 * w->oct.delta ||
1502
 
               (x + y) / 2 >= w->oct.viewMiddle + (rtt->trbl + 1) *
1503
 
               (w->oct.facetLength + w->oct.delta))
 
1507
                        (w->oct.facetLength + w->oct.delta) + 2 * w->oct.delta ||
 
1508
                        (x + y) / 2 >= w->oct.viewMiddle + (rtt->trbl + 1) *
 
1509
                        (w->oct.facetLength + w->oct.delta))
1504
1510
                rtt->trbl++;
1505
1511
        rtt->tlbr = 0;
1506
1512
        while (x <= y - 2 * (rtt->tlbr + 1) *
1507
 
               (w->oct.facetLength + w->oct.delta) - 2 ||
1508
 
               y <= x - 2 * (rtt->tlbr + 1) *
1509
 
               (w->oct.facetLength + w->oct.delta) - 2)
 
1513
                        (w->oct.facetLength + w->oct.delta) - 2 ||
 
1514
                        y <= x - 2 * (rtt->tlbr + 1) *
 
1515
                        (w->oct.facetLength + w->oct.delta) - 2)
1510
1516
                rtt->tlbr++;
1511
1517
        if (!w->oct.vertical && view == DOWN)
1512
1518
                *face = (*face + MAXSIDES / 2) % MAXSIDES;
1522
1528
static int
1523
1529
CheckMoveDir(OctWidget w, RTT rtt1, RTT rtt2, int face, int *direction)
1524
1530
{
1525
 
        int         which = -1, count = 0;
1526
 
        int         i, *p1, *p2;
 
1531
        int which = -1, count = 0;
 
1532
        int i, *p1, *p2;
1527
1533
 
1528
1534
        p1 = &(rtt1.row);
1529
1535
        p2 = &(rtt2.row);
1558
1564
        return count;
1559
1565
}
1560
1566
 
1561
 
static      Boolean
 
1567
static Boolean
1562
1568
NarrowSelection(int style, int *face, int *direction)
1563
1569
{
1564
 
        int         side;
 
1570
        int side;
1565
1571
 
1566
1572
        side = *face % MAXSIDES;
1567
1573
        if (!(*direction % 2) && !((*direction / 2 + side) % 2))
1573
1579
                        else    /* *direction == (2 * side + 6) % MAXFACES */
1574
1580
                                *direction = CCW;
1575
1581
                }
1576
 
/* if (*direction > TL) h = rtt->row; else if (!((*direction / 2) % 2)) h =
1577
 
                   rtt->trbl; else *//* (*direction / 2) % 2 == 1 *//*
1578
 
                   h = rtt->tlbr; */
 
1582
#if 0
 
1583
        if (*direction > TL)
 
1584
                h = rtt->row;
 
1585
        else if (!((*direction / 2) % 2)) h =
 
1586
                rtt->trbl;
 
1587
        else /* (*direction / 2) % 2 == 1*/
 
1588
                h = rtt->tlbr;
 
1589
#endif
1579
1590
        }
1580
1591
        return True;
1581
1592
}
1582
1593
 
1583
 
static      Boolean
 
1594
static Boolean
1584
1595
PositionPieces(OctWidget w, int x, int y, int style, int *face, RTT * rtt, int *direction)
1585
1596
{
1586
1597
        if (!SelectPieces(w, x, y, face, rtt))
1597
1608
void
1598
1609
MoveOctInput(OctWidget w, int x, int y, int direction, int shift, int control)
1599
1610
{
1600
 
        int         style, face;
1601
 
        RTT         rtt;
 
1611
        int style, face;
 
1612
        RTT rtt;
1602
1613
 
1603
1614
        if (w->oct.mode != BOTH) {
1604
1615
                if (control && shift)
1623
1634
static void
1624
1635
ResetPieces(OctWidget w)
1625
1636
{
1626
 
        int         face, position, orient;
 
1637
        int face, position, orient;
1627
1638
 
1628
1639
        w->oct.sizeSize = w->oct.size * w->oct.size;
1629
1640
        for (face = 0; face < MAXFACES; face++) {
1630
1641
                if (w->oct.facetLoc[face])
1631
1642
                        (void) free((void *) w->oct.facetLoc[face]);
1632
1643
                if (!(w->oct.facetLoc[face] = (OctLoc *)
1633
 
                      malloc(sizeof (OctLoc) * w->oct.sizeSize))) {
 
1644
                                malloc(sizeof (OctLoc) * w->oct.sizeSize))) {
1634
1645
                        DISPLAY_ERROR("Not enough memory, exiting.");
1635
1646
                }
1636
1647
                if (startLoc[face])
1637
1648
                        (void) free((void *) startLoc[face]);
1638
1649
                if (!(startLoc[face] = (OctLoc *)
1639
 
                      malloc(sizeof (OctLoc) * w->oct.sizeSize))) {
 
1650
                                malloc(sizeof (OctLoc) * w->oct.sizeSize))) {
1640
1651
                        DISPLAY_ERROR("Not enough memory, exiting.");
1641
1652
                }
1642
1653
        }
1644
1655
                if (w->oct.rowLoc[orient])
1645
1656
                        (void) free((void *) w->oct.rowLoc[orient]);
1646
1657
                if (!(w->oct.rowLoc[orient] = (OctLoc *)
1647
 
                      malloc(sizeof (OctLoc) * (2 * w->oct.size - 1)))) {
 
1658
                                malloc(sizeof (OctLoc) * (2 * w->oct.size - 1)))) {
1648
1659
                        DISPLAY_ERROR("Not enough memory, exiting.");
1649
1660
                }
1650
1661
        }
1651
1662
        if (w->oct.faceLoc)
1652
1663
                (void) free((void *) w->oct.faceLoc);
1653
1664
        if (!(w->oct.faceLoc = (OctLoc *)
1654
 
              malloc(sizeof (OctLoc) * w->oct.sizeSize))) {
 
1665
                        malloc(sizeof (OctLoc) * w->oct.sizeSize))) {
1655
1666
                DISPLAY_ERROR("Not enough memory, exiting.");
1656
1667
        }
1657
1668
        for (face = 0; face < MAXFACES; face++)
1667
1678
static void
1668
1679
ResizePieces(OctWidget w)
1669
1680
{
1670
 
        int         i, j;
 
1681
        int i, j;
1671
1682
 
1672
1683
        w->oct.facetLength = w->oct.faceLength / (2 * w->oct.size) -
1673
1684
                w->oct.delta - 1;
1696
1707
static void
1697
1708
GetPieces(OctWidget w)
1698
1709
{
1699
 
        FILE       *fp;
1700
 
        int         c, i, size, mode, sticky, orient, practice, moves;
 
1710
        FILE *fp;
 
1711
        int c, i, size, mode, sticky, orient, practice, moves;
1701
1712
        char *buf1 = NULL, *buf2 = NULL;
1702
1713
        char *fname, *lname, *name;
1703
1714
 
1812
1823
        ScanMoves(fp, w, moves);
1813
1824
        (void) fclose(fp);
1814
1825
        (void) printf("%s: size %d, mode %d, sticky %d, orient %d",
1815
 
                      name, size, mode, sticky, orient);
 
1826
                name, size, mode, sticky, orient);
1816
1827
        (void) printf(", practice %d, moves %d.\n", practice, moves);
1817
1828
        free(lname);
1818
1829
        free(fname);
1822
1833
static void
1823
1834
WritePieces(OctWidget w)
1824
1835
{
1825
 
        FILE       *fp;
 
1836
        FILE *fp;
1826
1837
        char *buf1 = NULL, *buf2 = NULL;
1827
1838
        char *fname, *lname, *name;
1828
1839
 
1890
1901
UndoPieces(OctWidget w)
1891
1902
{
1892
1903
        if (MadeMoves() && w->oct.currentFace < 0) {
1893
 
                int         face, position, direction, style, control;
 
1904
                int face, position, direction, style, control;
1894
1905
 
1895
1906
                GetMove(&face, &position, &direction, &style, &control);
1896
1907
                direction = (direction < COORD) ?
1898
1909
                if (control)
1899
1910
                        MoveControlCb(w, face, direction, style);
1900
1911
                else {
1901
 
                        MovePieces(w, face, ToRTT(position), direction, style);
 
1912
                        RTT rtt;
 
1913
 
 
1914
                        ToRTT(position, &rtt);
 
1915
                        MovePieces(w, face, rtt, direction, style);
1902
1916
                        SetOct(w, OCT_UNDO);
1903
1917
                }
1904
1918
        }
1913
1927
static void
1914
1928
RandomizePieces(OctWidget w)
1915
1929
{
1916
 
        int         randomDirection, face, position, style;
1917
 
        int         big = w->oct.sizeSize * 3 + NRAND(2);
 
1930
        int randomDirection, face, position, style;
 
1931
        int big = w->oct.sizeSize * 3 + NRAND(2);
1918
1932
 
1919
1933
        if (w->oct.currentFace >= 0)
1920
1934
                return;
2042
2056
SetValuesOct(OctWidget w)
2043
2057
{
2044
2058
        struct tagColor {
2045
 
                int         red, green, blue;
 
2059
                int red, green, blue;
2046
2060
        } color;
2047
 
        char        szBuf[80], buf[20], charbuf[2];
2048
 
        int         face;
 
2061
        char szBuf[80], buf[20], charbuf[2];
 
2062
        int face;
2049
2063
 
2050
2064
        w->oct.size = GetPrivateProfileInt(SECTION, "size",
2051
2065
                DEFAULTFACETS, INIFILE);
2113
2127
static void
2114
2128
GetColor(OctWidget w, int face)
2115
2129
{
2116
 
        XGCValues   values;
2117
 
        XtGCMask    valueMask;
2118
 
        XColor      colorCell, rgb;
 
2130
        XGCValues values;
 
2131
        XtGCMask valueMask;
 
2132
        XColor colorCell, rgb;
2119
2133
 
2120
2134
        valueMask = GCForeground | GCBackground;
2121
2135
        if (w->oct.reverse) {
2125
2139
        }
2126
2140
        if (!w->oct.mono) {
2127
2141
                if (XAllocNamedColor(XtDisplay(w),
2128
 
                                  DefaultColormapOfScreen(XtScreen(w)),
2129
 
                                  w->oct.faceName[face], &colorCell, &rgb)) {
 
2142
                                DefaultColormapOfScreen(XtScreen(w)),
 
2143
                                w->oct.faceName[face], &colorCell, &rgb)) {
2130
2144
                        values.foreground = w->oct.faceColor[face] = colorCell.pixel;
2131
2145
                        if (w->oct.faceGC[face])
2132
2146
                                XtReleaseGC((Widget) w, w->oct.faceGC[face]);
2160
2174
static void
2161
2175
SetAllColors(OctWidget w)
2162
2176
{
2163
 
        XGCValues   values;
2164
 
        XtGCMask    valueMask;
2165
 
        int         face;
 
2177
        XGCValues values;
 
2178
        XtGCMask valueMask;
 
2179
        int face;
2166
2180
 
2167
2181
        valueMask = GCForeground | GCBackground;
2168
2182
 
2213
2227
                        w->oct.fontInfo->fid);
2214
2228
}
2215
2229
 
2216
 
static      Boolean
 
2230
static Boolean
2217
2231
SetValuesOct(Widget current, Widget request, Widget renew)
2218
2232
{
2219
 
        OctWidget   c = (OctWidget) current, w = (OctWidget) renew;
2220
 
        Boolean     redraw = False, setColors = False;
2221
 
        int         face;
 
2233
        OctWidget c = (OctWidget) current, w = (OctWidget) renew;
 
2234
        Boolean redraw = False, setColors = False;
 
2235
        int face;
2222
2236
 
2223
2237
        CheckPieces(w);
2224
2238
        for (face = 0; face < MAXFACES; face++) {
2235
2249
                SetAllColors(w);
2236
2250
                redraw = True;
2237
2251
        } else if (w->oct.background != c->oct.background ||
2238
 
            w->oct.foreground != c->oct.foreground ||
2239
 
            setColors) {
 
2252
                        w->oct.foreground != c->oct.foreground ||
 
2253
                        setColors) {
2240
2254
                SetAllColors(w);
2241
2255
                redraw = True;
2242
2256
        }
2248
2262
                redraw = True;
2249
2263
        }
2250
2264
        if (w->oct.size != c->oct.size ||
2251
 
            w->oct.mode != c->oct.mode ||
2252
 
            w->oct.sticky != c->oct.sticky) {
 
2265
                        w->oct.mode != c->oct.mode ||
 
2266
                        w->oct.sticky != c->oct.sticky) {
2253
2267
                SizeOct(w);
2254
2268
                redraw = True;
2255
2269
        }
2327
2341
static void
2328
2342
DestroyOct(Widget old)
2329
2343
{
2330
 
        OctWidget   w = (OctWidget) old;
2331
 
        int         face;
 
2344
        OctWidget w = (OctWidget) old;
 
2345
        int face;
2332
2346
 
2333
2347
        for (face = 0; face < MAXFACES; face++)
2334
2348
                XtReleaseGC(old, w->oct.faceGC[face]);
2345
2359
void
2346
2360
ResizeOct(OctWidget w)
2347
2361
{
2348
 
        int         tempLength;
 
2362
        int tempLength;
2349
2363
#ifdef WINVER
2350
 
        RECT        rect;
 
2364
        RECT rect;
2351
2365
 
2352
2366
        /* Determine size of client area */
2353
2367
        (void) GetClientRect(w->core.hWnd, &rect);
2399
2413
#endif
2400
2414
)
2401
2415
{
2402
 
        int         face, orient;
 
2416
        int face, orient;
2403
2417
#ifdef WINVER
2404
 
        SetValuesOct(w);
 
2418
        SetValuesOct(w);
2405
2419
#else
2406
 
        OctWidget   w = (OctWidget) renew;
 
2420
        OctWidget w = (OctWidget) renew;
2407
2421
 
2408
2422
        w->oct.mono = (DefaultDepthOfScreen(XtScreen(w)) < 2 ||
2409
2423
                w->oct.mono);
2448
2462
)
2449
2463
{
2450
2464
#ifndef WINVER
2451
 
        OctWidget   w = (OctWidget) renew;
 
2465
        OctWidget w = (OctWidget) renew;
2452
2466
 
2453
2467
        if (!w->core.visible)
2454
2468
                return;
2483
2497
#endif
2484
2498
)
2485
2499
{
2486
 
        RTT         rtt;
 
2500
        RTT rtt;
2487
2501
#ifndef WINVER
2488
 
        int  x = event->xbutton.x, y = event->xbutton.y;
 
2502
        int x = event->xbutton.x, y = event->xbutton.y;
2489
2503
        int control = (int) (event->xkey.state & ControlMask);
2490
2504
#endif
2491
2505
 
2510
2524
#endif
2511
2525
)
2512
2526
{
2513
 
        int         style, face, count = -1, direction = 0;
2514
 
        RTT         rtt;
 
2527
        int style, face, count = -1, direction = 0;
 
2528
        RTT rtt;
2515
2529
#ifndef WINVER
2516
 
        int  x = event->xbutton.x, y = event->xbutton.y;
 
2530
        int x = event->xbutton.x, y = event->xbutton.y;
2517
2531
        int shift = (int) (event->xbutton.state & (ShiftMask | LockMask));
2518
2532
        int control = (int) (event->xkey.state & ControlMask);
2519
2533
#endif
2531
2545
                                style = (w->oct.mode == PERIOD3) ? PERIOD3 : PERIOD4;
2532
2546
                } else
2533
2547
                        style = (shift) ? PERIOD4 : PERIOD3;
2534
 
                if (face == w->oct.currentFace)
2535
 
                        count = CheckMoveDir(w, ToRTT(w->oct.currentPosition), rtt, face,
2536
 
                                             &direction);
 
2548
                if (face == w->oct.currentFace) {
 
2549
                        RTT rtt1;
 
2550
 
 
2551
                        ToRTT(w->oct.currentPosition, &rtt1);
 
2552
                        count = CheckMoveDir(w, rtt1, rtt, face, &direction);
 
2553
                }
2537
2554
                if (count == 1 && NarrowSelection(style, &face, &direction)) {
2538
2555
                        MoveOct(w, face, w->oct.currentPosition,
2539
2556
                                direction, style, (control) ? 1 : 0);
2818
2835
MoveOctCcw(OctWidget w, XEvent * event, char **args, int nArgs)
2819
2836
{
2820
2837
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, CCW,
2821
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2822
 
                     (int) (event->xbutton.state & ControlMask));
 
2838
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2839
                (int) (event->xbutton.state & ControlMask));
2823
2840
}
2824
2841
 
2825
2842
static void
2826
2843
MoveOctTl(OctWidget w, XEvent * event, char **args, int nArgs)
2827
2844
{
2828
2845
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, TL,
2829
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2830
 
                     (int) (event->xkey.state & ControlMask));
 
2846
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2847
                (int) (event->xkey.state & ControlMask));
2831
2848
}
2832
2849
 
2833
2850
static void
2834
2851
MoveOctTop(OctWidget w, XEvent * event, char **args, int nArgs)
2835
2852
{
2836
2853
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, TOP,
2837
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2838
 
                     (int) (event->xkey.state & ControlMask));
 
2854
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2855
                (int) (event->xkey.state & ControlMask));
2839
2856
}
2840
2857
 
2841
2858
static void
2842
2859
MoveOctTr(OctWidget w, XEvent * event, char **args, int nArgs)
2843
2860
{
2844
2861
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, TR,
2845
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2846
 
                     (int) (event->xkey.state & ControlMask));
 
2862
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2863
                (int) (event->xkey.state & ControlMask));
2847
2864
}
2848
2865
 
2849
2866
static void
2850
2867
MoveOctLeft(OctWidget w, XEvent * event, char **args, int nArgs)
2851
2868
{
2852
2869
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, LEFT,
2853
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2854
 
                     (int) (event->xkey.state & ControlMask));
 
2870
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2871
                (int) (event->xkey.state & ControlMask));
2855
2872
}
2856
2873
 
2857
2874
static void
2858
2875
MoveOctCw(OctWidget w, XEvent * event, char **args, int nArgs)
2859
2876
{
2860
2877
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, CW,
2861
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2862
 
                     (int) (event->xkey.state & ControlMask));
 
2878
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2879
                (int) (event->xkey.state & ControlMask));
2863
2880
}
2864
2881
 
2865
2882
static void
2866
2883
MoveOctRight(OctWidget w, XEvent * event, char **args, int nArgs)
2867
2884
{
2868
2885
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, RIGHT,
2869
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2870
 
                     (int) (event->xkey.state & ControlMask));
 
2886
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2887
                (int) (event->xkey.state & ControlMask));
2871
2888
}
2872
2889
 
2873
2890
static void
2874
2891
MoveOctBl(OctWidget w, XEvent * event, char **args, int nArgs)
2875
2892
{
2876
2893
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, BL,
2877
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2878
 
                     (int) (event->xkey.state & ControlMask));
 
2894
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2895
                (int) (event->xkey.state & ControlMask));
2879
2896
}
2880
2897
 
2881
2898
static void
2882
2899
MoveOctBottom(OctWidget w, XEvent * event, char **args, int nArgs)
2883
2900
{
2884
2901
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, BOTTOM,
2885
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2886
 
                     (int) (event->xkey.state & ControlMask));
 
2902
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2903
                (int) (event->xkey.state & ControlMask));
2887
2904
}
2888
2905
 
2889
2906
static void
2890
2907
MoveOctBr(OctWidget w, XEvent * event, char **args, int nArgs)
2891
2908
{
2892
2909
        MoveOctInput(w, event->xbutton.x, event->xbutton.y, BR,
2893
 
                     (int) (event->xbutton.state & (ShiftMask | LockMask)),
2894
 
                     (int) (event->xkey.state & ControlMask));
 
2910
                (int) (event->xbutton.state & (ShiftMask | LockMask)),
 
2911
                (int) (event->xkey.state & ControlMask));
2895
2912
}
2896
2913
#endif