MCPcopy Create free account
hub / github.com/SimHacker/micropolis / toolDrag

Method toolDrag

MicropolisCore/src/MicropolisEngine/src/tool.cpp:1516–1592  ·  view source on GitHub ↗

* Drag a tool from (\a fromX, \a fromY) to (\a toX, \a toY). * @param tool Tool being dragged. * @param fromX Horizontal coordinate of the starting position. * @param fromY Vertical coordinate of the starting position. * @param toX Horizontal coordinate of the ending position. * @param toY Vertical coordinate of the ending position. */

Source from the content-addressed store, hash-verified

1514 * @param toY Vertical coordinate of the ending position.
1515 */
1516void Micropolis::toolDrag(EditingTool tool,
1517 short fromX, short fromY, short toX, short toY)
1518{
1519 // Do not drag big tools.
1520 int toolSize = gToolSize[tool];
1521 if (toolSize > 1) {
1522 doTool(tool, toX, toY);
1523
1524 simPass = 0; // update editors overlapping this one
1525 invalidateMaps();
1526 return;
1527 }
1528
1529 short dirX = (toX > fromX) ? 1 : -1; // Horizontal step direction.
1530 short dirY = (toY > fromY) ? 1 : -1; // Vertical step direction.
1531
1532
1533 if (fromX == toX && fromY == toY) {
1534 return;
1535 }
1536
1537 doTool(tool, fromX, fromY); // Ensure the start position is done.
1538
1539 // Vertical line up or down
1540 if (fromX == toX && fromY != toY) {
1541
1542 while (fromY != toY) {
1543 fromY += dirY;
1544 doTool(tool, fromX, fromY);
1545 }
1546
1547 simPass = 0; // update editors overlapping this one
1548 invalidateMaps();
1549 return;
1550 }
1551
1552 // Horizontal line left/right
1553 if (fromX != toX && fromY == toY) {
1554
1555 while (fromX != toX) {
1556 fromX += dirX;
1557 doTool(tool, fromX, fromY);
1558 }
1559
1560 simPass = 0; // update editors overlapping this one
1561 invalidateMaps();
1562 return;
1563 }
1564
1565 // General case: both X and Y change.
1566
1567 short dx = absoluteValue(fromX - toX); // number of horizontal steps.
1568 short dy = absoluteValue(fromY - toY); // number of vertical steps.
1569
1570 short subX = 0; // Each X step is dy sub-steps.
1571 short subY = 0; // Each Y step is dx sub-steps.
1572 short numSubsteps = min(dx, dy); // Number of sub-steps we can do.
1573

Callers 2

handleMouseDragMethod · 0.80

Calls 2

absoluteValueFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected