summaryrefslogtreecommitdiff
path: root/byob.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-04-12 13:08:48 +0200
committerjmoenig <jens@moenig.org>2013-04-12 13:08:48 +0200
commit53a918175a5bfacf4c974a2e3defc4be165ae515 (patch)
treef88971e3194b6337bbb71e8d8bf86bfefa132d7e /byob.js
parent54415a2cfcf68763c4836b540d23737ed4c99a50 (diff)
downloadsnap-byow-53a918175a5bfacf4c974a2e3defc4be165ae515.tar.gz
snap-byow-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.js69
1 files changed, 67 insertions, 2 deletions
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 ////////////////////////////////////////////////////