diff --git a/main.go b/main.go index 5d5b212..820060c 100755 --- a/main.go +++ b/main.go @@ -76,6 +76,10 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) { }) } +func (server Server) addWatchArea(w http.ResponseWriter, r *http.Request) { + +} + func main() { staticFileServer := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static/", staticFileServer)) @@ -105,5 +109,6 @@ func main() { http.HandleFunc("/", server.index) http.HandleFunc("/addStream", server.addStream) + http.HandleFunc("/addWatchArea", server.addWatchArea) log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/static/js/stream.js b/static/js/stream.js index e4eec1f..5d6eca6 100755 --- a/static/js/stream.js +++ b/static/js/stream.js @@ -1,13 +1,25 @@ +let canvas = null +let ctx = null; +let img = null; + let isDrawing = false; + +// rectangle let x0 = 0; let y0 = 0; -let rectangle = null +let x1 = 0; +let y1 = 0; + +// color +let R = 0; +let G = 0; +let B = 0; document.addEventListener("DOMContentLoaded", function(){ - const canvas = document.getElementById("canvas"); - const ctx = canvas.getContext("2d"); - var src = document.getElementById("current_color_stream"); - var img = new Image(); + canvas = document.getElementById("canvas"); + ctx = canvas.getContext("2d"); + src = document.getElementById("current_color_stream"); + img = new Image(); img.src = src.src; img.onload = function() { draw(ctx, img); @@ -21,12 +33,10 @@ document.addEventListener("DOMContentLoaded", function(){ canvas.addEventListener("mousemove", e => { if(isDrawing === true) { - draw(ctx, img); x1 = e.offsetX; y1 = e.offsetY; - ctx.beginPath(); - ctx.rect(x0,y0,x1-x0,y1-y0); - ctx.stroke(); + draw(); + update(); } }); @@ -38,6 +48,63 @@ document.addEventListener("DOMContentLoaded", function(){ }); }); -function draw(ctx, img){ +function draw(){ + ctx.clearRect(0, 0, canvas.width, canvas.height); + drawImage(); + drawRectangle(); +} + +function drawImage(){ ctx.drawImage(img, 0, 0) -} \ No newline at end of file +} + +function drawRectangle(){ + ctx.beginPath(); + ctx.lineWidth = "5"; + ctx.strokeStyle = "rgb(" + R + ", " + G + ", " + B + ")"; + ctx.rect(x0,y0,x1-x0,y1-y0); + ctx.stroke(); +} + +function update() { + var existingRow = document.getElementById("addWatchAreaRow") + if (existingRow !== null) { + updateRectInputs(); + return + } + var newWatchAreaTemplate = document.getElementById("newWatchAreaTemplate"); + var newWatchArea = newWatchAreaTemplate.content.cloneNode(true); + var watchAreaTableBody = document.getElementById("watchAreas"); + watchAreaTableBody.appendChild(newWatchArea); + updateRectInputs(); +} + +function submitNewArea(){ + let nameInput = document.getElementsByName("name")[0]; + if (nameInput.value.length == 0){ + nameInput.select(); + return; + } + let name = nameInput.value; + document.getElementById("newWatchAreaForm").submit() +} + +function updateRectInputs(){ + document.getElementsByName("R")[0].value = R; + document.getElementsByName("G")[0].value = G; + document.getElementsByName("B")[0].value = B; + + document.getElementsByName("x0")[0].value = x0; + document.getElementsByName("y0")[0].value = y0; + document.getElementsByName("x1")[0].value = x1; + document.getElementsByName("y1")[0].value = y1; +} + +let changeR = function(elem){R = elem.value; draw();} +let changeG = function(elem){G = elem.value; draw();} +let changeB = function(elem){B = elem.value; draw();} + +let changeX0 = function(elem){x0 = elem.value; draw();} +let changeY0 = function(elem){y0 = elem.value; draw();} +let changeX1 = function(elem){x1 = elem.value; draw();} +let changeY1 = function(elem){y1 = elem.value; draw();} \ No newline at end of file diff --git a/templates/stream.html b/templates/stream.html index 38140c2..b2878c9 100755 --- a/templates/stream.html +++ b/templates/stream.html @@ -10,36 +10,57 @@ - - - - - - - - - - - - - - - - - - - - {{range $watchArea := .WatchAreas}} - - - - - - - - - - - {{end}} -
Watches
NameColorArea
RGBMinXMinYMaxXMaxY
{{ $watchArea.Name }}{{ $watchArea.Color.R }}{{ $watchArea.Color.G }}{{ $watchArea.Color.B }}{{ $watchArea.Area.Min.X }}{{ $watchArea.Area.Min.Y }}{{ $watchArea.Area.Max.X }}{{ $watchArea.Area.Max.Y }}
+
+ + + + + + + + + + + + + + + + + + + + + + + {{range $watchArea := .WatchAreas}} + + + + + + + + + + + + {{end}} + +
Watches
NameColorAreaAdd/Remove
RGBMinXMinYMaxXMaxY
{{ $watchArea.Name }}{{ $watchArea.Color.R }}{{ $watchArea.Color.G }}{{ $watchArea.Color.B }}{{ $watchArea.Area.Min.X }}{{ $watchArea.Area.Min.Y }}{{ $watchArea.Area.Max.X }}{{ $watchArea.Area.Max.Y }}Remove
+
+ + {{end}} \ No newline at end of file