Move all constants and types to raylib.go

This commit is contained in:
Milan Nikolic 2017-12-07 20:32:31 +01:00
parent f71025719c
commit 135a4637a6
12 changed files with 916 additions and 910 deletions

View file

@ -7,448 +7,89 @@ package raylib
import "C"
import (
"io"
"unsafe"
)
// Some basic Defines
const (
Pi = 3.1415927
Deg2rad = 0.017453292
Rad2deg = 57.295776
// Raylib Config Flags
// Set to show raylib logo at startup
FlagShowLogo = 1
// Set to run program in fullscreen
FlagFullscreenMode = 2
// Set to allow resizable window
FlagWindowResizable = 4
// Set to show window decoration (frame and buttons)
FlagWindowDecorated = 8
// Set to allow transparent window
FlagWindowTransparent = 16
// Set to try enabling MSAA 4X
FlagMsaa4xHint = 32
// Set to try enabling V-Sync on GPU
FlagVsyncHint = 64
// Keyboard Function Keys
KeySpace = 32
KeyEscape = 256
KeyEnter = 257
KeyBackspace = 259
KeyRight = 262
KeyLeft = 263
KeyDown = 264
KeyUp = 265
KeyF1 = 290
KeyF2 = 291
KeyF3 = 292
KeyF4 = 293
KeyF5 = 294
KeyF6 = 295
KeyF7 = 296
KeyF8 = 297
KeyF9 = 298
KeyF10 = 299
KeyF11 = 300
KeyF12 = 301
KeyLeftShift = 340
KeyLeftControl = 341
KeyLeftAlt = 342
KeyRightShift = 344
KeyRightControl = 345
KeyRightAlt = 346
// Keyboard Alpha Numeric Keys
KeyZero = 48
KeyOne = 49
KeyTwo = 50
KeyThree = 51
KeyFour = 52
KeyFive = 53
KeySix = 54
KeySeven = 55
KeyEight = 56
KeyNine = 57
KeyA = 65
KeyB = 66
KeyC = 67
KeyD = 68
KeyE = 69
KeyF = 70
KeyG = 71
KeyH = 72
KeyI = 73
KeyJ = 74
KeyK = 75
KeyL = 76
KeyM = 77
KeyN = 78
KeyO = 79
KeyP = 80
KeyQ = 81
KeyR = 82
KeyS = 83
KeyT = 84
KeyU = 85
KeyV = 86
KeyW = 87
KeyX = 88
KeyY = 89
KeyZ = 90
// Android keys
KeyBack = 4
KeyMenu = 82
KeyVolumeUp = 24
KeyVolumeDown = 25
// Mouse Buttons
MouseLeftButton = 0
MouseRightButton = 1
MouseMiddleButton = 2
// Touch points registered
MaxTouchPoints = 2
// Gamepad Number
GamepadPlayer1 = 0
GamepadPlayer2 = 1
GamepadPlayer3 = 2
GamepadPlayer4 = 3
// Gamepad Buttons/Axis
// PS3 USB Controller Buttons
GamepadPs3ButtonTriangle = 0
GamepadPs3ButtonCircle = 1
GamepadPs3ButtonCross = 2
GamepadPs3ButtonSquare = 3
GamepadPs3ButtonL1 = 6
GamepadPs3ButtonR1 = 7
GamepadPs3ButtonL2 = 4
GamepadPs3ButtonR2 = 5
GamepadPs3ButtonStart = 8
GamepadPs3ButtonSelect = 9
GamepadPs3ButtonUp = 24
GamepadPs3ButtonRight = 25
GamepadPs3ButtonDown = 26
GamepadPs3ButtonLeft = 27
GamepadPs3ButtonPs = 12
// PS3 USB Controller Axis
GamepadPs3AxisLeftX = 0
GamepadPs3AxisLeftY = 1
GamepadPs3AxisRightX = 2
GamepadPs3AxisRightY = 5
// [1..-1] (pressure-level)
GamepadPs3AxisL2 = 3
// [1..-1] (pressure-level)
GamepadPs3AxisR2 = 4
// Xbox360 USB Controller Buttons
GamepadXboxButtonA = 0
GamepadXboxButtonB = 1
GamepadXboxButtonX = 2
GamepadXboxButtonY = 3
GamepadXboxButtonLb = 4
GamepadXboxButtonRb = 5
GamepadXboxButtonSelect = 6
GamepadXboxButtonStart = 7
GamepadXboxButtonUp = 10
GamepadXboxButtonRight = 11
GamepadXboxButtonDown = 12
GamepadXboxButtonLeft = 13
GamepadXboxButtonHome = 8
// Xbox360 USB Controller Axis
// [-1..1] (left->right)
GamepadXboxAxisLeftX = 0
// [1..-1] (up->down)
GamepadXboxAxisLeftY = 1
// [-1..1] (left->right)
GamepadXboxAxisRightX = 2
// [1..-1] (up->down)
GamepadXboxAxisRightY = 3
// [-1..1] (pressure-level)
GamepadXboxAxisLt = 4
// [-1..1] (pressure-level)
GamepadXboxAxisRt = 5
)
// Some Basic Colors
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
var (
// Light Gray
LightGray = NewColor(200, 200, 200, 255)
// Gray
Gray = NewColor(130, 130, 130, 255)
// Dark Gray
DarkGray = NewColor(80, 80, 80, 255)
// Yellow
Yellow = NewColor(253, 249, 0, 255)
// Gold
Gold = NewColor(255, 203, 0, 255)
// Orange
Orange = NewColor(255, 161, 0, 255)
// Pink
Pink = NewColor(255, 109, 194, 255)
// Red
Red = NewColor(230, 41, 55, 255)
// Maroon
Maroon = NewColor(190, 33, 55, 255)
// Green
Green = NewColor(0, 228, 48, 255)
// Lime
Lime = NewColor(0, 158, 47, 255)
// Dark Green
DarkGreen = NewColor(0, 117, 44, 255)
// Sky Blue
SkyBlue = NewColor(102, 191, 255, 255)
// Blue
Blue = NewColor(0, 121, 241, 255)
// Dark Blue
DarkBlue = NewColor(0, 82, 172, 255)
// Purple
Purple = NewColor(200, 122, 255, 255)
// Violet
Violet = NewColor(135, 60, 190, 255)
// Dark Purple
DarkPurple = NewColor(112, 31, 126, 255)
// Beige
Beige = NewColor(211, 176, 131, 255)
// Brown
Brown = NewColor(127, 106, 79, 255)
// Dark Brown
DarkBrown = NewColor(76, 63, 47, 255)
// White
White = NewColor(255, 255, 255, 255)
// Black
Black = NewColor(0, 0, 0, 255)
// Blank (Transparent)
Blank = NewColor(0, 0, 0, 0)
// Magenta
Magenta = NewColor(255, 0, 255, 255)
// Ray White (RayLib Logo White)
RayWhite = NewColor(245, 245, 245, 255)
)
// Vector2 type
type Vector2 struct {
X float32
Y float32
}
// cptr returns C pointer
func (v *Vector2) cptr() *C.Vector2 {
return (*C.Vector2)(unsafe.Pointer(v))
}
// NewVector2 - Returns new Vector2
func NewVector2(x, y float32) Vector2 {
return Vector2{x, y}
}
// newVector2FromPointer - Returns new Vector2 from pointer
func newVector2FromPointer(ptr unsafe.Pointer) Vector2 {
return *(*Vector2)(ptr)
}
// Vector3 type
type Vector3 struct {
X float32
Y float32
Z float32
}
// cptr returns C pointer
func (v *Vector3) cptr() *C.Vector3 {
return (*C.Vector3)(unsafe.Pointer(v))
}
// NewVector3 - Returns new Vector3
func NewVector3(X, Y, Z float32) Vector3 {
return Vector3{X, Y, Z}
}
// newVector3FromPointer - Returns new Vector3 from pointer
func newVector3FromPointer(ptr unsafe.Pointer) Vector3 {
return *(*Vector3)(ptr)
}
// Matrix type (OpenGL style 4x4 - right handed, column major)
type Matrix struct {
M0, M4, M8, M12 float32
M1, M5, M9, M13 float32
M2, M6, M10, M14 float32
M3, M7, M11, M15 float32
}
// cptr returns C pointer
func (m *Matrix) cptr() *C.Matrix {
return (*C.Matrix)(unsafe.Pointer(m))
}
// NewMatrix - Returns new Matrix
func NewMatrix(m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15 float32) Matrix {
return Matrix{m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15}
}
// newMatrixFromPointer - Returns new Matrix from pointer
func newMatrixFromPointer(ptr unsafe.Pointer) Matrix {
return *(*Matrix)(ptr)
}
// Mat2 type (used for polygon shape rotation matrix)
type Mat2 struct {
M00 float32
M01 float32
M10 float32
M11 float32
}
// NewMat2 - Returns new Mat2
func NewMat2(m0, m1, m10, m11 float32) Mat2 {
return Mat2{m0, m1, m10, m11}
}
// Quaternion type
type Quaternion struct {
X float32
Y float32
Z float32
W float32
}
// NewQuaternion - Returns new Quaternion
func NewQuaternion(x, y, z, w float32) Quaternion {
return Quaternion{x, y, z, w}
}
// Color type, RGBA (32bit)
type Color struct {
R uint8
G uint8
B uint8
A uint8
}
// cptr returns C pointer
func (color *Color) cptr() *C.Color {
return (*C.Color)(unsafe.Pointer(color))
}
// NewColor - Returns new Color
func NewColor(r, g, b, a uint8) Color {
return Color{r, g, b, a}
}
// newColorFromPointer - Returns new Color from pointer
func newColorFromPointer(ptr unsafe.Pointer) Color {
return *(*Color)(ptr)
}
// Rectangle type
type Rectangle struct {
X int32
Y int32
Width int32
Height int32
}
// cptr returns C pointer
func (r *Rectangle) cptr() *C.Rectangle {
return (*C.Rectangle)(unsafe.Pointer(r))
}
// NewRectangle - Returns new Rectangle
func NewRectangle(x, y, width, height int32) Rectangle {
return Rectangle{x, y, width, height}
}
// newRectangleFromPointer - Returns new Rectangle from pointer
func newRectangleFromPointer(ptr unsafe.Pointer) Rectangle {
return *(*Rectangle)(ptr)
}
// Camera type, defines a camera position/orientation in 3d space
type Camera struct {
// Camera position
Position Vector3
// Camera target it looks-at
Target Vector3
// Camera up vector (rotation over its axis)
Up Vector3
// Camera field-of-view apperture in Y (degrees)
Fovy float32
}
// cptr returns C pointer
func (c *Camera) cptr() *C.Camera {
return (*C.Camera)(unsafe.Pointer(c))
}
// NewCamera - Returns new Camera
func NewCamera(pos, target, up Vector3, fovy float32) Camera {
return Camera{pos, target, up, fovy}
}
// newCameraFromPointer - Returns new Camera from pointer
func newCameraFromPointer(ptr unsafe.Pointer) Camera {
return *(*Camera)(ptr)
}
// Camera2D type, defines a 2d camera
type Camera2D struct {
// Camera offset (displacement from target)
Offset Vector2
// Camera target (rotation and zoom origin)
Target Vector2
// Camera rotation in degrees
Rotation float32
// Camera zoom (scaling), should be 1.0f by default
Zoom float32
}
// cptr returns C pointer
func (c *Camera2D) cptr() *C.Camera2D {
return (*C.Camera2D)(unsafe.Pointer(c))
}
// NewCamera2D - Returns new Camera2D
func NewCamera2D(offset, target Vector2, rotation, zoom float32) Camera2D {
return Camera2D{offset, target, rotation, zoom}
}
// newCamera2DFromPointer - Returns new Camera2D from pointer
func newCamera2DFromPointer(ptr unsafe.Pointer) Camera2D {
return *(*Camera2D)(ptr)
}
// BoundingBox type
type BoundingBox struct {
// Minimum vertex box-corner
Min Vector3
// Maximum vertex box-corner
Max Vector3
}
// cptr returns C pointer
func (b *BoundingBox) cptr() *C.BoundingBox {
return (*C.BoundingBox)(unsafe.Pointer(b))
}
// NewBoundingBox - Returns new BoundingBox
func NewBoundingBox(min, max Vector3) BoundingBox {
return BoundingBox{min, max}
}
// newBoundingBoxFromPointer - Returns new BoundingBox from pointer
func newBoundingBoxFromPointer(ptr unsafe.Pointer) BoundingBox {
return *(*BoundingBox)(ptr)
}
// Asset file
type Asset interface {
io.ReadSeeker
io.Closer
}
// CloseWindow - Close Window and Terminate Context
func CloseWindow() {
C.CloseWindow()