From d7f7efe4b2985d570b9403cbb16dec2db0bfec34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Thu, 27 Jan 2022 23:38:10 +0100 Subject: [PATCH] support dragging costumes and sounds out from variable watchers --- HISTORY.md | 4 ++-- src/objects.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 1e9cddf0..fb2b6197 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,8 +3,7 @@ ## in development: * **New Features:** - * support dragging blocks out from result bubbles, and from speech balloons and variable watchers when in edit mode - * support dragging costumes and sounds out from result bubbles and speech balloons + * support dragging blocks, costumes and sounds out from result bubbles, and from speech balloons and variable watchers when in edit mode * support deleting and inserting individual variadic slots, script vars & ring params * **Notable Changes:** * **Notable Fixes:** @@ -18,6 +17,7 @@ ### 2022-01-27 * blocks, gui: support dragging costumes and sounds out from result bubbles * objects: support dragging costumes and sounds out from speech balloons +* objects: support dragging costumes and sounds out from variable watchers ### 2022-01-26 * blocks: refactored slot context menus diff --git a/src/objects.js b/src/objects.js index 7ebf2d8c..187a5cf2 100644 --- a/src/objects.js +++ b/src/objects.js @@ -11538,8 +11538,62 @@ CellMorph.prototype.createContents = function () { this.contentsMorph.bounds.setWidth(img.width); this.contentsMorph.bounds.setHeight(img.height); this.contentsMorph.cachedImage = img; + + // support costumes to be dragged out of watchers: + this.contentsMorph.isDraggable = true; + + this.contentsMorph.selectForEdit = function () { + var cst = myself.contents.copy(), + icon, + prepare, + ide = this.parentThatIsA(IDE_Morph)|| + this.world().childThatIsA(IDE_Morph); + + cst.name = ide.currentSprite.newCostumeName(cst.name); + icon = new CostumeIconMorph(cst); + prepare = icon.prepareToBeGrabbed; + + icon.prepareToBeGrabbed = function (hand) { + hand.grabOrigin = { + origin: ide.palette, + position: ide.palette.center() + }; + this.prepareToBeGrabbed = prepare; + }; + + if (ide.isAppMode) {return; } + icon.setCenter(this.center()); + return icon; + }; } else if (this.contents instanceof Sound) { this.contentsMorph = new SymbolMorph('notes', 30); + + // support sounds to be dragged out of watchers: + this.contentsMorph.isDraggable = true; + + this.contentsMorph.selectForEdit = function () { + var snd = myself.contents.copy(), + icon, + prepare, + ide = this.parentThatIsA(IDE_Morph)|| + this.world().childThatIsA(IDE_Morph); + + snd.name = ide.currentSprite.newCostumeName(snd.name); + icon = new SoundIconMorph(snd); + prepare = icon.prepareToBeGrabbed; + + icon.prepareToBeGrabbed = function (hand) { + hand.grabOrigin = { + origin: ide.palette, + position: ide.palette.center() + }; + this.prepareToBeGrabbed = prepare; + }; + + if (ide.isAppMode) {return; } + icon.setCenter(this.center()); + return icon; + }; } else if (this.contents instanceof List) { if (this.contents.isTable()) { this.contentsMorph = new TableFrameMorph(new TableMorph(