1 # Raylib wrappers for some functions and structs
7 struct Color(r,g,b:Byte,a=Byte(255); extern)
9 struct Rectangle(x,y,width,height:Num32; extern)
10 func draw(r:Rectangle, color:Color)
11 DrawRectangleRec(r, color)
13 struct Camera2D(offset:Vector2, target:Vector2, rotation=Num32(0), zoom=Num32(1); extern)
15 struct Texture(id,width,height,mipmaps,format:Int32,wrapping=no)
16 func load(path:Path, wrap=no -> Texture; cached)
17 c_string := CString(path)
18 result := Texture(0,0,0,0,0)
20 Texture2D tex = LoadTexture(@c_string);
21 if (@wrap) SetTextureWrap(tex, TEXTURE_WRAP_REPEAT);
22 memcpy(&@result, &tex, sizeof(tex));
24 result.wrapping = wrap
27 func draw(t:Texture, pos,size:Vector2, texture_offset=Vector2(0,0), angle=Num32(0.0), tint=Color(0xFF,0xFF,0xFF))
32 (Rectangle){@texture_offset.x, @texture_offset.y, @texture_offset.x + @size.x, @texture_offset.y + @size.y},
33 (Rectangle){@pos.x,@pos.y,@size.x,@size.y},
42 (Rectangle){0,0,@t.width,@t.height},
43 (Rectangle){@pos.x,@pos.y,@size.x,@size.y},
44 (Vector2){@size.x/2,@size.y/2},
49 struct Vector2(x,y:Num32; extern)
51 func plus(a,b:Vector2->Vector2; inline)
52 return Vector2(a.x+b.x, a.y+b.y)
53 func minus(a,b:Vector2->Vector2; inline)
54 return Vector2(a.x-b.x, a.y-b.y)
55 func times(a,b:Vector2->Vector2; inline)
56 return Vector2(a.x*b.x, a.y*b.y)
57 func negative(v:Vector2->Vector2; inline)
58 return Vector2(-v.x, -v.y)
59 func dot(a,b:Vector2->Num32; inline)
60 return ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y))
61 func cross(a,b:Vector2->Num32; inline)
62 return a.x*b.y - a.y*b.x
63 func scaled_by(v:Vector2, k:Num32->Vector2; inline)
64 return Vector2(v.x*k, v.y*k)
65 func divided_by(v:Vector2, divisor:Num32->Vector2; inline)
66 return Vector2(v.x/divisor, v.y/divisor)
67 func length(v:Vector2->Num32; inline)
68 return (v.x*v.x + v.y*v.y).sqrt()
69 func dist(a,b:Vector2->Num32; inline)
70 return a.minus(b).length()
71 func angle(v:Vector2->Num32; inline)
72 return Num32.atan2(v.y, v.x)
73 func norm(v:Vector2->Vector2; inline)
74 if v.x == 0 and v.y == 0
77 return Vector2(v.x/len, v.y/len)
78 func rotated(v:Vector2, radians:Num32 -> Vector2)
79 cos := radians.cos() or return v
80 sin := radians.sin() or return v
81 return Vector2(cos*v.x - sin*v.y, sin*v.x + cos*v.y)
82 func mix(a,b:Vector2, amount:Num32 -> Vector2)
88 extern BeginDrawing:func()
89 extern BeginMode2D:func(camera:Camera2D)
90 extern ClearBackground:func(color:Color)
91 extern CloseWindow:func()
92 extern DrawCircleV:func(pos:Vector2, radius:Num32, color:Color)
93 extern DrawLineEx:func(start,end:Vector2, width:Num32, color:Color)
94 extern DrawRectangle:func(x,y,width,height:Int32, color:Color)
95 extern DrawRectangleRec:func(rec:Rectangle, color:Color)
96 extern DrawRectangleV:func(pos:Vector2, size:Vector2, color:Color)
97 extern DrawText:func(text:CString, x:Int32, y:Int32, font_size:Int32, color:Color)
98 extern EndDrawing:func()
99 extern EndMode2D:func()
100 extern GetFrameTime:func(->Num32)
101 extern GetScreenHeight:func(->Int32)
102 extern GetScreenWidth:func(->Int32)
103 extern InitWindow:func(width:Int32, height:Int32, title:CString)
104 extern MeasureText:func(text:CString, font_size:Int32 -> Int32)
105 extern SetTargetFPS:func(fps:Int32)
106 extern WindowShouldClose:func(->Bool)
107 extern GetTime:func(->Num)