|
1 | 1 | import { |
2 | 2 | canvasPosition, |
| 3 | + fixations, |
3 | 4 | originalSize, |
| 5 | + selectedFixation, |
4 | 6 | zoomFactor |
5 | 7 | } from '../data'; |
6 | 8 | import { |
@@ -36,9 +38,12 @@ const setViewPortOriginFromCenter = ( target: EditorPoint ) => { |
36 | 38 | // translate to percentages (canvasPosition is in percentages) |
37 | 39 | // Try to center target in the viewport |
38 | 40 | canvasPosition.value = { |
39 | | - 'x': toPercentageOfOriginal( limiter( originFromCenter( target.x, 'width' ), 'width' ), 'width' ), |
40 | | - 'y': toPercentageOfOriginal( limiter( originFromCenter( target.y, 'height' ), 'height' ), 'height' ) |
| 41 | + 'x': roundToDigits( toPercentageOfOriginal( limiter( centerCoordinateInViewPort( target.x, 'width' ), 'width' ), 'width' ) ), |
| 42 | + 'y': roundToDigits( toPercentageOfOriginal( limiter( centerCoordinateInViewPort( target.y, 'height' ), 'height' ), 'height' ) ) |
41 | 43 | }; |
| 44 | + console.log( { |
| 45 | + ...canvasPosition.value |
| 46 | + } ); |
42 | 47 | }; |
43 | 48 |
|
44 | 49 | /** |
@@ -68,8 +73,10 @@ const toPercentageOfOriginal = ( val: number, side: 'width' | 'height' ) => { |
68 | 73 | }; |
69 | 74 |
|
70 | 75 | /** Get the origin coordinate of the text from the center */ |
71 | | -const originFromCenter = ( val: number, side: 'width' | 'height' ) => { |
72 | | - return val - ( originalSize.value[ side ] / 2 ); |
| 76 | +const centerCoordinateInViewPort = ( val: number, side: 'width' | 'height' ) => { |
| 77 | + const shownPixels = originalSize.value[ side ] / zoomFactor.value; |
| 78 | + |
| 79 | + return val - ( shownPixels / 2 ); |
73 | 80 | }; |
74 | 81 |
|
75 | 82 | /** Sets limits for the zoom move (i.e. so you can't move the entire text out of view */ |
@@ -106,7 +113,13 @@ const setFactor = ( factor: number ) => { |
106 | 113 |
|
107 | 114 | // NOTE: If you want to do relative to mouse position, |
108 | 115 | // add a mouse position in here and use setViewPortOriginFromCenter |
109 | | - setViewPortOrigin( getViewPortOrigin() ); |
| 116 | + if ( selectedFixation.value < 0 ) |
| 117 | + setViewPortOrigin( getViewPortOrigin() ); |
| 118 | + else |
| 119 | + setViewPortOriginFromCenter( { |
| 120 | + 'x': fixations.value[ selectedFixation.value ]!.x!, |
| 121 | + 'y': fixations.value[ selectedFixation.value ]!.y! |
| 122 | + } ); |
110 | 123 | }; |
111 | 124 |
|
112 | 125 | /** Returns the zoom factor */ |
|
0 commit comments