sfml.js 0.0.1-preview.22 → 0.0.1-preview.24
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/binding.gyp +1 -0
- package/lib/drawable/rectangle_shape.d.ts +3 -0
- package/lib/drawable/rectangle_shape.js +12 -0
- package/lib/drawable/transformable.js +1 -1
- package/lib/image.d.ts +5 -0
- package/lib/image.js +10 -0
- package/lib/render_window.d.ts +5 -0
- package/lib/render_window.js +8 -0
- package/lib/sfml.js +1 -0
- package/lib/texture.d.ts +10 -0
- package/lib/texture.js +39 -1
- package/package.json +1 -1
- package/src/drawable/package_plugin-inl.h +10 -1
- package/src/drawable/rectangle_shape.cc +34 -0
- package/src/drawable/rectangle_shape.h +3 -0
- package/src/image.cc +56 -0
- package/src/image.h +32 -0
- package/src/render_window.cc +37 -0
- package/src/render_window.h +2 -0
- package/src/sfml.cc +2 -0
- package/src/texture.cc +37 -0
- package/src/texture.h +4 -0
package/binding.gyp
CHANGED
|
@@ -11,6 +11,18 @@ class RectangleShape extends Shape {
|
|
|
11
11
|
|
|
12
12
|
super('RectangleShape', size);
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
setSize(size) {
|
|
16
|
+
if (!(size instanceof Vector2F)) {
|
|
17
|
+
size = new Vector2F(size?.x, size?.y);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this._raw().setSize(size);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getSize() {
|
|
24
|
+
return this._raw().getSize();
|
|
25
|
+
}
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
module.exports = RectangleShape;
|
package/lib/image.d.ts
ADDED
package/lib/image.js
ADDED
package/lib/render_window.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as Drawable from './drawable/base';
|
|
2
|
+
import * as Image from './image';
|
|
2
3
|
import * as Event from './poll_event';
|
|
3
4
|
import * as VideoMode from './video_mode';
|
|
5
|
+
import { Vector2U } from './vector2';
|
|
4
6
|
|
|
5
7
|
declare class RenderWindow {
|
|
6
8
|
constructor(videoMode?: VideoMode, title?: string, style?: RenderWindow.Style);
|
|
7
9
|
|
|
10
|
+
capture(): Image;
|
|
8
11
|
clear(color: number): void;
|
|
9
12
|
close(): void;
|
|
10
13
|
draw(content: Drawable): void;
|
|
@@ -20,6 +23,8 @@ declare class RenderWindow {
|
|
|
20
23
|
setKeyRepeatEnabled(enabled: boolean): void;
|
|
21
24
|
setFramerateLimit(limit: number): void;
|
|
22
25
|
setActive(active?: boolean): void;
|
|
26
|
+
|
|
27
|
+
getSize(): Vector2U;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
declare namespace RenderWindow {
|
package/lib/render_window.js
CHANGED
|
@@ -26,6 +26,10 @@ class RenderWindow {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
capture() {
|
|
30
|
+
return this[RAW_RENDER_WINDOW].capture();
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
// TODO(XadillaX): Color object.
|
|
30
34
|
clear(color = 0) {
|
|
31
35
|
if (!(color instanceof Color)) {
|
|
@@ -100,6 +104,10 @@ class RenderWindow {
|
|
|
100
104
|
validateTypeOf(active, 'active', 'boolean');
|
|
101
105
|
this[RAW_RENDER_WINDOW].setActive(active);
|
|
102
106
|
}
|
|
107
|
+
|
|
108
|
+
getSize() {
|
|
109
|
+
return this[RAW_RENDER_WINDOW].getSize();
|
|
110
|
+
}
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
RenderWindow.Style = _RenderWindow.Style;
|
package/lib/sfml.js
CHANGED
package/lib/texture.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import * as Image from './image';
|
|
1
2
|
import { IntRect } from './rect';
|
|
3
|
+
import { Vector2F } from './vector2';
|
|
2
4
|
|
|
3
5
|
declare class Texture {
|
|
4
6
|
constructor();
|
|
7
|
+
|
|
8
|
+
create(x: number, y: number): void;
|
|
9
|
+
|
|
5
10
|
loadFromFile(filename: string, area?: IntRect): Promise<void>;
|
|
6
11
|
update(texture: Texture): void;
|
|
7
12
|
update(texture: Texture, x: number, y: number): void;
|
|
13
|
+
update(image: Image): void;
|
|
14
|
+
update(image: Image, x: number, y: number): void;
|
|
15
|
+
|
|
16
|
+
getSize(): Vector2F;
|
|
17
|
+
setSmooth(smooth?: boolean): void;
|
|
8
18
|
}
|
|
9
19
|
|
|
10
20
|
export = Texture;
|
package/lib/texture.js
CHANGED
|
@@ -5,7 +5,7 @@ const path = require('path');
|
|
|
5
5
|
require('./vector2');
|
|
6
6
|
const { createDeferred, validateTypeOf } = require('./common');
|
|
7
7
|
const { IntRect } = require('./rect');
|
|
8
|
-
const { Texture: _Texture } = require('../build/Release/binding.node');
|
|
8
|
+
const { Texture: _Texture, Image } = require('../build/Release/binding.node');
|
|
9
9
|
|
|
10
10
|
class Texture extends _Texture {
|
|
11
11
|
async loadFromFile(filename, area) {
|
|
@@ -28,11 +28,45 @@ class Texture extends _Texture {
|
|
|
28
28
|
return promise;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
create(x, y) {
|
|
32
|
+
validateTypeOf(x, 'x', 'number');
|
|
33
|
+
validateTypeOf(y, 'y', 'number');
|
|
34
|
+
|
|
35
|
+
if (x < 0 || y < 0) {
|
|
36
|
+
throw new RangeError('`x` and `y` should greater or equal to 0.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
super.create(x, y);
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
update() {
|
|
32
43
|
if (arguments.length >= 1 && (arguments[0] instanceof Texture)) {
|
|
33
44
|
this.updateByTexture(arguments[0], arguments[1], arguments[2]);
|
|
34
45
|
return;
|
|
35
46
|
}
|
|
47
|
+
|
|
48
|
+
if (arguments.length >= 1 && (arguments[0] instanceof Image)) {
|
|
49
|
+
this.updateByImage(arguments[0], arguments[1], arguments[2]);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
updateByImage(image, x, y) {
|
|
55
|
+
validateTypeOf(image, 'image', Image);
|
|
56
|
+
validateTypeOf(x, 'x', 'number', true);
|
|
57
|
+
validateTypeOf(y, 'y', 'number', true);
|
|
58
|
+
|
|
59
|
+
if (x === undefined || y === undefined) {
|
|
60
|
+
return super.updateByImage(image);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (x < 0 || y < 0) {
|
|
64
|
+
throw new RangeError('`x` and `y` should greater or equal to 0.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
x = parseInt(x);
|
|
68
|
+
y = parseInt(y);
|
|
69
|
+
super.updateByImage(image, x, y);
|
|
36
70
|
}
|
|
37
71
|
|
|
38
72
|
updateByTexture(texture, x, y) {
|
|
@@ -52,6 +86,10 @@ class Texture extends _Texture {
|
|
|
52
86
|
y = parseInt(y);
|
|
53
87
|
super.updateByTexture(texture, x, y);
|
|
54
88
|
}
|
|
89
|
+
|
|
90
|
+
setSmooth(smooth = true) {
|
|
91
|
+
super.setSmooth(!!smooth);
|
|
92
|
+
}
|
|
55
93
|
}
|
|
56
94
|
|
|
57
95
|
module.exports = Texture;
|
package/package.json
CHANGED
|
@@ -57,7 +57,16 @@ inline static NAN_METHOD(GetTextureRect) {
|
|
|
57
57
|
Nan::New<v8::Int32>(rect.width),
|
|
58
58
|
Nan::New<v8::Int32>(rect.height),
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
|
|
61
|
+
Nan::TryCatch try_catch;
|
|
62
|
+
v8::MaybeLocal<v8::Object> maybe_rect =
|
|
63
|
+
rect::IntRect::NewRealInstance(info.GetIsolate(), argc, argv);
|
|
64
|
+
if (maybe_rect.IsEmpty()) {
|
|
65
|
+
try_catch.ReThrow();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
info.GetReturnValue().Set(maybe_rect.ToLocalChecked());
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
} // namespace package_plugin_texture
|
|
@@ -9,6 +9,7 @@ namespace drawable {
|
|
|
9
9
|
|
|
10
10
|
using v8::FunctionTemplate;
|
|
11
11
|
using v8::Local;
|
|
12
|
+
using v8::MaybeLocal;
|
|
12
13
|
using v8::Object;
|
|
13
14
|
|
|
14
15
|
const char rectangle_shape_name[] = "RectangleShape";
|
|
@@ -19,6 +20,14 @@ NAN_MODULE_INIT(RectangleShape::Init) {
|
|
|
19
20
|
Shape::Init<RectangleShape, rectangle_shape_name>(target);
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
void RectangleShape::SetPrototype(Local<FunctionTemplate>* _tpl) {
|
|
24
|
+
Shape::SetPrototype(_tpl);
|
|
25
|
+
|
|
26
|
+
v8::Local<v8::FunctionTemplate>& tpl = *_tpl;
|
|
27
|
+
Nan::SetPrototypeMethod(tpl, "setSize", SetSize);
|
|
28
|
+
Nan::SetPrototypeMethod(tpl, "getSize", GetSize);
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
NAN_METHOD(RectangleShape::New) {
|
|
23
32
|
Local<Object> v8_size = info[0].As<Object>();
|
|
24
33
|
vector2::Vector2F* size = Nan::ObjectWrap::Unwrap<vector2::Vector2F>(v8_size);
|
|
@@ -27,6 +36,31 @@ NAN_METHOD(RectangleShape::New) {
|
|
|
27
36
|
info.GetReturnValue().Set(info.This());
|
|
28
37
|
}
|
|
29
38
|
|
|
39
|
+
NAN_METHOD(RectangleShape::GetSize) {
|
|
40
|
+
RectangleShape* shape =
|
|
41
|
+
Nan::ObjectWrap::Unwrap<RectangleShape>(info.Holder());
|
|
42
|
+
sf::Vector2f vec = shape->raw<sf::RectangleShape>().getSize();
|
|
43
|
+
|
|
44
|
+
Nan::TryCatch try_catch;
|
|
45
|
+
MaybeLocal<Object> maybe_vec =
|
|
46
|
+
vector2::Vector2F::NewRealInstance(info.GetIsolate(), vec);
|
|
47
|
+
if (maybe_vec.IsEmpty()) {
|
|
48
|
+
try_catch.ReThrow();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
info.GetReturnValue().Set(maybe_vec.ToLocalChecked());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
NAN_METHOD(RectangleShape::SetSize) {
|
|
56
|
+
RectangleShape* shape =
|
|
57
|
+
Nan::ObjectWrap::Unwrap<RectangleShape>(info.Holder());
|
|
58
|
+
vector2::Vector2F* vec =
|
|
59
|
+
Nan::ObjectWrap::Unwrap<vector2::Vector2F>(info[0].As<Object>());
|
|
60
|
+
|
|
61
|
+
shape->raw<sf::RectangleShape>().setSize(vec->vector2());
|
|
62
|
+
}
|
|
63
|
+
|
|
30
64
|
RectangleShape::RectangleShape(const sf::Vector2f& size)
|
|
31
65
|
: Shape(new sf::RectangleShape(size)) {}
|
|
32
66
|
|
|
@@ -11,9 +11,12 @@ class RectangleShape : public Shape {
|
|
|
11
11
|
static Nan::Persistent<v8::Function> constructor;
|
|
12
12
|
|
|
13
13
|
static NAN_MODULE_INIT(Init);
|
|
14
|
+
static void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl);
|
|
14
15
|
|
|
15
16
|
public:
|
|
16
17
|
static NAN_METHOD(New);
|
|
18
|
+
static NAN_METHOD(SetSize);
|
|
19
|
+
static NAN_METHOD(GetSize);
|
|
17
20
|
|
|
18
21
|
private:
|
|
19
22
|
explicit RectangleShape(const sf::Vector2f& size);
|
package/src/image.cc
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#include "image.h"
|
|
2
|
+
|
|
3
|
+
namespace node_sfml {
|
|
4
|
+
namespace image {
|
|
5
|
+
|
|
6
|
+
using v8::Function;
|
|
7
|
+
using v8::FunctionTemplate;
|
|
8
|
+
using v8::Isolate;
|
|
9
|
+
using v8::Local;
|
|
10
|
+
using v8::MaybeLocal;
|
|
11
|
+
using v8::Object;
|
|
12
|
+
using v8::String;
|
|
13
|
+
|
|
14
|
+
Nan::Persistent<Function> constructor;
|
|
15
|
+
Nan::Persistent<Function> real_constructor;
|
|
16
|
+
|
|
17
|
+
NAN_METHOD(SetRealConstructor) {
|
|
18
|
+
real_constructor.Reset(info[0].As<v8::Function>());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
MaybeLocal<Object> Image::NewRealInstance(Isolate* isolate) {
|
|
22
|
+
v8::Local<v8::Function> cons = real_constructor.Get(isolate);
|
|
23
|
+
v8::MaybeLocal<v8::Object> maybe_ret =
|
|
24
|
+
cons->NewInstance(isolate->GetCurrentContext());
|
|
25
|
+
return maybe_ret;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
NAN_MODULE_INIT(Image::Init) {
|
|
29
|
+
Local<String> name = Nan::New("Image").ToLocalChecked();
|
|
30
|
+
|
|
31
|
+
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
|
32
|
+
|
|
33
|
+
tpl->SetClassName(name);
|
|
34
|
+
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
35
|
+
|
|
36
|
+
Local<Function> func = Nan::GetFunction(tpl).ToLocalChecked();
|
|
37
|
+
constructor.Reset(func);
|
|
38
|
+
|
|
39
|
+
Nan::Set(target, name, func);
|
|
40
|
+
Nan::SetMethod(func, "setRealConstructor", SetRealConstructor);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
NAN_METHOD(Image::New) {
|
|
44
|
+
Image* Texture = new Image();
|
|
45
|
+
Texture->Wrap(info.This());
|
|
46
|
+
info.GetReturnValue().Set(info.This());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void Image::SetInnerImage(const sf::Image& image) {
|
|
50
|
+
_image = image;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Image::Image() {}
|
|
54
|
+
|
|
55
|
+
} // namespace image
|
|
56
|
+
} // namespace node_sfml
|
package/src/image.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#ifndef SRC_IMAGE_H_
|
|
2
|
+
#define SRC_IMAGE_H_
|
|
3
|
+
|
|
4
|
+
#include <nan.h>
|
|
5
|
+
|
|
6
|
+
#include <SFML/Graphics/Image.hpp>
|
|
7
|
+
|
|
8
|
+
namespace node_sfml {
|
|
9
|
+
namespace image {
|
|
10
|
+
|
|
11
|
+
class Image : public Nan::ObjectWrap {
|
|
12
|
+
public:
|
|
13
|
+
static NAN_MODULE_INIT(Init);
|
|
14
|
+
static v8::MaybeLocal<v8::Object> NewRealInstance(v8::Isolate* isolate);
|
|
15
|
+
|
|
16
|
+
public:
|
|
17
|
+
static NAN_METHOD(New);
|
|
18
|
+
|
|
19
|
+
void SetInnerImage(const sf::Image& image);
|
|
20
|
+
inline const sf::Image& image() const { return _image; }
|
|
21
|
+
|
|
22
|
+
private:
|
|
23
|
+
Image();
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
sf::Image _image;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace image
|
|
30
|
+
} // namespace node_sfml
|
|
31
|
+
|
|
32
|
+
#endif // SRC_IMAGE_H_
|
package/src/render_window.cc
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
#include "image.h"
|
|
1
2
|
#include "render_window.h"
|
|
2
3
|
#include "color.h"
|
|
3
4
|
#include "drawable/drawable.h"
|
|
4
5
|
#include "poll_event.h"
|
|
6
|
+
#include "vector2-inl.h"
|
|
5
7
|
#include "video_mode.h"
|
|
6
8
|
|
|
7
9
|
namespace node_sfml {
|
|
@@ -22,12 +24,14 @@ NAN_MODULE_INIT(RenderWindow::Init) {
|
|
|
22
24
|
|
|
23
25
|
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
|
24
26
|
|
|
27
|
+
Nan::SetPrototypeMethod(tpl, "capture", Capture);
|
|
25
28
|
Nan::SetPrototypeMethod(tpl, "clear", Clear);
|
|
26
29
|
Nan::SetPrototypeMethod(tpl, "close", Close);
|
|
27
30
|
Nan::SetPrototypeMethod(tpl, "display", Display);
|
|
28
31
|
Nan::SetPrototypeMethod(tpl, "drawDrawable", DrawDrawable);
|
|
29
32
|
Nan::SetPrototypeMethod(tpl, "isOpen", IsOpen);
|
|
30
33
|
Nan::SetPrototypeMethod(tpl, "pollEvent", PollEvent);
|
|
34
|
+
Nan::SetPrototypeMethod(tpl, "getSize", GetSize);
|
|
31
35
|
|
|
32
36
|
#define PRIMITIVE_VALUE_PROTOTYPE_METHOD(name, _) \
|
|
33
37
|
Nan::SetPrototypeMethod(tpl, "set" #name, Set##name);
|
|
@@ -116,6 +120,24 @@ NAN_METHOD(RenderWindow::New) {
|
|
|
116
120
|
info.GetReturnValue().Set(info.This());
|
|
117
121
|
}
|
|
118
122
|
|
|
123
|
+
NAN_METHOD(RenderWindow::Capture) {
|
|
124
|
+
RenderWindow* window = Nan::ObjectWrap::Unwrap<RenderWindow>(info.Holder());
|
|
125
|
+
sf::Image img = window->_window->capture();
|
|
126
|
+
|
|
127
|
+
Nan::TryCatch try_catch;
|
|
128
|
+
MaybeLocal<Object> maybe_img = image::Image::NewRealInstance(info.GetIsolate());
|
|
129
|
+
if (maybe_img.IsEmpty()) {
|
|
130
|
+
try_catch.ReThrow();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
Local<Object> img_obj = maybe_img.ToLocalChecked();
|
|
135
|
+
image::Image* node_sfml_img = Nan::ObjectWrap::Unwrap<image::Image>(img_obj);
|
|
136
|
+
node_sfml_img->SetInnerImage(img);
|
|
137
|
+
|
|
138
|
+
info.GetReturnValue().Set(img_obj);
|
|
139
|
+
}
|
|
140
|
+
|
|
119
141
|
NAN_METHOD(RenderWindow::Clear) {
|
|
120
142
|
RenderWindow* window = Nan::ObjectWrap::Unwrap<RenderWindow>(info.Holder());
|
|
121
143
|
color::Color* color =
|
|
@@ -161,6 +183,21 @@ NAN_METHOD(RenderWindow::PollEvent) {
|
|
|
161
183
|
info.GetReturnValue().Set(v8_event.ToLocalChecked());
|
|
162
184
|
}
|
|
163
185
|
|
|
186
|
+
NAN_METHOD(RenderWindow::GetSize) {
|
|
187
|
+
RenderWindow* window = Nan::ObjectWrap::Unwrap<RenderWindow>(info.Holder());
|
|
188
|
+
sf::Vector2u vec = window->_window->getSize();
|
|
189
|
+
|
|
190
|
+
Nan::TryCatch try_catch;
|
|
191
|
+
MaybeLocal<Object> maybe_vec =
|
|
192
|
+
vector2::Vector2U::NewRealInstance(info.GetIsolate(), vec);
|
|
193
|
+
if (maybe_vec.IsEmpty()) {
|
|
194
|
+
try_catch.ReThrow();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
info.GetReturnValue().Set(maybe_vec.ToLocalChecked());
|
|
199
|
+
}
|
|
200
|
+
|
|
164
201
|
#define SET_PRIMITIVE_VALUE(name, type) \
|
|
165
202
|
NAN_METHOD(RenderWindow::Set##name) { \
|
|
166
203
|
RenderWindow* window = \
|
package/src/render_window.h
CHANGED
|
@@ -18,12 +18,14 @@ class RenderWindow : public Nan::ObjectWrap {
|
|
|
18
18
|
private:
|
|
19
19
|
static NAN_METHOD(New);
|
|
20
20
|
|
|
21
|
+
static NAN_METHOD(Capture);
|
|
21
22
|
static NAN_METHOD(Clear);
|
|
22
23
|
static NAN_METHOD(Close);
|
|
23
24
|
static NAN_METHOD(Display);
|
|
24
25
|
static NAN_METHOD(DrawDrawable);
|
|
25
26
|
static NAN_METHOD(IsOpen);
|
|
26
27
|
static NAN_METHOD(PollEvent);
|
|
28
|
+
static NAN_METHOD(GetSize);
|
|
27
29
|
|
|
28
30
|
#define PRIMITIVE_VALUES(V) \
|
|
29
31
|
V(Visible, bool) \
|
package/src/sfml.cc
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include "clock.h"
|
|
4
4
|
#include "color.h"
|
|
5
5
|
#include "font.h"
|
|
6
|
+
#include "image.h"
|
|
6
7
|
#include "keyboard.h"
|
|
7
8
|
#include "mouse.h"
|
|
8
9
|
#include "rect.h"
|
|
@@ -27,6 +28,7 @@ void Init(v8::Local<v8::Object> target) {
|
|
|
27
28
|
clock::Clock::Init(target);
|
|
28
29
|
color::Color::Init(target);
|
|
29
30
|
font::Font::Init(target);
|
|
31
|
+
image::Image::Init(target);
|
|
30
32
|
render_window::RenderWindow::Init(target);
|
|
31
33
|
texture::Texture::Init(target);
|
|
32
34
|
time::Time::Init(target);
|
package/src/texture.cc
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#include "image.h"
|
|
1
2
|
#include "texture.h"
|
|
2
3
|
#include "rect.h"
|
|
3
4
|
#include "vector2.h"
|
|
@@ -77,10 +78,15 @@ NAN_MODULE_INIT(Texture::Init) {
|
|
|
77
78
|
|
|
78
79
|
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
|
79
80
|
|
|
81
|
+
Nan::SetPrototypeMethod(tpl, "create", Create);
|
|
80
82
|
Nan::SetPrototypeMethod(tpl, "loadFromFile", LoadFromFile);
|
|
81
83
|
Nan::SetPrototypeMethod(tpl, "getSize", GetSize);
|
|
84
|
+
|
|
85
|
+
Nan::SetPrototypeMethod(tpl, "updateByImage", UpdateByImage);
|
|
82
86
|
Nan::SetPrototypeMethod(tpl, "updateByTexture", UpdateByTexture);
|
|
83
87
|
|
|
88
|
+
Nan::SetPrototypeMethod(tpl, "setSmooth", SetSmooth);
|
|
89
|
+
|
|
84
90
|
tpl->SetClassName(name);
|
|
85
91
|
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
86
92
|
|
|
@@ -96,6 +102,13 @@ NAN_METHOD(Texture::New) {
|
|
|
96
102
|
info.GetReturnValue().Set(info.This());
|
|
97
103
|
}
|
|
98
104
|
|
|
105
|
+
NAN_METHOD(Texture::Create) {
|
|
106
|
+
Texture* texture = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
|
|
107
|
+
sf::Uint32 w = Nan::To<sf::Uint32>(info[0]).FromJust();
|
|
108
|
+
sf::Uint32 h = Nan::To<sf::Uint32>(info[1]).FromJust();
|
|
109
|
+
texture->_texture.create(w, h);
|
|
110
|
+
}
|
|
111
|
+
|
|
99
112
|
// TODO(XadillaX): more Node.js-styled `LoadFromFile`
|
|
100
113
|
NAN_METHOD(Texture::LoadFromFile) {
|
|
101
114
|
Texture* texture = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
|
|
@@ -143,6 +156,12 @@ NAN_METHOD(Texture::GetSize) {
|
|
|
143
156
|
info.GetReturnValue().Set(size_obj.ToLocalChecked());
|
|
144
157
|
}
|
|
145
158
|
|
|
159
|
+
NAN_METHOD(Texture::SetSmooth) {
|
|
160
|
+
Texture* texture = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
|
|
161
|
+
bool smooth = Nan::To<bool>(info[0]).FromJust();
|
|
162
|
+
texture->_texture.setSmooth(smooth);
|
|
163
|
+
}
|
|
164
|
+
|
|
146
165
|
NAN_METHOD(Texture::UpdateByTexture) {
|
|
147
166
|
Texture* texture = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
|
|
148
167
|
if (texture->_loading) {
|
|
@@ -161,6 +180,24 @@ NAN_METHOD(Texture::UpdateByTexture) {
|
|
|
161
180
|
texture->_texture.update(another->_texture, x, y);
|
|
162
181
|
}
|
|
163
182
|
|
|
183
|
+
NAN_METHOD(Texture::UpdateByImage) {
|
|
184
|
+
Texture* texture = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
|
|
185
|
+
if (texture->_loading) {
|
|
186
|
+
Nan::ThrowError("Texture is loading.");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
image::Image* img = Nan::ObjectWrap::Unwrap<image::Image>(info[0].As<Object>());
|
|
191
|
+
if (info.Length() <= 1) {
|
|
192
|
+
texture->_texture.update(img->image());
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
sf::Uint32 x = Nan::To<sf::Uint32>(info[1]).FromJust();
|
|
197
|
+
sf::Uint32 y = Nan::To<sf::Uint32>(info[2]).FromJust();
|
|
198
|
+
texture->_texture.update(img->image(), x, y);
|
|
199
|
+
}
|
|
200
|
+
|
|
164
201
|
Texture::Texture() : _texture(), _loading(false) {}
|
|
165
202
|
Texture::Texture(const Texture& texture)
|
|
166
203
|
: _texture(texture._texture), _loading(false) {}
|
package/src/texture.h
CHANGED
|
@@ -14,10 +14,14 @@ class Texture : public Nan::ObjectWrap {
|
|
|
14
14
|
|
|
15
15
|
public:
|
|
16
16
|
static NAN_METHOD(New);
|
|
17
|
+
static NAN_METHOD(Create);
|
|
17
18
|
static NAN_METHOD(LoadFromFile);
|
|
18
19
|
static NAN_METHOD(GetSize);
|
|
19
20
|
|
|
21
|
+
static NAN_METHOD(SetSmooth);
|
|
22
|
+
|
|
20
23
|
// Update family
|
|
24
|
+
static NAN_METHOD(UpdateByImage);
|
|
21
25
|
static NAN_METHOD(UpdateByTexture);
|
|
22
26
|
|
|
23
27
|
inline const sf::Texture& texture() const { return _texture; }
|