-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolor.go
68 lines (56 loc) · 2.03 KB
/
color.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
// Copyright (C) 2012-2014 by krepa098. All rights reserved.
// Use of this source code is governed by a zlib-style
// license that can be found in the license.txt file.
package gosfml2
// #include <SFML/Graphics/Color.h>
import "C"
/////////////////////////////////////
/// STRUCTS
/////////////////////////////////////
// RGBA Color
//
// Color{} represents Color{0,0,0,0} i.e. transparent
type Color struct {
//Created by cgo -godefs - DO NOT EDIT
R uint8 //<< Red component
G uint8 //<< Green component
B uint8 //<< Blue component
A uint8 //<< Alpha component (0 = transparent)
}
/////////////////////////////////////
/// CONSTS
/////////////////////////////////////
func ColorBlack() Color { return Color{0, 0, 0, 255} }
func ColorWhite() Color { return Color{255, 255, 255, 255} }
func ColorRed() Color { return Color{255, 0, 0, 255} }
func ColorGreen() Color { return Color{0, 255, 0, 255} }
func ColorBlue() Color { return Color{0, 0, 255, 255} }
func ColorYellow() Color { return Color{255, 255, 0, 255} }
func ColorMagenta() Color { return Color{255, 0, 255, 255} }
func ColorCyan() Color { return Color{0, 255, 255, 255} }
func ColorTransparent() Color { return Color{0, 0, 0, 0} }
/////////////////////////////////////
/// FUNCS
/////////////////////////////////////
// Component-wise saturated addition of the two colors
func (this Color) Add(other Color) (newColor Color) {
newColor.fromC(C.sfColor_add(this.toC(), other.toC()))
return
}
// Component-wise multiplication of the two colors
func (this Color) Modulate(other Color) (newColor Color) {
newColor.fromC(C.sfColor_modulate(this.toC(), other.toC()))
return
}
/////////////////////////////////////
/// GO <-> C
/////////////////////////////////////
func (this *Color) fromC(color C.sfColor) {
this.R = byte(color.r)
this.G = byte(color.g)
this.B = byte(color.b)
this.A = byte(color.a)
}
func (this Color) toC() C.sfColor {
return C.sfColor{r: C.sfUint8(this.R), g: C.sfUint8(this.G), b: C.sfUint8(this.B), a: C.sfUint8(this.A)}
}