-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.go
67 lines (56 loc) · 1.28 KB
/
window.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
package main
import (
"github.com/veandco/go-sdl2/sdl"
"time"
)
type Window struct {
title string
location F2
perspective F2
size F2
updateLastTick time.Time
updateDelta time.Duration
renderLastTick time.Time
renderDelta time.Duration
}
func (w *Window) GetLocation() F2 {
return w.location
}
func (w *Window) GetSize() F2 {
return w.size
}
func (w *Window) Configure() {
w.updateLastTick = time.Now()
w.renderLastTick = time.Now()
}
func (w *Window) HandleEvent(event sdl.Event) {
switch t := event.(type) {
case *sdl.MouseButtonEvent:
break
case *sdl.MouseMotionEvent:
w.perspective.X += float64(t.XRel)
w.perspective.Y += float64(t.YRel)
break
case *sdl.MouseWheelEvent:
break
}
}
func (w *Window) DrawFrame(g *Graphics) {
g.ColorSecondary()
g.FillRect(F2{1, 1}, F2{w.size.X - 2, 28})
g.ColorText()
g.Text(w.title, F2{8, 6})
g.ColorPrimary()
g.Rect(F2{1, 1}, F2{w.size.X - 2, w.size.Y - 2})
}
func (w *Window) Update() {
w.updateDelta = time.Duration(time.Since(w.updateLastTick).Nanoseconds())
w.updateLastTick = time.Now()
}
func (w *Window) Draw(g *Graphics) {
w.renderDelta = time.Duration(time.Since(w.renderLastTick).Nanoseconds())
w.renderLastTick = time.Now()
}
func (w *Window) GetBounds() (F2, F2) {
return w.location, w.size
}