@@ -15,7 +15,8 @@ var util = {
1515 } ,
1616 getMinicapRotate :function ( ) {
1717 return localStorage . getItem ( "minicap_rotate" ) ;
18- }
18+ } ,
19+ isRotate : false
1920} ;
2021var webSocket = null ;
2122
@@ -298,6 +299,7 @@ $("#uploadtofile").on("click", function() {
298299function requestStartMinicap ( ) {
299300 var rotate = parseInt ( util . getMinicapRotate ( ) ) ;
300301 var scale = parseFloat ( util . getMinicapScale ( ) ) ;
302+ util . isRotate = ( rotate === 90 || rotate === 270 ) ;
301303 webSocket . send ( "start://" + JSON . stringify ( { type :"minicap" , config :{ 'rotate' :rotate , 'scale' :scale } } ) ) ;
302304}
303305
@@ -317,37 +319,59 @@ function sendKeyEvent(keyevent) {
317319 webSocket . send ( "keyevent://" + convertAndroidKeyCode ( keyevent ) ) ;
318320}
319321
320- canvas . onmousedown = function ( event ) {
321- if ( ! util . serverConnected ) {
322- return ;
322+ function sendDown ( argx , argy , isRo ) {
323+ var scalex = 1080.0 / canvas . width ;
324+ var scaley = 1920.0 / canvas . height ;
325+ var x = argx , y = argy ;
326+ if ( isRo ) {
327+ x = ( canvas . height - argy ) * ( canvas . width / canvas . height ) ;
328+ y = argx * ( canvas . height / canvas . width ) ;
323329 }
324- isDown = true ;
330+ x = Math . round ( x * scalex ) ;
331+ y = Math . round ( y * scaley ) ;
332+ var command = "d 0 " + x + " " + y + " 50\n" ;
333+ command += "c\n" ;
334+ sendTouchEvent ( command ) ;
335+ }
325336
337+ function sendMove ( argx , argy , isRo ) {
326338 var scalex = 1080.0 / canvas . width ;
327339 var scaley = 1920.0 / canvas . height ;
328- var pos = getXAndY ( canvas , event ) ;
329- var x = Math . round ( pos . x * scalex ) ;
330- var y = Math . round ( pos . y * scaley ) ;
340+ var x = argx , y = argy ;
341+ if ( isRo ) {
342+ x = ( canvas . height - argy ) * ( canvas . width / canvas . height ) ;
343+ y = argx * ( canvas . height / canvas . width ) ;
344+ }
345+ x = Math . round ( x * scalex ) ;
346+ y = Math . round ( y * scaley ) ;
331347
332- var command = "d 0 " + x + " " + y + " 50\n" ;
348+ var command = "m 0 " + x + " " + y + " 50\n" ;
349+ command += "c\n" ;
350+ sendTouchEvent ( command ) ;
351+ }
352+
353+ function sendUp ( ) {
354+ var command = "u 0\n" ;
333355 command += "c\n" ;
334356 sendTouchEvent ( command ) ;
357+ }
358+
359+ canvas . onmousedown = function ( event ) {
360+ if ( ! util . serverConnected ) {
361+ return ;
362+ }
363+ isDown = true ;
364+ var pos = getXAndY ( canvas , event ) ;
365+ sendDown ( pos . x , pos . y , util . isRotate ) ;
335366} ;
336367
337368canvas . onmousemove = function ( event ) {
338-
339369 if ( ! util . serverConnected || ! isDown ) {
340370 return ;
341371 }
342- var scalex = 1080.0 / canvas . width ;
343- var scaley = 1920.0 / canvas . height ;
344372 var pos = getXAndY ( canvas , event ) ;
345- var x = Math . round ( pos . x * scalex ) ;
346- var y = Math . round ( pos . y * scaley ) ;
347373
348- var command = "m 0 " + x + " " + y + " 50\n" ;
349- command += "c\n" ;
350- sendTouchEvent ( command ) ;
374+ sendMove ( pos . x , pos . y , util . isRotate ) ;
351375} ;
352376
353377canvas . onmouseover = function ( event ) {
@@ -359,29 +383,13 @@ canvas.onmouseout = function (event) {
359383 return ;
360384 }
361385 isDown = false ;
362- var scalex = 1080.0 / canvas . width ;
363- var scaley = 1920.0 / canvas . height ;
364- var pos = getXAndY ( canvas , event ) ;
365- var x = Math . round ( pos . x * scalex ) ;
366- var y = Math . round ( pos . y * scaley ) ;
367-
368- var command = "u 0\n" ;
369- command += "c\n" ;
370- sendTouchEvent ( command ) ;
386+ sendUp ( ) ;
371387} ;
372388
373389canvas . onmouseup = function ( event ) {
374390 if ( ! util . serverConnected || ! isDown ) {
375391 return ;
376392 }
377393 isDown = false ;
378- var scalex = 1080.0 / canvas . width ;
379- var scaley = 1920.0 / canvas . height ;
380- var pos = getXAndY ( canvas , event ) ;
381- var x = Math . round ( pos . x * scalex ) ;
382- var y = Math . round ( pos . y * scaley ) ;
383-
384- var command = "u 0\n" ;
385- command += "c\n" ;
386- sendTouchEvent ( command ) ;
394+ sendUp ( ) ;
387395} ;
0 commit comments