diff options
| author | jmoenig <jens@moenig.org> | 2015-02-23 14:55:30 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2015-02-23 14:55:30 +0100 |
| commit | e5e216ccf2fbefd66885436220109c2a703413c6 (patch) | |
| tree | 4a0314e06533d4a085f6c83679758ac07556196c | |
| parent | 662a743f4ed564f2c296e2370c555ca44e12116d (diff) | |
| download | snap-e5e216ccf2fbefd66885436220109c2a703413c6.tar.gz snap-e5e216ccf2fbefd66885436220109c2a703413c6.zip | |
Add user-interaction choices to the “When I am ...” hat block
“clicked”, “pressed”, “dropped”, “mouse-entered”, “mouse-departed”
| -rw-r--r-- | blocks.js | 16 | ||||
| -rw-r--r-- | help/receiveInteraction.png (renamed from help/receiveClick.png) | bin | 49453 -> 49453 bytes | |||
| -rw-r--r-- | objects.js | 74 |
3 files changed, 78 insertions, 12 deletions
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2014-November-21'; +modules.blocks = '2015-February-23'; var SyntaxElementMorph; @@ -848,6 +848,20 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { true // read-only ); break; + case '%interaction': + part = new InputSlotMorph( + null, // text + false, // numeric? + { + 'clicked' : ['clicked'], + 'pressed' : ['pressed'], + 'dropped' : ['dropped'], + 'mouse-entered' : ['mouse-entered'], + 'mouse-departed' : ['mouse-departed'] + }, + true // read-only + ); + break; case '%dates': part = new InputSlotMorph( null, // text diff --git a/help/receiveClick.png b/help/receiveInteraction.png Binary files differindex 6ace2e3..6ace2e3 100644 --- a/help/receiveClick.png +++ b/help/receiveInteraction.png @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-January-28'; +modules.objects = '2015-February-23'; var SpriteMorph; var StageMorph; @@ -581,11 +581,22 @@ SpriteMorph.prototype.initBlocks = function () { category: 'control', spec: 'when %keyHat key pressed' }, + + /* migrated to a newer block version: + receiveClick: { type: 'hat', category: 'control', spec: 'when I am clicked' }, + */ + + receiveInteraction: { + type: 'hat', + category: 'control', + spec: 'when I am %interaction', + defaults: ['clicked'] + }, receiveMessage: { type: 'hat', category: 'control', @@ -1205,6 +1216,10 @@ SpriteMorph.prototype.initBlockMigrations = function () { doStopBlock: { selector: 'doStopThis', inputs: [['this block']] + }, + receiveClick: { + selector: 'receiveInteraction', + inputs: [['I am clicked']] } }; }; @@ -1253,8 +1268,6 @@ SpriteMorph.prototype.blockAlternatives = { setSize: ['changeSize'], // control: - receiveGo: ['receiveClick'], - receiveClick: ['receiveGo'], doBroadcast: ['doBroadcastAndWait'], doBroadcastAndWait: ['doBroadcast'], doIf: ['doIfElse', 'doUntil'], @@ -1829,7 +1842,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('receiveGo')); blocks.push(block('receiveKey')); - blocks.push(block('receiveClick')); + blocks.push(block('receiveInteraction')); blocks.push(block('receiveMessage')); blocks.push('-'); blocks.push(block('doBroadcast')); @@ -3169,6 +3182,7 @@ SpriteMorph.prototype.prepareToBeGrabbed = function (hand) { SpriteMorph.prototype.justDropped = function () { this.restoreLayers(); this.positionTalkBubble(); + this.receiveUserInteraction('dropped'); }; // SpriteMorph drawing: @@ -3500,9 +3514,6 @@ SpriteMorph.prototype.allHatBlocksFor = function (message) { if (morph.selector === 'receiveOnClone') { return message === '__clone__init__'; } - if (morph.selector === 'receiveClick') { - return message === '__click__'; - } } return false; }); @@ -3519,13 +3530,37 @@ SpriteMorph.prototype.allHatBlocksForKey = function (key) { }); }; +SpriteMorph.prototype.allHatBlocksForInteraction = function (interaction) { + return this.scripts.children.filter(function (morph) { + if (morph.selector) { + if (morph.selector === 'receiveInteraction') { + return morph.inputs()[0].evaluate()[0] === interaction; + } + } + return false; + }); +}; + // SpriteMorph events SpriteMorph.prototype.mouseClickLeft = function () { - var stage = this.parentThatIsA(StageMorph), - hats = this.allHatBlocksFor('__click__'), - procs = []; + return this.receiveUserInteraction('clicked'); +}; + +SpriteMorph.prototype.mouseEnter = function () { + return this.receiveUserInteraction('mouse-entered'); +}; + +SpriteMorph.prototype.mouseDownLeft = function () { + return this.receiveUserInteraction('pressed'); +}; +SpriteMorph.prototype.receiveUserInteraction = function (interaction) { + var stage = this.parentThatIsA(StageMorph), + procs = [], + hats; + if (!stage) {return; } // currently dragged + hats = this.allHatBlocksForInteraction(interaction); hats.forEach(function (block) { procs.push(stage.threads.startProcess(block, stage.isThreadSafe)); }); @@ -4190,6 +4225,7 @@ SpriteMorph.prototype.mouseEnterDragging = function () { }; SpriteMorph.prototype.mouseLeave = function () { + this.receiveUserInteraction('mouse-departed'); if (!this.enableNesting) {return; } this.removeHighlight(); }; @@ -5020,7 +5056,7 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('receiveGo')); blocks.push(block('receiveKey')); - blocks.push(block('receiveClick')); + blocks.push(block('receiveInteraction')); blocks.push(block('receiveMessage')); blocks.push('-'); blocks.push(block('doBroadcast')); @@ -5574,11 +5610,27 @@ StageMorph.prototype.allHatBlocksFor StageMorph.prototype.allHatBlocksForKey = SpriteMorph.prototype.allHatBlocksForKey; +StageMorph.prototype.allHatBlocksForInteraction + = SpriteMorph.prototype.allHatBlocksForInteraction; + // StageMorph events StageMorph.prototype.mouseClickLeft = SpriteMorph.prototype.mouseClickLeft; +StageMorph.prototype.mouseEnter + = SpriteMorph.prototype.mouseEnter; + +StageMorph.prototype.mouseLeave = function () { + this.receiveUserInteraction('mouse-departed'); +}; + +StageMorph.prototype.mouseDownLeft + = SpriteMorph.prototype.mouseDownLeft; + +StageMorph.prototype.receiveUserInteraction + = SpriteMorph.prototype.receiveUserInteraction; + // StageMorph custom blocks StageMorph.prototype.deleteAllBlockInstances |
