File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -1664,8 +1664,17 @@ function builtin_getMouse() {
1664
1664
builtin_getMouse . _apply_ = function ( rte , cont , this_ , params ) {
1665
1665
1666
1666
var code = function ( rte , cont ) {
1667
- pos = pixels_window . pageToRelative ( cb . mousePos ) ;
1668
- return return_fn_body ( rte , { x : pos . x , y : pos . y , down : cb . mouseDown } ) ;
1667
+ var state ;
1668
+ if ( showing_drawing_window ( ) ) {
1669
+ var pos = drawing_window . pageToRelative ( cb . mousePos ) ;
1670
+ state = { x : pos . x , y : pos . y , down : cb . mouseDown } ;
1671
+ } else if ( showing_pixels_window ( ) ) {
1672
+ var pos = pixels_window . pageToRelative ( cb . mousePos ) ;
1673
+ state = { x : pos . x , y : pos . y , down : cb . mouseDown } ;
1674
+ } else {
1675
+ state = { x : cb . mousePos . x , y : cb . mousePos . y , down : cb . mouseDown } ;
1676
+ }
1677
+ return return_fn_body ( rte , state ) ;
1669
1678
} ;
1670
1679
1671
1680
return exec_fn_body ( code ,
Original file line number Diff line number Diff line change @@ -316,6 +316,20 @@ DrawingWindow.prototype.drawtext = function (text) {
316
316
ctx . restore ( ) ;
317
317
} ;
318
318
319
+ DrawingWindow . prototype . pageToRelative = function ( coord ) {
320
+ var rect = getCoords ( this . drawing_canvas ) ;
321
+ var w = this . drawing_canvas . width ;
322
+ var h = this . drawing_canvas . height ;
323
+ var x = Math . max ( 0 , Math . min ( w , coord . x - rect . x - 3 ) ) - w / 2 ;
324
+ var y = h / 2 - Math . max ( 0 , Math . min ( h , coord . y - rect . y - 3 ) ) ;
325
+ return { x : x , y : y } ;
326
+ } ;
327
+
328
+ function getCoords ( elem ) {
329
+ var rect = elem . getBoundingClientRect ( ) ;
330
+ return { x : rect . left + pageXOffset , y : rect . top + pageYOffset } ;
331
+ }
332
+
319
333
var drawing_window ;
320
334
321
335
function create_drawing_window ( width , height ) {
You can’t perform that action at this time.
0 commit comments