@ -102,9 +102,6 @@ import { copyToAppClipboard, getClipboardContent } from "./clipboard";
let { elements } = createScene ( ) ;
let { elements } = createScene ( ) ;
const { history } = createHistory ( ) ;
const { history } = createHistory ( ) ;
const CANVAS_WINDOW_OFFSET_LEFT = 0 ;
const CANVAS_WINDOW_OFFSET_TOP = 0 ;
function resetCursor() {
function resetCursor() {
document . documentElement . style . cursor = "" ;
document . documentElement . style . cursor = "" ;
}
}
@ -142,8 +139,8 @@ export function viewportCoordsToSceneCoords(
{ clientX , clientY } : { clientX : number ; clientY : number } ,
{ clientX , clientY } : { clientX : number ; clientY : number } ,
{ scrollX , scrollY } : { scrollX : number ; scrollY : number } ,
{ scrollX , scrollY } : { scrollX : number ; scrollY : number } ,
) {
) {
const x = clientX - CANVAS_WINDOW_OFFSET_LEFT - scrollX;
const x = clientX - scrollX;
const y = clientY - CANVAS_WINDOW_OFFSET_TOP - scrollY;
const y = clientY - scrollY;
return { x , y } ;
return { x , y } ;
}
}
@ -740,8 +737,8 @@ export class App extends React.Component<any, AppState> {
} ;
} ;
public render() {
public render() {
const canvasWidth = window . innerWidth - CANVAS_WINDOW_OFFSET_LEFT ;
const canvasWidth = window . innerWidth ;
const canvasHeight = window . innerHeight - CANVAS_WINDOW_OFFSET_TOP ;
const canvasHeight = window . innerHeight ;
return (
return (
< div className = "container" >
< div className = "container" >
@ -910,10 +907,10 @@ export class App extends React.Component<any, AppState> {
isOverVerticalScrollBar ,
isOverVerticalScrollBar ,
} = isOverScrollBars (
} = isOverScrollBars (
elements ,
elements ,
e . clientX - CANVAS_WINDOW_OFFSET_LEFT ,
e . clientX / window . devicePixelRatio ,
e . clientY - CANVAS_WINDOW_OFFSET_TOP ,
e . clientY / window . devicePixelRatio ,
canvasWidth ,
canvasWidth / window . devicePixelRatio ,
canvasHeight ,
canvasHeight / window . devicePixelRatio ,
this . state . scrollX ,
this . state . scrollX ,
this . state . scrollY ,
this . state . scrollY ,
) ;
) ;
@ -1096,8 +1093,8 @@ export class App extends React.Component<any, AppState> {
let lastY = y ;
let lastY = y ;
if ( isOverHorizontalScrollBar || isOverVerticalScrollBar ) {
if ( isOverHorizontalScrollBar || isOverVerticalScrollBar ) {
lastX = e . clientX - CANVAS_WINDOW_OFFSET_LEFT ;
lastX = e . clientX ;
lastY = e . clientY - CANVAS_WINDOW_OFFSET_TOP ;
lastY = e . clientY ;
}
}
let resizeArrowFn :
let resizeArrowFn :
@ -1175,7 +1172,7 @@ export class App extends React.Component<any, AppState> {
}
}
if ( isOverHorizontalScrollBar ) {
if ( isOverHorizontalScrollBar ) {
const x = e . clientX - CANVAS_WINDOW_OFFSET_LEFT ;
const x = e . clientX ;
const dx = x - lastX ;
const dx = x - lastX ;
this . setState ( { scrollX : this.state.scrollX - dx } ) ;
this . setState ( { scrollX : this.state.scrollX - dx } ) ;
lastX = x ;
lastX = x ;
@ -1183,7 +1180,7 @@ export class App extends React.Component<any, AppState> {
}
}
if ( isOverVerticalScrollBar ) {
if ( isOverVerticalScrollBar ) {
const y = e . clientY - CANVAS_WINDOW_OFFSET_TOP ;
const y = e . clientY ;
const dy = y - lastY ;
const dy = y - lastY ;
this . setState ( { scrollY : this.state.scrollY - dy } ) ;
this . setState ( { scrollY : this.state.scrollY - dy } ) ;
lastY = y ;
lastY = y ;
@ -1690,12 +1687,10 @@ export class App extends React.Component<any, AppState> {
textX =
textX =
this . state . scrollX +
this . state . scrollX +
elementAtPosition . x +
elementAtPosition . x +
CANVAS_WINDOW_OFFSET_LEFT +
elementAtPosition . width / 2 ;
elementAtPosition . width / 2 ;
textY =
textY =
this . state . scrollY +
this . state . scrollY +
elementAtPosition . y +
elementAtPosition . y +
CANVAS_WINDOW_OFFSET_TOP +
elementAtPosition . height / 2 ;
elementAtPosition . height / 2 ;
// x and y will change after calling newTextElement function
// x and y will change after calling newTextElement function
@ -1833,13 +1828,8 @@ export class App extends React.Component<any, AppState> {
const elementsCenterX = distance ( minX , maxX ) / 2 ;
const elementsCenterX = distance ( minX , maxX ) / 2 ;
const elementsCenterY = distance ( minY , maxY ) / 2 ;
const elementsCenterY = distance ( minY , maxY ) / 2 ;
const dx =
const dx = cursorX - this . state . scrollX - elementsCenterX ;
cursorX -
const dy = cursorY - this . state . scrollY - elementsCenterY ;
this . state . scrollX -
CANVAS_WINDOW_OFFSET_LEFT -
elementsCenterX ;
const dy =
cursorY - this . state . scrollY - CANVAS_WINDOW_OFFSET_TOP - elementsCenterY ;
elements = [
elements = [
. . . elements ,
. . . elements ,
@ -1871,12 +1861,10 @@ export class App extends React.Component<any, AppState> {
const wysiwygX =
const wysiwygX =
this . state . scrollX +
this . state . scrollX +
elementClickedInside . x +
elementClickedInside . x +
CANVAS_WINDOW_OFFSET_LEFT +
elementClickedInside . width / 2 ;
elementClickedInside . width / 2 ;
const wysiwygY =
const wysiwygY =
this . state . scrollY +
this . state . scrollY +
elementClickedInside . y +
elementClickedInside . y +
CANVAS_WINDOW_OFFSET_TOP +
elementClickedInside . height / 2 ;
elementClickedInside . height / 2 ;
return { wysiwygX , wysiwygY , elementCenterX , elementCenterY } ;
return { wysiwygX , wysiwygY , elementCenterX , elementCenterY } ;
}
}