sfml.js 1.0.0 → 1.2.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/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +44 -51
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/src/graphics/image.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
native,
|
|
2
|
+
native,
|
|
3
|
+
type NativeGraphicsHandle,
|
|
4
|
+
type NativeImageMapping,
|
|
3
5
|
type NativeImageResource,
|
|
4
6
|
} from '../internal/native';
|
|
5
7
|
import { graphicsNative } from '../internal/graphics-state';
|
|
6
8
|
import { nativeStruct } from '../internal/struct-view';
|
|
7
9
|
import { streamDispatch } from '../internal/input-stream';
|
|
8
10
|
import type { InputStream } from '../system/input-stream';
|
|
9
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
colorStorage,
|
|
13
|
+
type ReadonlyValue,
|
|
14
|
+
} from '../internal/value-storage';
|
|
10
15
|
import { Vector2, Vector2u } from '../system/vector2';
|
|
11
16
|
import { Color } from './color';
|
|
12
17
|
import { IntRect } from './rect';
|
|
@@ -17,9 +22,20 @@ import { IntRect } from './rect';
|
|
|
17
22
|
* @ja コンパイル時の const ビュー。実行時ストレージは同じネイティブ Uint8Array です。
|
|
18
23
|
* @ko 컴파일 시점의 const 뷰입니다. 런타임 저장 공간은 동일한 네이티브 Uint8Array입니다.
|
|
19
24
|
*/
|
|
20
|
-
export type ReadonlyPixels = Readonly<
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
export type ReadonlyPixels = Readonly<
|
|
26
|
+
Pick<
|
|
27
|
+
Uint8Array,
|
|
28
|
+
| number
|
|
29
|
+
| 'length'
|
|
30
|
+
| 'byteLength'
|
|
31
|
+
| 'byteOffset'
|
|
32
|
+
| typeof Symbol.iterator
|
|
33
|
+
| 'slice'
|
|
34
|
+
| 'entries'
|
|
35
|
+
| 'keys'
|
|
36
|
+
| 'values'
|
|
37
|
+
>
|
|
38
|
+
>;
|
|
23
39
|
|
|
24
40
|
function coordinates(value: Readonly<Vector2u>): void {
|
|
25
41
|
if (!(value instanceof Vector2) || value.scalarType !== 'u32') {
|
|
@@ -27,15 +43,24 @@ function coordinates(value: Readonly<Vector2u>): void {
|
|
|
27
43
|
}
|
|
28
44
|
}
|
|
29
45
|
|
|
30
|
-
function content(
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
function content(
|
|
47
|
+
value: ReadonlyValue<Color> | Uint8Array,
|
|
48
|
+
): number | Uint8Array {
|
|
49
|
+
if (value instanceof Color) {
|
|
50
|
+
return value.toInteger();
|
|
51
|
+
}
|
|
52
|
+
if (value instanceof Uint8Array) {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
33
55
|
throw new TypeError('Expected a Color or RGBA Uint8Array');
|
|
34
56
|
}
|
|
35
57
|
|
|
36
58
|
function view(mapping: NativeImageMapping) {
|
|
37
|
-
return nativeStruct<{
|
|
38
|
-
|
|
59
|
+
return nativeStruct<{
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
pixels: Uint8Array;
|
|
63
|
+
}>(mapping.info, { pixels: new Uint8Array(mapping.buffer) });
|
|
39
64
|
}
|
|
40
65
|
|
|
41
66
|
/**
|
|
@@ -65,7 +90,9 @@ export class Image {
|
|
|
65
90
|
static {
|
|
66
91
|
imageFromMapping = mapping => {
|
|
67
92
|
const image = Object.create(Image.prototype) as Image;
|
|
68
|
-
Object.defineProperty(image, graphicsNative, {
|
|
93
|
+
Object.defineProperty(image, graphicsNative, {
|
|
94
|
+
value: mapping.handle,
|
|
95
|
+
});
|
|
69
96
|
image.state = view(mapping);
|
|
70
97
|
return image;
|
|
71
98
|
};
|
|
@@ -93,7 +120,8 @@ export class Image {
|
|
|
93
120
|
* @ko 지정한 픽셀 크기의 이미지를 만듭니다. 색상으로 채우거나 RGBA8 바이트를 복사하며 기본 색상은 검정입니다.
|
|
94
121
|
*/
|
|
95
122
|
constructor(
|
|
96
|
-
size: Readonly<Vector2u>,
|
|
123
|
+
size: Readonly<Vector2u>,
|
|
124
|
+
colorOrPixels?: ReadonlyValue<Color> | Uint8Array,
|
|
97
125
|
);
|
|
98
126
|
constructor(
|
|
99
127
|
sizeOrSource?: Readonly<Vector2u> | Image,
|
|
@@ -107,7 +135,9 @@ export class Image {
|
|
|
107
135
|
} else {
|
|
108
136
|
coordinates(sizeOrSource);
|
|
109
137
|
mapping = native.createImage(
|
|
110
|
-
sizeOrSource.x,
|
|
138
|
+
sizeOrSource.x,
|
|
139
|
+
sizeOrSource.y,
|
|
140
|
+
content(colorOrPixels),
|
|
111
141
|
);
|
|
112
142
|
}
|
|
113
143
|
this[graphicsNative] = mapping.handle;
|
|
@@ -157,9 +187,14 @@ export class Image {
|
|
|
157
187
|
colorOrPixels: ReadonlyValue<Color> | Uint8Array = Color.Black,
|
|
158
188
|
): void {
|
|
159
189
|
coordinates(size);
|
|
160
|
-
this.state = view(
|
|
161
|
-
|
|
162
|
-
|
|
190
|
+
this.state = view(
|
|
191
|
+
native.resizeImage(
|
|
192
|
+
this[graphicsNative],
|
|
193
|
+
size.x,
|
|
194
|
+
size.y,
|
|
195
|
+
content(colorOrPixels),
|
|
196
|
+
),
|
|
197
|
+
);
|
|
163
198
|
}
|
|
164
199
|
|
|
165
200
|
/**
|
|
@@ -172,8 +207,12 @@ export class Image {
|
|
|
172
207
|
getPixel(coords: Readonly<Vector2u>): Color {
|
|
173
208
|
const offset = this.offset(coords);
|
|
174
209
|
const pixels = this.pixels;
|
|
175
|
-
return new Color(
|
|
176
|
-
pixels[offset
|
|
210
|
+
return new Color(
|
|
211
|
+
pixels[offset],
|
|
212
|
+
pixels[offset + 1],
|
|
213
|
+
pixels[offset + 2],
|
|
214
|
+
pixels[offset + 3],
|
|
215
|
+
);
|
|
177
216
|
}
|
|
178
217
|
|
|
179
218
|
/**
|
|
@@ -185,7 +224,9 @@ export class Image {
|
|
|
185
224
|
*/
|
|
186
225
|
setPixel(coords: Readonly<Vector2u>, color: ReadonlyValue<Color>): void {
|
|
187
226
|
const offset = this.offset(coords);
|
|
188
|
-
if (!(color instanceof Color))
|
|
227
|
+
if (!(color instanceof Color)) {
|
|
228
|
+
throw new TypeError('Expected a Color');
|
|
229
|
+
}
|
|
189
230
|
this.pixels.set(color[colorStorage], offset);
|
|
190
231
|
}
|
|
191
232
|
|
|
@@ -197,13 +238,15 @@ export class Image {
|
|
|
197
238
|
* @ko color와 정확히 일치하는 픽셀의 알파를 alpha(기본값 0)로 설정하며 RGB는 유지합니다.
|
|
198
239
|
*/
|
|
199
240
|
createMaskFromColor(color: ReadonlyValue<Color>, alpha = 0): void {
|
|
200
|
-
if (!(color instanceof Color))
|
|
201
|
-
|
|
241
|
+
if (!(color instanceof Color)) {
|
|
242
|
+
throw new TypeError('Expected a Color');
|
|
243
|
+
}
|
|
244
|
+
if (typeof alpha !== 'number') {
|
|
245
|
+
throw new TypeError('Expected numeric alpha');
|
|
246
|
+
}
|
|
202
247
|
// eslint-disable-next-line no-bitwise
|
|
203
248
|
const byte = alpha & 255;
|
|
204
|
-
native.maskImage(
|
|
205
|
-
this[graphicsNative], color.toInteger(), byte,
|
|
206
|
-
);
|
|
249
|
+
native.maskImage(this[graphicsNative], color.toInteger(), byte);
|
|
207
250
|
}
|
|
208
251
|
|
|
209
252
|
/**
|
|
@@ -216,18 +259,28 @@ export class Image {
|
|
|
216
259
|
* 반환합니다.
|
|
217
260
|
*/
|
|
218
261
|
copy(
|
|
219
|
-
source: Image,
|
|
220
|
-
|
|
262
|
+
source: Image,
|
|
263
|
+
dest: Readonly<Vector2u>,
|
|
264
|
+
sourceRect?: ReadonlyValue<IntRect>,
|
|
265
|
+
applyAlpha = false,
|
|
221
266
|
): boolean {
|
|
222
|
-
if (!(source instanceof Image))
|
|
267
|
+
if (!(source instanceof Image)) {
|
|
268
|
+
throw new TypeError('Expected an Image');
|
|
269
|
+
}
|
|
223
270
|
coordinates(dest);
|
|
224
271
|
if (sourceRect !== undefined && !(sourceRect instanceof IntRect)) {
|
|
225
272
|
throw new TypeError('Expected an IntRect');
|
|
226
273
|
}
|
|
227
274
|
return native.copyImage(
|
|
228
|
-
this[graphicsNative],
|
|
229
|
-
|
|
230
|
-
|
|
275
|
+
this[graphicsNative],
|
|
276
|
+
source[graphicsNative],
|
|
277
|
+
dest.x,
|
|
278
|
+
dest.y,
|
|
279
|
+
sourceRect?.position.x ?? 0,
|
|
280
|
+
sourceRect?.position.y ?? 0,
|
|
281
|
+
sourceRect?.size.x ?? 0,
|
|
282
|
+
sourceRect?.size.y ?? 0,
|
|
283
|
+
applyAlpha,
|
|
231
284
|
);
|
|
232
285
|
}
|
|
233
286
|
|
|
@@ -286,7 +339,9 @@ export class Image {
|
|
|
286
339
|
*/
|
|
287
340
|
async loadFromStream(stream: InputStream): Promise<boolean> {
|
|
288
341
|
let failure: { error: unknown } | undefined;
|
|
289
|
-
const dispatch = streamDispatch(stream, error => {
|
|
342
|
+
const dispatch = streamDispatch(stream, error => {
|
|
343
|
+
failure = { error };
|
|
344
|
+
});
|
|
290
345
|
try {
|
|
291
346
|
return await this.load(callback => {
|
|
292
347
|
native.loadImageStream(this[graphicsNative], dispatch, callback);
|
|
@@ -305,10 +360,17 @@ export class Image {
|
|
|
305
360
|
*/
|
|
306
361
|
saveToFile(filename: string): Promise<boolean> {
|
|
307
362
|
return new Promise((resolve, reject) => {
|
|
308
|
-
native.saveImageFile(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
363
|
+
native.saveImageFile(
|
|
364
|
+
this[graphicsNative],
|
|
365
|
+
filename,
|
|
366
|
+
(error, result) => {
|
|
367
|
+
if (error) {
|
|
368
|
+
reject(error);
|
|
369
|
+
} else {
|
|
370
|
+
resolve(result);
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
);
|
|
312
374
|
});
|
|
313
375
|
}
|
|
314
376
|
|
|
@@ -321,10 +383,17 @@ export class Image {
|
|
|
321
383
|
*/
|
|
322
384
|
saveToMemory(format: string): Promise<Uint8Array | undefined> {
|
|
323
385
|
return new Promise((resolve, reject) => {
|
|
324
|
-
native.saveImageMemory(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
386
|
+
native.saveImageMemory(
|
|
387
|
+
this[graphicsNative],
|
|
388
|
+
format,
|
|
389
|
+
(error, result) => {
|
|
390
|
+
if (error) {
|
|
391
|
+
reject(error);
|
|
392
|
+
} else {
|
|
393
|
+
resolve(result);
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
);
|
|
328
397
|
});
|
|
329
398
|
}
|
|
330
399
|
|
|
@@ -335,14 +404,19 @@ export class Image {
|
|
|
335
404
|
* @ja コールバックでネイティブデコードを駆動する、共通の非同期読み込み入口。
|
|
336
405
|
* @ko 콜백으로 네이티브 디코딩을 구동하는 공통 비동기 로드 진입점입니다.
|
|
337
406
|
*/
|
|
338
|
-
private load(
|
|
339
|
-
|
|
340
|
-
|
|
407
|
+
private load(
|
|
408
|
+
start: (
|
|
409
|
+
callback: (error: Error | null, mapping?: NativeImageMapping) => void,
|
|
410
|
+
) => void,
|
|
411
|
+
): Promise<boolean> {
|
|
341
412
|
return new Promise((resolve, reject) => {
|
|
342
413
|
start((error, mapping) => {
|
|
343
|
-
if (error)
|
|
344
|
-
|
|
345
|
-
|
|
414
|
+
if (error) {
|
|
415
|
+
reject(error);
|
|
416
|
+
} else {
|
|
417
|
+
if (mapping) {
|
|
418
|
+
this.state = view(mapping);
|
|
419
|
+
}
|
|
346
420
|
resolve(mapping !== undefined);
|
|
347
421
|
}
|
|
348
422
|
});
|
package/src/graphics/rect.ts
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import { native, type NativeValueHandle } from '../internal/native';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
LazyValue,
|
|
4
|
+
nativeValue,
|
|
5
|
+
memberValue,
|
|
6
|
+
} from '../internal/lazy-value';
|
|
3
7
|
import { scalarArrays, toScalar } from '../internal/scalar';
|
|
4
8
|
import {
|
|
5
|
-
rectStorage,
|
|
9
|
+
rectStorage,
|
|
10
|
+
rectNative,
|
|
11
|
+
vector2Storage,
|
|
12
|
+
mutableValue,
|
|
13
|
+
type ReadonlyValue as R,
|
|
6
14
|
} from '../internal/value-storage';
|
|
7
15
|
import {
|
|
8
|
-
Vector2,
|
|
16
|
+
Vector2,
|
|
17
|
+
Vector2i,
|
|
18
|
+
Vector2f,
|
|
19
|
+
vector2FromState,
|
|
9
20
|
} from '../system/vector2';
|
|
10
21
|
|
|
11
22
|
type RectScalar = 'i32' | 'f32';
|
|
12
23
|
type RectArguments<T extends RectScalar> =
|
|
13
24
|
| []
|
|
14
|
-
| [
|
|
15
|
-
| [
|
|
25
|
+
| [source: R<Rect<RectScalar>>]
|
|
26
|
+
| [position: R<Vector2<T>>, size: R<Vector2<T>>];
|
|
16
27
|
|
|
17
28
|
// Match SFML's comparisons, including unordered floats and signed zero.
|
|
18
29
|
const min = (a: number, b: number): number => (a < b ? a : b);
|
|
@@ -57,8 +68,9 @@ export class Rect<T extends RectScalar> {
|
|
|
57
68
|
|
|
58
69
|
protected constructor(type: T, ...args: RectArguments<T>) {
|
|
59
70
|
this.type = type;
|
|
60
|
-
this.state = new LazyValue(new scalarArrays[type](4),
|
|
61
|
-
|
|
71
|
+
this.state = new LazyValue(new scalarArrays[type](4), buffer =>
|
|
72
|
+
native.wrapRect(type, buffer),
|
|
73
|
+
);
|
|
62
74
|
if (args.length === 1) {
|
|
63
75
|
const source = args[0];
|
|
64
76
|
if (!(source instanceof Rect)) {
|
|
@@ -103,10 +115,12 @@ export class Rect<T extends RectScalar> {
|
|
|
103
115
|
get position(): Vector2<T> {
|
|
104
116
|
if (!this.positionView) {
|
|
105
117
|
const parent = this.state;
|
|
106
|
-
this.positionView = vector2FromState(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
this.positionView = vector2FromState(
|
|
119
|
+
this.type,
|
|
120
|
+
memberValue(parent, parent.values.subarray(0, 2), handle =>
|
|
121
|
+
native.rectMember(handle, 0),
|
|
122
|
+
),
|
|
123
|
+
);
|
|
110
124
|
}
|
|
111
125
|
return this.positionView;
|
|
112
126
|
}
|
|
@@ -131,10 +145,12 @@ export class Rect<T extends RectScalar> {
|
|
|
131
145
|
get size(): Vector2<T> {
|
|
132
146
|
if (!this.sizeView) {
|
|
133
147
|
const parent = this.state;
|
|
134
|
-
this.sizeView = vector2FromState(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
this.sizeView = vector2FromState(
|
|
149
|
+
this.type,
|
|
150
|
+
memberValue(parent, parent.values.subarray(2, 4), handle =>
|
|
151
|
+
native.rectMember(handle, 1),
|
|
152
|
+
),
|
|
153
|
+
);
|
|
138
154
|
}
|
|
139
155
|
return this.sizeView;
|
|
140
156
|
}
|
|
@@ -162,8 +178,12 @@ export class Rect<T extends RectScalar> {
|
|
|
162
178
|
const data = this[rectStorage];
|
|
163
179
|
const endX = toScalar(this.type, data[0] + data[2]);
|
|
164
180
|
const endY = toScalar(this.type, data[1] + data[3]);
|
|
165
|
-
return
|
|
166
|
-
point.
|
|
181
|
+
return (
|
|
182
|
+
point.x >= min(data[0], endX) &&
|
|
183
|
+
point.x < max(data[0], endX) &&
|
|
184
|
+
point.y >= min(data[1], endY) &&
|
|
185
|
+
point.y < max(data[1], endY)
|
|
186
|
+
);
|
|
167
187
|
}
|
|
168
188
|
|
|
169
189
|
/**
|
|
@@ -175,7 +195,10 @@ export class Rect<T extends RectScalar> {
|
|
|
175
195
|
* 반환합니다.
|
|
176
196
|
*/
|
|
177
197
|
findIntersection(rectangle: R<Rect<T>>): Rect<T> | undefined {
|
|
178
|
-
if (
|
|
198
|
+
if (
|
|
199
|
+
!(rectangle instanceof Rect) ||
|
|
200
|
+
rectangle.scalarType !== this.type
|
|
201
|
+
) {
|
|
179
202
|
throw new TypeError('Rect operands must have the same scalar type');
|
|
180
203
|
}
|
|
181
204
|
const a = this[rectStorage];
|
|
@@ -188,7 +211,9 @@ export class Rect<T extends RectScalar> {
|
|
|
188
211
|
const top = max(min(a[1], ay), min(b[1], by));
|
|
189
212
|
const right = min(max(a[0], ax), max(b[0], bx));
|
|
190
213
|
const bottom = min(max(a[1], ay), max(b[1], by));
|
|
191
|
-
if (!(left < right && top < bottom))
|
|
214
|
+
if (!(left < right && top < bottom)) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
192
217
|
const result = this.createResult();
|
|
193
218
|
const data = result[rectStorage];
|
|
194
219
|
data[0] = left;
|
|
@@ -209,8 +234,9 @@ export class Rect<T extends RectScalar> {
|
|
|
209
234
|
const data = this[rectStorage];
|
|
210
235
|
const x = data[0] + toScalar(this.type, data[2] / 2);
|
|
211
236
|
const y = data[1] + toScalar(this.type, data[3] / 2);
|
|
212
|
-
return (
|
|
213
|
-
? new Vector2f(x, y) : new Vector2i(x, y)
|
|
237
|
+
return (
|
|
238
|
+
this.type === 'f32' ? new Vector2f(x, y) : new Vector2i(x, y)
|
|
239
|
+
) as Vector2<T>;
|
|
214
240
|
}
|
|
215
241
|
|
|
216
242
|
protected createResult(): Rect<T> {
|
|
@@ -225,7 +251,9 @@ export class Rect<T extends RectScalar> {
|
|
|
225
251
|
*/
|
|
226
252
|
private checkVector(value: R<Vector2<T>>): void {
|
|
227
253
|
if (!(value instanceof Vector2) || value.scalarType !== this.type) {
|
|
228
|
-
throw new TypeError(
|
|
254
|
+
throw new TypeError(
|
|
255
|
+
'Rect requires a Vector2 with the same scalar type',
|
|
256
|
+
);
|
|
229
257
|
}
|
|
230
258
|
}
|
|
231
259
|
}
|
|
@@ -329,7 +357,9 @@ export function intRectFromState(
|
|
|
329
357
|
state: LazyValue<'rect', Int32Array>,
|
|
330
358
|
): IntRect {
|
|
331
359
|
return Object.assign(Object.create(IntRect.prototype), {
|
|
332
|
-
[mutableValue]: true,
|
|
360
|
+
[mutableValue]: true,
|
|
361
|
+
type: 'i32',
|
|
362
|
+
state,
|
|
333
363
|
createResult: () => new IntRect(),
|
|
334
364
|
});
|
|
335
365
|
}
|
|
@@ -344,7 +374,9 @@ export function floatRectFromState(
|
|
|
344
374
|
state: LazyValue<'rect', Float32Array>,
|
|
345
375
|
): FloatRect {
|
|
346
376
|
return Object.assign(Object.create(FloatRect.prototype), {
|
|
347
|
-
[mutableValue]: true,
|
|
377
|
+
[mutableValue]: true,
|
|
378
|
+
type: 'f32',
|
|
379
|
+
state,
|
|
348
380
|
createResult: () => new FloatRect(),
|
|
349
381
|
});
|
|
350
382
|
}
|
|
@@ -49,8 +49,9 @@ export interface ReadonlyRenderStates {
|
|
|
49
49
|
* @ja ステンシルテスト設定。
|
|
50
50
|
* @ko 스텐실 테스트 설정입니다.
|
|
51
51
|
*/
|
|
52
|
-
readonly stencilMode: Readonly<
|
|
53
|
-
'stencilReference' | 'stencilMask'
|
|
52
|
+
readonly stencilMode: Readonly<
|
|
53
|
+
Omit<StencilMode, 'stencilReference' | 'stencilMask'>
|
|
54
|
+
> & {
|
|
54
55
|
/**
|
|
55
56
|
* Read-only stencil reference value.
|
|
56
57
|
* @zh 只读模板参考值。
|
|
@@ -111,8 +112,14 @@ export type RenderStatesOptions = Partial<ReadonlyRenderStates>;
|
|
|
111
112
|
* @ja 描画状態の入力。設定オブジェクト、または単一の変換、ブレンド、ステンシル、テクスチャ、シェーダーリソース。
|
|
112
113
|
* @ko 그리기 상태 입력입니다. 설정 객체 또는 단일 변환, 블렌드 모드, 스텐실 모드, 텍스처, 셰이더 리소스입니다.
|
|
113
114
|
*/
|
|
114
|
-
export type RenderStatesInput =
|
|
115
|
-
|
|
115
|
+
export type RenderStatesInput =
|
|
116
|
+
| RenderStatesOptions
|
|
117
|
+
| ReadonlyValue<Transform>
|
|
118
|
+
| Readonly<BlendMode>
|
|
119
|
+
| Readonly<StencilMode>
|
|
120
|
+
| ReadonlyTexture
|
|
121
|
+
| ReadonlyShader
|
|
122
|
+
| null;
|
|
116
123
|
|
|
117
124
|
const defaultOptions: RenderStatesOptions = Object.freeze({});
|
|
118
125
|
|
|
@@ -176,16 +183,25 @@ export class RenderStates {
|
|
|
176
183
|
*/
|
|
177
184
|
constructor(source: RenderStatesInput = defaultOptions) {
|
|
178
185
|
let options: RenderStatesOptions;
|
|
179
|
-
if (source === defaultOptions)
|
|
180
|
-
|
|
181
|
-
else if (source instanceof
|
|
182
|
-
|
|
183
|
-
else if (source instanceof
|
|
184
|
-
|
|
185
|
-
else if (source instanceof
|
|
186
|
+
if (source === defaultOptions) {
|
|
187
|
+
options = defaultOptions;
|
|
188
|
+
} else if (source instanceof RenderStates) {
|
|
189
|
+
options = source;
|
|
190
|
+
} else if (source instanceof Transform) {
|
|
191
|
+
options = { transform: source };
|
|
192
|
+
} else if (source instanceof BlendMode) {
|
|
193
|
+
options = { blendMode: source };
|
|
194
|
+
} else if (source instanceof StencilMode) {
|
|
195
|
+
options = { stencilMode: source };
|
|
196
|
+
} else if (source instanceof Shader) {
|
|
197
|
+
options = { shader: source };
|
|
198
|
+
} else if (source instanceof Texture || source === null) {
|
|
186
199
|
options = { texture: source };
|
|
187
|
-
} else if (typeof source === 'object')
|
|
188
|
-
|
|
200
|
+
} else if (typeof source === 'object') {
|
|
201
|
+
options = source as RenderStatesOptions;
|
|
202
|
+
} else {
|
|
203
|
+
throw new TypeError('Expected render states');
|
|
204
|
+
}
|
|
189
205
|
|
|
190
206
|
if (options.shader != null && !(options.shader instanceof Shader)) {
|
|
191
207
|
throw new TypeError('Expected a Shader or null');
|
|
@@ -193,7 +209,8 @@ export class RenderStates {
|
|
|
193
209
|
this.blendMode = new BlendMode(options.blendMode ?? BlendAlpha);
|
|
194
210
|
this.stencilMode = new StencilMode(options.stencilMode);
|
|
195
211
|
const transform = options.transform;
|
|
196
|
-
this.matrix =
|
|
212
|
+
this.matrix =
|
|
213
|
+
transform == null ? new Transform() : new Transform(transform);
|
|
197
214
|
numericProperties(this, { coordinateType: CoordinateType.Pixels });
|
|
198
215
|
this.coordinateType = options.coordinateType ?? CoordinateType.Pixels;
|
|
199
216
|
this.texture = options.texture ?? null;
|