Skip to content

Only create new blocks in flyout at certain angle #179 #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 11, 2016
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions core/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ Blockly.Flyout.prototype.height_ = 0;
*/
Blockly.Flyout.prototype.verticalOffset_ = 0;

/**
* Angle size at which blocks are created from a fixed flyout on touch.

This comment was marked as abuse.

* @type {number}
* @private
*/
Blockly.Flyout.prototype.directionRange_ = 140;

/**
* Creates the flyout's DOM. Only needs to be called once.
* @return {!Element} The flyout's SVG group.
Expand Down Expand Up @@ -301,7 +308,7 @@ Blockly.Flyout.prototype.setMetrics_ = function(xyRatio) {

Blockly.Flyout.prototype.setVerticalOffset = function(verticalOffset) {
this.verticalOffset_ = verticalOffset;
}
};

/**
* Move the toolbox to the edge of the workspace.
Expand Down Expand Up @@ -671,6 +678,8 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
// Left-click (or middle click)
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
// Record the current mouse position.
flyout.startDragMouseY_ = e.clientY;
flyout.startDragMouseX_ = e.clientX;
Blockly.Flyout.startDownEvent_ = e;
Blockly.Flyout.startBlock_ = block;
Blockly.Flyout.startFlyout_ = flyout;
Expand Down Expand Up @@ -751,12 +760,46 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) {
}
var dx = e.clientX - Blockly.Flyout.startDownEvent_.clientX;
var dy = e.clientY - Blockly.Flyout.startDownEvent_.clientY;
// Still dragging within the sticky DRAG_RADIUS.
if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) {

// Direction goes from -180 to 180, with 0 toward the right and 90 on top.
var direction = Math.atan2(dy, dx) / Math.PI * 180;

This comment was marked as abuse.


// Do a direction check based on the flyout position

This comment was marked as abuse.

This comment was marked as abuse.

var directionCheck = false;
var range = Blockly.Flyout.startFlyout_.directionRange_;
if (Blockly.Flyout.startFlyout_.horizontalLayout_) {
if (Blockly.Flyout.startFlyout_.toolboxPosition_ == Blockly.TOOLBOX_AT_TOP) {
if (direction < 90 + range / 2 && direction > 90 - range / 2) {
directionCheck = true;
}
} else {
if (direction > -90 - range / 2 && direction < -90 + range / 2) {
directionCheck = true;
}
}
} else {

This comment was marked as abuse.

if (Blockly.Flyout.startFlyout_.toolboxPosition_ == Blockly.TOOLBOX_AT_LEFT) {
if (direction < range / 2 && direction > -range / 2) {
directionCheck = true;
}
} else {
if (direction < -180 + range / 2 || direction > 180 - range / 2) {
directionCheck = true;
}
}
}

// Don't create a block within the sticky drag radius,
// or if we failed the direction check.
if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS && directionCheck) {

This comment was marked as abuse.

// Create the block.
Blockly.Flyout.startFlyout_.createBlockFunc_(Blockly.Flyout.startBlock_)(
Blockly.Flyout.startDownEvent_);
} else {
// Do a scroll
Blockly.Flyout.startFlyout_.onMouseMove_(e);
}
e.stopPropagation();
};

/**
Expand Down