sfml.js 1.0.0 → 1.1.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.
- 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 +40 -48
- 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/native/font-binding.cc
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#include
|
|
1
|
+
#include <filesystem>
|
|
2
|
+
|
|
2
3
|
#include "exception-boundary.h"
|
|
4
|
+
#include "font-state.h"
|
|
3
5
|
#include "image-state.h"
|
|
4
6
|
#include "value-binding.h"
|
|
5
7
|
|
|
6
|
-
#include <filesystem>
|
|
7
|
-
|
|
8
8
|
namespace sfmljs {
|
|
9
9
|
SFMLJS_MEMBER(FontSmooth, sf::Font, bool, m_isSmooth);
|
|
10
10
|
} // namespace sfmljs
|
|
@@ -17,12 +17,17 @@ using DataHandle = sfmljs::SharedHandle<FontData>;
|
|
|
17
17
|
|
|
18
18
|
v8::Local<v8::Object> MapFont(const std::shared_ptr<FontData>& owner) {
|
|
19
19
|
const auto& data = owner->font.getInfo();
|
|
20
|
-
auto result =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
auto result =
|
|
21
|
+
sfmljs::NumericFields()
|
|
22
|
+
.Add("id", data.id)
|
|
23
|
+
.Add("hasKerning", data.hasKerning)
|
|
24
|
+
.Add("hasVerticalMetrics", data.hasVerticalMetrics)
|
|
25
|
+
.Add("smooth", sfmljs::Field<sfmljs::FontSmooth>(owner->font))
|
|
26
|
+
.Map(owner);
|
|
27
|
+
Nan::Set(result,
|
|
28
|
+
Nan::New("family").ToLocalChecked(),
|
|
29
|
+
Nan::New(data.family).ToLocalChecked())
|
|
30
|
+
.FromJust();
|
|
26
31
|
return result;
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -40,25 +45,32 @@ NAN_METHOD(CreateSfmlFont) {
|
|
|
40
45
|
auto state = std::make_shared<sfmljs::FontState>(
|
|
41
46
|
sfmljs::FontState{context->owner(), std::move(data)});
|
|
42
47
|
auto result = MapFont(state->current);
|
|
43
|
-
Nan::Set(
|
|
44
|
-
FontHandle::Create(state))
|
|
48
|
+
Nan::Set(
|
|
49
|
+
result, Nan::New("handle").ToLocalChecked(), FontHandle::Create(state))
|
|
50
|
+
.FromJust();
|
|
45
51
|
info.GetReturnValue().Set(result);
|
|
46
|
-
} catch (const std::exception& error) {
|
|
52
|
+
} catch (const std::exception& error) {
|
|
53
|
+
sfmljs::ThrowError(error.what());
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
class OpenWorker final : public sfmljs::AsyncWorker {
|
|
50
58
|
public:
|
|
51
|
-
OpenWorker(Nan::Callback* callback,
|
|
59
|
+
OpenWorker(Nan::Callback* callback,
|
|
60
|
+
std::shared_ptr<FontData> data,
|
|
52
61
|
std::string path)
|
|
53
62
|
: sfmljs::AsyncWorker(callback, "sfml:Font"),
|
|
54
|
-
data_(std::move(data)),
|
|
63
|
+
data_(std::move(data)),
|
|
64
|
+
path_(std::move(path)) {}
|
|
55
65
|
void ExecuteWork() override {
|
|
56
66
|
try {
|
|
57
|
-
ok_ = data_->bytes
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} catch (const std::exception& error) {
|
|
67
|
+
ok_ = data_->bytes ? data_->font.openFromMemory(data_->bytes->data(),
|
|
68
|
+
data_->bytes->size())
|
|
69
|
+
: data_->font.openFromFile(std::filesystem::path(
|
|
70
|
+
std::u8string(path_.begin(), path_.end())));
|
|
71
|
+
} catch (const std::exception& error) {
|
|
72
|
+
SetErrorMessage(error.what());
|
|
73
|
+
}
|
|
62
74
|
}
|
|
63
75
|
void CompleteWork() override {
|
|
64
76
|
Nan::HandleScope scope;
|
|
@@ -67,6 +79,7 @@ class OpenWorker final : public sfmljs::AsyncWorker {
|
|
|
67
79
|
v8::Local<v8::Value> args[] = {Nan::Null(), result};
|
|
68
80
|
callback->Call(2, args, async_resource);
|
|
69
81
|
}
|
|
82
|
+
|
|
70
83
|
private:
|
|
71
84
|
std::shared_ptr<FontData> data_;
|
|
72
85
|
std::string path_;
|
|
@@ -87,14 +100,16 @@ NAN_METHOD(OpenFont) {
|
|
|
87
100
|
} else {
|
|
88
101
|
std::span<const std::uint8_t> bytes;
|
|
89
102
|
if (!sfmljs::ReadImageBytes(info[0], bytes)) return;
|
|
90
|
-
data->bytes = std::make_shared<std::vector<std::uint8_t>>(
|
|
91
|
-
|
|
103
|
+
data->bytes = std::make_shared<std::vector<std::uint8_t>>(bytes.begin(),
|
|
104
|
+
bytes.end());
|
|
92
105
|
}
|
|
93
106
|
auto callback = std::make_unique<Nan::Callback>(info[1].As<v8::Function>());
|
|
94
107
|
auto worker = std::make_unique<OpenWorker>(callback.get(), data, path);
|
|
95
108
|
callback.release();
|
|
96
109
|
Nan::AsyncQueueWorker(worker.release());
|
|
97
|
-
} catch (const std::exception& error) {
|
|
110
|
+
} catch (const std::exception& error) {
|
|
111
|
+
sfmljs::ThrowError(error.what());
|
|
112
|
+
}
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
NAN_METHOD(CommitFont) {
|
|
@@ -110,21 +125,27 @@ NAN_METHOD(CommitFont) {
|
|
|
110
125
|
NAN_METHOD(GetFontGlyph) {
|
|
111
126
|
auto* state = FontHandle::From(info[0]);
|
|
112
127
|
if (!state) return;
|
|
113
|
-
if (!info[1]->IsUint32() || !info[2]->IsUint32() ||
|
|
114
|
-
!info[
|
|
115
|
-
return Nan::ThrowTypeError(
|
|
128
|
+
if (!info[1]->IsUint32() || !info[2]->IsUint32() || !info[3]->IsBoolean() ||
|
|
129
|
+
!info[4]->IsNumber() || !info[5]->IsBoolean()) {
|
|
130
|
+
return Nan::ThrowTypeError(
|
|
131
|
+
"Expected glyph, size, bold, outline and ID flag");
|
|
116
132
|
}
|
|
117
133
|
try {
|
|
118
134
|
const auto& font = state->owner()->current->font;
|
|
119
135
|
const auto id = Nan::To<std::uint32_t>(info[1]).FromJust();
|
|
120
136
|
const auto size = Nan::To<unsigned>(info[2]).FromJust();
|
|
121
|
-
const auto outline =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
const auto outline =
|
|
138
|
+
static_cast<float>(Nan::To<double>(info[4]).FromJust());
|
|
139
|
+
const auto& glyph =
|
|
140
|
+
info[5]->IsTrue()
|
|
141
|
+
? font.getGlyphById(id, size, info[3]->IsTrue(), outline)
|
|
142
|
+
: font.getGlyph(
|
|
143
|
+
static_cast<char32_t>(id), size, info[3]->IsTrue(), outline);
|
|
125
144
|
// Independent value: JS cannot corrupt the font's glyph cache.
|
|
126
145
|
sfmljs::values::ReturnMapped(info, std::make_shared<sf::Glyph>(glyph));
|
|
127
|
-
} catch (const std::exception& error) {
|
|
146
|
+
} catch (const std::exception& error) {
|
|
147
|
+
sfmljs::ThrowError(error.what());
|
|
148
|
+
}
|
|
128
149
|
}
|
|
129
150
|
|
|
130
151
|
NAN_METHOD(FontMetric) {
|
|
@@ -137,23 +158,37 @@ NAN_METHOD(FontMetric) {
|
|
|
137
158
|
const auto value = Nan::To<unsigned>(info[2]).FromJust();
|
|
138
159
|
float result{};
|
|
139
160
|
switch (Nan::To<unsigned>(info[1]).FromJust()) {
|
|
140
|
-
case 0:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
case
|
|
144
|
-
|
|
161
|
+
case 0:
|
|
162
|
+
result = font.getAscent(value);
|
|
163
|
+
break;
|
|
164
|
+
case 1:
|
|
165
|
+
result = font.getDescent(value);
|
|
166
|
+
break;
|
|
167
|
+
case 2:
|
|
168
|
+
result = font.getLineSpacing(value);
|
|
169
|
+
break;
|
|
170
|
+
case 3:
|
|
171
|
+
result = font.getUnderlinePosition(value);
|
|
172
|
+
break;
|
|
173
|
+
case 4:
|
|
174
|
+
result = font.getUnderlineThickness(value);
|
|
175
|
+
break;
|
|
145
176
|
case 5:
|
|
146
177
|
info.GetReturnValue().Set(font.hasGlyph(static_cast<char32_t>(value)));
|
|
147
178
|
return;
|
|
148
179
|
case 6:
|
|
149
|
-
if (!info[3]->IsUint32() || !info[4]->IsUint32() ||
|
|
180
|
+
if (!info[3]->IsUint32() || !info[4]->IsUint32() ||
|
|
181
|
+
!info[5]->IsBoolean()) {
|
|
150
182
|
return Nan::ThrowTypeError("Expected kerning arguments");
|
|
151
183
|
}
|
|
152
|
-
result = font.getKerning(
|
|
184
|
+
result = font.getKerning(
|
|
185
|
+
static_cast<char32_t>(value),
|
|
153
186
|
static_cast<char32_t>(Nan::To<unsigned>(info[3]).FromJust()),
|
|
154
|
-
Nan::To<unsigned>(info[4]).FromJust(),
|
|
187
|
+
Nan::To<unsigned>(info[4]).FromJust(),
|
|
188
|
+
info[5]->IsTrue());
|
|
155
189
|
break;
|
|
156
|
-
default:
|
|
190
|
+
default:
|
|
191
|
+
return Nan::ThrowRangeError("Invalid font metric");
|
|
157
192
|
}
|
|
158
193
|
info.GetReturnValue().Set(Nan::New(result));
|
|
159
194
|
}
|
|
@@ -168,24 +203,30 @@ NAN_METHOD(SetFontSmooth) {
|
|
|
168
203
|
NAN_METHOD(GetFontTexture) {
|
|
169
204
|
auto* state = FontHandle::From(info[0]);
|
|
170
205
|
if (!state) return;
|
|
171
|
-
if (!info[1]->IsUint32())
|
|
206
|
+
if (!info[1]->IsUint32())
|
|
207
|
+
return Nan::ThrowTypeError("Expected character size");
|
|
172
208
|
try {
|
|
173
209
|
auto context = state->owner()->context;
|
|
174
210
|
auto font = state->owner()->current;
|
|
175
|
-
const auto& texture =
|
|
211
|
+
const auto& texture =
|
|
212
|
+
font->font.getTexture(Nan::To<unsigned>(info[1]).FromJust());
|
|
176
213
|
const auto id = context->nextId++;
|
|
177
|
-
auto atlas = sfmljs::MakeThreadOwned<sfmljs::FontAtlas>(
|
|
178
|
-
context, font, id);
|
|
214
|
+
auto atlas = sfmljs::MakeThreadOwned<sfmljs::FontAtlas>(context, font, id);
|
|
179
215
|
auto alias = std::shared_ptr<const sf::Texture>(atlas, &texture);
|
|
180
216
|
context->textures.emplace(id, alias);
|
|
181
217
|
auto result = Nan::New<v8::Object>();
|
|
182
|
-
Nan::Set(
|
|
183
|
-
sfmljs::MapTexture(alias))
|
|
184
|
-
|
|
185
|
-
|
|
218
|
+
Nan::Set(
|
|
219
|
+
result, Nan::New("info").ToLocalChecked(), sfmljs::MapTexture(alias))
|
|
220
|
+
.FromJust();
|
|
221
|
+
Nan::Set(result,
|
|
222
|
+
Nan::New("handle").ToLocalChecked(),
|
|
223
|
+
sfmljs::SharedHandle<const sf::Texture>::Create(alias))
|
|
224
|
+
.FromJust();
|
|
186
225
|
Nan::Set(result, Nan::New("id").ToLocalChecked(), Nan::New(id)).FromJust();
|
|
187
226
|
info.GetReturnValue().Set(result);
|
|
188
|
-
} catch (const std::exception& error) {
|
|
227
|
+
} catch (const std::exception& error) {
|
|
228
|
+
sfmljs::ThrowError(error.what());
|
|
229
|
+
}
|
|
189
230
|
}
|
|
190
231
|
|
|
191
232
|
NAN_METHOD(GetTextureInfo) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#include <nan.h>
|
|
2
|
-
#include <SFML/Graphics/Image.hpp>
|
|
3
|
-
|
|
4
|
-
#include "graphics-state.h"
|
|
5
|
-
#include "exception-boundary.h"
|
|
6
|
-
#include "context-settings.h"
|
|
7
|
-
#include "shared-handle.h"
|
|
8
2
|
|
|
9
3
|
#include <exception>
|
|
10
4
|
#include <limits>
|
|
11
5
|
|
|
6
|
+
#include "context-settings.h"
|
|
7
|
+
#include "exception-boundary.h"
|
|
8
|
+
#include "graphics-state.h"
|
|
9
|
+
#include "shared-handle.h"
|
|
10
|
+
#include <SFML/Graphics/Image.hpp>
|
|
11
|
+
|
|
12
12
|
namespace {
|
|
13
13
|
|
|
14
14
|
using Context = sfmljs::GraphicsContext;
|
|
@@ -16,8 +16,9 @@ using Sprite = sfmljs::SpriteState;
|
|
|
16
16
|
using Target = sfmljs::RenderTextureState;
|
|
17
17
|
using sfmljs::SharedHandle;
|
|
18
18
|
|
|
19
|
-
bool ReadSize(v8::Local<v8::Value> x,
|
|
20
|
-
|
|
19
|
+
bool ReadSize(v8::Local<v8::Value> x,
|
|
20
|
+
v8::Local<v8::Value> y,
|
|
21
|
+
sf::Vector2u& size) { // NOLINT(runtime/references)
|
|
21
22
|
if (!x->IsUint32() || !y->IsUint32()) {
|
|
22
23
|
Nan::ThrowRangeError("Expected positive integer dimensions");
|
|
23
24
|
return false;
|
|
@@ -36,8 +37,10 @@ NAN_METHOD(CreateGraphicsContext) {
|
|
|
36
37
|
SharedHandle<Context>::Create(sfmljs::MakeThreadOwned<Context>()));
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
bool ReadTextureId(const Context& context,
|
|
40
|
-
|
|
40
|
+
bool ReadTextureId(const Context& context,
|
|
41
|
+
const std::shared_ptr<const sf::Texture>& texture,
|
|
42
|
+
v8::Local<v8::Value> input,
|
|
43
|
+
std::uint32_t& id) { // NOLINT(runtime/references)
|
|
41
44
|
if (!input->IsUint32()) {
|
|
42
45
|
Nan::ThrowTypeError("Expected a texture ID");
|
|
43
46
|
return false;
|
|
@@ -65,21 +68,33 @@ NAN_METHOD(CreateSprite) {
|
|
|
65
68
|
context->owner(), texture, context->owner()->nextId++, textureId);
|
|
66
69
|
context->owner()->sprites.emplace(object->id, object);
|
|
67
70
|
auto result = Nan::New<v8::Object>();
|
|
68
|
-
Nan::Set(result,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
Nan::Set(result,
|
|
72
|
+
Nan::New("handle").ToLocalChecked(),
|
|
73
|
+
SharedHandle<Sprite>::Create(object))
|
|
74
|
+
.FromJust();
|
|
75
|
+
Nan::Set(result, Nan::New("id").ToLocalChecked(), Nan::New(object->id))
|
|
76
|
+
.FromJust();
|
|
72
77
|
// The adjusted base pointer and sprite handle share one control block.
|
|
73
78
|
const auto transformable = std::shared_ptr<sfmljs::TransformableState>(
|
|
74
79
|
object, static_cast<sfmljs::TransformableState*>(object.get()));
|
|
75
|
-
Nan::Set(result,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
sfmljs::MapShared(info.GetIsolate(),
|
|
82
|
-
|
|
80
|
+
Nan::Set(result,
|
|
81
|
+
Nan::New("transformable").ToLocalChecked(),
|
|
82
|
+
sfmljs::TransformableHandle(transformable))
|
|
83
|
+
.FromJust();
|
|
84
|
+
Nan::Set(result,
|
|
85
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
86
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
87
|
+
object,
|
|
88
|
+
object->values.data(),
|
|
89
|
+
sizeof(object->values)))
|
|
90
|
+
.FromJust();
|
|
91
|
+
Nan::Set(result,
|
|
92
|
+
Nan::New("appearance").ToLocalChecked(),
|
|
93
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
94
|
+
object,
|
|
95
|
+
&object->appearance,
|
|
96
|
+
sizeof(object->appearance)))
|
|
97
|
+
.FromJust();
|
|
83
98
|
info.GetReturnValue().Set(result);
|
|
84
99
|
}
|
|
85
100
|
|
|
@@ -102,11 +117,16 @@ NAN_METHOD(SpriteTextureRect) {
|
|
|
102
117
|
auto rectangle = std::shared_ptr<sf::IntRect>(
|
|
103
118
|
sprite->owner(), &sprite->owner()->appearance.rectangle);
|
|
104
119
|
auto result = Nan::New<v8::Object>();
|
|
105
|
-
Nan::Set(result,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
Nan::Set(result,
|
|
121
|
+
Nan::New("handle").ToLocalChecked(),
|
|
122
|
+
SharedHandle<sf::IntRect>::Create(rectangle))
|
|
123
|
+
.FromJust();
|
|
124
|
+
Nan::Set(
|
|
125
|
+
result,
|
|
126
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
127
|
+
sfmljs::MapShared(
|
|
128
|
+
info.GetIsolate(), rectangle, rectangle.get(), sizeof(sf::IntRect)))
|
|
129
|
+
.FromJust();
|
|
110
130
|
info.GetReturnValue().Set(result);
|
|
111
131
|
}
|
|
112
132
|
|
|
@@ -125,17 +145,26 @@ NAN_METHOD(CreateRenderTexture) {
|
|
|
125
145
|
return sfmljs::ThrowError("SFML could not create the render texture");
|
|
126
146
|
}
|
|
127
147
|
auto result = Nan::New<v8::Object>();
|
|
128
|
-
Nan::Set(result,
|
|
129
|
-
|
|
148
|
+
Nan::Set(result,
|
|
149
|
+
Nan::New("handle").ToLocalChecked(),
|
|
150
|
+
SharedHandle<Target>::Create(target))
|
|
151
|
+
.FromJust();
|
|
130
152
|
const auto commands = target->batch.Commands();
|
|
131
|
-
Nan::Set(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
153
|
+
Nan::Set(
|
|
154
|
+
result,
|
|
155
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
156
|
+
sfmljs::MapShared(
|
|
157
|
+
info.GetIsolate(), target, commands.data(), commands.size_bytes()))
|
|
158
|
+
.FromJust();
|
|
159
|
+
Nan::Set(result,
|
|
160
|
+
Nan::New("info").ToLocalChecked(),
|
|
135
161
|
sfmljs::MapTexture(std::shared_ptr<const sf::Texture>(
|
|
136
|
-
target, &target->target.getTexture())))
|
|
137
|
-
|
|
138
|
-
|
|
162
|
+
target, &target->target.getTexture())))
|
|
163
|
+
.FromJust();
|
|
164
|
+
Nan::Set(
|
|
165
|
+
result,
|
|
166
|
+
Nan::New("targetInfo").ToLocalChecked(),
|
|
167
|
+
sfmljs::NumericFields().Add("sRgb", target->targetSrgb).Map(target))
|
|
139
168
|
.FromJust();
|
|
140
169
|
info.GetReturnValue().Set(result);
|
|
141
170
|
} catch (const std::exception& error) {
|
|
@@ -163,8 +192,8 @@ NAN_METHOD(ResizeRenderTexture) {
|
|
|
163
192
|
}
|
|
164
193
|
|
|
165
194
|
NAN_METHOD(GetMaximumRenderTextureAntiAliasingLevel) {
|
|
166
|
-
info.GetReturnValue().Set(
|
|
167
|
-
sf::RenderTexture::getMaximumAntiAliasingLevel()));
|
|
195
|
+
info.GetReturnValue().Set(
|
|
196
|
+
Nan::New(sf::RenderTexture::getMaximumAntiAliasingLevel()));
|
|
168
197
|
}
|
|
169
198
|
|
|
170
199
|
template <bool Smooth>
|
|
@@ -172,21 +201,24 @@ NAN_METHOD(SetRenderTextureSampling) {
|
|
|
172
201
|
auto* handle = SharedHandle<Target>::From(info[0]);
|
|
173
202
|
if (!handle) return;
|
|
174
203
|
if (!info[1]->IsBoolean()) return Nan::ThrowTypeError("Expected a boolean");
|
|
175
|
-
if constexpr (Smooth)
|
|
176
|
-
|
|
204
|
+
if constexpr (Smooth)
|
|
205
|
+
handle->owner()->target.setSmooth(info[1]->IsTrue());
|
|
206
|
+
else
|
|
207
|
+
handle->owner()->target.setRepeated(info[1]->IsTrue());
|
|
177
208
|
}
|
|
178
209
|
|
|
179
210
|
NAN_METHOD(GenerateRenderTextureMipmap) {
|
|
180
211
|
auto* handle = SharedHandle<Target>::From(info[0]);
|
|
181
|
-
if (handle)
|
|
182
|
-
|
|
212
|
+
if (handle)
|
|
213
|
+
info.GetReturnValue().Set(handle->owner()->target.generateMipmap());
|
|
183
214
|
}
|
|
184
215
|
|
|
185
216
|
NAN_METHOD(SetRenderTextureActive) {
|
|
186
217
|
auto* handle = SharedHandle<Target>::From(info[0]);
|
|
187
218
|
if (!handle) return;
|
|
188
219
|
if (!info[1]->IsBoolean()) return Nan::ThrowTypeError("Expected a boolean");
|
|
189
|
-
info.GetReturnValue().Set(
|
|
220
|
+
info.GetReturnValue().Set(
|
|
221
|
+
handle->owner()->target.setActive(info[1]->IsTrue()));
|
|
190
222
|
}
|
|
191
223
|
|
|
192
224
|
NAN_METHOD(ChangeRenderTextureGLStates) {
|
|
@@ -198,18 +230,23 @@ NAN_METHOD(ChangeRenderTextureGLStates) {
|
|
|
198
230
|
auto& state = *handle->owner();
|
|
199
231
|
if (!state.initialized) return;
|
|
200
232
|
switch (Nan::To<std::uint32_t>(info[1]).FromJust()) {
|
|
201
|
-
case 0:
|
|
202
|
-
|
|
203
|
-
|
|
233
|
+
case 0:
|
|
234
|
+
state.target.pushGLStates();
|
|
235
|
+
break;
|
|
236
|
+
case 1:
|
|
237
|
+
state.target.popGLStates();
|
|
238
|
+
break;
|
|
239
|
+
case 2:
|
|
240
|
+
state.target.resetGLStates();
|
|
241
|
+
break;
|
|
204
242
|
}
|
|
205
243
|
}
|
|
206
244
|
|
|
207
245
|
NAN_METHOD(SubmitRenderTexture) {
|
|
208
246
|
auto* target = SharedHandle<Target>::From(info[0]);
|
|
209
247
|
if (!target) return;
|
|
210
|
-
if (!info[1]->IsUint32() ||
|
|
211
|
-
|
|
212
|
-
target->owner()->batch.Commands().size()) {
|
|
248
|
+
if (!info[1]->IsUint32() || Nan::To<std::uint32_t>(info[1]).FromJust() >
|
|
249
|
+
target->owner()->batch.Commands().size()) {
|
|
213
250
|
return Nan::ThrowRangeError("Invalid draw command count");
|
|
214
251
|
}
|
|
215
252
|
if (!info[2]->IsBoolean()) {
|
|
@@ -237,16 +274,19 @@ NAN_METHOD(GetRenderTextureTexture) {
|
|
|
237
274
|
}
|
|
238
275
|
owner->textureId = owner->context->nextId++;
|
|
239
276
|
}
|
|
240
|
-
const auto texture =
|
|
241
|
-
owner, &owner->target.getTexture());
|
|
277
|
+
const auto texture =
|
|
278
|
+
std::shared_ptr<const sf::Texture>(owner, &owner->target.getTexture());
|
|
242
279
|
owner->context->textures.insert_or_assign(owner->textureId, texture);
|
|
243
280
|
auto result = Nan::New<v8::Object>();
|
|
244
|
-
Nan::Set(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
281
|
+
Nan::Set(
|
|
282
|
+
result, Nan::New("info").ToLocalChecked(), sfmljs::MapTexture(texture))
|
|
283
|
+
.FromJust();
|
|
284
|
+
Nan::Set(result, Nan::New("id").ToLocalChecked(), Nan::New(owner->textureId))
|
|
285
|
+
.FromJust();
|
|
286
|
+
Nan::Set(result,
|
|
287
|
+
Nan::New("handle").ToLocalChecked(),
|
|
288
|
+
SharedHandle<const sf::Texture>::Create(texture))
|
|
289
|
+
.FromJust();
|
|
250
290
|
info.GetReturnValue().Set(result);
|
|
251
291
|
}
|
|
252
292
|
|
|
@@ -260,10 +300,13 @@ NAN_METHOD(AllocateRenderTextureVertices) {
|
|
|
260
300
|
try {
|
|
261
301
|
const auto storage = target->owner()->batch.AllocateVertices(
|
|
262
302
|
Nan::To<std::uint32_t>(info[1]).FromJust());
|
|
263
|
-
info.GetReturnValue().Set(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
303
|
+
info.GetReturnValue().Set(
|
|
304
|
+
storage->empty()
|
|
305
|
+
? v8::ArrayBuffer::New(info.GetIsolate(), 0)
|
|
306
|
+
: sfmljs::MapShared(info.GetIsolate(),
|
|
307
|
+
storage,
|
|
308
|
+
storage->data(),
|
|
309
|
+
storage->size() * sizeof(sf::Vertex)));
|
|
267
310
|
} catch (const std::exception& error) {
|
|
268
311
|
sfmljs::ThrowError(error.what());
|
|
269
312
|
}
|
|
@@ -274,8 +317,8 @@ NAN_METHOD(OpenRenderTexturePreview) {
|
|
|
274
317
|
if (!target) return;
|
|
275
318
|
auto preview = sfmljs::MakeThreadOwned<sfmljs::PreviewWindow>();
|
|
276
319
|
preview->window.create(sf::VideoMode(target->owner()->target.getSize()),
|
|
277
|
-
|
|
278
|
-
|
|
320
|
+
"sfml.js | Shared-memory sprite demo | Esc closes",
|
|
321
|
+
sf::Style::Titlebar | sf::Style::Close);
|
|
279
322
|
if (!preview->window.isOpen()) {
|
|
280
323
|
return sfmljs::ThrowError("SFML could not open the preview window");
|
|
281
324
|
}
|
|
@@ -298,9 +341,10 @@ NAN_METHOD(ReadRenderTexturePixels) {
|
|
|
298
341
|
if (bytes > std::numeric_limits<std::uint32_t>::max()) {
|
|
299
342
|
return Nan::ThrowRangeError("Image too large for the readback probe");
|
|
300
343
|
}
|
|
301
|
-
info.GetReturnValue().Set(
|
|
302
|
-
reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
303
|
-
|
|
344
|
+
info.GetReturnValue().Set(
|
|
345
|
+
Nan::CopyBuffer(reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
346
|
+
static_cast<std::uint32_t>(bytes))
|
|
347
|
+
.ToLocalChecked());
|
|
304
348
|
}
|
|
305
349
|
|
|
306
350
|
NAN_METHOD(ReadSpritePosition) {
|
|
@@ -324,15 +368,21 @@ NAN_MODULE_INIT(InitializeGraphics) {
|
|
|
324
368
|
sfmljs::SetMethod<ResizeRenderTexture>(target, "resizeRenderTexture");
|
|
325
369
|
sfmljs::SetMethod<GetMaximumRenderTextureAntiAliasingLevel>(
|
|
326
370
|
target, "getMaximumRenderTextureAntiAliasingLevel");
|
|
327
|
-
sfmljs::SetMethod<SetRenderTextureSampling<true>>(target,
|
|
328
|
-
|
|
329
|
-
sfmljs::SetMethod<
|
|
371
|
+
sfmljs::SetMethod<SetRenderTextureSampling<true>>(target,
|
|
372
|
+
"setRenderTextureSmooth");
|
|
373
|
+
sfmljs::SetMethod<SetRenderTextureSampling<false>>(
|
|
374
|
+
target, "setRenderTextureRepeated");
|
|
375
|
+
sfmljs::SetMethod<GenerateRenderTextureMipmap>(target,
|
|
376
|
+
"generateRenderTextureMipmap");
|
|
330
377
|
sfmljs::SetMethod<SetRenderTextureActive>(target, "setRenderTextureActive");
|
|
331
|
-
sfmljs::SetMethod<ChangeRenderTextureGLStates>(target,
|
|
378
|
+
sfmljs::SetMethod<ChangeRenderTextureGLStates>(target,
|
|
379
|
+
"changeRenderTextureGLStates");
|
|
332
380
|
sfmljs::SetMethod<SubmitRenderTexture>(target, "submitRenderTexture");
|
|
333
381
|
sfmljs::SetMethod<GetRenderTextureTexture>(target, "getRenderTextureTexture");
|
|
334
|
-
sfmljs::SetMethod<AllocateRenderTextureVertices>(
|
|
335
|
-
|
|
382
|
+
sfmljs::SetMethod<AllocateRenderTextureVertices>(
|
|
383
|
+
target, "allocateRenderTextureVertices");
|
|
384
|
+
sfmljs::SetMethod<OpenRenderTexturePreview>(target,
|
|
385
|
+
"openRenderTexturePreview");
|
|
336
386
|
sfmljs::SetMethod<ReadRenderTexturePixels>(target, "readRenderTexturePixels");
|
|
337
387
|
sfmljs::SetMethod<ReadSpritePosition>(target, "readSpritePosition");
|
|
338
388
|
}
|