@glyph-engine/desktop 0.0.0-stage → 0.1.1
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.
- package/LICENSE +201 -0
- package/README.md +25 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +419 -0
- package/dist/renderer.d.ts +18 -0
- package/dist/run.d.ts +7 -0
- package/dist/sdl.d.ts +172 -0
- package/package.json +45 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glyph-engine/desktop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[GlyphEngine](https://github.com/tomast1337/GlyphEngine) in a native window: `run()` draws through SDL3 with Vulkan, OpenGL, SDL GPU or a software renderer. No npm dependencies: SDL is linked with `bun:ffi`. Re-exports `@glyph-engine/core`.
|
|
4
|
+
|
|
5
|
+
Needs [Bun](https://bun.com), SDL3, SDL3_ttf and fontconfig. Linux only for now; macOS and Windows throw "not supported yet" (contributions welcome).
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pacman -S sdl3 sdl3_ttf # Arch
|
|
9
|
+
bun add @glyph-engine/desktop
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { run } from '@glyph-engine/desktop';
|
|
14
|
+
|
|
15
|
+
await run(
|
|
16
|
+
{
|
|
17
|
+
main(coord, context, cursor, out) {
|
|
18
|
+
out.char = '#';
|
|
19
|
+
out.color = 'red';
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{ renderer: 'vulkan' }, // or opengl, opengles2, gpu, software; omit to let SDL choose
|
|
23
|
+
);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Escape or closing the window quits.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/index.ts
|
|
3
|
+
export * from "@glyph-engine/core";
|
|
4
|
+
|
|
5
|
+
// src/sdl.ts
|
|
6
|
+
import { CString, dlopen, FFIType, read } from "bun:ffi";
|
|
7
|
+
var { ptr, i32, u32, u64, f32, bool, cstring, u64_fast } = FFIType;
|
|
8
|
+
var size_t = u64_fast;
|
|
9
|
+
var REPO = "https://github.com/tomast1337/GlyphEngine";
|
|
10
|
+
function libraries() {
|
|
11
|
+
switch (process.platform) {
|
|
12
|
+
case "linux":
|
|
13
|
+
return { sdl: "libSDL3.so.0", ttf: "libSDL3_ttf.so.0" };
|
|
14
|
+
case "darwin":
|
|
15
|
+
throw new Error(`The desktop runner does not support macOS yet. Contributions welcome: ${REPO}`);
|
|
16
|
+
case "win32":
|
|
17
|
+
throw new Error(`The desktop runner does not support Windows yet. Contributions welcome: ${REPO}`);
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`The desktop runner does not support ${process.platform}. Open an issue: ${REPO}/issues`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function open() {
|
|
23
|
+
const names = libraries();
|
|
24
|
+
try {
|
|
25
|
+
const sdl = dlopen(names.sdl, {
|
|
26
|
+
SDL_Init: { args: [u32], returns: bool },
|
|
27
|
+
SDL_Quit: { returns: FFIType.void },
|
|
28
|
+
SDL_GetError: { returns: ptr },
|
|
29
|
+
SDL_SetHint: { args: [cstring, cstring], returns: bool },
|
|
30
|
+
SDL_CreateWindow: { args: [cstring, i32, i32, u64], returns: ptr },
|
|
31
|
+
SDL_DestroyWindow: { args: [ptr], returns: FFIType.void },
|
|
32
|
+
SDL_GetWindowSizeInPixels: { args: [ptr, ptr, ptr], returns: bool },
|
|
33
|
+
SDL_GetWindowPixelDensity: { args: [ptr], returns: f32 },
|
|
34
|
+
SDL_GetNumRenderDrivers: { returns: i32 },
|
|
35
|
+
SDL_GetRenderDriver: { args: [i32], returns: ptr },
|
|
36
|
+
SDL_CreateRenderer: { args: [ptr, cstring], returns: ptr },
|
|
37
|
+
SDL_DestroyRenderer: { args: [ptr], returns: FFIType.void },
|
|
38
|
+
SDL_GetRendererName: { args: [ptr], returns: ptr },
|
|
39
|
+
SDL_SetRenderDrawColor: { args: [ptr, FFIType.u8, FFIType.u8, FFIType.u8, FFIType.u8], returns: bool },
|
|
40
|
+
SDL_RenderClear: { args: [ptr], returns: bool },
|
|
41
|
+
SDL_RenderGeometry: { args: [ptr, ptr, ptr, i32, ptr, i32], returns: bool },
|
|
42
|
+
SDL_RenderPresent: { args: [ptr], returns: bool },
|
|
43
|
+
SDL_RenderReadPixels: { args: [ptr, ptr], returns: ptr },
|
|
44
|
+
SDL_CreateTexture: { args: [ptr, u32, i32, i32, i32], returns: ptr },
|
|
45
|
+
SDL_DestroyTexture: { args: [ptr], returns: FFIType.void },
|
|
46
|
+
SDL_UpdateTexture: { args: [ptr, ptr, ptr, i32], returns: bool },
|
|
47
|
+
SDL_SetTextureBlendMode: { args: [ptr, u32], returns: bool },
|
|
48
|
+
SDL_SetTextureScaleMode: { args: [ptr, i32], returns: bool },
|
|
49
|
+
SDL_ConvertSurface: { args: [ptr, u32], returns: ptr },
|
|
50
|
+
SDL_DestroySurface: { args: [ptr], returns: FFIType.void },
|
|
51
|
+
SDL_PollEvent: { args: [ptr], returns: bool }
|
|
52
|
+
});
|
|
53
|
+
const ttf = dlopen(names.ttf, {
|
|
54
|
+
TTF_Init: { returns: bool },
|
|
55
|
+
TTF_OpenFont: { args: [cstring, f32], returns: ptr },
|
|
56
|
+
TTF_CloseFont: { args: [ptr], returns: FFIType.void },
|
|
57
|
+
TTF_AddFallbackFont: { args: [ptr, ptr], returns: bool },
|
|
58
|
+
TTF_SetFontStyle: { args: [ptr, u32], returns: FFIType.void },
|
|
59
|
+
TTF_GetFontHeight: { args: [ptr], returns: i32 },
|
|
60
|
+
TTF_GetStringSize: { args: [ptr, ptr, size_t, ptr, ptr], returns: bool },
|
|
61
|
+
TTF_RenderText_Blended: { args: [ptr, ptr, size_t, u32], returns: ptr }
|
|
62
|
+
});
|
|
63
|
+
return { ...sdl.symbols, ...ttf.symbols };
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throw new Error(`The desktop runner needs SDL3 and SDL3_ttf (${names.sdl}, ${names.ttf}): ${e.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
var lib;
|
|
69
|
+
function sdl() {
|
|
70
|
+
return lib ??= open();
|
|
71
|
+
}
|
|
72
|
+
function sdlError(what) {
|
|
73
|
+
const p = sdl().SDL_GetError();
|
|
74
|
+
return new Error(`${what}: ${p ? new CString(p) : "unknown SDL error"}`);
|
|
75
|
+
}
|
|
76
|
+
function renderDrivers() {
|
|
77
|
+
const s = sdl();
|
|
78
|
+
return Array.from({ length: s.SDL_GetNumRenderDrivers() }, (_, i) => String(new CString(s.SDL_GetRenderDriver(i))));
|
|
79
|
+
}
|
|
80
|
+
function surfaceInfo(surface) {
|
|
81
|
+
return { format: read.u32(surface, 4), w: read.i32(surface, 8), h: read.i32(surface, 12), pitch: read.i32(surface, 16), pixels: read.ptr(surface, 24) };
|
|
82
|
+
}
|
|
83
|
+
var SDL_INIT_VIDEO = 32;
|
|
84
|
+
var SDL_WINDOW_RESIZABLE = 0x20n;
|
|
85
|
+
var SDL_WINDOW_HIGH_PIXEL_DENSITY = 0x2000n;
|
|
86
|
+
var SDL_PIXELFORMAT_ARGB8888 = 372645892;
|
|
87
|
+
var SDL_TEXTUREACCESS_STATIC = 0;
|
|
88
|
+
var SDL_BLENDMODE_BLEND = 1;
|
|
89
|
+
var SDL_SCALEMODE_NEAREST = 0;
|
|
90
|
+
var SDL_EVENT_QUIT = 256;
|
|
91
|
+
var SDL_EVENT_WINDOW_EXPOSED = 516;
|
|
92
|
+
var SDL_EVENT_WINDOW_RESIZED = 518;
|
|
93
|
+
var SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED = 519;
|
|
94
|
+
var SDL_EVENT_KEY_DOWN = 768;
|
|
95
|
+
var SDL_EVENT_MOUSE_MOTION = 1024;
|
|
96
|
+
var SDL_EVENT_MOUSE_BUTTON_DOWN = 1025;
|
|
97
|
+
var SDL_EVENT_MOUSE_BUTTON_UP = 1026;
|
|
98
|
+
var SDLK_ESCAPE = 27;
|
|
99
|
+
var TTF_STYLE_NORMAL = 0;
|
|
100
|
+
var TTF_STYLE_BOLD = 1;
|
|
101
|
+
// src/run.ts
|
|
102
|
+
import { CString as CString2, ptr as addressOf2 } from "bun:ffi";
|
|
103
|
+
import { startLoop } from "@glyph-engine/core";
|
|
104
|
+
|
|
105
|
+
// src/renderer.ts
|
|
106
|
+
import { ptr as addressOf, toArrayBuffer } from "bun:ffi";
|
|
107
|
+
import { cssColor, getChar, weightCode } from "@glyph-engine/core";
|
|
108
|
+
var ATLAS = 2048;
|
|
109
|
+
var FLOATS = 8;
|
|
110
|
+
|
|
111
|
+
class Renderer {
|
|
112
|
+
renderer;
|
|
113
|
+
font;
|
|
114
|
+
cellW;
|
|
115
|
+
cellH;
|
|
116
|
+
#glyphs = new Map;
|
|
117
|
+
#next = 1;
|
|
118
|
+
#perRow;
|
|
119
|
+
#capacity;
|
|
120
|
+
#slotW;
|
|
121
|
+
#texture;
|
|
122
|
+
#vertices = new Float32Array(0);
|
|
123
|
+
#indices = new Int32Array(0);
|
|
124
|
+
#rect = new Int32Array(4);
|
|
125
|
+
#encoder = new TextEncoder;
|
|
126
|
+
constructor(renderer, font, cellW, cellH) {
|
|
127
|
+
this.renderer = renderer;
|
|
128
|
+
this.font = font;
|
|
129
|
+
this.cellW = cellW;
|
|
130
|
+
this.cellH = cellH;
|
|
131
|
+
const s = sdl();
|
|
132
|
+
this.#slotW = Math.ceil(cellW * 2);
|
|
133
|
+
this.#perRow = Math.floor(ATLAS / this.#slotW);
|
|
134
|
+
this.#capacity = this.#perRow * Math.floor(ATLAS / cellH);
|
|
135
|
+
const texture = s.SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ATLAS, ATLAS);
|
|
136
|
+
if (!texture)
|
|
137
|
+
throw sdlError("SDL_CreateTexture");
|
|
138
|
+
this.#texture = texture;
|
|
139
|
+
s.SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
|
140
|
+
s.SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
|
|
141
|
+
const white = new Uint32Array(4 * 4).fill(4294967295);
|
|
142
|
+
this.#upload(0, 0, 4, 4, addressOf(white), 16);
|
|
143
|
+
}
|
|
144
|
+
draw(frame, settings) {
|
|
145
|
+
const s = sdl();
|
|
146
|
+
const { cols, rows, fg, bg, weight } = frame;
|
|
147
|
+
const dFg = settings.color && cssColor(settings.color) || 255;
|
|
148
|
+
const dBg = settings.backgroundColor && cssColor(settings.backgroundColor) || 4294967295;
|
|
149
|
+
const dWeight = weightCode(settings.fontWeight);
|
|
150
|
+
const quads = cols * rows * 2;
|
|
151
|
+
if (this.#vertices.length < quads * 4 * FLOATS)
|
|
152
|
+
this.#grow(quads);
|
|
153
|
+
const v = this.#vertices;
|
|
154
|
+
const { cellW, cellH } = this;
|
|
155
|
+
const white = 2 / ATLAS;
|
|
156
|
+
let n = 0;
|
|
157
|
+
const quad = (x0, y0, x1, y1, c, u0, v0, u1, v1) => {
|
|
158
|
+
const r = (c >>> 24) / 255;
|
|
159
|
+
const g = (c >>> 16 & 255) / 255;
|
|
160
|
+
const b = (c >>> 8 & 255) / 255;
|
|
161
|
+
const a = (c & 255) / 255;
|
|
162
|
+
for (let i = 0;i < 4; i++) {
|
|
163
|
+
const right = i & 1;
|
|
164
|
+
const bottom = i >> 1;
|
|
165
|
+
v[n++] = right ? x1 : x0;
|
|
166
|
+
v[n++] = bottom ? y1 : y0;
|
|
167
|
+
v[n++] = r;
|
|
168
|
+
v[n++] = g;
|
|
169
|
+
v[n++] = b;
|
|
170
|
+
v[n++] = a;
|
|
171
|
+
v[n++] = right ? u1 : u0;
|
|
172
|
+
v[n++] = bottom ? v1 : v0;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
for (let y = 0;y < rows; y++) {
|
|
176
|
+
let col = 0;
|
|
177
|
+
for (let i = 0, k = y * cols;i < cols && col < cols; i++, k++) {
|
|
178
|
+
const char = getChar(frame, k);
|
|
179
|
+
const glyph = char && char !== " " ? this.#glyph(char, weight[k] || dWeight) : undefined;
|
|
180
|
+
const span = glyph?.wide && col + 1 < cols ? 2 : 1;
|
|
181
|
+
const x0 = col * cellW;
|
|
182
|
+
const y0 = y * cellH;
|
|
183
|
+
quad(x0, y0, x0 + span * cellW, y0 + cellH, bg[k] || dBg, white, white, white, white);
|
|
184
|
+
if (glyph) {
|
|
185
|
+
const gx = glyph.slot % this.#perRow * this.#slotW;
|
|
186
|
+
const gy = Math.floor(glyph.slot / this.#perRow) * cellH;
|
|
187
|
+
const w = this.#slotW;
|
|
188
|
+
quad(x0, y0, x0 + w, y0 + cellH, glyph.colored ? 4294967295 : fg[k] || dFg, gx / ATLAS, gy / ATLAS, (gx + w) / ATLAS, (gy + cellH) / ATLAS);
|
|
189
|
+
}
|
|
190
|
+
col += span;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const r = dBg >>> 24;
|
|
194
|
+
s.SDL_SetRenderDrawColor(this.renderer, r, dBg >>> 16 & 255, dBg >>> 8 & 255, 255);
|
|
195
|
+
s.SDL_RenderClear(this.renderer);
|
|
196
|
+
const count = n / FLOATS;
|
|
197
|
+
if (count && !s.SDL_RenderGeometry(this.renderer, this.#texture, addressOf(v), count, addressOf(this.#indices), count / 4 * 6))
|
|
198
|
+
throw sdlError("SDL_RenderGeometry");
|
|
199
|
+
}
|
|
200
|
+
present() {
|
|
201
|
+
sdl().SDL_RenderPresent(this.renderer);
|
|
202
|
+
}
|
|
203
|
+
destroy() {
|
|
204
|
+
sdl().SDL_DestroyTexture(this.#texture);
|
|
205
|
+
}
|
|
206
|
+
#grow(quads) {
|
|
207
|
+
this.#vertices = new Float32Array(quads * 4 * FLOATS);
|
|
208
|
+
this.#indices = new Int32Array(quads * 6);
|
|
209
|
+
for (let q = 0;q < quads; q++)
|
|
210
|
+
this.#indices.set([0, 1, 2, 2, 1, 3].map((i) => i + q * 4), q * 6);
|
|
211
|
+
}
|
|
212
|
+
#glyph(char, weight) {
|
|
213
|
+
const key = weight + char;
|
|
214
|
+
let glyph = this.#glyphs.get(key);
|
|
215
|
+
if (glyph)
|
|
216
|
+
return glyph;
|
|
217
|
+
if (this.#next >= this.#capacity) {
|
|
218
|
+
this.#glyphs.clear();
|
|
219
|
+
this.#next = 1;
|
|
220
|
+
}
|
|
221
|
+
const s = sdl();
|
|
222
|
+
const slot = this.#next++;
|
|
223
|
+
const text = this.#encoder.encode(char);
|
|
224
|
+
if (weight >= 6)
|
|
225
|
+
s.TTF_SetFontStyle(this.font, TTF_STYLE_BOLD);
|
|
226
|
+
let surface = s.TTF_RenderText_Blended(this.font, addressOf(text), text.length, 4294967295);
|
|
227
|
+
if (weight >= 6)
|
|
228
|
+
s.TTF_SetFontStyle(this.font, TTF_STYLE_NORMAL);
|
|
229
|
+
glyph = { slot, wide: false, colored: false };
|
|
230
|
+
if (surface) {
|
|
231
|
+
if (surfaceInfo(surface).format !== SDL_PIXELFORMAT_ARGB8888) {
|
|
232
|
+
const converted = s.SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
|
|
233
|
+
s.SDL_DestroySurface(surface);
|
|
234
|
+
surface = converted;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (surface) {
|
|
238
|
+
const { w, h, pitch, pixels } = surfaceInfo(surface);
|
|
239
|
+
glyph.wide = w > this.cellW * 1.5;
|
|
240
|
+
glyph.colored = isColored(new Uint8Array(toArrayBuffer(pixels, 0, pitch * h)), w, h, pitch);
|
|
241
|
+
this.#upload(slot % this.#perRow * this.#slotW, Math.floor(slot / this.#perRow) * this.cellH, Math.min(w, this.#slotW), Math.min(h, this.cellH), pixels, pitch);
|
|
242
|
+
s.SDL_DestroySurface(surface);
|
|
243
|
+
}
|
|
244
|
+
this.#glyphs.set(key, glyph);
|
|
245
|
+
return glyph;
|
|
246
|
+
}
|
|
247
|
+
#upload(x, y, w, h, pixels, pitch) {
|
|
248
|
+
this.#rect.set([x, y, w, h]);
|
|
249
|
+
if (!sdl().SDL_UpdateTexture(this.#texture, addressOf(this.#rect), pixels, pitch))
|
|
250
|
+
throw sdlError("SDL_UpdateTexture");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function isColored(px, w, h, pitch) {
|
|
254
|
+
for (let y = 0;y < h; y++) {
|
|
255
|
+
for (let x = 0, o = y * pitch;x < w; x++, o += 4) {
|
|
256
|
+
if (px[o + 3] > 0 && (px[o] !== px[o + 1] || px[o + 1] !== px[o + 2]))
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/run.ts
|
|
264
|
+
var defaultSettings = {
|
|
265
|
+
element: null,
|
|
266
|
+
cols: 0,
|
|
267
|
+
rows: 0,
|
|
268
|
+
once: false,
|
|
269
|
+
fps: 30,
|
|
270
|
+
renderer: "",
|
|
271
|
+
allowSelect: false,
|
|
272
|
+
restoreState: false,
|
|
273
|
+
fontFamily: "monospace",
|
|
274
|
+
fontSize: "16px"
|
|
275
|
+
};
|
|
276
|
+
function fontFile(family) {
|
|
277
|
+
const first = family.split(",")[0].trim().replace(/^["']|["']$/g, "") || "monospace";
|
|
278
|
+
const found = Bun.spawnSync(["fc-match", "-f", "%{file}", first]);
|
|
279
|
+
if (!found.success || !found.stdout.length)
|
|
280
|
+
throw new Error(`No font file for "${first}" (fontconfig's fc-match is needed)`);
|
|
281
|
+
return found.stdout.toString();
|
|
282
|
+
}
|
|
283
|
+
function emojiFile() {
|
|
284
|
+
const found = Bun.spawnSync(["fc-match", "-f", "%{file}", "emoji"]);
|
|
285
|
+
return found.success && found.stdout.length ? found.stdout.toString() : undefined;
|
|
286
|
+
}
|
|
287
|
+
function driverFor(runSettings, settings) {
|
|
288
|
+
const drivers = renderDrivers();
|
|
289
|
+
for (const name of [runSettings.renderer, settings.renderer])
|
|
290
|
+
if (name && drivers.includes(name))
|
|
291
|
+
return name;
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function run(program, runSettings = {}, userData = {}) {
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
const settings = { ...defaultSettings, ...runSettings, ...program.settings };
|
|
297
|
+
const s = sdl();
|
|
298
|
+
const ints = new Int32Array(2);
|
|
299
|
+
const event = new Uint8Array(128);
|
|
300
|
+
const view = new DataView(event.buffer);
|
|
301
|
+
let window = null;
|
|
302
|
+
let gpu = null;
|
|
303
|
+
let renderer;
|
|
304
|
+
let font = null;
|
|
305
|
+
let started = false;
|
|
306
|
+
let last;
|
|
307
|
+
let polling;
|
|
308
|
+
const close = () => {
|
|
309
|
+
clearInterval(polling);
|
|
310
|
+
renderer?.destroy();
|
|
311
|
+
renderer = undefined;
|
|
312
|
+
if (gpu)
|
|
313
|
+
s.SDL_DestroyRenderer(gpu);
|
|
314
|
+
if (window)
|
|
315
|
+
s.SDL_DestroyWindow(window);
|
|
316
|
+
gpu = window = null;
|
|
317
|
+
s.SDL_Quit();
|
|
318
|
+
};
|
|
319
|
+
const fail = (e) => {
|
|
320
|
+
close();
|
|
321
|
+
if (!started)
|
|
322
|
+
reject(e);
|
|
323
|
+
else
|
|
324
|
+
throw e;
|
|
325
|
+
};
|
|
326
|
+
try {
|
|
327
|
+
if (!s.SDL_Init(SDL_INIT_VIDEO))
|
|
328
|
+
throw sdlError("SDL_Init");
|
|
329
|
+
if (!s.TTF_Init())
|
|
330
|
+
throw sdlError("TTF_Init");
|
|
331
|
+
window = s.SDL_CreateWindow(Buffer.from("GlyphEngine\x00"), 960, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
|
332
|
+
if (!window)
|
|
333
|
+
throw sdlError("SDL_CreateWindow");
|
|
334
|
+
const driver = driverFor(runSettings, settings);
|
|
335
|
+
gpu = s.SDL_CreateRenderer(window, driver ? Buffer.from(driver + "\x00") : null);
|
|
336
|
+
if (!gpu)
|
|
337
|
+
throw sdlError(`SDL_CreateRenderer (${driver ?? "default"})`);
|
|
338
|
+
settings.renderer = String(new CString2(s.SDL_GetRendererName(gpu)));
|
|
339
|
+
const density = s.SDL_GetWindowPixelDensity(window) || 1;
|
|
340
|
+
font = s.TTF_OpenFont(Buffer.from(fontFile(settings.fontFamily ?? "monospace") + "\x00"), (parseFloat(settings.fontSize ?? "16") || 16) * density);
|
|
341
|
+
if (!font)
|
|
342
|
+
throw sdlError("TTF_OpenFont");
|
|
343
|
+
const emoji = emojiFile();
|
|
344
|
+
const emojiFont = emoji && s.TTF_OpenFont(Buffer.from(emoji + "\x00"), (parseFloat(settings.fontSize ?? "16") || 16) * density);
|
|
345
|
+
if (emojiFont)
|
|
346
|
+
s.TTF_AddFallbackFont(font, emojiFont);
|
|
347
|
+
const x = Buffer.from("X");
|
|
348
|
+
s.TTF_GetStringSize(font, addressOf2(x), 1, addressOf2(ints), addressOf2(ints, 4));
|
|
349
|
+
const cellW = ints[0];
|
|
350
|
+
const cellH = s.TTF_GetFontHeight(font);
|
|
351
|
+
renderer = new Renderer(gpu, font, cellW, cellH);
|
|
352
|
+
const state = { time: 0, frame: 0, cycle: 0, fps: settings.fps };
|
|
353
|
+
const pointer = { x: 0, y: 0, pressed: false, px: 0, py: 0, ppressed: false };
|
|
354
|
+
const events = [];
|
|
355
|
+
const poll = () => {
|
|
356
|
+
while (s.SDL_PollEvent(addressOf2(event))) {
|
|
357
|
+
const type = view.getUint32(0, true);
|
|
358
|
+
if (type === SDL_EVENT_QUIT || type === SDL_EVENT_KEY_DOWN && view.getUint32(28, true) === SDLK_ESCAPE) {
|
|
359
|
+
close();
|
|
360
|
+
process.exit(0);
|
|
361
|
+
} else if (type === SDL_EVENT_WINDOW_EXPOSED || type === SDL_EVENT_WINDOW_RESIZED || type === SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
|
362
|
+
if (last) {
|
|
363
|
+
renderer.draw(last, settings);
|
|
364
|
+
renderer.present();
|
|
365
|
+
}
|
|
366
|
+
} else if (type === SDL_EVENT_MOUSE_MOTION || type === SDL_EVENT_MOUSE_BUTTON_DOWN || type === SDL_EVENT_MOUSE_BUTTON_UP) {
|
|
367
|
+
pointer.x = view.getFloat32(28, true) * density;
|
|
368
|
+
pointer.y = view.getFloat32(32, true) * density;
|
|
369
|
+
if (type === SDL_EVENT_MOUSE_MOTION) {
|
|
370
|
+
events.push("pointerMove");
|
|
371
|
+
} else {
|
|
372
|
+
pointer.pressed = type === SDL_EVENT_MOUSE_BUTTON_DOWN;
|
|
373
|
+
events.push(pointer.pressed ? "pointerDown" : "pointerUp");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const host = {
|
|
379
|
+
requestFrame: (cb) => setTimeout(() => {
|
|
380
|
+
try {
|
|
381
|
+
cb(performance.now());
|
|
382
|
+
} catch (e) {
|
|
383
|
+
fail(e);
|
|
384
|
+
}
|
|
385
|
+
}, 4),
|
|
386
|
+
metrics: { aspect: cellW / cellH, cellWidth: cellW, lineHeight: cellH, fontFamily: settings.fontFamily ?? "monospace", fontSize: cellH, _update: () => {} },
|
|
387
|
+
size: () => {
|
|
388
|
+
s.SDL_GetWindowSizeInPixels(window, addressOf2(ints), addressOf2(ints, 4));
|
|
389
|
+
return { width: ints[0], height: ints[1] };
|
|
390
|
+
},
|
|
391
|
+
pointer,
|
|
392
|
+
events,
|
|
393
|
+
render: (_context, frame) => {
|
|
394
|
+
last = frame;
|
|
395
|
+
renderer.draw(frame, settings);
|
|
396
|
+
renderer.present();
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
polling = setInterval(() => {
|
|
400
|
+
try {
|
|
401
|
+
poll();
|
|
402
|
+
} catch (e) {
|
|
403
|
+
fail(e);
|
|
404
|
+
}
|
|
405
|
+
}, 4);
|
|
406
|
+
startLoop(program, settings, userData, state, host, (context) => {
|
|
407
|
+
started = true;
|
|
408
|
+
resolve(context);
|
|
409
|
+
});
|
|
410
|
+
} catch (e) {
|
|
411
|
+
fail(e);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
export {
|
|
416
|
+
run as default,
|
|
417
|
+
renderDrivers,
|
|
418
|
+
run
|
|
419
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@module renderer
|
|
3
|
+
@desc draws frames into an SDL window: glyph atlas texture + one SDL_RenderGeometry per frame
|
|
4
|
+
@category desktop
|
|
5
|
+
*/
|
|
6
|
+
import { type Pointer } from 'bun:ffi';
|
|
7
|
+
import { type Frame, type Settings } from '@glyph-engine/core';
|
|
8
|
+
export declare class Renderer {
|
|
9
|
+
#private;
|
|
10
|
+
readonly renderer: Pointer;
|
|
11
|
+
readonly font: Pointer;
|
|
12
|
+
readonly cellW: number;
|
|
13
|
+
readonly cellH: number;
|
|
14
|
+
constructor(renderer: Pointer, font: Pointer, cellW: number, cellH: number);
|
|
15
|
+
draw(frame: Frame, settings: Partial<Settings>): void;
|
|
16
|
+
present(): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
}
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Runs a program in a native window through SDL3 (bun:ffi, no npm dependencies).
|
|
3
|
+
settings.renderer picks SDL's backend: "vulkan", "opengl", "opengles2", "gpu" or
|
|
4
|
+
"software"; anything else lets SDL choose. Closing the window or Escape quits.
|
|
5
|
+
*/
|
|
6
|
+
import { type Context, type Program, type Settings } from '@glyph-engine/core';
|
|
7
|
+
export declare function run(program: Program, runSettings?: Partial<Settings>, userData?: object): Promise<Context>;
|
package/dist/sdl.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@module sdl
|
|
3
|
+
@desc the parts of SDL3 and SDL3_ttf the desktop runner uses, through bun:ffi
|
|
4
|
+
@category desktop
|
|
5
|
+
*/
|
|
6
|
+
import { CString, type Pointer } from 'bun:ffi';
|
|
7
|
+
export declare function sdl(): {
|
|
8
|
+
TTF_Init: {
|
|
9
|
+
(): boolean;
|
|
10
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
11
|
+
};
|
|
12
|
+
TTF_OpenFont: {
|
|
13
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
14
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
15
|
+
};
|
|
16
|
+
TTF_CloseFont: {
|
|
17
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): undefined;
|
|
18
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
19
|
+
};
|
|
20
|
+
TTF_AddFallbackFont: {
|
|
21
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
22
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
23
|
+
};
|
|
24
|
+
TTF_SetFontStyle: {
|
|
25
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): undefined;
|
|
26
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
27
|
+
};
|
|
28
|
+
TTF_GetFontHeight: {
|
|
29
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): number;
|
|
30
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
31
|
+
};
|
|
32
|
+
TTF_GetStringSize: {
|
|
33
|
+
(...args: (number | bigint | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
34
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
35
|
+
};
|
|
36
|
+
TTF_RenderText_Blended: {
|
|
37
|
+
(...args: (number | bigint | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
38
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
39
|
+
};
|
|
40
|
+
SDL_Init: {
|
|
41
|
+
(...args: number[]): boolean;
|
|
42
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
43
|
+
};
|
|
44
|
+
SDL_Quit: {
|
|
45
|
+
(): undefined;
|
|
46
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
47
|
+
};
|
|
48
|
+
SDL_GetError: {
|
|
49
|
+
(): Pointer | null;
|
|
50
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
51
|
+
};
|
|
52
|
+
SDL_SetHint: {
|
|
53
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
54
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
55
|
+
};
|
|
56
|
+
SDL_CreateWindow: {
|
|
57
|
+
(...args: (number | bigint | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
58
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
59
|
+
};
|
|
60
|
+
SDL_DestroyWindow: {
|
|
61
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): undefined;
|
|
62
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
63
|
+
};
|
|
64
|
+
SDL_GetWindowSizeInPixels: {
|
|
65
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
66
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
67
|
+
};
|
|
68
|
+
SDL_GetWindowPixelDensity: {
|
|
69
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): number;
|
|
70
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
71
|
+
};
|
|
72
|
+
SDL_GetNumRenderDrivers: {
|
|
73
|
+
(): number;
|
|
74
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
75
|
+
};
|
|
76
|
+
SDL_GetRenderDriver: {
|
|
77
|
+
(...args: number[]): Pointer | null;
|
|
78
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
79
|
+
};
|
|
80
|
+
SDL_CreateRenderer: {
|
|
81
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
82
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
83
|
+
};
|
|
84
|
+
SDL_DestroyRenderer: {
|
|
85
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): undefined;
|
|
86
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
87
|
+
};
|
|
88
|
+
SDL_GetRendererName: {
|
|
89
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
90
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
91
|
+
};
|
|
92
|
+
SDL_SetRenderDrawColor: {
|
|
93
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
94
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
95
|
+
};
|
|
96
|
+
SDL_RenderClear: {
|
|
97
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
98
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
99
|
+
};
|
|
100
|
+
SDL_RenderGeometry: {
|
|
101
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
102
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
103
|
+
};
|
|
104
|
+
SDL_RenderPresent: {
|
|
105
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
106
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
107
|
+
};
|
|
108
|
+
SDL_RenderReadPixels: {
|
|
109
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
110
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
111
|
+
};
|
|
112
|
+
SDL_CreateTexture: {
|
|
113
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
114
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
115
|
+
};
|
|
116
|
+
SDL_DestroyTexture: {
|
|
117
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): undefined;
|
|
118
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
119
|
+
};
|
|
120
|
+
SDL_UpdateTexture: {
|
|
121
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
122
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
123
|
+
};
|
|
124
|
+
SDL_SetTextureBlendMode: {
|
|
125
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
126
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
127
|
+
};
|
|
128
|
+
SDL_SetTextureScaleMode: {
|
|
129
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
130
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
131
|
+
};
|
|
132
|
+
SDL_ConvertSurface: {
|
|
133
|
+
(...args: (number | Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): Pointer | null;
|
|
134
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
135
|
+
};
|
|
136
|
+
SDL_DestroySurface: {
|
|
137
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): undefined;
|
|
138
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
139
|
+
};
|
|
140
|
+
SDL_PollEvent: {
|
|
141
|
+
(...args: (Pointer | CString | NodeJS.TypedArray<ArrayBufferLike> | null)[]): boolean;
|
|
142
|
+
__ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
export declare function sdlError(what: string): Error;
|
|
146
|
+
export declare function renderDrivers(): string[];
|
|
147
|
+
export declare function surfaceInfo(surface: Pointer): {
|
|
148
|
+
format: number;
|
|
149
|
+
w: number;
|
|
150
|
+
h: number;
|
|
151
|
+
pitch: number;
|
|
152
|
+
pixels: Pointer;
|
|
153
|
+
};
|
|
154
|
+
export declare const SDL_INIT_VIDEO = 32;
|
|
155
|
+
export declare const SDL_WINDOW_RESIZABLE = 32n;
|
|
156
|
+
export declare const SDL_WINDOW_HIGH_PIXEL_DENSITY = 8192n;
|
|
157
|
+
export declare const SDL_WINDOW_HIDDEN = 8n;
|
|
158
|
+
export declare const SDL_PIXELFORMAT_ARGB8888 = 372645892;
|
|
159
|
+
export declare const SDL_TEXTUREACCESS_STATIC = 0;
|
|
160
|
+
export declare const SDL_BLENDMODE_BLEND = 1;
|
|
161
|
+
export declare const SDL_SCALEMODE_NEAREST = 0;
|
|
162
|
+
export declare const SDL_EVENT_QUIT = 256;
|
|
163
|
+
export declare const SDL_EVENT_WINDOW_EXPOSED = 516;
|
|
164
|
+
export declare const SDL_EVENT_WINDOW_RESIZED = 518;
|
|
165
|
+
export declare const SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED = 519;
|
|
166
|
+
export declare const SDL_EVENT_KEY_DOWN = 768;
|
|
167
|
+
export declare const SDL_EVENT_MOUSE_MOTION = 1024;
|
|
168
|
+
export declare const SDL_EVENT_MOUSE_BUTTON_DOWN = 1025;
|
|
169
|
+
export declare const SDL_EVENT_MOUSE_BUTTON_UP = 1026;
|
|
170
|
+
export declare const SDLK_ESCAPE = 27;
|
|
171
|
+
export declare const TTF_STYLE_NORMAL = 0;
|
|
172
|
+
export declare const TTF_STYLE_BOLD = 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@glyph-engine/desktop",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "GlyphEngine in a native window: run() draws through SDL3 (OpenGL, Vulkan, SDL GPU or software) via bun:ffi. Linux for now; needs SDL3 and SDL3_ttf.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ascii",
|
|
7
|
+
"ascii-art",
|
|
8
|
+
"sdl3",
|
|
9
|
+
"vulkan",
|
|
10
|
+
"opengl",
|
|
11
|
+
"bun",
|
|
12
|
+
"ffi"
|
|
13
|
+
],
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"homepage": "https://github.com/tomast1337/GlyphEngine#readme",
|
|
16
|
+
"bugs": "https://github.com/tomast1337/GlyphEngine/issues",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/tomast1337/GlyphEngine.git",
|
|
20
|
+
"directory": "packages/desktop"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"bun": ">=1.4.4"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rm -rf dist && bun build src/index.ts --target bun --outdir dist --external @glyph-engine/core && tsc -p tsconfig.build.json",
|
|
40
|
+
"prepublishOnly": "bun run build",
|
|
41
|
+
"prepack": "cp ../../LICENSE ."
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@glyph-engine/core": "0.1.1"
|
|
45
|
+
}
|
|
46
|
+
}
|