-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwindow.go
More file actions
58 lines (49 loc) · 1.5 KB
/
window.go
File metadata and controls
58 lines (49 loc) · 1.5 KB
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
package main
import (
"math"
rl "github.com/gen2brain/raylib-go/raylib"
)
type Window struct {
title string
width int32
height int32
fullscreen bool
musicVolume float32
sfxVolume float32
maxScreenWidth int32
maxScreenHeight int32
}
func (c *Window) GetScreenDimensions() (float32, float32) {
if c.fullscreen {
w := float32(rl.GetScreenWidth())
h := float32(rl.GetScreenHeight())
return w, h
} else {
return float32(c.width), float32(c.height)
}
}
func (c *Window) GetScreenBoundary() rl.Rectangle {
screenWidth, screenHeight := c.GetScreenDimensions()
screenRect := rl.NewRectangle(0, 0, screenWidth, screenHeight)
return screenRect
}
// GetScreenBoundaryLines - returns the boundary lines in the order of
// TOP, LEFT, BOTTOM, RIGHT
func (c *Window) GetScreenBoundaryLines(screenBoundary rl.Rectangle) [4][2]rl.Vector2 {
topLeft := rl.NewVector2(screenBoundary.X, screenBoundary.Y)
topRight := rl.NewVector2(screenBoundary.X+screenBoundary.Width, screenBoundary.Y)
bottomLeft := rl.NewVector2(screenBoundary.X, screenBoundary.Y+screenBoundary.Height)
bottomRight := rl.NewVector2(screenBoundary.X+screenBoundary.Width, screenBoundary.Y+screenBoundary.Height)
lines := [4][2]rl.Vector2{
{topLeft, topRight},
{topLeft, bottomLeft},
{bottomLeft, bottomRight},
{topRight, bottomRight},
}
return lines
}
func (c *Window) GetScreenDiagonal() float32 {
w, h := c.GetScreenDimensions()
res := math.Sqrt(float64(w*w + h*h))
return float32(res)
}