UNPKG

cloud-blocks

Version:

Cloud Blocks is a library for building scratch computing interfaces with Luxrobo MODI.

135 lines (121 loc) 4.06 kB
/** * @license * Visual Blocks Editor * * Copyright 2017 Google Inc. * https://developers.google.com/blockly/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @fileoverview The class representing an in-progress gesture, usually a drag * or a tap. * @author Sophie */ 'use strict'; goog.provide('Blockly.CengageGesture'); goog.require('Blockly.CengageBlockDragger'); /* * Note: In this file "start" refers to touchstart, mousedown, and pointerstart * events. "End" refers to touchend, mouseup, and pointerend events. */ // TODO: Consider touchcancel/pointercancel. /** * Class for one gesture. * @param {!Event} e The event that kicked off this gesture. * @param {!Blockly.WorkspaceSvg} creatorWorkspace The workspace that created * this gesture and has a reference to it. * @constructor */ Blockly.CengageGesture = function (e, creatorWorkspace) { Blockly.CengageGesture.superClass_.constructor.call( this, e, creatorWorkspace ); }; goog.inherits(Blockly.CengageGesture, Blockly.Gesture); /** * Create a block dragger and start dragging the selected block. * @private */ Blockly.CengageGesture.prototype.startDraggingBlock_ = function () { if (this.shouldDuplicateOnDrag_) { this.duplicateOnDrag_(); } this.blockDragger_ = new Blockly.CengageBlockDragger( this.targetBlock_, this.startWorkspace_ ); this.blockDragger_.startBlockDrag(this.currentDragDeltaXY_); this.blockDragger_.dragBlock(this.mostRecentEvent_, this.currentDragDeltaXY_); var flyout = this.creatorWorkspace_.toolbox_.flyout_.getClientRect(); this.blockDragger_.isFromFlyout_ = flyout.contains(this.mouseDownXY_); }; Blockly.CengageGesture.prototype.handleMove = function (e) { var stopPropagation = true; this.updateFromEvent_(e); if (this.isDraggingWorkspace_ && !this.creatorWorkspace_.tutorialOn) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { if ( this.blockDragger_.dragBlock( this.mostRecentEvent_, this.currentDragDeltaXY_ ) ) { stopPropagation = false; } } else if (this.isDraggingBubble_) { this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_ ); } if (stopPropagation) { e.preventDefault(); e.stopPropagation(); } }; Blockly.CengageGesture.prototype.handleUp = function (e) { this.updateFromEvent_(e); Blockly.longStop_(); if (this.isEnding_) { return; } this.isEnding_ = true; // The ordering of these checks is important: drags have higher priority than // clicks. Fields have higher priority than blocks; blocks have higher // priority than workspaces. // The ordering within drags does not matter, because the three types of // dragging are exclusive. if (this.isDraggingBubble_) { this.bubbleDragger_.endBubbleDrag(e, this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { this.blockDragger_.endBlockDrag(e, this.currentDragDeltaXY_); } else if (this.isDraggingWorkspace_ && !this.creatorWorkspace_.tutorialOn) { this.workspaceDragger_.endDrag(this.currentDragDeltaXY_); } else if (this.isBubbleClick_()) { // Bubbles are in front of all fields and blocks. this.doBubbleClick_(); } else if (this.isFieldClick_()) { this.doFieldClick_(); } else if (this.isBlockClick_()) { this.doBlockClick_(); } else if (this.isWorkspaceClick_()) { this.doWorkspaceClick_(); } e.preventDefault(); e.stopPropagation(); this.dispose(); };