added visual “map-pin” icon to indicate local method blocks

upd4.1
Jens Mönig 2017-09-18 17:25:20 +02:00
rodzic a6fa360bd8
commit c4a05854f9
3 zmienionych plików z 98 dodań i 9 usunięć

Wyświetl plik

@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2017-September-15';
modules.blocks = '2017-September-18';
var SyntaxElementMorph;
var BlockMorph;
@ -1591,6 +1591,8 @@ SyntaxElementMorph.prototype.fixLayout = function (silently) {
lines = [],
space = this.isPrototype ?
1 : Math.floor(fontHeight(this.fontSize) / 3),
ico = this.isCustomBlock && !this.isGlobal ?
this.methodIconExtent().x + space : 0,
bottomCorrection,
initialExtent = this.extent();
@ -1659,11 +1661,11 @@ SyntaxElementMorph.prototype.fixLayout = function (silently) {
y = this.top();
}
lines.forEach(function (line) {
x = myself.left() + myself.edge + myself.labelPadding;
x = myself.left() + ico + myself.edge + myself.labelPadding;
if (myself instanceof RingMorph) {
x = myself.left() + space; //myself.labelPadding;
} else if (myself.isPredicate) {
x = myself.left() + myself.rounding;
x = myself.left() + ico + myself.rounding;
} else if (myself instanceof MultiArgMorph
|| myself instanceof ArgLabelMorph) {
x = myself.left();
@ -1674,7 +1676,7 @@ SyntaxElementMorph.prototype.fixLayout = function (silently) {
if (part instanceof CSlotMorph) {
x -= myself.labelPadding;
if (myself.isPredicate) {
x = myself.left() + myself.rounding;
x = myself.left() + ico + myself.rounding;
}
part.setColor(myself.color);
part.setPosition(new Point(x, y));
@ -1764,9 +1766,9 @@ SyntaxElementMorph.prototype.fixLayout = function (silently) {
parts.forEach(function (part) {
if (part instanceof CSlotMorph) {
if (myself.isPredicate) {
part.setWidth(blockWidth - myself.rounding * 2);
part.setWidth(blockWidth - ico - myself.rounding * 2);
} else {
part.setWidth(blockWidth - myself.edge);
part.setWidth(blockWidth - myself.edge - ico);
}
}
});
@ -1821,6 +1823,13 @@ SyntaxElementMorph.prototype.fixHighlight = function () {
}
};
SyntaxElementMorph.prototype.methodIconExtent = function () {
// answer the span of the icon for the "local method" indicator
var ico = this.fontSize * 1.2;
return this.isCustomBlock && !this.isGlobal ?
new Point(ico * 0.66, ico) : new Point(0, 0);
};
// SyntaxElementMorph evaluating:
SyntaxElementMorph.prototype.evaluate = function () {
@ -3922,6 +3931,41 @@ BlockMorph.prototype.scriptPic = function () {
return pic;
};
// BlockMorph local method indicator drawing
BlockMorph.prototype.drawMethodIcon = function (context) {
var ext = this.methodIconExtent(),
w = ext.x,
h = ext.y,
r = w / 2,
x = this.edge + this.labelPadding,
y = this.edge,
isNormal =
this.color === SpriteMorph.prototype.blockColor[this.category];
if (this.isPredicate) {
x = this.rounding;
}
if (this instanceof CommandBlockMorph) {
y += this.corner;
}
context.fillStyle = isNormal ? this.cachedClrBright : this.cachedClrDark;
// pin
context.beginPath();
context.arc(x + r, y + r, r, radians(-210), radians(30), false);
context.lineTo(x + r, y + h);
context.closePath();
context.fill();
// hole
context.fillStyle = this.cachedClr;
context.beginPath();
context.arc(x + r, y + r, r * 0.4, radians(0), radians(360), false);
context.closePath();
context.fill();
};
// BlockMorph dragging and dropping
BlockMorph.prototype.rootForGrab = function () {
@ -4543,6 +4587,11 @@ CommandBlockMorph.prototype.drawNew = function () {
*/
}
// draw method icon if applicable
if (this.isCustomBlock && !this.isGlobal) {
this.drawMethodIcon(context);
}
// erase CommandSlots
this.eraseHoles(context);
};
@ -5314,6 +5363,10 @@ ReporterBlockMorph.prototype.drawNew = function () {
this.drawRounded(context);
}
// draw method icon if applicable
if (this.isCustomBlock && !this.isGlobal) {
this.drawMethodIcon(context);
}
// erase CommandSlots
this.eraseHoles(context);
};

Wyświetl plik

@ -3628,12 +3628,18 @@ Fixes:
* Blocks, Objects: added “inherited” option to inheritable variable templates context menu in the palette
* Objects: disabled context menu and dragging for watchers in presentation mode
170918
------
* Symbols: added location icon (map-pin)
* Blocks: added visual “map-pin” icon to indicate local method blocks
v4.1 Features:
* polymorphic sprite-local custom blocks
* inheritance of sprite-local custom blocks
* inheritance of sprite attributes (x, y, direction, size, costumes, costume #, sounds, scripts)
* first-class costumes and sounds
* visual indicator (map-pin icon) for sprite-local custom blocks (i.e. methods)
* [experimental, hidden] camera snapshots for costumes and new sprites
* localization support when typing expressions
* support for user-forced line-breaks in custom block labels

Wyświetl plik

@ -41,7 +41,7 @@
// Global stuff ////////////////////////////////////////////////////////
modules.symbols = '2017-September-08';
modules.symbols = '2017-September-18';
var SymbolMorph;
@ -51,7 +51,7 @@ WorldMorph.prototype.customMorphs = function () {
return [
new SymbolMorph(
'notes',
'location',
50,
new Color(250, 250, 250),
new Point(-1, -1),
@ -130,7 +130,8 @@ SymbolMorph.prototype.names = [
'robot',
'magnifyingGlass',
'notes',
'camera'
'camera',
'location'
];
// SymbolMorph instance creation:
@ -306,6 +307,8 @@ SymbolMorph.prototype.symbolCanvasColored = function (aColor) {
return this.drawSymbolNotes(canvas, aColor);
case 'camera':
return this.drawSymbolCamera(canvas, aColor);
case 'location':
return this.drawSymbolLocation(canvas, aColor);
default:
return canvas;
}
@ -321,6 +324,8 @@ SymbolMorph.prototype.symbolWidth = function () {
switch (this.name) {
case 'pointRight':
return Math.sqrt(size * size - Math.pow(size / 2, 2));
case 'location':
return size * 0.6;
case 'flash':
case 'file':
return size * 0.8;
@ -1554,3 +1559,28 @@ SymbolMorph.prototype.drawSymbolCamera = function (canvas, color) {
return canvas;
};
SymbolMorph.prototype.drawSymbolLocation = function (canvas, color) {
// answer a canvas showing a camera
var ctx = canvas.getContext('2d'),
w = canvas.width,
h = canvas.height,
r = w / 2;
// pin
ctx.fillStyle = color.toString();
ctx.beginPath();
ctx.arc(r, r, r, radians(-210), radians(30), false);
ctx.lineTo(r, h);
ctx.closePath();
ctx.fill();
// hole
ctx.globalCompositeOperation = 'destination-out';
ctx.beginPath();
ctx.arc(r, r, r * 0.5, radians(0), radians(360), false);
ctx.closePath();
ctx.fill();
return canvas;
};