Skip to content

Commit

Permalink
Merge pull request #33 from xendke/manual-rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
owulveryck authored Jul 20, 2022
2 parents 6a18aff + 437d742 commit 8fe2e35
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
28 changes: 28 additions & 0 deletions client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,38 @@ html, body {
max-height: 100%;
max-width: 100%;
}
.orientation {
position: absolute;
top: 10px;
left: 10px;
}
.orientation button {
background-color: #04AA6D;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container center">
{{ if not .AutoRotate }}
<div class="orientation">
<iframe name="dummyframe" id="dummyframe" style="display: none;"></iframe>
<form action="/orientation" method="GET" target="dummyframe">
<input type="hidden" name="orientation" value="portrait" />
<button>portrait</button>
</form>
<form action="/orientation" method="GET" target="dummyframe">
<input type="hidden" name="orientation" value="landscape" />
<button>landscape</button>
</form>
</div>
{{end}}
<a href="/screenshot" download>
<img src="/video">
</a>
Expand Down
9 changes: 7 additions & 2 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"compress/zlib"
"html/template"
"context"
"fmt"
"log"
"net/http"

Expand Down Expand Up @@ -37,7 +37,12 @@ func main() {

mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, index)
t := template.Must(template.New("index").Parse(index))
err := t.Execute(w, c)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
mux.HandleFunc("/favicon.ico", faviconHandler)
mux.HandleFunc("/screenshot", g.GetScreenshot)
Expand Down
15 changes: 7 additions & 8 deletions internal/client/orientation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ type rotation struct {
}

func (r *rotation) rotate(img *image.Gray) {
if !r.isActive {
return
}
switch {
case (isPortraitLeft(img.Pix) || isPortraitRight(img.Pix)) && r.orientation != portrait:
r.orientation = portrait
case (isLandscapeLeft(img.Pix) || isLandscapeRight(img.Pix)) && r.orientation != landscape:
r.orientation = landscape
if r.isActive {
switch {
case (isPortraitLeft(img.Pix) || isPortraitRight(img.Pix)) && r.orientation != portrait:
r.orientation = portrait
case (isLandscapeLeft(img.Pix) || isLandscapeRight(img.Pix)) && r.orientation != landscape:
r.orientation = landscape
}
}
if r.orientation == portrait {
rotate(img)
Expand Down

0 comments on commit 8fe2e35

Please sign in to comment.