summaryrefslogtreecommitdiff
path: root/morphic.js
diff options
context:
space:
mode:
Diffstat (limited to 'morphic.js')
-rw-r--r--morphic.js65
1 files changed, 44 insertions, 21 deletions
diff --git a/morphic.js b/morphic.js
index 0115c82..2850e32 100644
--- a/morphic.js
+++ b/morphic.js
@@ -8,7 +8,7 @@
written by Jens Mönig
jens@moenig.org
- Copyright (C) 2014 by Jens Mönig
+ Copyright (C) 2015 by Jens Mönig
This file is part of Snap!.
@@ -527,6 +527,12 @@
a duplicate of the template whose "isDraggable" flag is true and
whose "isTemplate" flag is false, in other words: a non-template.
+ When creating a copy from a template, the copy's
+
+ reactToTemplateCopy
+
+ is invoked, if it is present.
+
Dragging is indicated by adding a drop shadow to the morph in hand.
If a morph follows the hand without displaying a drop shadow it is
merely being moved about without changing its parent (owner morph),
@@ -1020,9 +1026,10 @@
programming hero.
I have originally written morphic.js in Florian Balmer's Notepad2
- editor for Windows and later switched to Apple's Dashcode. I've also
- come to depend on both Douglas Crockford's JSLint, Mozilla's Firebug
- and Google's Chrome to get it right.
+ editor for Windows, later switched to Apple's Dashcode and later
+ still to Apple's Xcode. I've also come to depend on both Douglas
+ Crockford's JSLint, Mozilla's Firebug and Google's Chrome to get
+ it right.
IX. contributors
@@ -1041,7 +1048,7 @@
/*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio,
FileList, getBlurredShadowSupport*/
-var morphicVersion = '2014-November-06';
+var morphicVersion = '2015-May-01';
var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@@ -1931,7 +1938,9 @@ Rectangle.prototype.round = function () {
Rectangle.prototype.spread = function () {
// round me by applying floor() to my origin and ceil() to my corner
- return this.origin.floor().corner(this.corner.ceil());
+ // expand by 1 to be on the safe side, this eliminates rounding
+ // artefacts caused by Safari's auto-scaling on retina displays
+ return this.origin.floor().corner(this.corner.ceil()).expandBy(1);
};
Rectangle.prototype.amountToTranslateWithin = function (aRect) {
@@ -3978,6 +3987,7 @@ PenMorph.prototype.init = function () {
this.size = 1;
this.wantsRedraw = false;
this.penPoint = 'tip'; // or 'center"
+ this.penBounds = null; // rect around the visible arrow shape
HandleMorph.uber.init.call(this);
this.setExtent(new Point(size, size));
@@ -4000,11 +4010,9 @@ PenMorph.prototype.changed = function () {
// PenMorph display:
PenMorph.prototype.drawNew = function (facing) {
-/*
- my orientation can be overridden with the "facing" parameter to
- implement Scratch-style rotation styles
+ // my orientation can be overridden with the "facing" parameter to
+ // implement Scratch-style rotation styles
-*/
var context, start, dest, left, right, len,
direction = facing || this.heading;
@@ -4027,6 +4035,15 @@ PenMorph.prototype.drawNew = function (facing) {
right = start.distanceAngle(len * 0.33, direction - 230);
}
+ // cache penBounds
+ this.penBounds = new Rectangle(
+ Math.min(start.x, dest.x, left.x, right.x),
+ Math.min(start.y, dest.y, left.y, right.y),
+ Math.max(start.x, dest.x, left.x, right.x),
+ Math.max(start.y, dest.y, left.y, right.y)
+ );
+
+ // draw arrow shape
context.fillStyle = this.color.toString();
context.beginPath();
@@ -4043,7 +4060,6 @@ PenMorph.prototype.drawNew = function (facing) {
context.lineWidth = 1;
context.stroke();
context.fill();
-
};
// PenMorph access:
@@ -5760,7 +5776,7 @@ SliderMorph.prototype.rangeSize = function () {
};
SliderMorph.prototype.ratio = function () {
- return this.size / this.rangeSize();
+ return this.size / (this.rangeSize() + 1);
};
SliderMorph.prototype.unitSize = function () {
@@ -5917,7 +5933,7 @@ SliderMorph.prototype.userSetStart = function (num) {
this.start = Math.max(num, this.stop);
};
-SliderMorph.prototype.setStart = function (num) {
+SliderMorph.prototype.setStart = function (num, noUpdate) {
// for context menu demo purposes
var newStart;
if (typeof num === 'number') {
@@ -5935,12 +5951,12 @@ SliderMorph.prototype.setStart = function (num) {
}
}
this.value = Math.max(this.value, this.start);
- this.updateTarget();
+ if (!noUpdate) {this.updateTarget(); }
this.drawNew();
this.changed();
};
-SliderMorph.prototype.setStop = function (num) {
+SliderMorph.prototype.setStop = function (num, noUpdate) {
// for context menu demo purposes
var newStop;
if (typeof num === 'number') {
@@ -5952,12 +5968,12 @@ SliderMorph.prototype.setStop = function (num) {
}
}
this.value = Math.min(this.value, this.stop);
- this.updateTarget();
+ if (!noUpdate) {this.updateTarget(); }
this.drawNew();
this.changed();
};
-SliderMorph.prototype.setSize = function (num) {
+SliderMorph.prototype.setSize = function (num, noUpdate) {
// for context menu demo purposes
var newSize;
if (typeof num === 'number') {
@@ -5975,7 +5991,7 @@ SliderMorph.prototype.setSize = function (num) {
}
}
this.value = Math.min(this.value, this.stop - this.size);
- this.updateTarget();
+ if (!noUpdate) {this.updateTarget(); }
this.drawNew();
this.changed();
};
@@ -7438,6 +7454,8 @@ StringMorph.prototype.mouseClickLeft = function (pos) {
StringMorph.prototype.enableSelecting = function () {
this.mouseDownLeft = function (pos) {
+ var crs = this.root().cursor,
+ already = crs ? crs.target === this : false;
this.clearSelection();
if (this.isEditable && (!this.isDraggable)) {
this.edit();
@@ -7445,6 +7463,7 @@ StringMorph.prototype.enableSelecting = function () {
this.startMark = this.slotAt(pos);
this.endMark = this.startMark;
this.currentlySelecting = true;
+ if (!already) {this.escalateEvent('mouseDownLeft', pos); }
}
};
this.mouseMove = function (pos) {
@@ -8051,7 +8070,7 @@ TriggerMorph.prototype.init = function (
this.environment = environment || null;
this.labelString = labelString || null;
this.label = null;
- this.hint = hint || null;
+ this.hint = hint || null; // null, String, or Function
this.fontSize = fontSize || MorphicPreferences.menuFontSize;
this.fontStyle = fontStyle || 'sans-serif';
this.highlightColor = new Color(192, 192, 192);
@@ -8200,10 +8219,11 @@ TriggerMorph.prototype.triggerDoubleClick = function () {
// TriggerMorph events:
TriggerMorph.prototype.mouseEnter = function () {
+ var contents = this.hint instanceof Function ? this.hint() : this.hint;
this.image = this.highlightImage;
this.changed();
- if (this.hint) {
- this.bubbleHelp(this.hint);
+ if (contents) {
+ this.bubbleHelp(contents);
}
};
@@ -9674,6 +9694,9 @@ HandMorph.prototype.processMouseMove = function (event) {
morph = this.morphToGrab.fullCopy();
morph.isTemplate = false;
morph.isDraggable = true;
+ if (morph.reactToTemplateCopy) {
+ morph.reactToTemplateCopy();
+ }
this.grab(morph);
this.grabOrigin = this.morphToGrab.situation();
}