@@ -780,10 +780,30 @@ Blockly.BlockSvg.SEP_SPACE_Y = 8;
780
780
*/
781
781
Blockly . BlockSvg . INLINE_PADDING_Y = 5 ;
782
782
/**
783
- * Minimum height of a block.
783
+ * Height of user inputs
784
784
* @const
785
785
*/
786
- Blockly . BlockSvg . MIN_BLOCK_Y = 25 ;
786
+ Blockly . BlockSvg . FIELD_HEIGHT = 32 ;
787
+ /**
788
+ * Width of user inputs
789
+ * @const
790
+ */
791
+ Blockly . BlockSvg . FIELD_WIDTH = 48 ;
792
+ /**
793
+ * Corner radius of number inputs
794
+ * @const
795
+ */
796
+ Blockly . BlockSvg . NUMBER_FIELD_CORNER_RADIUS = 16 ;
797
+ /**
798
+ * Corner radius of text inputs
799
+ * @const
800
+ */
801
+ Blockly . BlockSvg . TEXT_FIELD_CORNER_RADIUS = 4 ;
802
+ /**
803
+ * Minimum width of a block.
804
+ * @const
805
+ */
806
+ Blockly . BlockSvg . MIN_BLOCK_X = 40 ;
787
807
/**
788
808
* Width of horizontal puzzle tab.
789
809
* @const
@@ -1122,13 +1142,13 @@ Blockly.BlockSvg.disconnectUiStop_.group = null;
1122
1142
*/
1123
1143
Blockly . BlockSvg . prototype . updateColour = function ( ) {
1124
1144
// Render block fill
1125
- var hexColour = this . getColour ( ) ;
1145
+ var hexColour = this . parentBlock_ ? this . parentBlock_ . getColour ( ) : this . getColour ( ) ;
1126
1146
var rgb = goog . color . hexToRgb ( hexColour ) ;
1127
1147
if ( this . isShadow ( ) ) {
1128
- rgb = goog . color . lighten ( rgb , 0.6 ) ;
1129
- hexColour = goog . color . rgbArrayToHex ( rgb ) ;
1148
+ this . svgPath_ . setAttribute ( 'fill' , '#ffffff' ) ;
1149
+ } else {
1150
+ this . svgPath_ . setAttribute ( 'fill' , hexColour ) ;
1130
1151
}
1131
- this . svgPath_ . setAttribute ( 'fill' , hexColour ) ;
1132
1152
1133
1153
// Render block stroke
1134
1154
var colorShift = goog . color . darken ( rgb , 0.1 ) ;
@@ -1345,13 +1365,26 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) {
1345
1365
Blockly . BlockSvg . prototype . renderCompute_ = function ( ) {
1346
1366
var metrics = {
1347
1367
statement : null ,
1368
+ valueInput : null ,
1348
1369
icon : null ,
1349
1370
width : 0 ,
1350
1371
height : 0 ,
1351
1372
bayHeight : 0 ,
1352
- bayWidth : 0
1373
+ bayWidth : 0 ,
1374
+ fieldWidth : 0 ,
1375
+ fieldHeight : 0 ,
1376
+ fieldRadius : 0 ,
1377
+ startHat : false ,
1378
+ endHat : false
1353
1379
} ;
1354
1380
1381
+ if ( this . nextConnection && ! this . previousConnection ) {
1382
+ metrics . startHat = true ;
1383
+ }
1384
+ if ( this . previousConnection && ! this . nextConnection ) {
1385
+ metrics . endHat = true ;
1386
+ }
1387
+
1355
1388
// Does block have a statement?
1356
1389
for ( var i = 0 , input ; input = this . inputList [ i ] ; i ++ ) {
1357
1390
if ( input . type == Blockly . NEXT_STATEMENT ) {
@@ -1361,7 +1394,7 @@ Blockly.BlockSvg.prototype.renderCompute_ = function() {
1361
1394
metrics . bayHeight = Blockly . BlockSvg . NOTCH_HEIGHT + 16 +
1362
1395
Blockly . BlockSvg . CORNER_RADIUS * 3 ;
1363
1396
metrics . bayWidth = Blockly . BlockSvg . NOTCH_WIDTH * 2 +
1364
- Blockly . BlockSvg . SEP_SPACE_X ;
1397
+ Blockly . BlockSvg . MIN_BLOCK_X ;
1365
1398
// Expand input size if there is a connection.
1366
1399
if ( input . connection && input . connection . targetConnection ) {
1367
1400
var linkedBlock = input . connection . targetBlock ( ) ;
@@ -1376,6 +1409,22 @@ Blockly.BlockSvg.prototype.renderCompute_ = function() {
1376
1409
if ( field instanceof Blockly . FieldImage ) {
1377
1410
metrics . icon = field ;
1378
1411
}
1412
+ if ( field instanceof Blockly . FieldTextInput ) {
1413
+ var fieldBBox = field . textElement_ . getBBox ( ) ;
1414
+ metrics . fieldWidth = fieldBBox . width + Blockly . BlockSvg . SEP_SPACE_X ;
1415
+ metrics . fieldHeight = fieldBBox . height ;
1416
+ if ( field . sourceBlock_ . type === 'math_number' ) {
1417
+ metrics . fieldRadius = Blockly . BlockSvg . NUMBER_FIELD_CORNER_RADIUS ;
1418
+ } else {
1419
+ metrics . fieldRadius = Blockly . BlockSvg . TEXT_FIELD_CORNER_RADIUS ;
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+
1425
+ for ( var i = 0 , child ; child = this . childBlocks_ [ i ] ; i ++ ) {
1426
+ if ( child . isShadow ( ) ) {
1427
+ metrics . valueInput = child ;
1379
1428
}
1380
1429
}
1381
1430
@@ -1385,11 +1434,16 @@ Blockly.BlockSvg.prototype.renderCompute_ = function() {
1385
1434
if ( metrics . statement ) {
1386
1435
metrics . width += 2 * Blockly . BlockSvg . CORNER_RADIUS + 8 ;
1387
1436
}
1388
- metrics . height = Math . max (
1389
- Blockly . BlockSvg . SEP_SPACE_Y * 2 + iconSize . height ,
1390
- Blockly . BlockSvg . NOTCH_HEIGHT + 16 + Blockly . BlockSvg . CORNER_RADIUS * 2 ,
1391
- metrics . bayHeight + Blockly . BlockSvg . SEP_SPACE_Y
1392
- ) ;
1437
+ if ( this . outputConnection ) {
1438
+ metrics . height = Blockly . BlockSvg . FIELD_HEIGHT ;
1439
+ metrics . width = Blockly . BlockSvg . FIELD_WIDTH ;
1440
+ } else {
1441
+ metrics . height = Math . max (
1442
+ Blockly . BlockSvg . SEP_SPACE_Y * 2 + iconSize . height ,
1443
+ Blockly . BlockSvg . NOTCH_HEIGHT + 16 + Blockly . BlockSvg . CORNER_RADIUS * 2 ,
1444
+ metrics . bayHeight + Blockly . BlockSvg . SEP_SPACE_Y
1445
+ ) ;
1446
+ }
1393
1447
return metrics ;
1394
1448
} ;
1395
1449
@@ -1433,6 +1487,16 @@ Blockly.BlockSvg.prototype.renderDraw_ = function(metrics) {
1433
1487
( metrics . height - iconSize . height - Blockly . BlockSvg . SEP_SPACE_Y ) + ')' ) ;
1434
1488
// @todo RTL
1435
1489
}
1490
+
1491
+ // Position value input
1492
+ if ( metrics . valueInput ) {
1493
+ var input = metrics . valueInput . getSvgRoot ( ) ;
1494
+ var inputBBox = input . getBBox ( ) ;
1495
+ var transformation = 'translate(' +
1496
+ ( Blockly . BlockSvg . NOTCH_WIDTH + ( metrics . bayWidth ? 8 + Blockly . BlockSvg . NOTCH_WIDTH * 2 : 0 ) + metrics . bayWidth ) + ',' +
1497
+ ( metrics . height - 8 ) + ')' ;
1498
+ input . setAttribute ( 'transform' , transformation ) ;
1499
+ }
1436
1500
} ;
1437
1501
1438
1502
/**
@@ -1446,7 +1510,15 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
1446
1510
function ( steps , connectionsXY , metrics ) {
1447
1511
1448
1512
// Top edge.
1449
- if ( this . previousConnection ) {
1513
+ if ( metrics . startHat ) {
1514
+ // Hat block
1515
+ // Position the cursor at the top-left starting point.
1516
+ steps . push ( Blockly . BlockSvg . HAT_TOP_LEFT_CORNER_START ) ;
1517
+ // Top-left rounded corner.
1518
+ steps . push ( Blockly . BlockSvg . HAT_TOP_LEFT_CORNER ) ;
1519
+ steps . push ( 'V' , metrics . height - Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1520
+ } else if ( this . previousConnection ) {
1521
+ // Regular block
1450
1522
// Position the cursor at the top-left starting point.
1451
1523
steps . push ( Blockly . BlockSvg . TOP_LEFT_CORNER_START ) ;
1452
1524
// Top-left rounded corner.
@@ -1461,11 +1533,15 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
1461
1533
// This connection will be tightened when the parent renders.
1462
1534
steps . push ( 'V' , metrics . height - Blockly . BlockSvg . CORNER_RADIUS ) ;
1463
1535
} else {
1536
+ // Input
1464
1537
// Position the cursor at the top-left starting point.
1465
- steps . push ( Blockly . BlockSvg . HAT_TOP_LEFT_CORNER_START ) ;
1538
+ steps . push ( 'm' , metrics . fieldRadius + ',0' ) ;
1466
1539
// Top-left rounded corner.
1467
- steps . push ( Blockly . BlockSvg . HAT_TOP_LEFT_CORNER ) ;
1468
- steps . push ( 'V' , metrics . height - Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1540
+ steps . push (
1541
+ 'A' , metrics . fieldRadius + ',' + metrics . fieldRadius ,
1542
+ '0' , '0,0' , '0,' + metrics . fieldRadius ) ;
1543
+ steps . push (
1544
+ 'V' , metrics . height - metrics . fieldRadius ) ;
1469
1545
}
1470
1546
} ;
1471
1547
@@ -1482,16 +1558,21 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
1482
1558
Blockly . BlockSvg . prototype . renderDrawBottom_ = function ( steps ,
1483
1559
connectionsXY , metrics ) {
1484
1560
1485
- if ( this . previousConnection ) {
1561
+ if ( metrics . startHat ) {
1562
+ steps . push ( 'a' , Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1563
+ Blockly . BlockSvg . HAT_CORNER_RADIUS + ' 0 0,0 ' +
1564
+ Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1565
+ Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1566
+ } else if ( this . previousConnection ) {
1486
1567
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1487
1568
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,0 ' +
1488
1569
Blockly . BlockSvg . CORNER_RADIUS + ',' +
1489
1570
Blockly . BlockSvg . CORNER_RADIUS ) ;
1490
1571
} else {
1491
- steps . push ( 'a' , Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1492
- Blockly . BlockSvg . HAT_CORNER_RADIUS + ' 0 0,0 ' +
1493
- Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1494
- Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1572
+ // Input
1573
+ steps . push (
1574
+ 'a' , metrics . fieldRadius + ',' + metrics . fieldRadius ,
1575
+ '0' , '0,0' , metrics . fieldRadius + ',' + metrics . fieldRadius ) ;
1495
1576
}
1496
1577
1497
1578
// Has statement
@@ -1533,10 +1614,13 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
1533
1614
}
1534
1615
}
1535
1616
1536
- if ( this . nextConnection ) {
1617
+ if ( metrics . endHat ) {
1618
+ steps . push ( 'H' , metrics . width - Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1619
+ } else if ( this . nextConnection ) {
1537
1620
steps . push ( 'H' , metrics . width - Blockly . BlockSvg . CORNER_RADIUS ) ;
1538
1621
} else {
1539
- steps . push ( 'H' , metrics . width - Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1622
+ // input
1623
+ steps . push ( 'H' , metrics . width - metrics . fieldRadius ) ;
1540
1624
}
1541
1625
} ;
1542
1626
@@ -1549,20 +1633,29 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
1549
1633
*/
1550
1634
Blockly . BlockSvg . prototype . renderDrawRight_ =
1551
1635
function ( steps , connectionsXY , metrics ) {
1552
- if ( this . nextConnection ) {
1636
+ if ( metrics . endHat ) {
1637
+ steps . push ( 'a' , Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1638
+ Blockly . BlockSvg . HAT_CORNER_RADIUS + ' 0 0,0 ' +
1639
+ Blockly . BlockSvg . HAT_CORNER_RADIUS + ',-' +
1640
+ Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1641
+ steps . push ( 'v' , - 8 ) ;
1642
+ } else if ( this . nextConnection ) {
1553
1643
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1554
1644
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,0 ' +
1555
1645
Blockly . BlockSvg . CORNER_RADIUS + ',-' +
1556
1646
Blockly . BlockSvg . CORNER_RADIUS ) ;
1647
+ steps . push ( 'v' , - 8 ) ;
1557
1648
} else {
1558
- steps . push ( 'a' , Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1559
- Blockly . BlockSvg . HAT_CORNER_RADIUS + ' 0 0,0 ' +
1560
- Blockly . BlockSvg . HAT_CORNER_RADIUS + ',-' +
1561
- Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1649
+ // Input
1650
+ steps . push (
1651
+ 'a' , metrics . fieldRadius + ',' + metrics . fieldRadius ,
1652
+ '0' , '0,0' , metrics . fieldRadius + ',' + - 1 * metrics . fieldRadius ) ;
1653
+ steps . push ( 'v' , - 1 * ( metrics . height - metrics . fieldRadius * 2 ) ) ;
1562
1654
}
1563
- steps . push ( 'v' , - 8 ) ;
1564
1655
1565
- if ( this . nextConnection ) {
1656
+ if ( metrics . endHat ) {
1657
+ steps . push ( 'V' , Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1658
+ } else if ( this . nextConnection ) {
1566
1659
steps . push ( Blockly . BlockSvg . NOTCH_PATH_UP ) ;
1567
1660
1568
1661
// Create next block connection.
@@ -1579,8 +1672,6 @@ Blockly.BlockSvg.prototype.renderDrawRight_ =
1579
1672
}
1580
1673
this . height += 4 ; // Height of tab.
1581
1674
steps . push ( 'V' , Blockly . BlockSvg . CORNER_RADIUS ) ;
1582
- } else {
1583
- steps . push ( 'V' , Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1584
1675
}
1585
1676
} ;
1586
1677
@@ -1593,16 +1684,20 @@ Blockly.BlockSvg.prototype.renderDrawRight_ =
1593
1684
*/
1594
1685
Blockly . BlockSvg . prototype . renderDrawTop_ =
1595
1686
function ( steps , connectionsXY , metrics ) {
1596
- if ( this . nextConnection ) {
1687
+ if ( metrics . endHat ) {
1688
+ steps . push ( 'a' , Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1689
+ Blockly . BlockSvg . HAT_CORNER_RADIUS + ' 0 0,0 -' +
1690
+ Blockly . BlockSvg . HAT_CORNER_RADIUS + ',-' +
1691
+ Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1692
+ } else if ( this . nextConnection ) {
1597
1693
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1598
1694
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,0 -' +
1599
1695
Blockly . BlockSvg . CORNER_RADIUS + ',-' +
1600
1696
Blockly . BlockSvg . CORNER_RADIUS ) ;
1601
1697
} else {
1602
- steps . push ( 'a' , Blockly . BlockSvg . HAT_CORNER_RADIUS + ',' +
1603
- Blockly . BlockSvg . HAT_CORNER_RADIUS + ' 0 0,0 -' +
1604
- Blockly . BlockSvg . HAT_CORNER_RADIUS + ',-' +
1605
- Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1698
+ steps . push (
1699
+ 'a' , metrics . fieldRadius + ',' + metrics . fieldRadius ,
1700
+ '0' , '0,0' , '-' + metrics . fieldRadius + ',-' + metrics . fieldRadius ) ;
1606
1701
}
1607
1702
steps . push ( 'z' ) ;
1608
1703
} ;
0 commit comments