draw.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //画布
  2. var canvas;
  3. var context;
  4. //蒙版
  5. var canvas_bak = document.getElementById("box");;
  6. var context_bak;
  7. var canvasWidth = 720;
  8. var canvasHeight = 1280;
  9. var canvasTop;
  10. var canvasLeft;
  11. var winHeight = window.screen.height - window.innerHeight
  12. var vowidth = window.screen.width
  13. var topwinHeightDraw = window.screen.height - window.innerHeight + 30; //计算title top 头部
  14. var numse = window.screen.height //-winHeight
  15. //计算title top 头部
  16. if (numse <= 70) {
  17. var voheight = window.screen.height - winHeight - 34
  18. } else {
  19. console.log("numse>>>", numse)
  20. var voheight = window.screen.height - topwinHeightDraw
  21. }
  22. //console.log("画笔大小>>>",window.innerHeight)
  23. //画笔大小
  24. var size = 1;
  25. var color = '#000000';
  26. var resolving
  27. //alert(winHeight)
  28. var url = window.location.href;
  29. url = url.split('/')
  30. var query = window.location.search.substring(1);
  31. var vars = query.split("&");
  32. var data = {}
  33. var clientType = vars.find(e => {
  34. return e.startsWith('clientType')
  35. })
  36. var cardIp = vars.find(e => {
  37. return e.startsWith('cardIp')
  38. })
  39. var port = vars.find(e => {
  40. return e.startsWith('port')
  41. })
  42. var sn = vars.find(e => {
  43. return e.startsWith('sn')
  44. })
  45. var data = {}
  46. data.clientType=clientType.substring(11, clientType.length)
  47. data.cardIp=cardIp.substring(7, cardIp.length)
  48. data.port=port.substring(5, port.length)
  49. data.sn=sn.substring(3, sn.length)
  50. var urlss= url[2]
  51. var wsss = new WebSocket("ws://"+urlss+"/controlWebSocket?"+"clientType="+data.clientType+"&cardIp="+data.cardIp+"&port="+data.port+"&sn="+data.sn);
  52. ////
  53. // var wsss = new WebSocket(
  54. // "ws://14.215.128.96/controlWebSocket?clientType=0&cardIp=30.30.30.58&port=9100&sn=RK3930C2301900060");
  55. wsss.onopen = function() {
  56. var pings = {
  57. "event": "getScreenStatus"
  58. }
  59. wsss.send(JSON.stringify(pings));
  60. var bitRate ={"data":{"bitRate":400},"event":"bitRate"}
  61. wsss.send(JSON.stringify(bitRate));
  62. };
  63. wsss.onmessage = function(event) {
  64. var resets = JSON.parse(event.data)
  65. resolving = resets.data.orientation
  66. if (resolving == 1) {} else {}
  67. };
  68. wsss.onclose = function(event) {
  69. };
  70. wsss.onerror = function(event) {
  71. };
  72. $('#box').on("click", function() {
  73. draw_graph('pencil', this)
  74. })
  75. //剪切板
  76. $(".upload").on("click",function(){
  77. let texts = $(this).attr("data-text")
  78. if(texts == "uploads"){
  79. $(".mainbox").css({"display":"block"})
  80. $(".sbox").css({"display":"none"})
  81. }
  82. })
  83. //home 控制home
  84. $(".botmat1img").on("click",function(){
  85. let codes= $(this).attr("data-text")
  86. console.log(codes)
  87. if(codes == "home"){
  88. var bitRate ={"data":{"keyCode":"3"},"event":"keyCode"}
  89. wsss.send(JSON.stringify(bitRate));
  90. }else if(codes == "return"){
  91. var bitRate ={"data":{"keyCode":"4"},"event":"keyCode"}
  92. wsss.send(JSON.stringify(bitRate));
  93. }else if(codes == "gengduo"){
  94. var bitRate ={"data":{"keyCode":"187"},"event":"keyCode"}
  95. wsss.send(JSON.stringify(bitRate));
  96. }
  97. })
  98. //高清控制
  99. $(".PictureQuality").on("click",function(){
  100. $(this).addClass("avit").siblings().removeClass('avit')
  101. let id= $(this).attr("data-id")
  102. var bitRate ={"data":{"bitRate":id},"event":"bitRate"}
  103. wsss.send(JSON.stringify(bitRate));
  104. console.log(id)
  105. })
  106. //画图形
  107. var draw_graph = function(graphType, obj) {
  108. console.log('111》》》', graphType)
  109. //把蒙版放于画板上面
  110. //$("#canvas_bak").css("z-index",1);
  111. $("#container").css("z-index", 30);
  112. $("#dedit").css("z-index", 20);
  113. //先画在蒙版上 再复制到画布上
  114. chooseImg(obj);
  115. var canDraw = false;
  116. var startX;
  117. var startY;
  118. var touchNum = 0
  119. var touchPos = {};
  120. //鼠标按下获取 开始xy开始画图
  121. var touchstart = function(e) {
  122. // .toFixed(2)
  123. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  124. var touch = e.originalEvent.targetTouches[0];
  125. var thochlethng = e.originalEvent.targetTouches.length
  126. touchNum = thochlethng;
  127. touchPos = touch;
  128. e.preventDefault()
  129. if(touchfor.length == 1){
  130. var pingssfe = {
  131. "event": "getScreenStatus"
  132. }
  133. wsss.send(JSON.stringify(pingssfe));
  134. }
  135. //是否横屏
  136. if (resolving == 0) {
  137. let ping
  138. for (let i = 0; i < touchfor.length; i++) {
  139. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  140. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  141. ping = {"data":{"action":0,"count":touchfor.length,"pointerId":i,"x":cawidthXs.toFixed(2),"y":caheightYs.toFixed(2)},"event":"0"}
  142. wsss.send(JSON.stringify(ping));
  143. }
  144. } else {
  145. let ping
  146. for (let i = 0; i < touchfor.length; i++) {
  147. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  148. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  149. ping = {"data":{"action":0,"count":touchfor.length,"pointerId":i,"x":cawidthXs.toFixed(2),"y":caheightYs.toFixed(2)},"event":"0"}
  150. wsss.send(JSON.stringify(ping));
  151. }
  152. }
  153. canDraw = true;
  154. };
  155. //鼠标离开 把蒙版canvas的图片生成到canvas中
  156. var touchend = function(e) {
  157. e.preventDefault()
  158. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  159. var touch = e.originalEvent.changedTouches[0];
  160. var thochlethng = e.originalEvent.changedTouches.length
  161. // alert(thochlethng)
  162. //是否横屏 morePortionUp
  163. if (resolving == 0) {
  164. let ping
  165. for (let i = 0; i < touchfor.length; i++) {
  166. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  167. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  168. ping = {"data":{"action":1,"count":touchfor.length,"pointerId":i,"x":cawidthXs.toFixed(2),"y":caheightYs.toFixed(2)},"event":"1"}
  169. }
  170. (touchNum <= 1 || (touch.pageY == touchPos.pageY && touch.pageX == touchPos.pageX)) && wsss.send(JSON.stringify(ping));
  171. } else {
  172. let ping
  173. for (let i = 0; i < touchfor.length; i++) {
  174. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  175. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  176. ping = {"data":{"action":1,"count":touchfor.length,"pointerId":i,"x":cawidthXs.toFixed(2),"y":caheightYs.toFixed(2)},"event":"1"}
  177. }
  178. (touchNum <= 1 || (touch.pageY == touchPos.pageY && touch.pageX == touchPos.pageX)) && wsss.send(JSON.stringify(ping));
  179. }
  180. canDraw = false;
  181. };
  182. //清空层 云手机超出屏幕的开关
  183. var clearContext = function(type) {
  184. canDraw = false;
  185. }
  186. // 鼠标移动
  187. var touchmove = function(e) {
  188. e = e || window.event;
  189. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  190. var touch = e.originalEvent.targetTouches[0];
  191. var thochlethng = e.originalEvent.targetTouches.length
  192. touchNum = thochlethng;
  193. touchPos = touch;
  194. e.preventDefault();
  195. let ping
  196. //是否横屏 morePortionMove
  197. if (resolving == 0) {
  198. let obj = []
  199. for (let i = 0; i < touchfor.length; i++) {
  200. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  201. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  202. ping = {"data":{"action":2,"count":touchfor.length,"pointerId":i,"x":cawidthXs.toFixed(2),"y":caheightYs.toFixed(2)},"event":"2"}
  203. wsss.send(JSON.stringify(ping));
  204. }
  205. } else {
  206. let ping
  207. for (let i = 0; i < touchfor.length; i++) {
  208. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  209. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  210. ping = {"data":{"action":2,"count":touchfor.length,"pointerId":i,"x":cawidthXs.toFixed(2),"y":caheightYs.toFixed(2)},"event":"2"}
  211. wsss.send(JSON.stringify(ping));
  212. }
  213. }
  214. // var ping = {"data":{"action":2,"count":1,"pointerId":0,"x":cawidthX.toFixed(2),"y":caheightY.toFixed(2)},"event":"2"}
  215. };
  216. //鼠标离开区域以外 除了涂鸦 都清空
  217. var mouseout = function() {
  218. if (graphType != 'handwriting') {
  219. clearContext();
  220. }
  221. }
  222. $(canvas_bak).unbind();
  223. $(canvas_bak).bind('touchstart', touchstart);
  224. $(canvas_bak).bind('touchmove', touchmove);
  225. $(canvas_bak).bind('touchend', touchend);
  226. $(canvas_bak).bind('mouseout', mouseout);
  227. }
  228. //选择功能按钮 修改样式
  229. function chooseImg(obj) {
  230. }