Skip to content

Commit

Permalink
added flashSpriteScriptOutlineAt() and unflashSpriteScriptsOutline() …
Browse files Browse the repository at this point in the history
…API methods
  • Loading branch information
jmoenig committed Feb 20, 2024
1 parent c25731e commit 9c45b58
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
25 changes: 25 additions & 0 deletions pyret/inline.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
}
});

};
Expand Down

0 comments on commit 9c45b58

Please sign in to comment.