summaryrefslogtreecommitdiff
path: root/paint.js
diff options
context:
space:
mode:
authorHardmath123 <hardmath123@gmail.com>2014-06-03 15:28:07 -0700
committerHardmath123 <hardmath123@gmail.com>2014-06-03 15:28:07 -0700
commit6d9ce7b61c61ff737133dd3490c6caf854793f04 (patch)
treec373e14ab107a6fb094c2b32865d742b307f1236 /paint.js
parent6a4b4afbe98fa99623a81a89e2f6505ff5704d38 (diff)
downloadsnap-6d9ce7b61c61ff737133dd3490c6caf854793f04.tar.gz
snap-6d9ce7b61c61ff737133dd3490c6caf854793f04.zip
Added scaling and flipping
Diffstat (limited to 'paint.js')
-rw-r--r--paint.js44
1 files changed, 41 insertions, 3 deletions
diff --git a/paint.js b/paint.js
index ee40b23..12f4f82 100644
--- a/paint.js
+++ b/paint.js
@@ -3,12 +3,12 @@
a paint editor for Snap!
inspired by the Scratch paint editor.
-
+
written by Kartik Chandra
Copyright (C) 2014 by Kartik Chandra
-
+
This file is part of Snap!.
-
+
Snap! is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of
@@ -133,6 +133,10 @@ PaintEditorMorph.prototype.buildContents = function () {
this.buildToolbox();
this.controls.add(this.toolbox);
+ this.scaleBox = new AlignmentMorph('row', this.padding);
+ this.buildScaleBox();
+ this.controls.add(this.scaleBox);
+
this.propertiesControls = {
colorpicker: null,
penSizeSlider: null,
@@ -218,6 +222,27 @@ PaintEditorMorph.prototype.buildEdits = function () {
this.edits.fixLayout();
};
+PaintEditorMorph.prototype.buildScaleBox = function () {
+ var paper = this.paper;
+ this.scaleBox.add(this.pushButton(
+ "grow",
+ function () {paper.scale(0.05, 0.05); }
+ ));
+ this.scaleBox.add(this.pushButton(
+ "shrink",
+ function () {paper.scale(-0.05, -0.05); }
+ ));
+ this.scaleBox.add(this.pushButton(
+ "flipX",
+ function () {paper.scale(-2, 0); }
+ ));
+ this.scaleBox.add(this.pushButton(
+ "flipY",
+ function () {paper.scale(0, -2); }
+ ));
+ this.scaleBox.fixLayout();
+};
+
PaintEditorMorph.prototype.openIn = function (world, oldim, oldrc, callback) {
// Open the editor in a world with an optional image to edit
this.oldim = oldim;
@@ -558,6 +583,19 @@ PaintCanvasMorph.prototype.init = function (shift) {
this.buildContents();
};
+PaintCanvasMorph.prototype.scale = function(x, y) {
+ this.mask = newCanvas(this.extent());
+ var c = newCanvas(this.extent());
+ c.getContext("2d").save();
+ c.getContext("2d").translate(this.rotationCenter.x, this.rotationCenter.y);
+ c.getContext("2d").scale(1 + x, 1 + y);
+ c.getContext("2d").drawImage(this.paper, -this.rotationCenter.x, -this.rotationCenter.y);
+ c.getContext("2d").restore();
+ this.paper = c;
+ this.drawNew();
+ this.changed();
+};
+
PaintCanvasMorph.prototype.cacheUndo = function () {
var cachecan = newCanvas(this.extent());
this.merge(this.paper, cachecan);