-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_ui.go
106 lines (88 loc) · 2.56 KB
/
draw_ui.go
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
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
_ "image/png"
"fmt"
)
const (
steps = 5
)
var (
screenHeight int
screenWidth int
ppan int
pzoom float64
subj int
tframes int
cframes int
termUI bool
)
func setupUI() {
// Setup dimensions for player-only and algorithm show modes
if !playOnlyMode {
screenHeight = screenHeight*steps
} else {
screenWidth = screenHeight
ebiten.SetWindowFloating(true)
// ebiten.SetWindowDecorated(false)
// ebiten.SetFullscreen(true)
// ebiten.SetWindowMousePassthrough(true)
}
termUI = false
fmt.Println("w_size", screenWidth,screenHeight)
ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("1:1 Content-Aware Video Crop")
}
type Game struct {
}
func (g *Game) Update() error {
// called every tick
if termUI {
return ebiten.Termination
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
if !playOnlyMode {
inputFrameRW.Lock()
screen.DrawImage(ebiten.NewImageFromImage(inputFrame), &ebiten.DrawImageOptions{})
inputFrameRW.Unlock()
op1 := &ebiten.DrawImageOptions{}
op1.GeoM.Translate(0, float64(squareSize))
grayFrameRW.Lock()
screen.DrawImage(ebiten.NewImageFromImage(grayFrame), op1)
grayFrameRW.Unlock()
op2 := &ebiten.DrawImageOptions{}
op2.GeoM.Translate(0, float64(squareSize*2))
binaryFrameRW.Lock()
screen.DrawImage(ebiten.NewImageFromImage(binaryFrame), op2)
binaryFrameRW.Unlock()
op3 := &ebiten.DrawImageOptions{}
op3.GeoM.Translate(0, float64(squareSize*3))
calcFrameRW.Lock()
screen.DrawImage(ebiten.NewImageFromImage(calcFrame), op3)
calcFrameRW.Unlock()
op4 := &ebiten.DrawImageOptions{}
op4.GeoM.Translate(float64((screenWidth-squareSize))/2, float64(squareSize*4))
croppedFrameRW.Lock()
screen.DrawImage(ebiten.NewImageFromImage(croppedFrame), op4)
croppedFrameRW.Unlock()
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f\nPan: %dpx\nZoom: %.2f%%\nSubj: %d\nProg: %.2f%%", ebiten.ActualFPS(), ppan, pzoom, subj, float64(float64(cframes)/float64(tframes))*100))
} else {
// Player-only mode
croppedFrameRW.Lock()
screen.DrawImage(ebiten.NewImageFromImage(croppedFrame), nil)
croppedFrameRW.Unlock()
}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}
func runUI() {
if err := ebiten.RunGameWithOptions(&Game{}, &ebiten.RunGameOptions{ScreenTransparent: true}); err != nil {
fmt.Println(err.Error())
selfExit()
return
}
}