forked from tbolis/react-sketch
-
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 tbolis#101 from tarik-djurdjevic/rectangle_label_tool
Rectangle label tool
- Loading branch information
Showing
9 changed files
with
482 additions
and
142 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
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,19 @@ | ||
/*eslint no-unused-vars: 0*/ | ||
|
||
import FabricCanvasTool from './fabrictool' | ||
|
||
const fabric = require('fabric').fabric; | ||
|
||
class DefaultTool extends FabricCanvasTool { | ||
configureCanvas(props) { | ||
let canvas = this._canvas; | ||
canvas.isDrawingMode = canvas.selection = false; | ||
canvas.forEachObject((o) => o.selectable = o.evented = false); | ||
canvas.discardActiveObject(); | ||
canvas.defaultCursor = 'pointer'; | ||
canvas.renderAll(); | ||
} | ||
|
||
} | ||
|
||
export default DefaultTool; |
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,35 @@ | ||
/* eslint no-unused-vars: 0 */ | ||
|
||
const fabric = require('fabric').fabric; | ||
|
||
class RectangleLabelObject { | ||
constructor(canvas, text, rectProps, textProps){ | ||
this._canvas = canvas; | ||
this._text = text; | ||
this._rectObj = new fabric.Rect(rectProps); | ||
this._textObj = new fabric.Textbox(text, textProps); | ||
canvas.on({'object:scaling': this.update}); | ||
canvas.on({'object:moving' : this.update}); | ||
} | ||
|
||
update = (e) => { | ||
//e.target.set({scaleX:1, scaleY:1}) | ||
if(!this._textObj || !this._rectObj) return; | ||
if(e.target === this._rectObj){ | ||
this._textObj.set({ | ||
'width' : this._rectObj.getScaledWidth(), | ||
'scaleX' : 1, | ||
'scaleY' : 1, | ||
'top' : this._rectObj.top - this._textObj.getScaledHeight(), | ||
'left' : this._rectObj.left, | ||
}) | ||
} | ||
} | ||
|
||
setText(text) { | ||
this._text = text; | ||
this._textObj.set({ text }); | ||
} | ||
} | ||
|
||
export default RectangleLabelObject; |
Oops, something went wrong.