From 9c45b58bf79b3f0d787c71e24f78243cb1676800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Tue, 20 Feb 2024 14:15:55 +0100 Subject: [PATCH] added flashSpriteScriptOutlineAt() and unflashSpriteScriptsOutline() API methods --- HISTORY.md | 2 ++ pyret/inline.html | 25 +++++++++++++++++++++++++ src/api.js | 25 +++++++++++++++++++++++++ src/blocks.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 4c343b2fa8..bf731e09ad 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,11 +5,13 @@ * **New Features:** * new "Lirin" costume series, thanks, Meghan and Brian! * new showScriptBalloonAt() and closePopUps() API methods + * new flashSpriteScriptOutlineAt() and unflashSpriteScriptsOutline() API methods 2024-02-20 * new dev version for v9.2.7 * added new Lirin costumes, thanks, Brian and Meghan! * api: added showScriptBalloonAt() and closePopUps() API methods +* api: added flashSpriteScriptOutlineAt() and unflashSpriteScriptsOutline() API methods ## 9.2.6: * **Notable Changes:** diff --git a/pyret/inline.html b/pyret/inline.html index 31b2123a52..fb8d257421 100755 --- a/pyret/inline.html +++ b/pyret/inline.html @@ -79,6 +79,7 @@ null, // optional sprite name null // '200,100,130' // optional rgb(a) color csv ); + /* // alternatively: highlight the block at the // selection start idx @@ -88,6 +89,30 @@ null // '200,100,130' // optional rgb(a) color csv ); */ + + /* + // highlight the outline of block at the + // selection start idx + ide.flashSpriteScriptOutlineAt( + this.selectionStart, + null, // optional sprite name + '200,100,130', // optional rgb(a) color csv + 3 // border + ); + */ + + /* + // apop-up a balloon at the block at the + // selection start idx + ide.showScriptBalloonAt( + 'selection:\n' + + this.selectionStart + + ' - ' + + this.selectionEnd, + this.selectionStart, + null, // optional sprite name + ); + */ } }; requestAnimationFrame(loop); diff --git a/src/api.js b/src/api.js index d6489a5258..d9c0cbe41b 100644 --- a/src/api.js +++ b/src/api.js @@ -311,6 +311,31 @@ IDE_Morph.prototype.unflashSpriteScripts = function (name) { this.spriteNamed(name).scripts.unflash(); }; +IDE_Morph.prototype.flashSpriteScriptOutlineAt = function ( + charIdx, + name, + clr, + border +) { + // highlight the outline of the innermost block of the scripts of the sprite + // indicated by name or the current sprite or stage if none that corresponds + // to the index of the text given the current codification mapping. + // Optionally a string of comma-separated "r,g,b[,a]" values can be passed + // in to specify a specific highlight color, where each color component is + // a number between 0 and 255 and alpha is a fraction between 0 and 1. + // If none is supplied the default flash color is used. + // Also optionally a border width of pixels can be specified + var scripts = this.spriteNamed(name).scripts; + // scripts.unflash(); + scripts.flashOutlineCodeIdx(charIdx, clr, border); +}; + +IDE_Morph.prototype.unflashSpriteScriptsOutline = function (name) { + // un-highlight the script outlines of the sprite indicated by name or the + // current sprite or stage if none + this.spriteNamed(name).scripts.unflashOutline(); +}; + IDE_Morph.prototype.showScriptBalloonAt = function (contents, charIdx, name) { // popup a balloon at the innermost block of the scripts of the sprite // indicated by name or the current sprite or stage if none that corresponds diff --git a/src/blocks.js b/src/blocks.js index acf3801d7d..2fbfb59595 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -5398,6 +5398,12 @@ BlockMorph.prototype.getHighlight = function () { return null; }; +BlockMorph.prototype.flashOutline = function (color, border) { + this.removeHighlight(); + this.addBack(this.outline(color, border)); + this.fullChanged(); +}; + BlockMorph.prototype.outline = function (color, border) { var highlight = new BlockHighlightMorph(), fb = this.fullBounds(), @@ -9283,6 +9289,31 @@ ScriptsMorph.prototype.unflash = function () { if (each instanceof SyntaxElementMorph && each.unflash) { each.unflash(); } + if (each instanceof BlockMorph) { + each.removeHighlight(); + } + }); + +}; + +ScriptsMorph.prototype.flashOutlineCodeIdx = function ( + idx, + color = null, +border = 3) { + // highlight the innermost block located in the textual code indicated + // by the given character index. Optional color string, form "r,g,b[,a]". + var block = this.blockAtIdx(idx); + this.unflashOutline(); + if (block) { + block.flashOutline(color ? Color.fromString(color) : null, border); + } +}; + +ScriptsMorph.prototype.unflashOutline = function () { + this.forAllChildren(each => { + if (each instanceof BlockMorph) { + each.removeHighlight(); + } }); };