diff options
| author | jmoenig <jens@moenig.org> | 2013-04-12 13:08:48 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-04-12 13:08:48 +0200 |
| commit | 53a918175a5bfacf4c974a2e3defc4be165ae515 (patch) | |
| tree | f88971e3194b6337bbb71e8d8bf86bfefa132d7e /byob.js | |
| parent | 54415a2cfcf68763c4836b540d23737ed4c99a50 (diff) | |
| download | snap-53a918175a5bfacf4c974a2e3defc4be165ae515.tar.gz snap-53a918175a5bfacf4c974a2e3defc4be165ae515.zip | |
Tooltips for custom block templates (sitting in the palette)
mousing over a custom block in the palette pops up its definition hat
comment in a comment-colored speech bubble
Diffstat (limited to 'byob.js')
| -rw-r--r-- | byob.js | 69 |
1 files changed, 67 insertions, 2 deletions
@@ -101,11 +101,11 @@ Context, StringMorph, nop, newCanvas, radians, BoxMorph, ArrowMorph, PushButtonMorph, contains, InputSlotMorph, ShadowMorph, ToggleButtonMorph, IDE_Morph, MenuMorph, copy, ToggleElementMorph, Morph, fontHeight, StageMorph, SyntaxElementMorph, SnapSerializer, -CommentMorph, localize, CSlotMorph*/ +CommentMorph, localize, CSlotMorph, SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2013-April-04'; +modules.byob = '2013-April-12'; // Declarations @@ -700,6 +700,56 @@ CustomCommandBlockMorph.prototype.deleteBlockDefinition = function () { ); }; +// CustomCommandBlockMorph events: + +CustomCommandBlockMorph.prototype.mouseEnter = function () { + var comment, help; + if (this.isTemplate && this.definition.comment) { + comment = this.definition.comment.fullCopy(); + comment.contents.parse(); + help = ''; + comment.contents.lines.forEach(function (line) { + help = help + '\n' + line; + }); + this.bubbleHelp( + help.substr(1), + this.definition.comment.color + ); + } +}; + +CustomCommandBlockMorph.prototype.mouseLeave = function () { + if (this.isTemplate && this.definition.comment) { + this.world().hand.destroyTemporaries(); + } +}; + +// CustomCommandBlockMorph bubble help: + +CustomCommandBlockMorph.prototype.bubbleHelp = function (contents, color) { + var myself = this; + this.fps = 2; + this.step = function () { + if (this.bounds.containsPoint(this.world().hand.position())) { + myself.popUpbubbleHelp(contents, color); + } + myself.fps = 0; + delete myself.step; + }; +}; + +CustomCommandBlockMorph.prototype.popUpbubbleHelp = function ( + contents, + color +) { + new SpeechBubbleMorph( + contents, + color, + null, + 1 + ).popUp(this.world(), this.rightCenter().add(new Point(-8, 0))); +}; + // CustomReporterBlockMorph //////////////////////////////////////////// // CustomReporterBlockMorph inherits from ReporterBlockMorph: @@ -799,6 +849,21 @@ CustomReporterBlockMorph.prototype.userMenu CustomReporterBlockMorph.prototype.deleteBlockDefinition = CustomCommandBlockMorph.prototype.deleteBlockDefinition; +// CustomReporterBlockMorph events: + +CustomReporterBlockMorph.prototype.mouseEnter + = CustomCommandBlockMorph.prototype.mouseEnter; + +CustomReporterBlockMorph.prototype.mouseLeave + = CustomCommandBlockMorph.prototype.mouseLeave; + +// CustomReporterBlockMorph bubble help: + +CustomReporterBlockMorph.prototype.bubbleHelp + = CustomCommandBlockMorph.prototype.bubbleHelp; + +CustomReporterBlockMorph.prototype.popUpbubbleHelp + = CustomCommandBlockMorph.prototype.popUpbubbleHelp; // JaggedBlockMorph //////////////////////////////////////////////////// |
