-
Notifications
You must be signed in to change notification settings - Fork 1
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 #27 from projectstorm/feature_scaling
Feature: image scaling and better initial loading
- Loading branch information
Showing
10 changed files
with
208 additions
and
43 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
52 changes: 52 additions & 0 deletions
52
tornado-frontend/src/routes/content/widgets/react-canvas/ResizeElementState.ts
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,52 @@ | ||
import { AbstractDisplacementState, AbstractDisplacementStateEvent } from '@projectstorm/react-canvas-core'; | ||
import { CornerPosition } from './controls-layer/ControlsElementWidget'; | ||
import { ImageElement } from './image-element/ImageElementFactory'; | ||
|
||
export class ResizeElementState extends AbstractDisplacementState { | ||
position: CornerPosition; | ||
element: ImageElement; | ||
width: number; | ||
height: number; | ||
x: number; | ||
y: number; | ||
|
||
constructor() { | ||
super({ | ||
name: 'resize-elements' | ||
}); | ||
} | ||
|
||
setup(position: CornerPosition, element: ImageElement) { | ||
this.position = position; | ||
this.element = element; | ||
this.width = element.width; | ||
this.height = element.height; | ||
this.x = element.getX(); | ||
this.y = element.getY(); | ||
} | ||
|
||
fireMouseMoved(event: AbstractDisplacementStateEvent): any { | ||
if (this.position === CornerPosition.SE) { | ||
const newWidth = this.width + event.virtualDisplacementX; | ||
const newHeight = (newWidth / this.width) * this.height; | ||
this.element.setSize(newWidth, newHeight); | ||
} else if (this.position === CornerPosition.NW) { | ||
const newWidth = this.width - event.virtualDisplacementX; | ||
const newHeight = (newWidth / this.width) * this.height; | ||
this.element.setSize(newWidth, newHeight); | ||
this.element.setPosition(this.x + event.virtualDisplacementX, this.height - newHeight + this.y); | ||
} else if (this.position === CornerPosition.SW) { | ||
const newWidth = this.width - event.virtualDisplacementX; | ||
const newHeight = (newWidth / this.width) * this.height; | ||
this.element.setSize(newWidth, newHeight); | ||
this.element.setPosition(this.x + event.virtualDisplacementX, this.y); | ||
} else if (this.position === CornerPosition.NE) { | ||
const newWidth = this.width + event.virtualDisplacementX; | ||
const newHeight = (newWidth / this.width) * this.height; | ||
this.element.setSize(newWidth, newHeight); | ||
this.element.setPosition(this.x, this.height - newHeight + this.y); | ||
} | ||
|
||
this.engine.repaintCanvas(); | ||
} | ||
} |
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
Oops, something went wrong.