use new first-class animations framework

pull/29/head
jmoenig 2016-11-25 14:42:20 +01:00
rodzic 3d8ef5519c
commit 5b1b4a5e36
4 zmienionych plików z 51 dodań i 74 usunięć

Wyświetl plik

@ -149,7 +149,7 @@ isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2016-November-24';
modules.blocks = '2016-November-25';
var SyntaxElementMorph;
var BlockMorph;
@ -5358,6 +5358,7 @@ ScriptsMorph.prototype.init = function (owner) {
this.noticesTransparentClick = true;
// initialize "undrop" queue
this.isAnimating = false;
this.recordDrop();
};
@ -5846,30 +5847,38 @@ ScriptsMorph.prototype.addComment = function () {
};
ScriptsMorph.prototype.undrop = function () {
var myself = this;
if (this.isAnimating) {return; }
if (!this.dropRecord || !this.dropRecord.lastRecord) {return; }
if (!this.dropRecord.situation) {
this.dropRecord.situation =
this.dropRecord.lastDroppedBlock.situation();
}
this.isAnimating = true;
this.dropRecord.lastDroppedBlock.slideBackTo(
this.dropRecord.lastOrigin,
null,
this.recoverLastDrop()
this.recoverLastDrop(),
function () {myself.isAnimating = false; }
);
this.dropRecord = this.dropRecord.lastRecord;
};
ScriptsMorph.prototype.redrop = function () {
var myself = this;
if (this.isAnimating) {return; }
if (!this.dropRecord || !this.dropRecord.nextRecord) {return; }
this.dropRecord = this.dropRecord.nextRecord;
if (this.dropRecord.action === 'delete') {
this.recoverLastDrop(true);
this.dropRecord.lastDroppedBlock.destroy();
} else {
this.isAnimating = true;
this.dropRecord.lastDroppedBlock.slideBackTo(
this.dropRecord.situation,
null,
this.recoverLastDrop(true)
this.recoverLastDrop(true),
function () {myself.isAnimating = false; }
);
}
};

77
gui.js
Wyświetl plik

@ -68,11 +68,11 @@ fontHeight, hex_sha512, sb, CommentMorph, CommandBlockMorph,
BlockLabelPlaceHolderMorph, Audio, SpeechBubbleMorph, ScriptFocusMorph,
XML_Element, WatcherMorph, BlockRemovalDialogMorph, saveAs, TableMorph,
isSnapObject, isRetinaEnabled, disableRetinaSupport, enableRetinaSupport,
isRetinaSupported, SliderMorph*/
isRetinaSupported, SliderMorph, Animation*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2016-November-22';
modules.gui = '2016-November-25';
// Declarations
@ -1047,16 +1047,16 @@ IDE_Morph.prototype.createPalette = function (forSearching) {
myself.removeSprite(droppedMorph.object);
} else if (droppedMorph instanceof CostumeIconMorph) {
myself.currentSprite.wearCostume(null);
droppedMorph.destroy();
droppedMorph.perish();
} else if (droppedMorph instanceof BlockMorph) {
if (hand && hand.grabOrigin.origin instanceof ScriptsMorph) {
hand.grabOrigin.origin.clearDropInfo();
hand.grabOrigin.origin.lastDroppedBlock = droppedMorph;
hand.grabOrigin.origin.recordDrop(hand.grabOrigin);
}
droppedMorph.destroy();
droppedMorph.perish();
} else {
droppedMorph.destroy();
droppedMorph.perish();
}
};
@ -4391,6 +4391,7 @@ IDE_Morph.prototype.toggleAppMode = function (appMode) {
IDE_Morph.prototype.toggleStageSize = function (isSmall, forcedRatio) {
var myself = this,
smallRatio = forcedRatio || 0.5,
msecs = this.isAnimating ? 100 : 0,
world = this.world(),
shiftClicked = (world.currentKey === 16),
altClicked = (world.currentKey === 18);
@ -4400,25 +4401,23 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall, forcedRatio) {
}
function zoomTo(targetRatio) {
var count = 1,
steps = 5;
myself.fps = 30;
myself.isSmallStage = true;
myself.step = function () {
var diff;
if (count >= steps) {
myself.stageRatio = targetRatio;
delete myself.step;
myself.fps = 0;
world.animations.push(new Animation(
function (ratio) {
myself.stageRatio = ratio;
myself.setExtent(world.extent());
},
function () {
return myself.stageRatio;
},
targetRatio - myself.stageRatio,
msecs,
null, // easing
function () {
myself.isSmallStage = (targetRatio !== 1);
myself.controlBar.stageSizeButton.refresh();
} else {
count += 1;
diff = (targetRatio - myself.stageRatio) / 2;
myself.stageRatio += diff;
}
myself.setExtent(world.extent());
};
));
}
if (shiftClicked) {
@ -4436,39 +4435,29 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall, forcedRatio) {
} else {
toggle();
}
if (this.isAnimating) {
if (this.isSmallStage) {
zoomTo(smallRatio);
} else {
zoomTo(1);
}
if (this.isSmallStage) {
zoomTo(smallRatio);
} else {
if (this.isSmallStage) {this.stageRatio = smallRatio; }
this.setExtent(world.extent());
zoomTo(1);
}
};
IDE_Morph.prototype.setPaletteWidth = function (newWidth) {
var count = 1,
steps = this.isAnimating ? 5 : 1,
var msecs = this.isAnimating ? 100 : 0,
world = this.world(),
myself = this;
newWidth = Math.max(newWidth, 200);
this.fps = 30;
this.step = function () {
var diff;
if (count >= steps) {
world.animations.push(new Animation(
function (newWidth) {
myself.paletteWidth = newWidth;
delete myself.step;
myself.fps = 0;
} else {
count += 1;
diff = (myself.paletteWidth - newWidth) / 2;
myself.paletteWidth -= diff;
}
myself.setExtent(world.extent());
};
myself.setExtent(world.extent());
},
function () {
return myself.paletteWidth;
},
newWidth - myself.paletteWidth,
msecs
));
};
IDE_Morph.prototype.createNewProject = function () {

Wyświetl plik

@ -3135,3 +3135,8 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
------
* Morphic, Store: work around a dreaded FF NS_ERROR_FAILURE for supporting retina
* Blocks: drag-origin support for blocks and comments duplicated inside a block editor
161125
------
* Morphic: First-class animations
* Blocks, Objects, GUI: Switch to new animation mechanism, add a few

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
modules.objects = '2016-November-22';
modules.objects = '2016-November-25';
var SpriteMorph;
var StageMorph;
@ -3714,32 +3714,6 @@ SpriteMorph.prototype.rootForGrab = function () {
return SpriteMorph.uber.rootForGrab.call(this);
};
SpriteMorph.prototype.slideBackTo = function (situation, inSteps) {
// override the inherited default to make sure my parts follow
var steps = inSteps || 5,
pos = situation.origin.position().add(situation.position),
xStep = -(this.left() - pos.x) / steps,
yStep = -(this.top() - pos.y) / steps,
stepCount = 0,
oldStep = this.step,
oldFps = this.fps,
myself = this;
this.fps = 0;
this.step = function () {
myself.moveBy(new Point(xStep, yStep));
stepCount += 1;
if (stepCount === steps) {
situation.origin.add(myself);
if (situation.origin.reactToDropOf) {
situation.origin.reactToDropOf(myself);
}
myself.step = oldStep;
myself.fps = oldFps;
}
};
};
SpriteMorph.prototype.setCenter = function (aPoint, justMe) {
// override the inherited default to make sure my parts follow
// unless it's justMe