Skip to content

Commit 8a415ab

Browse files
committed
Merge pull request #47 from rschamp/feature/rounded-hats
Round corners for hat/end blocks
2 parents ce875d0 + 0f05678 commit 8a415ab

File tree

1 file changed

+74
-22
lines changed

1 file changed

+74
-22
lines changed

core/block_horizontal_scratch.js

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,11 @@ Blockly.BlockSvg.NOTCH_HEIGHT = 32;
799799
* @const
800800
*/
801801
Blockly.BlockSvg.CORNER_RADIUS = 4;
802+
/**
803+
* Rounded corner radius.
804+
* @const
805+
*/
806+
Blockly.BlockSvg.HAT_CORNER_RADIUS = 16;
802807
/**
803808
* SVG path for drawing next/previous notch from left to right.
804809
* @const
@@ -830,6 +835,20 @@ Blockly.BlockSvg.TOP_LEFT_CORNER =
830835
'A ' + Blockly.BlockSvg.CORNER_RADIUS + ',' +
831836
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
832837
'0,' + Blockly.BlockSvg.CORNER_RADIUS;
838+
/**
839+
* SVG start point for drawing the top-left corner.
840+
* @const
841+
*/
842+
Blockly.BlockSvg.HAT_TOP_LEFT_CORNER_START =
843+
'm ' + Blockly.BlockSvg.HAT_CORNER_RADIUS + ',0';
844+
/**
845+
* SVG path for drawing the rounded top-left corner.
846+
* @const
847+
*/
848+
Blockly.BlockSvg.HAT_TOP_LEFT_CORNER =
849+
'A ' + Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
850+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ' 0 0,0 ' +
851+
'0,' + Blockly.BlockSvg.HAT_CORNER_RADIUS;
833852
/**
834853
* SVG path for drawing the top-left corner of a statement input.
835854
* Includes the top notch, a horizontal space, and the rounded inside corner.
@@ -1554,13 +1573,13 @@ Blockly.BlockSvg.prototype.renderDraw_ = function(metrics) {
15541573
*/
15551574
Blockly.BlockSvg.prototype.renderDrawLeft_ =
15561575
function(steps, connectionsXY, metrics) {
1557-
// Position the cursor at the top-left starting point.
1558-
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_START);
1559-
// Top-left rounded corner.
1560-
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER);
15611576

15621577
// Top edge.
15631578
if (this.previousConnection) {
1579+
// Position the cursor at the top-left starting point.
1580+
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_START);
1581+
// Top-left rounded corner.
1582+
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER);
15641583
var cursorY = metrics.height - Blockly.BlockSvg.CORNER_RADIUS - 8 - Blockly.BlockSvg.NOTCH_HEIGHT;
15651584
steps.push('V', cursorY);
15661585
steps.push(Blockly.BlockSvg.NOTCH_PATH_DOWN);
@@ -1569,8 +1588,14 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
15691588
var connectionY = connectionsXY.y + metrics.height - Blockly.BlockSvg.CORNER_RADIUS * 2;
15701589
this.previousConnection.moveTo(connectionX, connectionY);
15711590
// This connection will be tightened when the parent renders.
1591+
steps.push('V', metrics.height - Blockly.BlockSvg.CORNER_RADIUS);
1592+
} else {
1593+
// Position the cursor at the top-left starting point.
1594+
steps.push(Blockly.BlockSvg.HAT_TOP_LEFT_CORNER_START);
1595+
// Top-left rounded corner.
1596+
steps.push(Blockly.BlockSvg.HAT_TOP_LEFT_CORNER);
1597+
steps.push('V', metrics.height - Blockly.BlockSvg.HAT_CORNER_RADIUS);
15721598
}
1573-
steps.push('V', metrics.height - Blockly.BlockSvg.CORNER_RADIUS);
15741599
this.height = metrics.height;
15751600
};
15761601

@@ -1587,12 +1612,20 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
15871612
Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
15881613
connectionsXY, metrics) {
15891614

1590-
// Has statement
1591-
if (metrics.hasStatement) {
1615+
if (this.previousConnection) {
15921616
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
15931617
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
15941618
Blockly.BlockSvg.CORNER_RADIUS + ',' +
15951619
Blockly.BlockSvg.CORNER_RADIUS);
1620+
} else {
1621+
steps.push('a', Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
1622+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ' 0 0,0 ' +
1623+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
1624+
Blockly.BlockSvg.HAT_CORNER_RADIUS);
1625+
}
1626+
1627+
// Has statement
1628+
if (metrics.hasStatement) {
15961629
steps.push('h', 8);
15971630
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
15981631
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
@@ -1613,6 +1646,10 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
16131646
steps.push('v', 50 - (Blockly.BlockSvg.CORNER_RADIUS * 2) - Blockly.BlockSvg.NOTCH_HEIGHT - 8);
16141647
steps.push(Blockly.BlockSvg.NOTCH_PATH_DOWN);
16151648
steps.push('v', 8);
1649+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
1650+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
1651+
Blockly.BlockSvg.CORNER_RADIUS + ',' +
1652+
Blockly.BlockSvg.CORNER_RADIUS);
16161653

16171654
// // Nested statement.
16181655
// var input = row[0];
@@ -1658,12 +1695,11 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
16581695
// }
16591696
}
16601697

1661-
// Render corner
1662-
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
1663-
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
1664-
Blockly.BlockSvg.CORNER_RADIUS + ',' +
1665-
Blockly.BlockSvg.CORNER_RADIUS);
1666-
steps.push('H', metrics.width - Blockly.BlockSvg.CORNER_RADIUS);
1698+
if (this.nextConnection) {
1699+
steps.push('H', metrics.width - Blockly.BlockSvg.CORNER_RADIUS);
1700+
} else {
1701+
steps.push('H', metrics.width - Blockly.BlockSvg.HAT_CORNER_RADIUS);
1702+
}
16671703
};
16681704

16691705
/**
@@ -1675,10 +1711,17 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
16751711
*/
16761712
Blockly.BlockSvg.prototype.renderDrawRight_ =
16771713
function(steps, connectionsXY, metrics) {
1678-
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
1679-
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
1680-
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
1681-
Blockly.BlockSvg.CORNER_RADIUS);
1714+
if (this.nextConnection) {
1715+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
1716+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
1717+
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
1718+
Blockly.BlockSvg.CORNER_RADIUS);
1719+
} else {
1720+
steps.push('a', Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
1721+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ' 0 0,0 ' +
1722+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ',-' +
1723+
Blockly.BlockSvg.HAT_CORNER_RADIUS);
1724+
}
16821725
steps.push('v', -8);
16831726

16841727
if (this.nextConnection) {
@@ -1697,8 +1740,10 @@ Blockly.BlockSvg.prototype.renderDrawRight_ =
16971740
this.nextConnection.tighten_();
16981741
}
16991742
this.height += 4; // Height of tab.
1743+
steps.push('V', Blockly.BlockSvg.CORNER_RADIUS);
1744+
} else {
1745+
steps.push('V', Blockly.BlockSvg.HAT_CORNER_RADIUS);
17001746
}
1701-
steps.push('V', Blockly.BlockSvg.CORNER_RADIUS);
17021747
};
17031748

17041749
/**
@@ -1710,9 +1755,16 @@ Blockly.BlockSvg.prototype.renderDrawRight_ =
17101755
*/
17111756
Blockly.BlockSvg.prototype.renderDrawTop_ =
17121757
function(steps, connectionsXY, metrics) {
1713-
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
1714-
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 -' +
1715-
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
1716-
Blockly.BlockSvg.CORNER_RADIUS);
1758+
if (this.nextConnection) {
1759+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
1760+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 -' +
1761+
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
1762+
Blockly.BlockSvg.CORNER_RADIUS);
1763+
} else {
1764+
steps.push('a', Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
1765+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ' 0 0,0 -' +
1766+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ',-' +
1767+
Blockly.BlockSvg.HAT_CORNER_RADIUS);
1768+
}
17171769
steps.push('z');
17181770
};

0 commit comments

Comments
 (0)