Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d23372
commit 9fc971f
Showing
10 changed files
with
149 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(function () { | ||
var ns = $.namespace('pskl.controller.settings'); | ||
|
||
ns.ResizeController = function (piskelController) { | ||
this.piskelController = piskelController; | ||
}; | ||
|
||
ns.ResizeController.prototype.init = function () { | ||
this.resizeWidth = $('[name=resize-width]'); | ||
this.resizeHeight = $('[name=resize-height]'); | ||
|
||
this.resizeWidth.val(this.piskelController.getWidth()); | ||
this.resizeHeight.val(this.piskelController.getHeight()); | ||
|
||
this.cancelButton = $('.resize-cancel-button'); | ||
this.cancelButton.click(this.onCancelButtonClicked_.bind(this)); | ||
|
||
this.resizeForm = $("[name=resize-form]"); | ||
this.resizeForm.submit(this.onResizeFormSubmit_.bind(this)); | ||
}; | ||
|
||
ns.ResizeController.prototype.onResizeFormSubmit_ = function (evt) { | ||
evt.originalEvent.preventDefault(); | ||
|
||
var width = parseInt(this.resizeWidth.val(), 10); | ||
var height = parseInt(this.resizeHeight.val(), 10); | ||
|
||
var layers = []; | ||
var fromLayers = this.piskelController.getLayers(); | ||
for (var i = 0 ; i < fromLayers.length ; i++) { | ||
var frames = []; | ||
var fromFrames = fromLayers[i].getFrames(); | ||
for (var j = 0 ; j < fromFrames.length ; j++) { | ||
var frame = new pskl.model.Frame(width, height); | ||
this.copyFromFrameToFrame(fromFrames[j], frame); | ||
frames.push(frame); | ||
} | ||
var layer = pskl.model.Layer.fromFrames(fromLayers[i].getName(), frames); | ||
layers.push(layer); | ||
} | ||
|
||
var piskel = pskl.model.Piskel.fromLayers(layers, this.piskelController.piskel.getDescriptor()); | ||
pskl.app.piskelController.setPiskel(piskel); | ||
$.publish(Events.CLOSE_SETTINGS_DRAWER); | ||
}; | ||
|
||
ns.ResizeController.prototype.copyFromFrameToFrame = function (from, to) { | ||
from.forEachPixel(function (color, x, y) { | ||
if (x < to.getWidth() && y < to.getHeight()) { | ||
to.setPixel(x, y, color); | ||
} | ||
}); | ||
}; | ||
|
||
ns.ResizeController.prototype.onCancelButtonClicked_ = function (evt) { | ||
$.publish(Events.CLOSE_SETTINGS_DRAWER); | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="settings-section"> | ||
<div class="settings-title"> | ||
Resize drawing area | ||
</div> | ||
<div class="settings-item"> | ||
<form action="" method="POST" name="resize-form"> | ||
<span class="resize-warning-message">Existing frames will be cropped !</span> | ||
<div class="resize-section"> | ||
<span class="resize-section-title resize-section-title-small">Size :</span> | ||
<input type="text" class="textfield resize-size-field" name="resize-width"/>x | ||
<input type="text" class="textfield resize-size-field" name="resize-height"/> | ||
</div> | ||
<input type="submit" class="button button-primary resize-button" value="Resize" /> | ||
<input type="button" class="button resize-cancel-button" value="Cancel" /> | ||
</form> | ||
</div> | ||
</div> |