mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-03-25 21:33:00 +01:00
first commit
This commit is contained in:
36
gogame/color/color.go
Normal file
36
gogame/color/color.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package color
|
||||
|
||||
//import "github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
|
||||
type Color struct {
|
||||
R uint32
|
||||
G uint32
|
||||
B uint32
|
||||
A uint32
|
||||
}
|
||||
|
||||
func (c *Color) ToHex() int {
|
||||
return int( c.A<< 24 | c.R << 16 | c.G << 8 | c.B )
|
||||
}
|
||||
|
||||
func (c *Color) ToBytes() []byte {
|
||||
bytes := make([]byte,4)
|
||||
bytes[0] = byte(c.R)
|
||||
bytes[1] = byte(c.G)
|
||||
bytes[2] = byte(c.B)
|
||||
bytes[3] = byte(c.A)
|
||||
return bytes
|
||||
}
|
||||
|
||||
func (c *Color) RGBA() (r, g, b, a uint32) {
|
||||
r = uint32(c.R)
|
||||
r |= r << 8
|
||||
g = uint32(c.G)
|
||||
g |= g << 8
|
||||
b = uint32(c.B)
|
||||
b |= b << 8
|
||||
a = uint32(c.A)
|
||||
a |= a << 8
|
||||
return
|
||||
}
|
||||
14
gogame/color/color_test.go
Normal file
14
gogame/color/color_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package color
|
||||
|
||||
// > go test color.go color_test.go -v
|
||||
// Or
|
||||
// > go test -v
|
||||
// to test all test files
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestColor(t *testing.T) {
|
||||
c := &Color{244,124,244,0}
|
||||
t.Logf("%x", c.ToHex())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user