2022-02-10 19:58:51 +08:00
|
|
|
package igwrap
|
|
|
|
|
|
|
|
import (
|
2022-02-22 14:28:35 +08:00
|
|
|
"math"
|
|
|
|
|
2024-08-02 18:38:33 +08:00
|
|
|
"edgaru089.ink/go/gl01/internal/util/itype"
|
2022-02-10 19:58:51 +08:00
|
|
|
"github.com/inkyblackness/imgui-go/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Color converts non-premultiplied RGBA color into imgui.Vec4.
|
|
|
|
func Color(r, g, b, a uint8) imgui.Vec4 {
|
|
|
|
return imgui.Vec4{
|
|
|
|
X: float32(r) / 255,
|
|
|
|
Y: float32(g) / 255,
|
|
|
|
Z: float32(b) / 255,
|
|
|
|
W: float32(a) / 255,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 21:13:55 +08:00
|
|
|
// PackedColor converts RGBA to imgui.PackedColor.
|
|
|
|
func PackedColor(color itype.Vec4f) imgui.PackedColor {
|
|
|
|
return imgui.PackedColorFromVec4(Vec4(color))
|
|
|
|
}
|
|
|
|
|
2022-02-22 14:28:35 +08:00
|
|
|
// UnpackedColor unpacks a color to RGBA.
|
|
|
|
func UnpackedColor(color imgui.PackedColor) itype.Vec4f {
|
|
|
|
r, g, b, a := color.RGBA()
|
|
|
|
return itype.Vec4f{
|
|
|
|
float32(r) / float32(math.MaxUint32),
|
|
|
|
float32(g) / float32(math.MaxUint32),
|
|
|
|
float32(b) / float32(math.MaxUint32),
|
|
|
|
float32(a) / float32(math.MaxUint32),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 19:58:51 +08:00
|
|
|
// Vec2 converts itype.Vec2f to imgui.Vec2.
|
|
|
|
func Vec2(v itype.Vec2f) imgui.Vec2 {
|
|
|
|
return imgui.Vec2{X: v[0], Y: v[1]}
|
|
|
|
}
|
|
|
|
|
2022-02-10 21:13:55 +08:00
|
|
|
// Vec2f converts imgui.Vec2 to itype.Vec2f.
|
|
|
|
func Vec2f(v imgui.Vec2) itype.Vec2f {
|
|
|
|
return itype.Vec2f{v.X, v.Y}
|
|
|
|
}
|
|
|
|
|
2022-02-10 19:58:51 +08:00
|
|
|
// Vec4 converts itype.Vec4f to imgui.Vec4.
|
|
|
|
func Vec4(v itype.Vec4f) imgui.Vec4 {
|
|
|
|
return imgui.Vec4{X: v[0], Y: v[1], Z: v[2], W: v[3]}
|
|
|
|
}
|