-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml.cpp
146 lines (141 loc) · 3.64 KB
/
html.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "html.h"
html::html()
{
htmlPage = makeHtml();
pageSize = htmlPage.length();
jsFile = makeJs();
jsSize = jsFile.length();
}
String html::makeHtml()
{
return "<!DOCTYPE html>\
<html lang='fr'>\
<head>\
<meta charset='utf-8'>\
<script language = 'javascript'type = 'text/javascript'>\
var wsUri = 'ws://192.168.1.28:81/';\
var output;\
function init() {\
testWebSocket();\
}\
function testWebSocket() {\
websocket = new WebSocket(wsUri);\
websocket.onopen = function(evt) {\
console.log('CONNECTED');\
};\
websocket.onclose = function(evt) {\
console.log('DISCONNECTED');\
};\
websocket.onmessage = function(evt) {\
console.log('RECEIVED: ' + evt.data);\
};\
websocket.onerror = function(evt) {\
console.log('ERROR: ' + evt.data);\
};\
}\
function changeMousePos(xPosition, yPosition) {\
var xPosition = (xPosition*2)-1;\
var yPosition = ((1-yPosition)*2)-1;\
console.log('X: ' + xPosition);\
console.log('Y: ' + yPosition);\
\
var messageX = parseInt(xPosition*1023);\
websocket.send('X:' + messageX);\
var messageY = parseInt(yPosition*1023);\
websocket.send('Y:' + messageY);\
}\
window.addEventListener('load', init, false);\
</script>\
<style type='text/css'>\
#contentContainer {\
border-radius:50%;\
width: 550px;\
height: 550px;\
border: 5px black solid;\
overflow: hidden;\
background-color: #F2F2F2;\
cursor: pointer;\
}\
</style>\
</head>\
<body>\
<h1 align='center'>radio-command</h1>\
<div align='center'>\
<div id='contentContainer'>\
</div>\
<a href='?d=stop'>\
<button class='stop'>\
STOP\
</button>\
</a>\
<div>\
<a href='?d=Fn1'>\
<button class='function'>\
Fn1\
</button>\
</a>\
<a href='?d=Fn2'>\
<button class='function'>\
Fn2\
</button>\
</a>\
</div>\
<p>Uptime: %02d:%02d:%02d</p>\
</div>\
<script src='scripts/mouse.js'></script>\
</body>\
</html>";
}
String html::makeJs()
{
return "function getPosition(el) {\
var xPos = 0;\
var yPos = 0;\
while (el) {\
if (el.tagName == 'BODY') {\
var xScroll = el.scrollLeft || document.documentElement.scrollLeft;\
var yScroll = el.scrollTop || document.documentElement.scrollTop;\
\
xPos += (el.offsetLeft - xScroll + el.clientLeft);\
yPos += (el.offsetTop - yScroll + el.clientTop);\
} else {\
xPos += (el.offsetLeft - el.scrollLeft + el.clientLeft);\
yPos += (el.offsetTop - el.scrollTop + el.clientTop);\
}\
el = el.offsetParent;\
}\
return {\
x: xPos,\
y: yPos\
};\
}\
function getClickPosition(e) {\
if(!isMouseDown)\
return;\
var parentPosition = getPosition(e.currentTarget);\
var xPosition = e.clientX - parentPosition.x;\
var yPosition = e.clientY - parentPosition.y;\
if(xPosition < 0)\
xPosition = 0;\
if(xPosition > container.offsetWidth)\
return;\
if(yPosition < 0)\
yPosition = 0;\
if(yPosition > container.offsetHeight)\
return;\
changeMousePos(xPosition/container.offsetWidth, yPosition/container.offsetHeight);\
}\
var container = document.querySelector('#contentContainer');\
var isMouseDown = false;\
container.addEventListener('mousedown', enterMouse);\
container.addEventListener('mouseup', leaveMouse);\
container.addEventListener('mousemove', getClickPosition);\
function enterMouse() {\
console.log('MOUSE: down');\
isMouseDown = true;\
}\
function leaveMouse() {\
console.log('MOUSE: up');\
isMouseDown = false;\
}";
}