kopia lustrzana https://github.com/backface/turtlestitch
allow sprites’ rotation centers to be adjusted onstage
rodzic
4db428b65c
commit
50a86060f9
|
@ -3385,3 +3385,7 @@ Fixes:
|
|||
------
|
||||
* Objects: experiment with new dynamic method (cache) updating
|
||||
* Objects, Blocks, BYOB, Store, Threads, GUI: roll-back double-pointer container cache for methods
|
||||
|
||||
170307
|
||||
------
|
||||
* Morphic, Objects, translation: let sprites’s rotation centers be adjusted onstage
|
||||
|
|
|
@ -185,7 +185,7 @@ SnapTranslator.dict.de = {
|
|||
'translator_e-mail':
|
||||
'jens@moenig.org', // optional
|
||||
'last_changed':
|
||||
'2017-01-24', // this, too, will appear in the Translators tab
|
||||
'2017-03-07', // this, too, will appear in the Translators tab
|
||||
|
||||
// GUI
|
||||
// control bar:
|
||||
|
@ -911,6 +911,10 @@ SnapTranslator.dict.de = {
|
|||
'Bearbeiten',
|
||||
'move':
|
||||
'Verschieben',
|
||||
'pivot':
|
||||
'Angelpunkt',
|
||||
'edit the costume\'s\nrotation center':
|
||||
'Drehpunkt des Kostüms\nanzeigen und verschieben',
|
||||
'detach from':
|
||||
'Abtrennen von',
|
||||
'detach all parts':
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
/*global modules, contains*/
|
||||
|
||||
modules.locale = '2017-January-24';
|
||||
modules.locale = '2017-March-07';
|
||||
|
||||
// Global stuff
|
||||
|
||||
|
@ -160,7 +160,7 @@ SnapTranslator.dict.de = {
|
|||
'translator_e-mail':
|
||||
'jens@moenig.org',
|
||||
'last_changed':
|
||||
'2017-01-24'
|
||||
'2017-03-07'
|
||||
};
|
||||
|
||||
SnapTranslator.dict.it = {
|
||||
|
|
58
morphic.js
58
morphic.js
|
@ -1137,7 +1137,7 @@
|
|||
|
||||
/*global window, HTMLCanvasElement, FileReader, Audio, FileList*/
|
||||
|
||||
var morphicVersion = '2017-January-09';
|
||||
var morphicVersion = '2017-March-07';
|
||||
var modules = {}; // keep track of additional loaded modules
|
||||
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
|
||||
|
||||
|
@ -4432,11 +4432,14 @@ HandleMorph.prototype.init = function (
|
|||
this.target = target || null;
|
||||
this.minExtent = new Point(minX || 0, minY || 0);
|
||||
this.inset = new Point(insetX || 0, insetY || insetX || 0);
|
||||
this.type = type || 'resize'; // can also be 'move', 'moveCenter'
|
||||
this.type = type || 'resize'; // also: 'move', 'moveCenter', 'movePivot'
|
||||
HandleMorph.uber.init.call(this);
|
||||
this.color = new Color(255, 255, 255);
|
||||
this.isDraggable = false;
|
||||
this.noticesTransparentClick = true;
|
||||
if (this.type === 'movePivot') {
|
||||
size *= 2;
|
||||
}
|
||||
this.setExtent(new Point(size, size));
|
||||
};
|
||||
|
||||
|
@ -4445,20 +4448,27 @@ HandleMorph.prototype.init = function (
|
|||
HandleMorph.prototype.drawNew = function () {
|
||||
this.normalImage = newCanvas(this.extent());
|
||||
this.highlightImage = newCanvas(this.extent());
|
||||
this.drawOnCanvas(
|
||||
this.normalImage,
|
||||
this.color,
|
||||
new Color(100, 100, 100)
|
||||
);
|
||||
this.drawOnCanvas(
|
||||
this.highlightImage,
|
||||
new Color(100, 100, 255),
|
||||
new Color(255, 255, 255)
|
||||
);
|
||||
if (this.type === 'movePivot') {
|
||||
this.drawCrosshairsOnCanvas(this.normalImage, 0.6);
|
||||
this.drawCrosshairsOnCanvas(this.highlightImage, 0.5);
|
||||
} else {
|
||||
this.drawOnCanvas(
|
||||
this.normalImage,
|
||||
this.color,
|
||||
new Color(100, 100, 100)
|
||||
);
|
||||
this.drawOnCanvas(
|
||||
this.highlightImage,
|
||||
new Color(100, 100, 255),
|
||||
new Color(255, 255, 255)
|
||||
);
|
||||
}
|
||||
this.image = this.normalImage;
|
||||
if (this.target) {
|
||||
if (this.type === 'moveCenter') {
|
||||
this.setCenter(this.target.center());
|
||||
} else if (this.type === 'movePivot') {
|
||||
this.setCenter(this.target.rotationCenter());
|
||||
} else { // 'resize', 'move'
|
||||
this.setPosition(
|
||||
this.target.bottomRight().subtract(
|
||||
|
@ -4471,6 +4481,25 @@ HandleMorph.prototype.drawNew = function () {
|
|||
}
|
||||
};
|
||||
|
||||
HandleMorph.prototype.drawCrosshairsOnCanvas = function (aCanvas, fract) {
|
||||
var ctx = aCanvas.getContext('2d'),
|
||||
r = aCanvas.width / 2;
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
|
||||
ctx.arc(r, r, r * 0.9, radians(0), radians(360), false);
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = 'black';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.arc(r, r, r * fract, radians(0), radians(360), false);
|
||||
ctx.stroke();
|
||||
ctx.moveTo(0, r);
|
||||
ctx.lineTo(aCanvas.width, r);
|
||||
ctx.stroke();
|
||||
ctx.moveTo(r, 0);
|
||||
ctx.lineTo(r, aCanvas.height);
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
HandleMorph.prototype.drawOnCanvas = function (
|
||||
aCanvas,
|
||||
color,
|
||||
|
@ -4574,7 +4603,7 @@ HandleMorph.prototype.mouseDownLeft = function (pos) {
|
|||
if (!this.target) {
|
||||
return null;
|
||||
}
|
||||
if (this.type === 'moveCenter') {
|
||||
if (this.type.indexOf('move') === 0) {
|
||||
offset = pos.subtract(this.center());
|
||||
} else {
|
||||
offset = pos.subtract(this.bounds.origin);
|
||||
|
@ -4597,6 +4626,9 @@ HandleMorph.prototype.mouseDownLeft = function (pos) {
|
|||
);
|
||||
} else if (this.type === 'moveCenter') {
|
||||
myself.target.setCenter(newPos);
|
||||
} else if (this.type === 'movePivot') {
|
||||
myself.target.setPivot(newPos);
|
||||
myself.setCenter(this.target.rotationCenter());
|
||||
} else { // type === 'move'
|
||||
myself.target.setPosition(
|
||||
newPos.subtract(this.target.extent())
|
||||
|
|
37
objects.js
37
objects.js
|
@ -80,9 +80,9 @@ document, isNaN, isString, newCanvas, nop, parseFloat, radians, window,
|
|||
modules, IDE_Morph, VariableDialogMorph, HTMLCanvasElement, Context, List,
|
||||
SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
|
||||
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
|
||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
|
||||
|
||||
modules.objects = '2017-March-01';
|
||||
modules.objects = '2017-March-07';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
@ -3032,6 +3032,13 @@ SpriteMorph.prototype.userMenu = function () {
|
|||
}
|
||||
menu.addItem("delete", 'remove');
|
||||
menu.addItem("move", 'moveCenter');
|
||||
if (this.costume) {
|
||||
menu.addItem(
|
||||
"pivot",
|
||||
'moveRotationCenter',
|
||||
'edit the costume\'s\nrotation center'
|
||||
);
|
||||
}
|
||||
if (!this.isClone) {
|
||||
menu.addItem("edit", 'edit');
|
||||
}
|
||||
|
@ -4230,6 +4237,32 @@ SpriteMorph.prototype.setRotationCenter = function (absoluteCoordinate) {
|
|||
this.drawNew();
|
||||
};
|
||||
|
||||
SpriteMorph.prototype.moveRotationCenter = function () {
|
||||
// make this a method of Snap >> SpriteMorph
|
||||
this.world().activeHandle = new HandleMorph(
|
||||
this,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'movePivot'
|
||||
);
|
||||
};
|
||||
|
||||
SpriteMorph.prototype.setPivot = function (worldCoordinate) {
|
||||
var stage = this.parentThatIsA(StageMorph),
|
||||
cntr;
|
||||
if (stage) {
|
||||
cntr = stage.center();
|
||||
this.setRotationCenter(
|
||||
new Point(
|
||||
(worldCoordinate.x - cntr.x) / stage.scale,
|
||||
(cntr.y - worldCoordinate.y) / stage.scale
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
SpriteMorph.prototype.xCenter = function () {
|
||||
var stage = this.parentThatIsA(StageMorph);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue