From 53a918175a5bfacf4c974a2e3defc4be165ae515 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 12 Apr 2013 13:08:48 +0200 Subject: 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 --- byob.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'byob.js') diff --git a/byob.js b/byob.js index c21cf11..bc7e96a 100644 --- a/byob.js +++ b/byob.js @@ -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 //////////////////////////////////////////////////// -- cgit v1.3.1