diff --git a/main.go b/main.go
index 820060c..37882bd 100755
--- a/main.go
+++ b/main.go
@@ -2,6 +2,8 @@ package main
import (
"encoding/json"
+ "image"
+ "image/color"
"io/ioutil"
"log"
"net/http"
@@ -39,6 +41,7 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
log.Fatal(err)
}
streamTemplate.Execute(w, stream)
+ log.Println(server.Streams)
}
func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
@@ -77,7 +80,66 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
}
func (server Server) addWatchArea(w http.ResponseWriter, r *http.Request) {
-
+ if r.Method != "POST" {
+ //return
+ }
+ streamName := r.FormValue("streamName")
+ if streamName == "" {
+ return
+ }
+ stream, exists := server.Streams[streamName]
+ if !exists {
+ return
+ }
+ name := r.FormValue("name")
+ if name == "" {
+ return
+ }
+ x0 := r.FormValue("x0")
+ if x0 == "" {
+ return
+ }
+ y0 := r.FormValue("y0")
+ if y0 == "" {
+ return
+ }
+ x1 := r.FormValue("x1")
+ if x1 == "" {
+ return
+ }
+ y1 := r.FormValue("y1")
+ if y1 == "" {
+ return
+ }
+ R := r.FormValue("R")
+ if R == "" {
+ return
+ }
+ G := r.FormValue("G")
+ if G == "" {
+ return
+ }
+ B := r.FormValue("B")
+ if B == "" {
+ return
+ }
+ stream.WatchAreas = append(stream.WatchAreas, WatchArea{
+ Name: name,
+ Color: color.RGBA{
+ uint8(StrToInt(R)),
+ uint8(StrToInt(G)),
+ uint8(StrToInt(B)),
+ 255,
+ },
+ Area: image.Rect(
+ StrToInt(x0),
+ StrToInt(y0),
+ StrToInt(x1),
+ StrToInt(y1),
+ ),
+ })
+ stream.WriteStreamJSON()
+ http.Redirect(w, r, "/?name="+streamName, http.StatusTemporaryRedirect)
}
func main() {
diff --git a/stream.go b/stream.go
index 6ee602e..b87efe6 100755
--- a/stream.go
+++ b/stream.go
@@ -174,6 +174,11 @@ func (s Stream) SwapInstants(previous string, current string, next string) {
}
}
+// AddWatchArea adds the given WatchArea to the list of WatchAreas
+func (s Stream) AddWatchArea(watchArea WatchArea) {
+ s.WatchAreas = append(s.WatchAreas, watchArea)
+}
+
// GetStreamJSONPath returns filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
func (s Stream) GetStreamJSONPath() string {
return filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
diff --git a/templates/stream.html b/templates/stream.html
index f6b984a..f95a762 100755
--- a/templates/stream.html
+++ b/templates/stream.html
@@ -11,6 +11,7 @@