@dayme/bunraylib 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +60 -11
  2. package/package.json +11 -3
  3. package/src/Raylib.ts +58 -3678
  4. package/src/c/common.h +0 -2
  5. package/src/constants.ts +2 -2
  6. package/src/index.ts +6 -6
  7. package/src/main.c +0 -1
  8. package/src/main.d.ts +1 -1
  9. package/src/modules/audio/AudioModule.ts +197 -0
  10. package/src/modules/audio/symbols.ts +70 -0
  11. package/src/{c/audio.c → modules/audio/wrapper.c} +40 -80
  12. package/src/modules/camera/CameraModule.ts +239 -0
  13. package/src/modules/camera/symbols.ts +49 -0
  14. package/src/modules/camera/wrapper.c +141 -0
  15. package/src/modules/collision/CollisionModule.ts +363 -0
  16. package/src/modules/collision/symbols.ts +149 -0
  17. package/src/modules/collision/wrapper.c +176 -0
  18. package/src/modules/color/ColorModule.ts +65 -0
  19. package/src/modules/color/symbols.ts +26 -0
  20. package/src/modules/color/wrapper.c +16 -0
  21. package/src/modules/draw3d/Draw3DModule.ts +441 -0
  22. package/src/modules/draw3d/symbols.ts +199 -0
  23. package/src/modules/draw3d/wrapper.c +202 -0
  24. package/src/modules/font/FontModule.ts +250 -0
  25. package/src/modules/font/symbols.ts +46 -0
  26. package/src/{c/font.c → modules/font/wrapper.c} +50 -70
  27. package/src/modules/image/ImageModule.ts +451 -0
  28. package/src/{symbols/image.ts → modules/image/symbols.ts} +15 -12
  29. package/src/{c/image.c → modules/image/wrapper.c} +23 -45
  30. package/src/modules/input/InputModule.ts +160 -0
  31. package/src/modules/input/symbols.ts +54 -0
  32. package/src/modules/input/wrapper.c +31 -0
  33. package/src/modules/model/ModelModule.ts +228 -0
  34. package/src/{symbols/model.ts → modules/model/symbols.ts} +17 -14
  35. package/src/{c/model.c → modules/model/wrapper.c} +30 -30
  36. package/src/modules/shader/ShaderModule.ts +78 -0
  37. package/src/{symbols/shader.ts → modules/shader/symbols.ts} +3 -1
  38. package/src/{c/shader.c → modules/shader/wrapper.c} +11 -1
  39. package/src/modules/shapes/ShapesModule.ts +687 -0
  40. package/src/modules/shapes/symbols.ts +161 -0
  41. package/src/modules/shapes/wrapper.c +183 -0
  42. package/src/modules/texture/TextureModule.ts +190 -0
  43. package/src/{symbols/texture.ts → modules/texture/symbols.ts} +15 -9
  44. package/src/{c/texture.c → modules/texture/wrapper.c} +7 -22
  45. package/src/modules/window/WindowModule.ts +248 -0
  46. package/src/modules/window/symbols.ts +85 -0
  47. package/src/modules/window/wrapper.c +39 -0
  48. package/src/symbols.ts +87 -47
  49. package/src/utils.ts +63 -15
  50. package/src/c/camera.c +0 -161
  51. package/src/c/collision.c +0 -176
  52. package/src/c/color.c +0 -100
  53. package/src/c/draw3d.c +0 -222
  54. package/src/c/filesystem.c +0 -36
  55. package/src/c/input.c +0 -85
  56. package/src/c/shapes.c +0 -283
  57. package/src/c/window.c +0 -150
  58. package/src/symbols/audio.ts +0 -64
  59. package/src/symbols/camera.ts +0 -46
  60. package/src/symbols/collision.ts +0 -116
  61. package/src/symbols/color.ts +0 -22
  62. package/src/symbols/draw3d.ts +0 -137
  63. package/src/symbols/filesystem.ts +0 -30
  64. package/src/symbols/font.ts +0 -40
  65. package/src/symbols/input.ts +0 -51
  66. package/src/symbols/shapes.ts +0 -92
  67. package/src/symbols/window.ts +0 -83
@@ -0,0 +1,199 @@
1
+ import { FFIType } from 'bun:ffi';
2
+ const { i32, f32, ptr } = FFIType;
3
+
4
+ export const draw3dDirectSymbols = {
5
+ DrawGrid: { args: [i32, f32], returns: FFIType.void },
6
+ DrawTriangleStrip3D: { args: [ptr, i32, i32], returns: FFIType.void },
7
+ } as const;
8
+
9
+ export const draw3dSymbols = {
10
+ DrawLine3DW: {
11
+ args: [f32, f32, f32, f32, f32, f32, i32],
12
+ returns: FFIType.void,
13
+ },
14
+ DrawPoint3DW: { args: [f32, f32, f32, i32], returns: FFIType.void },
15
+ DrawCircle3DW: {
16
+ args: [f32, f32, f32, f32, f32, f32, f32, f32, i32],
17
+ returns: FFIType.void,
18
+ },
19
+ DrawTriangle3DW: {
20
+ args: [f32, f32, f32, f32, f32, f32, f32, f32, f32, i32],
21
+ returns: FFIType.void,
22
+ },
23
+ DrawCubeW: {
24
+ args: [f32, f32, f32, f32, f32, f32, i32],
25
+ returns: FFIType.void,
26
+ },
27
+ DrawCubeVW: {
28
+ args: [f32, f32, f32, f32, f32, f32, i32],
29
+ returns: FFIType.void,
30
+ },
31
+ DrawCubeWiresW: {
32
+ args: [f32, f32, f32, f32, f32, f32, i32],
33
+ returns: FFIType.void,
34
+ },
35
+ DrawCubeWiresVW: {
36
+ args: [f32, f32, f32, f32, f32, f32, i32],
37
+ returns: FFIType.void,
38
+ },
39
+ DrawSphereW: {
40
+ args: [f32, f32, f32, f32, i32],
41
+ returns: FFIType.void,
42
+ },
43
+ DrawSphereExW: {
44
+ args: [f32, f32, f32, f32, i32, i32, i32],
45
+ returns: FFIType.void,
46
+ },
47
+ DrawSphereWiresW: {
48
+ args: [f32, f32, f32, f32, i32, i32, i32],
49
+ returns: FFIType.void,
50
+ },
51
+ DrawCylinderW: {
52
+ args: [f32, f32, f32, f32, f32, f32, i32, i32],
53
+ returns: FFIType.void,
54
+ },
55
+ DrawCylinderExW: {
56
+ args: [f32, f32, f32, f32, f32, f32, f32, f32, i32, i32],
57
+ returns: FFIType.void,
58
+ },
59
+ DrawCylinderWiresW: {
60
+ args: [f32, f32, f32, f32, f32, f32, i32, i32],
61
+ returns: FFIType.void,
62
+ },
63
+ DrawCylinderWiresExW: {
64
+ args: [f32, f32, f32, f32, f32, f32, f32, f32, i32, i32],
65
+ returns: FFIType.void,
66
+ },
67
+ DrawCapsuleW: {
68
+ args: [f32, f32, f32, f32, f32, f32, f32, i32, i32, i32],
69
+ returns: FFIType.void,
70
+ },
71
+ DrawCapsuleWiresW: {
72
+ args: [f32, f32, f32, f32, f32, f32, f32, i32, i32, i32],
73
+ returns: FFIType.void,
74
+ },
75
+ DrawPlaneW: {
76
+ args: [f32, f32, f32, f32, f32, i32],
77
+ returns: FFIType.void,
78
+ },
79
+ DrawRayW: {
80
+ args: [f32, f32, f32, f32, f32, f32, i32],
81
+ returns: FFIType.void,
82
+ },
83
+ DrawModelW: {
84
+ args: [i32, f32, f32, f32, f32, i32],
85
+ returns: FFIType.void,
86
+ },
87
+ DrawModelExW: {
88
+ args: [i32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, i32],
89
+ returns: FFIType.void,
90
+ },
91
+ DrawModelWiresW: {
92
+ args: [i32, f32, f32, f32, f32, i32],
93
+ returns: FFIType.void,
94
+ },
95
+ DrawModelWiresExW: {
96
+ args: [i32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, i32],
97
+ returns: FFIType.void,
98
+ },
99
+ DrawBoundingBoxW: {
100
+ args: [f32, f32, f32, f32, f32, f32, i32],
101
+ returns: FFIType.void,
102
+ },
103
+ DrawBillboardW: {
104
+ args: [
105
+ f32,
106
+ f32,
107
+ f32,
108
+ f32,
109
+ f32,
110
+ f32,
111
+ f32,
112
+ f32,
113
+ f32,
114
+ f32,
115
+ i32,
116
+ i32,
117
+ i32,
118
+ i32,
119
+ f32,
120
+ f32,
121
+ f32,
122
+ f32,
123
+ i32,
124
+ ],
125
+ returns: FFIType.void,
126
+ },
127
+ DrawBillboardRecW: {
128
+ args: [
129
+ f32,
130
+ f32,
131
+ f32,
132
+ f32,
133
+ f32,
134
+ f32,
135
+ f32,
136
+ f32,
137
+ f32,
138
+ f32,
139
+ i32,
140
+ i32,
141
+ i32,
142
+ i32,
143
+ i32,
144
+ i32,
145
+ i32,
146
+ i32,
147
+ f32,
148
+ f32,
149
+ f32,
150
+ f32,
151
+ f32,
152
+ i32,
153
+ ],
154
+ returns: FFIType.void,
155
+ },
156
+ DrawBillboardProW: {
157
+ args: [
158
+ f32,
159
+ f32,
160
+ f32,
161
+ f32,
162
+ f32,
163
+ f32,
164
+ f32,
165
+ f32,
166
+ f32,
167
+ f32,
168
+ i32,
169
+ i32,
170
+ i32,
171
+ i32,
172
+ i32,
173
+ i32,
174
+ i32,
175
+ i32,
176
+ f32,
177
+ f32,
178
+ f32,
179
+ f32,
180
+ f32,
181
+ f32,
182
+ f32,
183
+ f32,
184
+ f32,
185
+ f32,
186
+ f32,
187
+ i32,
188
+ ],
189
+ returns: FFIType.void,
190
+ },
191
+ DrawMeshW: {
192
+ args: [i32, i32, ptr],
193
+ returns: FFIType.void,
194
+ },
195
+ DrawMeshInstancedW: {
196
+ args: [i32, i32, ptr, i32],
197
+ returns: FFIType.void,
198
+ },
199
+ } as const;
@@ -0,0 +1,202 @@
1
+ #include "../../c/common.h"
2
+
3
+ void DrawLine3DW(float sx, float sy, float sz, float ex, float ey, float ez, Color color) {
4
+ DrawLine3D((Vector3){sx, sy, sz}, (Vector3){ex, ey, ez}, color);
5
+ }
6
+
7
+ void DrawPoint3DW(float px, float py, float pz, Color color) {
8
+ DrawPoint3D((Vector3){px, py, pz}, color);
9
+ }
10
+
11
+ void DrawCircle3DW(float cx, float cy, float cz, float radius, float rax, float ray, float raz, float angle, Color color) {
12
+ DrawCircle3D((Vector3){cx, cy, cz}, radius, (Vector3){rax, ray, raz}, angle, color);
13
+ }
14
+
15
+ void DrawTriangle3DW(float v1x, float v1y, float v1z, float v2x, float v2y, float v2z, float v3x, float v3y, float v3z, Color color) {
16
+ DrawTriangle3D(
17
+ (Vector3){v1x, v1y, v1z},
18
+ (Vector3){v2x, v2y, v2z},
19
+ (Vector3){v3x, v3y, v3z},
20
+ color
21
+ );
22
+ }
23
+
24
+ void DrawCubeW(float px, float py, float pz, float w, float h, float l, Color color) {
25
+ DrawCube((Vector3){px, py, pz}, w, h, l, color);
26
+ }
27
+
28
+ void DrawCubeVW(float px, float py, float pz, float sx, float sy, float sz, Color color) {
29
+ DrawCubeV((Vector3){px, py, pz}, (Vector3){sx, sy, sz}, color);
30
+ }
31
+
32
+ void DrawCubeWiresW(float px, float py, float pz, float w, float h, float l, Color color) {
33
+ DrawCubeWires((Vector3){px, py, pz}, w, h, l, color);
34
+ }
35
+
36
+ void DrawCubeWiresVW(float px, float py, float pz, float sx, float sy, float sz, Color color) {
37
+ DrawCubeWiresV((Vector3){px, py, pz}, (Vector3){sx, sy, sz}, color);
38
+ }
39
+
40
+ void DrawSphereW(float cx, float cy, float cz, float radius, Color color) {
41
+ DrawSphere((Vector3){cx, cy, cz}, radius, color);
42
+ }
43
+
44
+ void DrawSphereExW(float cx, float cy, float cz, float radius, int rings, int slices, Color color) {
45
+ DrawSphereEx((Vector3){cx, cy, cz}, radius, rings, slices, color);
46
+ }
47
+
48
+ void DrawSphereWiresW(float cx, float cy, float cz, float radius, int rings, int slices, Color color) {
49
+ DrawSphereWires((Vector3){cx, cy, cz}, radius, rings, slices, color);
50
+ }
51
+
52
+ void DrawCylinderW(float px, float py, float pz, float rt, float rb, float h, int slices, Color color) {
53
+ DrawCylinder((Vector3){px, py, pz}, rt, rb, h, slices, color);
54
+ }
55
+
56
+ void DrawCylinderExW(float sx, float sy, float sz, float ex, float ey, float ez, float sr, float er, int sides, Color color) {
57
+ DrawCylinderEx((Vector3){sx, sy, sz}, (Vector3){ex, ey, ez}, sr, er, sides, color);
58
+ }
59
+
60
+ void DrawCylinderWiresW(float px, float py, float pz, float rt, float rb, float h, int slices, Color color) {
61
+ DrawCylinderWires((Vector3){px, py, pz}, rt, rb, h, slices, color);
62
+ }
63
+
64
+ void DrawCylinderWiresExW(float sx, float sy, float sz, float ex, float ey, float ez, float sr, float er, int sides, Color color) {
65
+ DrawCylinderWiresEx((Vector3){sx, sy, sz}, (Vector3){ex, ey, ez}, sr, er, sides, color);
66
+ }
67
+
68
+ void DrawCapsuleW(float sx, float sy, float sz, float ex, float ey, float ez, float radius, int slices, int rings, Color color) {
69
+ DrawCapsule((Vector3){sx, sy, sz}, (Vector3){ex, ey, ez}, radius, slices, rings, color);
70
+ }
71
+
72
+ void DrawCapsuleWiresW(float sx, float sy, float sz, float ex, float ey, float ez, float radius, int slices, int rings, Color color) {
73
+ DrawCapsuleWires((Vector3){sx, sy, sz}, (Vector3){ex, ey, ez}, radius, slices, rings, color);
74
+ }
75
+
76
+ void DrawPlaneW(float cx, float cy, float cz, float sw, float sh, Color color) {
77
+ DrawPlane((Vector3){cx, cy, cz}, (Vector2){sw, sh}, color);
78
+ }
79
+
80
+ void DrawRayW(float px, float py, float pz, float dx, float dy, float dz, Color color) {
81
+ Ray ray = {{px, py, pz}, {dx, dy, dz}};
82
+ DrawRay(ray, color);
83
+ }
84
+
85
+ void DrawModelW(int id, float posX, float posY, float posZ, float scale, Color tint) {
86
+ if (id < 0 || id >= MAX_MODELS || !modelUsed[id]) return;
87
+ DrawModel(modelRegistry[id], (Vector3){posX, posY, posZ}, scale, tint);
88
+ }
89
+
90
+ void DrawModelExW(int id,
91
+ float posX, float posY, float posZ,
92
+ float rotAxisX, float rotAxisY, float rotAxisZ, float rotAngle,
93
+ float scaleX, float scaleY, float scaleZ, Color tint) {
94
+ if (id < 0 || id >= MAX_MODELS || !modelUsed[id]) return;
95
+ DrawModelEx(modelRegistry[id],
96
+ (Vector3){posX, posY, posZ},
97
+ (Vector3){rotAxisX, rotAxisY, rotAxisZ}, rotAngle,
98
+ (Vector3){scaleX, scaleY, scaleZ}, tint);
99
+ }
100
+
101
+ void DrawModelWiresW(int id, float posX, float posY, float posZ, float scale, Color tint) {
102
+ if (id < 0 || id >= MAX_MODELS || !modelUsed[id]) return;
103
+ DrawModelWires(modelRegistry[id], (Vector3){posX, posY, posZ}, scale, tint);
104
+ }
105
+
106
+ void DrawModelWiresExW(int id,
107
+ float posX, float posY, float posZ,
108
+ float rotAxisX, float rotAxisY, float rotAxisZ, float rotAngle,
109
+ float scaleX, float scaleY, float scaleZ, Color tint) {
110
+ if (id < 0 || id >= MAX_MODELS || !modelUsed[id]) return;
111
+ DrawModelWiresEx(modelRegistry[id],
112
+ (Vector3){posX, posY, posZ},
113
+ (Vector3){rotAxisX, rotAxisY, rotAxisZ}, rotAngle,
114
+ (Vector3){scaleX, scaleY, scaleZ}, tint);
115
+ }
116
+
117
+ void DrawBoundingBoxW(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, Color color) {
118
+ BoundingBox bb = {
119
+ {minX, minY, minZ},
120
+ {maxX, maxY, maxZ}
121
+ };
122
+ DrawBoundingBox(bb, color);
123
+ }
124
+
125
+ void DrawBillboardW(
126
+ float camPosX, float camPosY, float camPosZ,
127
+ float camTarX, float camTarY, float camTarZ,
128
+ float camUpX, float camUpY, float camUpZ,
129
+ float camFovy, int camProj,
130
+ unsigned int texId, int texW, int texH,
131
+ float posX, float posY, float posZ,
132
+ float scale, Color tint) {
133
+ Camera3D cam = {
134
+ {camPosX, camPosY, camPosZ},
135
+ {camTarX, camTarY, camTarZ},
136
+ {camUpX, camUpY, camUpZ},
137
+ camFovy, camProj
138
+ };
139
+ Texture2D tex = {texId, texW, texH, 1, 7};
140
+ DrawBillboard(cam, tex, (Vector3){posX, posY, posZ}, scale, tint);
141
+ }
142
+
143
+ void DrawBillboardRecW(
144
+ float camPosX, float camPosY, float camPosZ,
145
+ float camTarX, float camTarY, float camTarZ,
146
+ float camUpX, float camUpY, float camUpZ,
147
+ float camFovy, int camProj,
148
+ unsigned int texId, int texW, int texH,
149
+ int srcX, int srcY, int srcW, int srcH,
150
+ float posX, float posY, float posZ,
151
+ float sizeX, float sizeY, Color tint) {
152
+ Camera3D cam = {
153
+ {camPosX, camPosY, camPosZ},
154
+ {camTarX, camTarY, camTarZ},
155
+ {camUpX, camUpY, camUpZ},
156
+ camFovy, camProj
157
+ };
158
+ Texture2D tex = {texId, texW, texH, 1, 7};
159
+ Rectangle src = {srcX, srcY, srcW, srcH};
160
+ DrawBillboardRec(cam, tex, src, (Vector3){posX, posY, posZ}, (Vector2){sizeX, sizeY}, tint);
161
+ }
162
+
163
+ void DrawBillboardProW(
164
+ float camPosX, float camPosY, float camPosZ,
165
+ float camTarX, float camTarY, float camTarZ,
166
+ float camUpX, float camUpY, float camUpZ,
167
+ float camFovy, int camProj,
168
+ unsigned int texId, int texW, int texH,
169
+ int srcX, int srcY, int srcW, int srcH,
170
+ float posX, float posY, float posZ,
171
+ float upX, float upY, float upZ,
172
+ float sizeX, float sizeY,
173
+ float originX, float originY,
174
+ float rotation, Color tint) {
175
+ Camera3D cam = {
176
+ {camPosX, camPosY, camPosZ},
177
+ {camTarX, camTarY, camTarZ},
178
+ {camUpX, camUpY, camUpZ},
179
+ camFovy, camProj
180
+ };
181
+ Texture2D tex = {texId, texW, texH, 1, 7};
182
+ Rectangle src = {srcX, srcY, srcW, srcH};
183
+ DrawBillboardPro(cam, tex, src,
184
+ (Vector3){posX, posY, posZ},
185
+ (Vector3){upX, upY, upZ},
186
+ (Vector2){sizeX, sizeY},
187
+ (Vector2){originX, originY},
188
+ rotation, tint);
189
+ }
190
+
191
+ void DrawMeshW(int meshId, int materialId, const float* transform) {
192
+ if (meshId < 0 || meshId >= MAX_MESHES || !meshUsed[meshId]) return;
193
+ if (materialId < 0 || materialId >= MAX_MATERIALS || !materialUsed[materialId]) return;
194
+ DrawMesh(meshRegistry[meshId], materialRegistry[materialId], *(Matrix*)transform);
195
+ }
196
+
197
+ void DrawMeshInstancedW(int meshId, int materialId, const float* transforms, int instances) {
198
+ if (meshId < 0 || meshId >= MAX_MESHES || !meshUsed[meshId]) return;
199
+ if (materialId < 0 || materialId >= MAX_MATERIALS || !materialUsed[materialId]) return;
200
+ DrawMeshInstanced(meshRegistry[meshId], materialRegistry[materialId],
201
+ (const Matrix*)transforms, instances);
202
+ }
@@ -0,0 +1,250 @@
1
+ import { getSymbols } from '../../symbols';
2
+ import { bufs as b, cstr, f, i } from '../../utils';
3
+ import type { Vec2, Rectangle, Font, Image, GlyphInfo, Color } from '../../types';
4
+
5
+ const r = () => getSymbols();
6
+
7
+ export class FontModule {
8
+ static drawText(text: string, x: number, y: number, fontSize: number, col: Color): void {
9
+ r().symbols.DrawText(cstr(text), i(x), i(y), i(fontSize), i(col));
10
+ }
11
+ static loadFont(fileName: string): Font {
12
+ return r().symbols.LoadFontW(cstr(fileName));
13
+ }
14
+ static loadFontEx(fileName: string, fontSize: number): Font {
15
+ return r().symbols.LoadFontExW(cstr(fileName), i(fontSize));
16
+ }
17
+ static getFontDefault(): Font {
18
+ return r().symbols.GetFontDefaultW();
19
+ }
20
+ static unloadFont(font: Font): void {
21
+ r().symbols.UnloadFontW(i(font));
22
+ }
23
+ static isFontValid(font: Font): boolean {
24
+ return r().symbols.IsFontValidW(i(font));
25
+ }
26
+ static measureText(text: string, fontSize: number): number {
27
+ return r().symbols.MeasureText(cstr(text), i(fontSize));
28
+ }
29
+ static measureTextEx(font: Font, text: string, fontSize: number, spacing: number): Vec2 {
30
+ r().symbols.MeasureTextExW(b._vec2Buf, i(font), cstr(text), f(fontSize), f(spacing));
31
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
32
+ }
33
+ static drawTextEx(
34
+ font: Font,
35
+ text: string,
36
+ position: Vec2,
37
+ fontSize: number,
38
+ spacing: number,
39
+ tint: Color,
40
+ ): void {
41
+ r().symbols.DrawTextExW(
42
+ i(font),
43
+ cstr(text),
44
+ f(position.x),
45
+ f(position.y),
46
+ f(fontSize),
47
+ f(spacing),
48
+ i(tint),
49
+ );
50
+ }
51
+ static drawTextPro(
52
+ font: Font,
53
+ text: string,
54
+ position: Vec2,
55
+ origin: Vec2,
56
+ rotation: number,
57
+ fontSize: number,
58
+ spacing: number,
59
+ tint: Color,
60
+ ): void {
61
+ r().symbols.DrawTextProW(
62
+ i(font),
63
+ cstr(text),
64
+ f(position.x),
65
+ f(position.y),
66
+ f(origin.x),
67
+ f(origin.y),
68
+ f(rotation),
69
+ f(fontSize),
70
+ f(spacing),
71
+ i(tint),
72
+ );
73
+ }
74
+ static setTextLineSpacing(spacing: number): void {
75
+ r().symbols.SetTextLineSpacing(i(spacing));
76
+ }
77
+ static loadFontFromImage(image: Image, key: Color, firstChar: number): Font {
78
+ return r().symbols.LoadFontFromImageW(i(image), i(key), i(firstChar));
79
+ }
80
+ static loadFontFromMemory(
81
+ fileType: string,
82
+ fileData: Uint8Array,
83
+ dataSize: number,
84
+ fontSize: number,
85
+ ): Font {
86
+ return r().symbols.LoadFontFromMemoryW(cstr(fileType), fileData, i(dataSize), i(fontSize));
87
+ }
88
+ static exportFontAsCode(font: Font, fileName: string): boolean {
89
+ return r().symbols.ExportFontAsCodeW(i(font), cstr(fileName));
90
+ }
91
+ static drawTextCodepoint(
92
+ font: Font,
93
+ codepoint: number,
94
+ position: Vec2,
95
+ fontSize: number,
96
+ tint: Color,
97
+ ): void {
98
+ r().symbols.DrawTextCodepointW(
99
+ i(font),
100
+ i(codepoint),
101
+ f(position.x),
102
+ f(position.y),
103
+ f(fontSize),
104
+ i(tint),
105
+ );
106
+ }
107
+ static drawTextCodepoints(
108
+ font: Font,
109
+ codepoints: Int32Array,
110
+ count: number,
111
+ position: Vec2,
112
+ fontSize: number,
113
+ spacing: number,
114
+ tint: Color,
115
+ ): void {
116
+ r().symbols.DrawTextCodepointsW(
117
+ i(font),
118
+ codepoints,
119
+ i(count),
120
+ f(position.x),
121
+ f(position.y),
122
+ f(fontSize),
123
+ f(spacing),
124
+ i(tint),
125
+ );
126
+ }
127
+ static getGlyphIndex(font: Font, codepoint: number): number {
128
+ return r().symbols.GetGlyphIndexW(i(font), i(codepoint));
129
+ }
130
+ static getGlyphInfo(font: Font, codepoint: number): GlyphInfo {
131
+ r().symbols.GetGlyphInfoW(
132
+ b._glyphValue,
133
+ b._glyphOffsetX,
134
+ b._glyphOffsetY,
135
+ b._glyphAdvanceX,
136
+ b._glyphImageSlot,
137
+ i(font),
138
+ i(codepoint),
139
+ );
140
+ return {
141
+ value: b._glyphValue[0]!,
142
+ offsetX: b._glyphOffsetX[0]!,
143
+ offsetY: b._glyphOffsetY[0]!,
144
+ advanceX: b._glyphAdvanceX[0]!,
145
+ image: b._glyphImageSlot[0]!,
146
+ };
147
+ }
148
+ static getGlyphAtlasRec(font: Font, codepoint: number): Rectangle {
149
+ r().symbols.GetGlyphAtlasRecW(b._recBuf, i(font), i(codepoint));
150
+ return {
151
+ x: b._recBuf[0]!,
152
+ y: b._recBuf[1]!,
153
+ width: b._recBuf[2]!,
154
+ height: b._recBuf[3]!,
155
+ };
156
+ }
157
+ static getCodepoint(text: string): { codepoint: number; size: number } {
158
+ const cp = r().symbols.GetCodepoint(cstr(text), b._cpSize);
159
+ return { codepoint: cp, size: b._cpSize[0]! };
160
+ }
161
+ static getCodepointNext(text: string): { codepoint: number; size: number } {
162
+ const cp = r().symbols.GetCodepointNext(cstr(text), b._cpSize);
163
+ return { codepoint: cp, size: b._cpSize[0]! };
164
+ }
165
+ static getCodepointPrevious(text: string): { codepoint: number; size: number } {
166
+ const cp = r().symbols.GetCodepointPrevious(cstr(text), b._cpSize);
167
+ return { codepoint: cp, size: b._cpSize[0]! };
168
+ }
169
+ static getCodepointCount(text: string): number {
170
+ return r().symbols.GetCodepointCount(cstr(text));
171
+ }
172
+ static textIsEqual(text1: string, text2: string): boolean {
173
+ return r().symbols.TextIsEqual(cstr(text1), cstr(text2));
174
+ }
175
+ static textLength(text: string): number {
176
+ return r().symbols.TextLength(cstr(text));
177
+ }
178
+ static textToInteger(text: string): number {
179
+ return r().symbols.TextToInteger(cstr(text));
180
+ }
181
+ static textToFloat(text: string): number {
182
+ return r().symbols.TextToFloat(cstr(text));
183
+ }
184
+ static textFindIndex(text: string, find: string): number {
185
+ return r().symbols.TextFindIndex(cstr(text), cstr(find));
186
+ }
187
+ static unloadFontData(ptr: number, glyphCount: number): void {
188
+ r().symbols.UnloadFontData(ptr as unknown as Buffer, i(glyphCount));
189
+ }
190
+ static unloadUTF8(ptr: number): void {
191
+ r().symbols.UnloadUTF8(ptr as unknown as Buffer);
192
+ }
193
+ static unloadCodepoints(ptr: number): void {
194
+ r().symbols.UnloadCodepoints(ptr as unknown as Buffer);
195
+ }
196
+ static textCopy(dst: Uint8Array, src: string): number {
197
+ return r().symbols.TextCopy(dst, cstr(src));
198
+ }
199
+ static textAppend(text: Uint8Array, append: string, position: number): number {
200
+ b._textAppendPos[0] = position;
201
+ r().symbols.TextAppend(text, cstr(append), b._textAppendPos);
202
+ return b._textAppendPos[0];
203
+ }
204
+ static genImageFontAtlas(
205
+ glyphs: GlyphInfo[],
206
+ fontSize: number,
207
+ padding: number,
208
+ packMethod: number,
209
+ ): { image: Image; glyphRecs: Float32Array } {
210
+ const glyphCount = glyphs.length;
211
+ const glyphData = new Int32Array(glyphCount * 5);
212
+ for (let idx = 0; idx < glyphCount; idx++) {
213
+ glyphData[idx * 5] = glyphs[idx]!.value;
214
+ glyphData[idx * 5 + 1] = glyphs[idx]!.offsetX;
215
+ glyphData[idx * 5 + 2] = glyphs[idx]!.offsetY;
216
+ glyphData[idx * 5 + 3] = glyphs[idx]!.advanceX;
217
+ glyphData[idx * 5 + 4] = glyphs[idx]!.image;
218
+ }
219
+ const recs = new Float32Array(glyphCount * 4);
220
+ const img = r().symbols.GenImageFontAtlasW(
221
+ recs,
222
+ glyphData,
223
+ i(glyphCount),
224
+ i(fontSize),
225
+ i(padding),
226
+ i(packMethod),
227
+ );
228
+ return { image: img, glyphRecs: recs };
229
+ }
230
+ static measureTextCodepoints(
231
+ font: Font,
232
+ codepoints: Int32Array,
233
+ length: number,
234
+ fontSize: number,
235
+ spacing: number,
236
+ ): Vec2 {
237
+ r().symbols.MeasureTextCodepointsW(
238
+ b._vec2Buf,
239
+ i(font),
240
+ codepoints,
241
+ i(length),
242
+ f(fontSize),
243
+ f(spacing),
244
+ );
245
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
246
+ }
247
+ static unloadTextLines(text: number, lineCount: number): void {
248
+ r().symbols.UnloadTextLines(text as unknown as Buffer, i(lineCount));
249
+ }
250
+ }
@@ -0,0 +1,46 @@
1
+ import { FFIType } from 'bun:ffi';
2
+ const { i32, cstring, f32, ptr } = FFIType;
3
+
4
+ export const fontDirectSymbols = {
5
+ MeasureText: { args: [cstring, i32], returns: i32 },
6
+ SetTextLineSpacing: { args: [i32], returns: FFIType.void },
7
+ GetCodepoint: { args: [cstring, ptr], returns: i32 },
8
+ GetCodepointNext: { args: [cstring, ptr], returns: i32 },
9
+ GetCodepointPrevious: { args: [cstring, ptr], returns: i32 },
10
+ GetCodepointCount: { args: [cstring], returns: i32 },
11
+ TextIsEqual: { args: [cstring, cstring], returns: FFIType.bool },
12
+ TextLength: { args: [cstring], returns: i32 },
13
+ TextToInteger: { args: [cstring], returns: i32 },
14
+ TextToFloat: { args: [cstring], returns: f32 },
15
+ TextFindIndex: { args: [cstring, cstring], returns: i32 },
16
+ TextCopy: { args: [ptr, cstring], returns: i32 },
17
+ TextAppend: { args: [ptr, cstring, ptr], returns: FFIType.void },
18
+ UnloadUTF8: { args: [ptr], returns: FFIType.void },
19
+ UnloadCodepoints: { args: [ptr], returns: FFIType.void },
20
+ UnloadFontData: { args: [ptr, i32], returns: FFIType.void },
21
+ UnloadTextLines: { args: [ptr, i32], returns: FFIType.void },
22
+ } as const;
23
+
24
+ export const fontWrapperSymbols = {
25
+ LoadFontW: { args: [cstring], returns: i32 },
26
+ LoadFontExW: { args: [cstring, i32], returns: i32 },
27
+ GetFontDefaultW: { args: [], returns: i32 },
28
+ UnloadFontW: { args: [i32], returns: FFIType.void },
29
+ IsFontValidW: { args: [i32], returns: FFIType.bool },
30
+ MeasureTextExW: { args: [ptr, i32, cstring, f32, f32], returns: FFIType.void },
31
+ DrawTextExW: { args: [i32, cstring, f32, f32, f32, f32, i32], returns: FFIType.void },
32
+ DrawTextProW: {
33
+ args: [i32, cstring, f32, f32, f32, f32, f32, f32, f32, i32],
34
+ returns: FFIType.void,
35
+ },
36
+ LoadFontFromImageW: { args: [i32, i32, i32], returns: i32 },
37
+ LoadFontFromMemoryW: { args: [cstring, ptr, i32, i32], returns: i32 },
38
+ ExportFontAsCodeW: { args: [i32, cstring], returns: FFIType.bool },
39
+ DrawTextCodepointW: { args: [i32, i32, f32, f32, f32, i32], returns: FFIType.void },
40
+ DrawTextCodepointsW: { args: [i32, ptr, i32, f32, f32, f32, f32, i32], returns: FFIType.void },
41
+ GetGlyphIndexW: { args: [i32, i32], returns: i32 },
42
+ GetGlyphInfoW: { args: [ptr, ptr, ptr, ptr, ptr, i32, i32], returns: FFIType.void },
43
+ GetGlyphAtlasRecW: { args: [ptr, i32, i32], returns: FFIType.void },
44
+ GenImageFontAtlasW: { args: [ptr, ptr, i32, i32, i32, i32], returns: i32 },
45
+ MeasureTextCodepointsW: { args: [ptr, i32, ptr, i32, f32, f32], returns: FFIType.void },
46
+ } as const;