@@ -34,9 +34,24 @@ function setupSelection(engraver) {
34
34
engraver . renderer . paper . svg . addEventListener ( 'mouseup' , mouseUp . bind ( engraver ) ) ;
35
35
}
36
36
37
- function getCoord ( ev ) {
38
- var x = ev . offsetX ;
39
- var y = ev . offsetY ;
37
+ function getCoord ( ev , svg ) {
38
+ var scaleX = 1 ;
39
+ var scaleY = 1 ;
40
+
41
+ // when renderer.options.responsive === 'resize' the click coords are in relation to the HTML
42
+ // element, we need to convert to the SVG viewBox coords
43
+ if ( svg . viewBox . baseVal ) { // Firefox passes null to this when no viewBox is given
44
+ // Chrome makes these values null when no viewBox is given.
45
+ if ( svg . viewBox . baseVal . width !== 0 )
46
+ scaleX = svg . viewBox . baseVal . width / svg . clientWidth
47
+ if ( svg . viewBox . baseVal . height !== 0 )
48
+ scaleY = svg . viewBox . baseVal . height / svg . clientHeight
49
+ }
50
+
51
+ var x = ev . offsetX * scaleX ;
52
+ var y = ev . offsetY * scaleY ;
53
+ //console.log(x, y)
54
+
40
55
// The target might be the SVG that we want, or it could be an item in the SVG (usually a path). If it is not the SVG then
41
56
// add an offset to the coordinates.
42
57
// if (ev.target.tagName.toLowerCase() !== 'svg') {
@@ -120,7 +135,7 @@ function keyboardSelection(ev) {
120
135
function mouseDown ( ev ) {
121
136
// "this" is the EngraverController because of the bind(this) when setting the event listener.
122
137
123
- var box = getCoord ( ev ) ;
138
+ var box = getCoord ( ev , this . renderer . paper . svg ) ;
124
139
var x = box [ 0 ] ;
125
140
var y = box [ 1 ] ;
126
141
@@ -180,7 +195,7 @@ function mouseMove(ev) {
180
195
if ( ! this . dragTarget || ! this . dragging || ! this . dragTarget . isDraggable || this . dragMechanism !== 'mouse' )
181
196
return ;
182
197
183
- var box = getCoord ( ev ) ;
198
+ var box = getCoord ( ev , this . renderer . paper . svg ) ;
184
199
var x = box [ 0 ] ;
185
200
var y = box [ 1 ] ;
186
201
0 commit comments