sfml.js 0.0.1-preview.19 → 0.0.1-preview.22
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 +0 -1
- package/lib/clock.d.ts +1 -1
- package/lib/color.d.ts +4 -2
- package/lib/drawable/circle_shape.d.ts +3 -1
- package/lib/drawable/circle_shape.js +1 -1
- package/lib/drawable/convex_shape.d.ts +3 -3
- package/lib/drawable/convex_shape.js +2 -2
- package/lib/drawable/drawable.d.ts +8 -0
- package/lib/drawable/{base.js → drawable.js} +7 -4
- package/lib/drawable/plugin_package.d.ts +31 -0
- package/lib/drawable/plugin_package.js +102 -0
- package/lib/drawable/rectangle_shape.d.ts +4 -2
- package/lib/drawable/shape.d.ts +10 -2
- package/lib/drawable/shape.js +15 -4
- package/lib/drawable/sprite.d.ts +8 -13
- package/lib/drawable/sprite.js +13 -29
- package/lib/drawable/text.d.ts +7 -5
- package/lib/drawable/text.js +17 -9
- package/lib/drawable/{common_drawable.d.ts → transformable.d.ts} +11 -16
- package/lib/drawable/transformable.js +94 -0
- package/lib/font.js +1 -1
- package/lib/keyboard.js +1 -1
- package/lib/mouse.d.ts +1 -1
- package/lib/mouse.js +1 -1
- package/lib/rect.d.ts +1 -1
- package/lib/rect.js +1 -1
- package/lib/render_window.d.ts +3 -3
- package/lib/render_window.js +3 -3
- package/lib/texture.js +2 -2
- package/lib/time.d.ts +1 -1
- package/lib/vector2.js +1 -1
- package/lib/video_mode.d.ts +1 -1
- package/package.json +2 -3
- package/src/clock.h +1 -1
- package/src/color.h +1 -1
- package/src/drawable/circle_shape.cc +2 -1
- package/src/drawable/convex_shape.cc +3 -2
- package/src/drawable/drawable.cc +25 -0
- package/src/drawable/drawable.h +15 -1
- package/src/drawable/package_plugin-inl.h +181 -0
- package/src/drawable/package_plugin.h +60 -0
- package/src/drawable/rectangle_shape.cc +3 -2
- package/src/drawable/shape.cc +18 -8
- package/src/drawable/shape.h +14 -2
- package/src/drawable/sprite.cc +18 -54
- package/src/drawable/sprite.h +11 -9
- package/src/drawable/text.cc +8 -5
- package/src/drawable/text.h +11 -2
- package/src/font.h +1 -1
- package/src/keyboard.h +5 -1
- package/src/mouse.h +5 -1
- package/src/plugins/transformable_plugin-inl.h +121 -0
- package/src/plugins/transformable_plugin.h +42 -0
- package/src/poll_event.h +2 -1
- package/src/rect.h +1 -0
- package/src/render_window.h +3 -1
- package/src/texture.h +2 -1
- package/src/time.h +2 -1
- package/src/utils.h +1 -0
- package/src/vector2.h +3 -1
- package/src/video_mode.h +2 -1
- package/lib/drawable/base.d.ts +0 -3
- package/lib/drawable/common_drawable.js +0 -116
- package/src/drawable/common_drawable-inl.h +0 -198
- package/src/drawable/common_drawable.cc +0 -14
- package/src/drawable/common_drawable.h +0 -78
package/lib/mouse.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
getPosition: _getPosition,
|
|
5
|
-
setPosition: _setPosition,
|
|
6
5
|
isButtonPressed: _isButtonPressed,
|
|
6
|
+
setPosition: _setPosition,
|
|
7
7
|
} = require('../build/Release/binding.node');
|
|
8
8
|
const RenderWindow = require('./render_window');
|
|
9
9
|
const { Vector2I } = require('./vector2');
|
package/lib/rect.d.ts
CHANGED
package/lib/rect.js
CHANGED
|
@@ -4,7 +4,7 @@ const util = require('util');
|
|
|
4
4
|
|
|
5
5
|
const { FloatRect: _FloatRect, IntRect: _IntRect } = require('../build/Release/binding.node');
|
|
6
6
|
const { validateTypeOf } = require('./common');
|
|
7
|
-
const {
|
|
7
|
+
const { Vector2F, Vector2I } = require('./vector2');
|
|
8
8
|
|
|
9
9
|
function createClass(name, BaseClz, Vector) {
|
|
10
10
|
return class Rect extends BaseClz {
|
package/lib/render_window.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as VideoMode from './video_mode';
|
|
2
1
|
import * as Drawable from './drawable/base';
|
|
3
2
|
import * as Event from './poll_event';
|
|
3
|
+
import * as VideoMode from './video_mode';
|
|
4
4
|
|
|
5
5
|
declare class RenderWindow {
|
|
6
6
|
constructor(videoMode?: VideoMode, title?: string, style?: RenderWindow.Style);
|
|
7
7
|
|
|
8
|
-
clear(color: number
|
|
8
|
+
clear(color: number): void;
|
|
9
9
|
close(): void;
|
|
10
10
|
draw(content: Drawable): void;
|
|
11
11
|
display(): void;
|
|
@@ -19,7 +19,7 @@ declare class RenderWindow {
|
|
|
19
19
|
setMouseCursorGrabbed(grabbed: boolean): void;
|
|
20
20
|
setKeyRepeatEnabled(enabled: boolean): void;
|
|
21
21
|
setFramerateLimit(limit: number): void;
|
|
22
|
-
setActive(active?: boolean
|
|
22
|
+
setActive(active?: boolean): void;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
declare namespace RenderWindow {
|
package/lib/render_window.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const Color = require('./color');
|
|
4
|
+
const Drawable = require('./drawable/drawable');
|
|
3
5
|
const { RenderWindow: _RenderWindow } = require('../build/Release/binding.node');
|
|
4
6
|
const { validateTypeOf } = require('./common');
|
|
5
7
|
const VideoMode = require('./video_mode');
|
|
6
|
-
const Color = require('./color');
|
|
7
|
-
const Drawable = require('./drawable/base');
|
|
8
8
|
|
|
9
9
|
const DRAW_DRAWABLE = Symbol('RenderWindow::drawDrawable');
|
|
10
10
|
const RAW_RENDER_WINDOW = Symbol('RenderWindow::rawRenderWindow');
|
|
@@ -46,7 +46,7 @@ class RenderWindow {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
[DRAW_DRAWABLE](content) {
|
|
49
|
-
this[RAW_RENDER_WINDOW].drawDrawable(content
|
|
49
|
+
this[RAW_RENDER_WINDOW].drawDrawable(content._raw());
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
display() {
|
package/lib/texture.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
5
|
require('./vector2');
|
|
6
|
-
const { Texture: _Texture } = require('../build/Release/binding.node');
|
|
7
|
-
const { IntRect } = require('./rect');
|
|
8
6
|
const { createDeferred, validateTypeOf } = require('./common');
|
|
7
|
+
const { IntRect } = require('./rect');
|
|
8
|
+
const { Texture: _Texture } = require('../build/Release/binding.node');
|
|
9
9
|
|
|
10
10
|
class Texture extends _Texture {
|
|
11
11
|
async loadFromFile(filename, area) {
|
package/lib/time.d.ts
CHANGED
package/lib/vector2.js
CHANGED
package/lib/video_mode.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ declare class VideoMode {
|
|
|
2
2
|
static getDesktopMode(): VideoMode;
|
|
3
3
|
static getFullscreenModes(): VideoMode[];
|
|
4
4
|
|
|
5
|
-
constructor(modeWidth?: number, modeHeight?: number, modeBitsPerPixel
|
|
5
|
+
constructor(modeWidth?: number, modeHeight?: number, modeBitsPerPixel?: number);
|
|
6
6
|
|
|
7
7
|
isValid(): boolean;
|
|
8
8
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfml.js",
|
|
3
|
-
"version": "0.0.1-preview.
|
|
3
|
+
"version": "0.0.1-preview.22",
|
|
4
4
|
"description": "SFML's Node.js binding.",
|
|
5
5
|
"main": "lib/sfml.js",
|
|
6
6
|
"scripts": {
|
|
@@ -46,6 +46,5 @@
|
|
|
46
46
|
"third_party/sfml/platform/macOS/lib/libsfml-graphics.2.5.1.dylib",
|
|
47
47
|
"third_party/sfml/platform/macOS/Frameworks/**/*",
|
|
48
48
|
"tools/*"
|
|
49
|
-
]
|
|
50
|
-
"__npminstall_done": false
|
|
49
|
+
]
|
|
51
50
|
}
|
package/src/clock.h
CHANGED
package/src/color.h
CHANGED
package/src/drawable/drawable.cc
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
#include "drawable.h"
|
|
2
|
+
#include "../texture.h"
|
|
2
3
|
|
|
3
4
|
namespace node_sfml {
|
|
4
5
|
namespace drawable {
|
|
5
6
|
|
|
7
|
+
using v8::Isolate;
|
|
8
|
+
using v8::Local;
|
|
9
|
+
using v8::MaybeLocal;
|
|
10
|
+
using v8::Object;
|
|
11
|
+
|
|
6
12
|
Drawable::Drawable() : _raw(nullptr) {}
|
|
7
13
|
Drawable::Drawable(sf::Drawable* raw) : _raw(raw) {}
|
|
8
14
|
Drawable::~Drawable() {
|
|
@@ -12,5 +18,24 @@ Drawable::~Drawable() {
|
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
|
|
21
|
+
DrawableWithTexture::DrawableWithTexture() : Drawable(nullptr) {}
|
|
22
|
+
DrawableWithTexture::DrawableWithTexture(sf::Drawable* raw) : Drawable(raw) {}
|
|
23
|
+
DrawableWithTexture::~DrawableWithTexture() {
|
|
24
|
+
_texture.Reset();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void DrawableWithTexture::SetTexture(Local<Object> texture_object,
|
|
28
|
+
bool reset_rect) {
|
|
29
|
+
_texture.Reset(texture_object);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
MaybeLocal<Object> DrawableWithTexture::GetTexture() {
|
|
33
|
+
if (_texture.IsEmpty()) {
|
|
34
|
+
return MaybeLocal<Object>();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return _texture.Get(Isolate::GetCurrent());
|
|
38
|
+
}
|
|
39
|
+
|
|
15
40
|
} // namespace drawable
|
|
16
41
|
} // namespace node_sfml
|
package/src/drawable/drawable.h
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#define SRC_DRAWABLE_DRAWABLE_H_
|
|
3
3
|
|
|
4
4
|
#include <nan.h>
|
|
5
|
-
#include <SFML/Graphics.hpp>
|
|
5
|
+
#include <SFML/Graphics/Drawable.hpp>
|
|
6
6
|
|
|
7
7
|
namespace node_sfml {
|
|
8
8
|
namespace drawable {
|
|
@@ -29,6 +29,20 @@ class Drawable : public Nan::ObjectWrap {
|
|
|
29
29
|
sf::Drawable* _raw;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
class DrawableWithTexture : public Drawable {
|
|
33
|
+
public:
|
|
34
|
+
DrawableWithTexture();
|
|
35
|
+
explicit DrawableWithTexture(sf::Drawable* raw);
|
|
36
|
+
virtual ~DrawableWithTexture();
|
|
37
|
+
|
|
38
|
+
virtual void SetTexture(v8::Local<v8::Object> texture_object,
|
|
39
|
+
bool reset_rect = false);
|
|
40
|
+
v8::MaybeLocal<v8::Object> GetTexture();
|
|
41
|
+
|
|
42
|
+
private:
|
|
43
|
+
Nan::Persistent<v8::Object> _texture;
|
|
44
|
+
};
|
|
45
|
+
|
|
32
46
|
} // namespace drawable
|
|
33
47
|
} // namespace node_sfml
|
|
34
48
|
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#ifndef SRC_DRAWABLE_PACKAGE_PLUGIN_INL_H_
|
|
2
|
+
#define SRC_DRAWABLE_PACKAGE_PLUGIN_INL_H_
|
|
3
|
+
|
|
4
|
+
#include "../color.h"
|
|
5
|
+
#include "../rect-inl.h"
|
|
6
|
+
#include "../texture.h"
|
|
7
|
+
#include "drawable.h"
|
|
8
|
+
#include "package_plugin.h"
|
|
9
|
+
|
|
10
|
+
namespace node_sfml {
|
|
11
|
+
namespace drawable {
|
|
12
|
+
namespace package_plugin_texture {
|
|
13
|
+
|
|
14
|
+
template <class T, class RAW_T>
|
|
15
|
+
inline void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl) {
|
|
16
|
+
v8::Local<v8::FunctionTemplate>& tpl = *_tpl;
|
|
17
|
+
|
|
18
|
+
Nan::SetPrototypeMethod(tpl, "setTexture", SetTexture<T>);
|
|
19
|
+
Nan::SetPrototypeMethod(tpl, "getTexture", GetTexture<T>);
|
|
20
|
+
Nan::SetPrototypeMethod(tpl, "setTextureRect", SetTextureRect<RAW_T>);
|
|
21
|
+
Nan::SetPrototypeMethod(tpl, "getTextureRect", GetTextureRect<RAW_T>);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
template <class T>
|
|
25
|
+
inline static NAN_METHOD(SetTexture) {
|
|
26
|
+
T* drawable = Nan::ObjectWrap::Unwrap<T>(info.Holder());
|
|
27
|
+
drawable->SetTexture(info[0].As<v8::Object>());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
template <class T>
|
|
31
|
+
inline static NAN_METHOD(SetTextureRect) {
|
|
32
|
+
Drawable* target = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
33
|
+
rect::IntRect* rect =
|
|
34
|
+
Nan::ObjectWrap::Unwrap<rect::IntRect>(info[0].As<v8::Object>());
|
|
35
|
+
target->raw<T>().setTextureRect(rect->rect());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
template <class T>
|
|
39
|
+
inline static NAN_METHOD(GetTexture) {
|
|
40
|
+
T* drawable = Nan::ObjectWrap::Unwrap<T>(info.Holder());
|
|
41
|
+
v8::MaybeLocal<v8::Object> texture = drawable->GetTexture();
|
|
42
|
+
if (texture.IsEmpty()) {
|
|
43
|
+
info.GetReturnValue().Set(Nan::Null());
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
info.GetReturnValue().Set(texture.ToLocalChecked());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
template <class T>
|
|
50
|
+
inline static NAN_METHOD(GetTextureRect) {
|
|
51
|
+
Drawable* sprite = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
52
|
+
sf::IntRect rect = sprite->raw<T>().getTextureRect();
|
|
53
|
+
int argc = 4;
|
|
54
|
+
v8::Local<v8::Value> argv[] = {
|
|
55
|
+
Nan::New<v8::Int32>(rect.left),
|
|
56
|
+
Nan::New<v8::Int32>(rect.top),
|
|
57
|
+
Nan::New<v8::Int32>(rect.width),
|
|
58
|
+
Nan::New<v8::Int32>(rect.height),
|
|
59
|
+
};
|
|
60
|
+
rect::IntRect::NewRealInstance(info.GetIsolate(), argc, argv);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
} // namespace package_plugin_texture
|
|
64
|
+
|
|
65
|
+
namespace package_plugin_bounds {
|
|
66
|
+
|
|
67
|
+
template <class T>
|
|
68
|
+
inline void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl) {
|
|
69
|
+
v8::Local<v8::FunctionTemplate>& tpl = *_tpl;
|
|
70
|
+
|
|
71
|
+
Nan::SetPrototypeMethod(tpl, "getLocalBounds", GetLocalBounds<T>);
|
|
72
|
+
Nan::SetPrototypeMethod(tpl, "getGlobalBounds", GetGlobalBounds<T>);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#define GET_BOUNDS_IMPL(type) \
|
|
76
|
+
template <class T> \
|
|
77
|
+
inline NAN_METHOD(Get##type##Bounds) { \
|
|
78
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder()); \
|
|
79
|
+
sf::FloatRect rect = drawable->raw<T>().get##type##Bounds(); \
|
|
80
|
+
\
|
|
81
|
+
Nan::TryCatch try_catch; \
|
|
82
|
+
v8::MaybeLocal<v8::Object> maybe_rect = \
|
|
83
|
+
rect::FloatRect::NewRealInstance(info.GetIsolate()); \
|
|
84
|
+
if (try_catch.HasCaught()) { \
|
|
85
|
+
try_catch.ReThrow(); \
|
|
86
|
+
return; \
|
|
87
|
+
} \
|
|
88
|
+
\
|
|
89
|
+
v8::Local<v8::Object> node_rect = maybe_rect.ToLocalChecked(); \
|
|
90
|
+
sf::FloatRect& ret = \
|
|
91
|
+
Nan::ObjectWrap::Unwrap<rect::FloatRect>(node_rect)->rect(); \
|
|
92
|
+
ret.top = rect.top; \
|
|
93
|
+
ret.left = rect.left; \
|
|
94
|
+
ret.width = rect.width; \
|
|
95
|
+
ret.height = rect.height; \
|
|
96
|
+
\
|
|
97
|
+
info.GetReturnValue().Set(node_rect); \
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
GET_BOUNDS_IMPL(Local);
|
|
101
|
+
GET_BOUNDS_IMPL(Global);
|
|
102
|
+
|
|
103
|
+
#undef GET_BOUNDS_IMPL
|
|
104
|
+
|
|
105
|
+
} // namespace package_plugin_bounds
|
|
106
|
+
|
|
107
|
+
namespace package_plugin_color_and_thickness {
|
|
108
|
+
|
|
109
|
+
template <class T>
|
|
110
|
+
inline void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl) {
|
|
111
|
+
v8::Local<v8::FunctionTemplate>& tpl = *_tpl;
|
|
112
|
+
|
|
113
|
+
Nan::SetPrototypeMethod(tpl, "setFillColor", SetFillColor<T>);
|
|
114
|
+
Nan::SetPrototypeMethod(tpl, "getFillColor", GetFillColor<T>);
|
|
115
|
+
|
|
116
|
+
Nan::SetPrototypeMethod(tpl, "setOutlineColor", SetOutlineColor<T>);
|
|
117
|
+
Nan::SetPrototypeMethod(tpl, "getOutlineColor", GetOutlineColor<T>);
|
|
118
|
+
|
|
119
|
+
Nan::SetPrototypeMethod(tpl, "setOutlineThickness", SetOutlineThickness<T>);
|
|
120
|
+
Nan::SetPrototypeMethod(tpl, "getOutlineThickness", GetOutlineThickness<T>);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
template <class T>
|
|
124
|
+
inline NAN_METHOD(SetFillColor) {
|
|
125
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
126
|
+
color::Color* color =
|
|
127
|
+
Nan::ObjectWrap::Unwrap<color::Color>(info[0].As<v8::Object>());
|
|
128
|
+
drawable->raw<T>().setFillColor(color->color());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
template <class T>
|
|
132
|
+
inline NAN_METHOD(GetFillColor) {
|
|
133
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
134
|
+
const sf::Color color = drawable->raw<T>().getFillColor();
|
|
135
|
+
|
|
136
|
+
v8::MaybeLocal<v8::Object> ret =
|
|
137
|
+
color::Color::NewRealColorInstance(info.GetIsolate(), color.toInteger());
|
|
138
|
+
if (ret.IsEmpty()) return;
|
|
139
|
+
|
|
140
|
+
info.GetReturnValue().Set(ret.ToLocalChecked());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
template <class T>
|
|
144
|
+
inline NAN_METHOD(SetOutlineColor) {
|
|
145
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
146
|
+
color::Color* color =
|
|
147
|
+
Nan::ObjectWrap::Unwrap<color::Color>(info[0].As<v8::Object>());
|
|
148
|
+
drawable->raw<T>().setOutlineColor(color->color());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
template <class T>
|
|
152
|
+
inline NAN_METHOD(GetOutlineColor) {
|
|
153
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
154
|
+
const sf::Color color = drawable->raw<T>().getOutlineColor();
|
|
155
|
+
|
|
156
|
+
v8::MaybeLocal<v8::Object> ret =
|
|
157
|
+
color::Color::NewRealColorInstance(info.GetIsolate(), color.toInteger());
|
|
158
|
+
if (ret.IsEmpty()) return;
|
|
159
|
+
|
|
160
|
+
info.GetReturnValue().Set(ret.ToLocalChecked());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
template <class T>
|
|
164
|
+
inline NAN_METHOD(SetOutlineThickness) {
|
|
165
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
166
|
+
float thickness = static_cast<float>(Nan::To<double>(info[0]).FromJust());
|
|
167
|
+
drawable->raw<T>().setOutlineThickness(thickness);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
template <class T>
|
|
171
|
+
inline NAN_METHOD(GetOutlineThickness) {
|
|
172
|
+
Drawable* drawable = Nan::ObjectWrap::Unwrap<Drawable>(info.Holder());
|
|
173
|
+
float thickness = drawable->raw<T>().getOutlineThickness();
|
|
174
|
+
info.GetReturnValue().Set(static_cast<double>(thickness));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
} // namespace package_plugin_color_and_thickness
|
|
178
|
+
} // namespace drawable
|
|
179
|
+
} // namespace node_sfml
|
|
180
|
+
|
|
181
|
+
#endif // SRC_DRAWABLE_PACKAGE_PLUGIN_INL_H_
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#ifndef SRC_DRAWABLE_PACKAGE_PLUGIN_H_
|
|
2
|
+
#define SRC_DRAWABLE_PACKAGE_PLUGIN_H_
|
|
3
|
+
|
|
4
|
+
#include <nan.h>
|
|
5
|
+
|
|
6
|
+
namespace node_sfml {
|
|
7
|
+
namespace drawable {
|
|
8
|
+
namespace package_plugin_texture {
|
|
9
|
+
|
|
10
|
+
template <class T, class RAW_T>
|
|
11
|
+
inline void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl);
|
|
12
|
+
|
|
13
|
+
template <class T>
|
|
14
|
+
inline static NAN_METHOD(SetTexture);
|
|
15
|
+
template <class T>
|
|
16
|
+
inline static NAN_METHOD(SetTextureRect);
|
|
17
|
+
template <class T>
|
|
18
|
+
inline static NAN_METHOD(GetTexture);
|
|
19
|
+
template <class T>
|
|
20
|
+
inline static NAN_METHOD(GetTextureRect);
|
|
21
|
+
|
|
22
|
+
} // namespace package_plugin_texture
|
|
23
|
+
|
|
24
|
+
namespace package_plugin_bounds {
|
|
25
|
+
|
|
26
|
+
template <class T>
|
|
27
|
+
inline void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl);
|
|
28
|
+
|
|
29
|
+
template <class T>
|
|
30
|
+
inline static NAN_METHOD(GetLocalBounds);
|
|
31
|
+
template <class T>
|
|
32
|
+
inline static NAN_METHOD(GetGlobalBounds);
|
|
33
|
+
|
|
34
|
+
} // namespace package_plugin_bounds
|
|
35
|
+
|
|
36
|
+
namespace package_plugin_color_and_thickness {
|
|
37
|
+
|
|
38
|
+
template <class T>
|
|
39
|
+
inline void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl);
|
|
40
|
+
|
|
41
|
+
template <class T>
|
|
42
|
+
inline static NAN_METHOD(SetFillColor);
|
|
43
|
+
template <class T>
|
|
44
|
+
inline static NAN_METHOD(GetFillColor);
|
|
45
|
+
|
|
46
|
+
template <class T>
|
|
47
|
+
inline static NAN_METHOD(SetOutlineColor);
|
|
48
|
+
template <class T>
|
|
49
|
+
inline static NAN_METHOD(GetOutlineColor);
|
|
50
|
+
|
|
51
|
+
template <class T>
|
|
52
|
+
inline static NAN_METHOD(SetOutlineThickness);
|
|
53
|
+
template <class T>
|
|
54
|
+
inline static NAN_METHOD(GetOutlineThickness);
|
|
55
|
+
|
|
56
|
+
} // namespace package_plugin_color_and_thickness
|
|
57
|
+
} // namespace drawable
|
|
58
|
+
} // namespace node_sfml
|
|
59
|
+
|
|
60
|
+
#endif // SRC_DRAWABLE_PACKAGE_PLUGIN_H_
|
package/src/drawable/shape.cc
CHANGED
|
@@ -2,22 +2,25 @@
|
|
|
2
2
|
#define SRC_DRAWABLE_SHAPE_INL_H_
|
|
3
3
|
|
|
4
4
|
#include "shape.h"
|
|
5
|
-
#include "../
|
|
6
|
-
#include "
|
|
7
|
-
#include "../vector2-inl.h"
|
|
8
|
-
#include "common_drawable-inl.h"
|
|
9
|
-
#include "drawable-inl.h"
|
|
5
|
+
#include "../plugins/transformable_plugin-inl.h"
|
|
6
|
+
#include "package_plugin-inl.h"
|
|
10
7
|
|
|
11
8
|
namespace node_sfml {
|
|
12
9
|
namespace drawable {
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
using v8::Local;
|
|
12
|
+
using v8::Object;
|
|
16
13
|
|
|
14
|
+
void Shape::SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl) {
|
|
17
15
|
v8::Local<v8::FunctionTemplate>& tpl = *_tpl;
|
|
18
16
|
|
|
19
17
|
Nan::SetPrototypeMethod(tpl, "getPointCount", GetPointCount);
|
|
20
18
|
Nan::SetPrototypeMethod(tpl, "getPoint", GetPoint);
|
|
19
|
+
|
|
20
|
+
transformable::SetPrototype<Shape>(_tpl);
|
|
21
|
+
package_plugin_bounds::SetPrototype<sf::Shape>(_tpl);
|
|
22
|
+
package_plugin_color_and_thickness::SetPrototype<sf::Shape>(_tpl);
|
|
23
|
+
package_plugin_texture::SetPrototype<Shape, sf::Shape>(_tpl);
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
NAN_METHOD(Shape::GetPointCount) {
|
|
@@ -47,7 +50,14 @@ NAN_METHOD(Shape::GetPoint) {
|
|
|
47
50
|
info.GetReturnValue().Set(maybe_vec.ToLocalChecked());
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
Shape::Shape(sf::Shape* raw) :
|
|
53
|
+
Shape::Shape(sf::Shape* raw) : DrawableWithTexture(raw) {}
|
|
54
|
+
|
|
55
|
+
void Shape::SetTexture(Local<Object> texture_object, bool reset_rect) {
|
|
56
|
+
texture::Texture* texture =
|
|
57
|
+
Nan::ObjectWrap::Unwrap<texture::Texture>(texture_object);
|
|
58
|
+
raw<sf::Shape>().setTexture(&texture->texture());
|
|
59
|
+
DrawableWithTexture::SetTexture(texture_object);
|
|
60
|
+
}
|
|
51
61
|
|
|
52
62
|
} // namespace drawable
|
|
53
63
|
} // namespace node_sfml
|
package/src/drawable/shape.h
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
#ifndef SRC_DRAWABLE_SHAPE_H_
|
|
2
2
|
#define SRC_DRAWABLE_SHAPE_H_
|
|
3
3
|
|
|
4
|
-
#include
|
|
4
|
+
#include <SFML/Graphics/Shape.hpp>
|
|
5
|
+
#include <SFML/Graphics/Transformable.hpp>
|
|
6
|
+
|
|
7
|
+
#include "drawable.h"
|
|
5
8
|
|
|
6
9
|
namespace node_sfml {
|
|
7
10
|
namespace drawable {
|
|
8
11
|
|
|
9
|
-
class Shape : public
|
|
12
|
+
class Shape : public DrawableWithTexture {
|
|
10
13
|
public:
|
|
11
14
|
static void SetPrototype(v8::Local<v8::FunctionTemplate>* _tpl);
|
|
12
15
|
|
|
16
|
+
const sf::Shape& transformable() const {
|
|
17
|
+
return *reinterpret_cast<sf::Shape*>(_raw);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
sf::Shape& transformable() { return *reinterpret_cast<sf::Shape*>(_raw); }
|
|
21
|
+
|
|
22
|
+
virtual void SetTexture(v8::Local<v8::Object> texture_object,
|
|
23
|
+
bool reset_rect = false);
|
|
24
|
+
|
|
13
25
|
protected:
|
|
14
26
|
static NAN_METHOD(GetPointCount);
|
|
15
27
|
static NAN_METHOD(GetPoint);
|