-
-
Notifications
You must be signed in to change notification settings - Fork 425
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
113818e
commit 5511e13
Showing
4 changed files
with
85 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,80 @@ | ||
import Handler from './Handler'; | ||
|
||
class AlignmentHandler { | ||
handler: Handler; | ||
constructor(handler: Handler) { | ||
this.handler = handler; | ||
} | ||
handler: Handler; | ||
constructor(handler: Handler) { | ||
this.handler = handler; | ||
} | ||
|
||
/** | ||
* Align left at selection | ||
*/ | ||
public left = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
const activeObjectLeft = -(activeObject.width / 2); | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
left: activeObjectLeft, | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
} | ||
/** | ||
* Align left at selection | ||
*/ | ||
public left = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
const activeObjectLeft = -(activeObject.width / 2); | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
left: activeObjectLeft, | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Align center at selection | ||
*/ | ||
public center = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
left: 0 - ((obj.width * obj.scaleX) / 2), | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
} | ||
/** | ||
* Align center at selection | ||
*/ | ||
public center = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
left: 0 - (obj.width * obj.scaleX) / 2, | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Align right at selection | ||
*/ | ||
public right = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
const activeObjectLeft = (activeObject.width / 2); | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
left: activeObjectLeft - (obj.width * obj.scaleX), | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
} | ||
/** | ||
* Align center at selection | ||
*/ | ||
public middle = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
top: 0 - (obj.width * obj.scaleX) / 2, | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Align right at selection | ||
*/ | ||
public right = () => { | ||
const activeObject = this.handler.canvas.getActiveObject(); | ||
if (activeObject && activeObject.type === 'activeSelection') { | ||
const activeSelection = activeObject as fabric.ActiveSelection; | ||
const activeObjectLeft = activeObject.width / 2; | ||
activeSelection.forEachObject(obj => { | ||
obj.set({ | ||
left: activeObjectLeft - obj.width * obj.scaleX, | ||
}); | ||
obj.setCoords(); | ||
this.handler.canvas.renderAll(); | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
export default AlignmentHandler; |
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