@kmamal/sdl 0.10.7 → 0.10.9
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.md
CHANGED
|
@@ -208,6 +208,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
208
208
|
* [window.stopFlashing()](#windowstopflashing)
|
|
209
209
|
* [window.destroyed](#windowdestroyed)
|
|
210
210
|
* [window.destroy()](#windowdestroy)
|
|
211
|
+
* [window.destroyGently()](#windowdestroygently)
|
|
211
212
|
* [sdl.keyboard](#sdlkeyboard)
|
|
212
213
|
* [Virtual keys](#virtual-keys)
|
|
213
214
|
* [Enum: SCANCODE](#enum-scancode)
|
|
@@ -1058,6 +1059,11 @@ A destroyed window object should not be used any further.
|
|
|
1058
1059
|
|
|
1059
1060
|
Destroys the window.
|
|
1060
1061
|
|
|
1062
|
+
### window.destroyGently()
|
|
1063
|
+
|
|
1064
|
+
Asks before destroying the window.
|
|
1065
|
+
The difference between this function and [destroy()](#windowdestroy) is that this function will first make the window emit the [`'beforeClose'`](#event-beforeclose) event, giving you a chance to prevent the window from being destroyed.
|
|
1066
|
+
|
|
1061
1067
|
|
|
1062
1068
|
## sdl.keyboard
|
|
1063
1069
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.10.
|
|
2
|
+
"version": "0.10.9",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"clean": "cd scripts && node clean.mjs"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"tar": "^7.
|
|
63
|
+
"tar": "^7.4.3"
|
|
64
64
|
},
|
|
65
65
|
"sdl": {
|
|
66
66
|
"owner": "kmamal",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@kmamal/evdev": "^0.0.1",
|
|
72
|
-
"@kmamal/testing": "^0.0.
|
|
73
|
-
"@types/node": "^
|
|
74
|
-
"node-addon-api": "^8.
|
|
75
|
-
"node-gyp": "^
|
|
72
|
+
"@kmamal/testing": "^0.0.31",
|
|
73
|
+
"@types/node": "^22.10.7",
|
|
74
|
+
"node-addon-api": "^8.3.0",
|
|
75
|
+
"node-gyp": "^11.0.0"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -74,6 +74,12 @@ const handleEvent = (event) => {
|
|
|
74
74
|
delete event.family
|
|
75
75
|
|
|
76
76
|
switch (family) {
|
|
77
|
+
case 'quit': {
|
|
78
|
+
for (const window of Globals.windows.all.values()) {
|
|
79
|
+
window.destroyGently()
|
|
80
|
+
}
|
|
81
|
+
} break
|
|
82
|
+
|
|
77
83
|
// TODO: this also needs a reconcile function
|
|
78
84
|
case 'display': {
|
|
79
85
|
const { displayIndex } = event
|
|
@@ -153,13 +159,9 @@ const handleEvent = (event) => {
|
|
|
153
159
|
} break
|
|
154
160
|
|
|
155
161
|
case 'close': {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const event2 = { type: type2, prevent }
|
|
160
|
-
window.emit(type2, event2)
|
|
161
|
-
if (shouldPrevent) { return }
|
|
162
|
-
} break
|
|
162
|
+
window.destroyGently()
|
|
163
|
+
return
|
|
164
|
+
}
|
|
163
165
|
|
|
164
166
|
default: return
|
|
165
167
|
}
|
|
@@ -395,6 +395,19 @@ class Window extends EventsViaPoll {
|
|
|
395
395
|
|
|
396
396
|
this.emit('close', { type: 'close' })
|
|
397
397
|
}
|
|
398
|
+
|
|
399
|
+
destroyGently () {
|
|
400
|
+
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
401
|
+
|
|
402
|
+
let shouldPrevent = false
|
|
403
|
+
this.emit('beforeClose', {
|
|
404
|
+
type: 'beforeClose',
|
|
405
|
+
prevent: () => { shouldPrevent = true },
|
|
406
|
+
})
|
|
407
|
+
if (shouldPrevent) { return }
|
|
408
|
+
|
|
409
|
+
this.destroy()
|
|
410
|
+
}
|
|
398
411
|
}
|
|
399
412
|
|
|
400
413
|
module.exports = { Window }
|
package/src/native/events.cpp
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include <sstream>
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
std::string events::families::QUIT;
|
|
12
13
|
std::string events::families::DISPLAY;
|
|
13
14
|
std::string events::families::WINDOW;
|
|
14
15
|
std::string events::families::DROP;
|
|
@@ -72,6 +73,11 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
72
73
|
Napi::Object packed = Napi::Object::New(env);
|
|
73
74
|
|
|
74
75
|
switch (event.type) {
|
|
76
|
+
case SDL_QUIT: {
|
|
77
|
+
packed.Set("family", events::families::QUIT);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
75
81
|
case SDL_DISPLAYEVENT: {
|
|
76
82
|
packed.Set("family", events::families::DISPLAY);
|
|
77
83
|
packed.Set("displayIndex", Napi::Number::New(env, event.display.display));
|
package/src/native/events.h
CHANGED
package/src/native/global.cpp
CHANGED
package/src/types/index.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export namespace Events {
|
|
|
62
62
|
export interface MouseButtonUp extends MouseButtonEvent { readonly type: 'mouseButtonUp' }
|
|
63
63
|
|
|
64
64
|
export interface MouseWheel extends MouseEvent {
|
|
65
|
-
readonly type: '
|
|
65
|
+
readonly type: 'mouseWheel'
|
|
66
66
|
readonly dx: number
|
|
67
67
|
readonly dy: number
|
|
68
68
|
readonly flipped: boolean
|