mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-20 16:42:02 +00:00
Add rotate-left button to bitmap editor toolbar
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*\
|
||||
title: $:/core/modules/editor/operations/bitmap/rotate-left.js
|
||||
type: application/javascript
|
||||
module-type: bitmapeditoroperation
|
||||
|
||||
Bitmap editor operation to rotate the image left by 90 degrees
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports["rotate-left"] = function(event) {
|
||||
// Rotate the canvas left by 90 degrees
|
||||
this.rotateCanvasLeft();
|
||||
// Update the input controls
|
||||
this.refreshToolbar();
|
||||
// Save the image into the tiddler
|
||||
this.saveChanges();
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -189,6 +189,33 @@ EditBitmapWidget.prototype.changeCanvasSize = function(newWidth,newHeight) {
|
||||
ctx.drawImage(this.currCanvas,0,0);
|
||||
};
|
||||
|
||||
/*
|
||||
** Rotate the canvas left by 90 degrees
|
||||
*/
|
||||
EditBitmapWidget.prototype.rotateCanvasLeft = function() {
|
||||
// Get the current size of the image
|
||||
var origWidth = this.canvasDomNode.width,
|
||||
origHeight = this.canvasDomNode.height;
|
||||
// Create and size a new canvas
|
||||
var newCanvas = this.document.createElement("canvas"),
|
||||
newWidth = origHeight,
|
||||
newHeight = origWidth;
|
||||
this.initCanvas(newCanvas,newWidth,newHeight);
|
||||
// Copy the old image
|
||||
var ctx = newCanvas.getContext("2d");
|
||||
ctx.translate(newWidth / 2,newHeight / 2);
|
||||
ctx.rotate(-Math.PI / 2);
|
||||
ctx.drawImage(this.currCanvas,-origWidth / 2,-origHeight / 2);
|
||||
// Set the new canvas as the current one
|
||||
this.currCanvas = newCanvas;
|
||||
// Set the size of the onscreen canvas
|
||||
this.canvasDomNode.width = newWidth;
|
||||
this.canvasDomNode.height = newHeight;
|
||||
// Paint the onscreen canvas with the offscreen canvas
|
||||
ctx = this.canvasDomNode.getContext("2d");
|
||||
ctx.drawImage(this.currCanvas,0,0);
|
||||
};
|
||||
|
||||
EditBitmapWidget.prototype.handleTouchStartEvent = function(event) {
|
||||
this.brushDown = true;
|
||||
this.strokeStart(event.touches[0].clientX,event.touches[0].clientY);
|
||||
|
||||
Reference in New Issue
Block a user