mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Make hats have height!
This commit is contained in:
@@ -723,14 +723,6 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) {
|
||||
rect.setAttribute('width', blockHW.width);
|
||||
rect.setAttribute('height', blockHW.height);
|
||||
|
||||
// For hat blocks we want to shift them down by the hat height
|
||||
// since the y coordinate is the corner, not the top of the hat.
|
||||
var hatOffset =
|
||||
block.startHat_ ? Blockly.BlockSvg.START_HAT_HEIGHT : 0;
|
||||
if (hatOffset) {
|
||||
block.moveBy(0, hatOffset);
|
||||
}
|
||||
|
||||
// Blocks with output tabs are shifted a bit.
|
||||
var tab = block.outputConnection ? Blockly.BlockSvg.TAB_WIDTH : 0;
|
||||
var blockXY = block.getRelativeToSurfaceXY();
|
||||
|
||||
@@ -133,7 +133,7 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() {
|
||||
}
|
||||
this.positionPreviousConnection_();
|
||||
this.steps_.push(
|
||||
Blockly.utils.svgPaths.moveBy(this.info_.startX, this.info_.startY));
|
||||
Blockly.utils.svgPaths.moveBy(this.info_.startX, 0));
|
||||
for (var i = 0, elem; elem = elements[i]; i++) {
|
||||
if (elem.type === 'round corner') {
|
||||
this.steps_.push(Blockly.blockRendering.constants.OUTSIDE_CORNERS.topLeft);
|
||||
@@ -225,7 +225,7 @@ Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) {
|
||||
this.highlighter_.drawRightSideRow(row);
|
||||
}
|
||||
this.steps_.push('H', this.info_.startX + row.width);
|
||||
this.steps_.push('V', this.info_.startY + row.yPos + row.height);
|
||||
this.steps_.push('V', row.yPos + row.height);
|
||||
};
|
||||
|
||||
|
||||
@@ -269,8 +269,7 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() {
|
||||
var outputConnection = this.info_.outputConnection;
|
||||
this.positionOutputConnection_();
|
||||
if (outputConnection) {
|
||||
var tabBottom = this.info_.startY +
|
||||
outputConnection.connectionOffsetY + outputConnection.height;
|
||||
var tabBottom = outputConnection.connectionOffsetY + outputConnection.height;
|
||||
// Draw a line up to the bottom of the tab.
|
||||
this.steps_.push('V', tabBottom);
|
||||
this.steps_.push(Blockly.blockRendering.constants.PUZZLE_TAB.pathUp);
|
||||
@@ -442,7 +441,7 @@ Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = function()
|
||||
if (this.info_.topRow.hasPreviousConnection) {
|
||||
var x = this.info_.startX + Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;
|
||||
var connX = (this.info_.RTL ? -x : x);
|
||||
this.info_.topRow.connection.setOffsetInBlock(connX, this.info_.startY);
|
||||
this.info_.topRow.connection.setOffsetInBlock(connX, 0);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -458,7 +457,7 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() {
|
||||
var x = connInfo.xPos; // Already contains info about startX
|
||||
var connX = (this.info_.RTL ? -x : x) + 0.5;
|
||||
bottomRow.connection.setOffsetInBlock(
|
||||
connX, this.info_.startY + this.info_.height +
|
||||
connX, this.info_.height +
|
||||
Blockly.blockRendering.constants.DARK_PATH_OFFSET);
|
||||
}
|
||||
};
|
||||
@@ -473,6 +472,6 @@ Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() {
|
||||
var x = this.info_.startX;
|
||||
var connX = this.info_.RTL ? -x : x;
|
||||
this.block_.outputConnection.setOffsetInBlock(connX,
|
||||
this.info_.startY + this.info_.outputConnection.connectionOffsetY);
|
||||
this.info_.outputConnection.connectionOffsetY);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ Blockly.blockRendering.Highlighter = function(info, pathObject) {
|
||||
|
||||
Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) {
|
||||
this.steps_.push(
|
||||
Blockly.utils.svgPaths.moveBy(this.info_.startX, this.info_.startY));
|
||||
Blockly.utils.svgPaths.moveBy(this.info_.startX, 0));
|
||||
for (var i = 0, elem; elem = row.elements[i]; i++) {
|
||||
if (elem.type === 'square corner') {
|
||||
this.steps_.push(Blockly.blockRendering.highlightConstants.START_POINT);
|
||||
@@ -151,8 +151,7 @@ Blockly.blockRendering.Highlighter.prototype.drawRightSideRow = function(row) {
|
||||
}
|
||||
if (this.RTL_) {
|
||||
this.steps_.push('H', rightEdge);
|
||||
this.steps_.push('V',
|
||||
this.info_.startY + row.yPos + row.height - this.highlightOffset_);
|
||||
this.steps_.push('V', row.yPos + row.height - this.highlightOffset_);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -180,12 +179,12 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomRow = function(row) {
|
||||
Blockly.blockRendering.Highlighter.prototype.drawLeft = function() {
|
||||
var outputConnection = this.info_.outputConnection;
|
||||
if (outputConnection) {
|
||||
var tabBottom = this.info_.startY +
|
||||
var tabBottom =
|
||||
outputConnection.connectionOffsetY + outputConnection.height;
|
||||
// Draw a line up to the bottom of the tab.
|
||||
if (!this.RTL_) {
|
||||
var left = this.info_.startX + this.highlightOffset_;
|
||||
var bottom = this.info_.startY + this.info_.height - this.highlightOffset_;
|
||||
var bottom = this.info_.height - this.highlightOffset_;
|
||||
this.steps_.push(Blockly.utils.svgPaths.moveTo(left, bottom));
|
||||
this.steps_.push('V', tabBottom);
|
||||
} else {
|
||||
@@ -198,14 +197,9 @@ Blockly.blockRendering.Highlighter.prototype.drawLeft = function() {
|
||||
if (!this.RTL_) {
|
||||
var topRow = this.info_.topRow;
|
||||
if (topRow.elements[0].isRoundedCorner()) {
|
||||
this.steps_.push('V', this.info_.startY + this.outsideCornerPaths_.height);
|
||||
} else if (topRow.elements.length >= 3 && topRow.elements[2].type === 'hat'){
|
||||
this.steps_.push('V',
|
||||
this.info_.startY +
|
||||
Blockly.blockRendering.constants.START_HAT.height +
|
||||
this.highlightOffset_);
|
||||
this.steps_.push('V', this.outsideCornerPaths_.height);
|
||||
} else {
|
||||
this.steps_.push('V', this.info_.startY + this.highlightOffset_);
|
||||
this.steps_.push('V', topRow.startY + this.highlightOffset_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,7 +228,7 @@ Blockly.blockRendering.RenderInfo.prototype.createTopRow_ = function() {
|
||||
if (hasHat) {
|
||||
var hat = new Blockly.blockRendering.Hat();
|
||||
this.topRow.elements.push(hat);
|
||||
//this.startY = hat.height;
|
||||
this.startY = hat.startY;
|
||||
} else if (hasPrevious) {
|
||||
this.topRow.elements.push(new Blockly.blockRendering.PreviousConnection());
|
||||
}
|
||||
@@ -700,11 +700,10 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() {
|
||||
var yCursor = 0;
|
||||
for (var r = 0; r < this.rows.length; r++) {
|
||||
var row = this.rows[r];
|
||||
row.yPos = yCursor + this.startY;
|
||||
row.yPos = yCursor;
|
||||
yCursor += row.height;
|
||||
// Add padding to the bottom row if block height is less than minimum
|
||||
var heightWithoutHat =
|
||||
this.block_.hat ? yCursor - Blockly.blockRendering.constants.START_HAT.height : yCursor;
|
||||
var heightWithoutHat = yCursor - this.topRow.startY;
|
||||
if (row == this.bottomRow &&
|
||||
heightWithoutHat < Blockly.blockRendering.constants.MIN_BLOCK_HEIGHT) {
|
||||
// But the hat height shouldn't be part of this.
|
||||
|
||||
@@ -380,6 +380,7 @@ Blockly.blockRendering.Hat = function() {
|
||||
this.type = 'hat';
|
||||
this.height = Blockly.blockRendering.constants.START_HAT.height;
|
||||
this.width = Blockly.blockRendering.constants.START_HAT.width;
|
||||
this.startY = this.height;
|
||||
|
||||
};
|
||||
goog.inherits(Blockly.blockRendering.Hat, Blockly.blockRendering.Measurable);
|
||||
@@ -512,6 +513,7 @@ Blockly.blockRendering.TopRow = function(block) {
|
||||
|
||||
this.elements = [];
|
||||
this.type = 'top row';
|
||||
this.startY = 0;
|
||||
|
||||
this.hasPreviousConnection = !!block.previousConnection;
|
||||
this.connection = block.previousConnection;
|
||||
@@ -543,13 +545,15 @@ Blockly.blockRendering.TopRow.prototype.measure = function() {
|
||||
this.width += elem.width;
|
||||
if (!(elem.isSpacer())) {
|
||||
if (elem.type == 'hat') {
|
||||
this.height = elem.height + this.height;
|
||||
this.startY = elem.startY;
|
||||
this.height = this.height + elem.height;
|
||||
}
|
||||
this.height = Math.max(this.height, elem.height);
|
||||
}
|
||||
}
|
||||
this.widthWithConnectedBlocks = this.width;
|
||||
};
|
||||
|
||||
Blockly.blockRendering.BottomRow = function(block) {
|
||||
Blockly.blockRendering.BottomRow.superClass_.constructor.call(this);
|
||||
this.type = 'bottom row';
|
||||
|
||||
Reference in New Issue
Block a user