forked from fabricjs/fabric.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fabricjs#11 from wmaillard/master
Added a Pan Tool (by wmaillard)
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
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
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,41 @@ | ||
/*eslint no-unused-vars: 0*/ | ||
'use strict'; | ||
|
||
import FabricCanvasTool from './fabrictool' | ||
const fabric = require('fabric').fabric; | ||
|
||
class Pan extends FabricCanvasTool { | ||
|
||
configureCanvas(props) { | ||
let canvas = this._canvas; | ||
canvas.isDrawingMode = canvas.selection = false; | ||
canvas.forEachObject((o) => o.selectable = o.evented = false); | ||
//Change the cursor to the move grabber | ||
canvas.defaultCursor = 'move'; | ||
} | ||
|
||
doMouseDown(o) { | ||
let canvas = this._canvas; | ||
this.isDown = true; | ||
let pointer = canvas.getPointer(o.e); | ||
this.startX = pointer.x; | ||
this.startY = pointer.y; | ||
} | ||
|
||
doMouseMove(o) { | ||
if (!this.isDown) return; | ||
let canvas = this._canvas; | ||
let pointer = canvas.getPointer(o.e); | ||
|
||
canvas.relativePan({ x : pointer.x - this.startX, | ||
y : pointer.y - this.startY}); | ||
canvas.renderAll(); | ||
} | ||
|
||
doMouseUp(o) { | ||
this.isDown = false; | ||
} | ||
|
||
} | ||
|
||
export default Pan; |
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