@kmamal/sdl 0.9.6-0 → 0.9.6-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.md CHANGED
@@ -118,8 +118,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
118
118
  * [sdl.info](#sdlinfo)
119
119
  * [sdl.video](#sdlvideo)
120
120
  * [Image data](#image-data)
121
+ * [High-DPI](#high-dpi)
121
122
  * [Pixel formats](#pixel-formats)
122
- * [High-DPI](#highdpi)
123
123
  * [Event: 'displayAdd'](#event-displayadd)
124
124
  * [Event: 'displayRemove'](#event-displayremove)
125
125
  * [Event: 'displayOrient'](#event-displayorient)
@@ -207,7 +207,6 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
207
207
  * [sdl.keyboard.getScancode(key)](#sdlkeyboardgetscancodekey)
208
208
  * [sdl.keyboard.getState()](#sdlkeyboardgetstate)
209
209
  * [sdl.mouse](#sdlmouse)
210
- * [Mouse cursors](#mouse-cursors)
211
210
  * [Enum: BUTTON](#enum-button)
212
211
  * [sdl.mouse.getButton(button)](#sdlmousegetbuttonbutton)
213
212
  * [sdl.mouse.position](#sdlmouseposition)
@@ -221,9 +220,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
221
220
  * [sdl.mouse.capture([capture])](#sdlmousecapturecapture)
222
221
  * [sdl.mouse.uncapture()](#sdlmouseuncapture)
223
222
  * [sdl.joystick](#sdljoystick)
224
- * [Joystick types](#joystick-types)
225
223
  * [Hat positions](#hat-positions)
226
- * [Power levels](#power-levels)
227
224
  * [Event: 'deviceAdd'](#joystick-event-deviceadd)
228
225
  * [Event: 'deviceRemove'](#joystick-event-deviceremove)
229
226
  * [sdl.joystick.devices](#sdljoystickdevices)
@@ -429,6 +426,14 @@ for (let i = 0; i < height; i++) {
429
426
  window.render(width, height, stride, 'rgba32', buffer)
430
427
  ```
431
428
 
429
+ ### High-DPI
430
+
431
+ On a high-dpi display, windows have more pixels that their `width` and `height` would indicate.
432
+ On such systems `width` and `height` (and all other measurements such as `x` and `y`) are in "points".
433
+ Points are abstract and don't have to correspond to pixels.
434
+ If you need to know a window's width and height in pixels, you should use the `pixelWidth` and `pixelHeight` properties.
435
+ You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.
436
+
432
437
  ### Pixel formats
433
438
 
434
439
  String values used to represent how the pixels of an image are stored in a Buffer.
@@ -473,15 +478,6 @@ String values used to represent how the pixels of an image are stored in a Buffe
473
478
  | `'nv21'` | `SDL_PIXELFORMAT_NV21` | planar mode: Y + V/U interleaved (2 planes) |
474
479
 
475
480
 
476
- ### High-DPI
477
-
478
- On a high-dpi display, windows have more pixels that their `width` and `height` would indicate.
479
- On such systems `width` and `height` (and all other measurements such as `x` and `y`) are in "points".
480
- Points are abstract and don't have to correspond to pixels.
481
- If you need to know a window's width and height in pixels, you should use the `pixelWidth` and `pixelHeight` properties.
482
- You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.
483
-
484
-
485
481
  ### Event: 'displayAdd'
486
482
 
487
483
  * `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
@@ -489,7 +485,6 @@ You should be doing this always, since you don't know beforehand if your program
489
485
  Fired when a display is added to the system.
490
486
  Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
491
487
 
492
-
493
488
  ### Event: 'displayRemove'
494
489
 
495
490
  * `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
@@ -497,7 +492,6 @@ Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
497
492
  Fired when a display is removed from the system.
498
493
  Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
499
494
 
500
-
501
495
  ### Event: 'displayOrient'
502
496
 
503
497
  * `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
@@ -1085,6 +1079,16 @@ Trying to handle text input by manually translating key presses to text is not a
1085
1079
  It's better to let the OS handle all the text logic, and get the final text by handling the rasulting ([`'textInput'`](#event-textinput)) events.
1086
1080
 
1087
1081
 
1082
+ ### Virtual keys
1083
+
1084
+ String values used to represent virtual keys in the context of the current keyboard mapping.
1085
+ Note that some keys do not correspond to any virtual key.
1086
+ A Key can be either one of the values below __or__ any unicode character.
1087
+ Keys that produce characters are represented by that character.
1088
+ All others are represented by one of these values:
1089
+
1090
+ `'&&'`, `'+/-'`, `'||'`, `'00'`, `'000'`, `'again'`, `'alt'`, `'altErase'`, `'app1'`, `'app2'`, `'application'`, `'audioFastForward'`, `'audioMute'`, `'audioNext'`, `'audioPlay'`, `'audioPrev'`, `'audioRewind'`, `'audioStop'`, `'back'`, `'backspace'`, `'binary'`, `'bookmarks'`, `'brightnessDown'`, `'brightnessUp'`, `'calculator'`, `'cancel'`, `'capsLock'`, `'clear'`, `'clearEntry'`, `'computer'`, `'copy'`, `'crSel'`, `'ctrl'`, `'currencySubUnit'`, `'currencyUnit'`, `'cut'`, `'decimal'`, `'decimalSeparator'`, `'delete'`, `'displaySwitch'`, `'down'`, `'eject'`, `'end'`, `'enter'`, `'escape'`, `'execute'`, `'exSel'`, `'f1'`, `'f2'`, `'f3'`, `'f4'`, `'f5'`, `'f6'`, `'f7'`, `'f8'`, `'f9'`, `'f10'`, `'f11'`, `'f12'`, `'f13'`, `'f14'`, `'f15'`, `'f16'`, `'f17'`, `'f18'`, `'f19'`, `'f20'`, `'f21'`, `'f22'`, `'f23'`, `'f24'`, `'find'`, `'forward'`, `'gui'`, `'help'`, `'hexadecimal'`, `'home'`, `'illumDown'`, `'illumToggle'`, `'illumUp'`, `'insert'`, `'left'`, `'mail'`, `'mediaSelect'`, `'memAdd'`, `'memClear'`, `'memDivide'`, `'memMultiply'`, `'memRecall'`, `'memStore'`, `'memSubtract'`, `'menu'`, `'modeSwitch'`, `'mute'`, `'numlock'`, `'octal'`, `'oper'`, `'out'`, `'pageDown'`, `'pageUp'`, `'paste'`, `'pause'`, `'power'`, `'printScreen'`, `'prior'`, `'refresh'`, `'return'`, `'right'`, `'scrollLock'`, `'search'`, `'select'`, `'separator'`, `'shift'`, `'sleep'`, `'space'`, `'stop'`, `'sysReq'`, `'tab'`, `'thousandsSeparator'`, `'undo'`, `'up'`, `'volumeDown'`, `'volumeUp'`, `'www'`, `'xor'`.
1091
+
1088
1092
  ### Enum: SCANCODE
1089
1093
 
1090
1094
  Used to represent physical keys on the keyboard.
@@ -1340,16 +1344,6 @@ Values are based on the [USB usage page standard](https://www.usb.org/sites/defa
1340
1344
  | `sdl.keyboard.SCANCODE.AUDIOFASTFORWARD` | `SDL_SCANCODE_AUDIOFASTFORWARD` | |
1341
1345
  </details>
1342
1346
 
1343
- ### Virtual keys
1344
-
1345
- String values used to represent virtual keys in the context of the current keyboard mapping.
1346
- Note that some keys do not correspond to any virtual key.
1347
- A Key can be either one of the values below __or__ any unicode character.
1348
- Keys that produce characters are represented by that character.
1349
- All others are represented by one of these values:
1350
-
1351
- `'&&'`, `'+/-'`, `'||'`, `'00'`, `'000'`, `'again'`, `'alt'`, `'altErase'`, `'app1'`, `'app2'`, `'application'`, `'audioFastForward'`, `'audioMute'`, `'audioNext'`, `'audioPlay'`, `'audioPrev'`, `'audioRewind'`, `'audioStop'`, `'back'`, `'backspace'`, `'binary'`, `'bookmarks'`, `'brightnessDown'`, `'brightnessUp'`, `'calculator'`, `'cancel'`, `'capsLock'`, `'clear'`, `'clearEntry'`, `'computer'`, `'copy'`, `'crSel'`, `'ctrl'`, `'currencySubUnit'`, `'currencyUnit'`, `'cut'`, `'decimal'`, `'decimalSeparator'`, `'delete'`, `'displaySwitch'`, `'down'`, `'eject'`, `'end'`, `'enter'`, `'escape'`, `'execute'`, `'exSel'`, `'f1'`, `'f2'`, `'f3'`, `'f4'`, `'f5'`, `'f6'`, `'f7'`, `'f8'`, `'f9'`, `'f10'`, `'f11'`, `'f12'`, `'f13'`, `'f14'`, `'f15'`, `'f16'`, `'f17'`, `'f18'`, `'f19'`, `'f20'`, `'f21'`, `'f22'`, `'f23'`, `'f24'`, `'find'`, `'forward'`, `'gui'`, `'help'`, `'hexadecimal'`, `'home'`, `'illumDown'`, `'illumToggle'`, `'illumUp'`, `'insert'`, `'left'`, `'mail'`, `'mediaSelect'`, `'memAdd'`, `'memClear'`, `'memDivide'`, `'memMultiply'`, `'memRecall'`, `'memStore'`, `'memSubtract'`, `'menu'`, `'modeSwitch'`, `'mute'`, `'numlock'`, `'octal'`, `'oper'`, `'out'`, `'pageDown'`, `'pageUp'`, `'paste'`, `'pause'`, `'power'`, `'printScreen'`, `'prior'`, `'refresh'`, `'return'`, `'right'`, `'scrollLock'`, `'search'`, `'select'`, `'separator'`, `'shift'`, `'sleep'`, `'space'`, `'stop'`, `'sysReq'`, `'tab'`, `'thousandsSeparator'`, `'undo'`, `'up'`, `'volumeDown'`, `'volumeUp'`, `'www'`, `'xor'`.
1352
-
1353
1347
  ### sdl.keyboard.getKey(scancode)
1354
1348
 
1355
1349
  * `scancode: `[`<Scancode>`](#enum-scancode)
@@ -1377,25 +1371,6 @@ The values will be `true` for keys that are pressed and `false` otherwise.
1377
1371
 
1378
1372
  ## sdl.mouse
1379
1373
 
1380
- ### Mouse cursors
1381
-
1382
- String values used to represent the types of cursors available on most systems.
1383
-
1384
- | Value | Corresponding `SDL_SystemCursor` | Description |
1385
- | --- | --- | --- |
1386
- | `'arrow'` | `SDL_SYSTEM_CURSOR_ARROW` | arrow |
1387
- | `'ibeam'` | `SDL_SYSTEM_CURSOR_IBEAM` | i-beam |
1388
- | `'wait'` | `SDL_SYSTEM_CURSOR_WAIT` | wait |
1389
- | `'crosshair'` | `SDL_SYSTEM_CURSOR_CROSSHAIR` | crosshair |
1390
- | `'waitarrow'` | `SDL_SYSTEM_CURSOR_WAITARROW` | small wait cursor (or wait if not available) |
1391
- | `'sizenwse'` | `SDL_SYSTEM_CURSOR_SIZENWSE` | double arrow pointing northwest and southeast |
1392
- | `'sizenesw'` | `SDL_SYSTEM_CURSOR_SIZENESW` | double arrow pointing northeast and southwest |
1393
- | `'sizewe'` | `SDL_SYSTEM_CURSOR_SIZEWE` | double arrow pointing west and east |
1394
- | `'sizens'` | `SDL_SYSTEM_CURSOR_SIZENS` | double arrow pointing north and south |
1395
- | `'sizeall'` | `SDL_SYSTEM_CURSOR_SIZEALL` | four pointed arrow pointing north, south, east, and west |
1396
- | `'no'` | `SDL_SYSTEM_CURSOR_NO` | slashed circle or crossbones |
1397
- | `'hand'` | `SDL_SYSTEM_CURSOR_HAND` | hand |
1398
-
1399
1374
  ### Enum: BUTTON
1400
1375
 
1401
1376
  Used to represent the buttons on a mouse.
@@ -1431,10 +1406,27 @@ Moves the mouse to the specified position.
1431
1406
 
1432
1407
  ### sdl.mouse.setCursor(cursor)
1433
1408
 
1434
- * `cursor: `[`<MouseCursor>`](#mouse-cursors) The icon to use for the cursor.
1409
+ * `cursor: <MouseCursor>` The icon to use for the cursor.
1435
1410
 
1436
1411
  Changes the icon that is displayed for the mouse cursor.
1437
1412
 
1413
+ Possible values for `cursor` are:
1414
+
1415
+ | Value | Corresponding `SDL_SystemCursor` | Description |
1416
+ | --- | --- | --- |
1417
+ | `'arrow'` | `SDL_SYSTEM_CURSOR_ARROW` | arrow |
1418
+ | `'ibeam'` | `SDL_SYSTEM_CURSOR_IBEAM` | i-beam |
1419
+ | `'wait'` | `SDL_SYSTEM_CURSOR_WAIT` | wait |
1420
+ | `'crosshair'` | `SDL_SYSTEM_CURSOR_CROSSHAIR` | crosshair |
1421
+ | `'waitarrow'` | `SDL_SYSTEM_CURSOR_WAITARROW` | small wait cursor (or wait if not available) |
1422
+ | `'sizenwse'` | `SDL_SYSTEM_CURSOR_SIZENWSE` | double arrow pointing northwest and southeast |
1423
+ | `'sizenesw'` | `SDL_SYSTEM_CURSOR_SIZENESW` | double arrow pointing northeast and southwest |
1424
+ | `'sizewe'` | `SDL_SYSTEM_CURSOR_SIZEWE` | double arrow pointing west and east |
1425
+ | `'sizens'` | `SDL_SYSTEM_CURSOR_SIZENS` | double arrow pointing north and south |
1426
+ | `'sizeall'` | `SDL_SYSTEM_CURSOR_SIZEALL` | four pointed arrow pointing north, south, east, and west |
1427
+ | `'no'` | `SDL_SYSTEM_CURSOR_NO` | slashed circle or crossbones |
1428
+ | `'hand'` | `SDL_SYSTEM_CURSOR_HAND` | hand |
1429
+
1438
1430
  ### sdl.mouse.resetCursor()
1439
1431
 
1440
1432
  Switched back to the default cursor.
@@ -1475,27 +1467,11 @@ Equivalent to [`sdl.mouse.capture(false)`](#sdlmousecapturecapture).
1475
1467
 
1476
1468
  ## sdl.joystick
1477
1469
 
1478
- ### Joystick types
1479
-
1480
- String values used to represent the type of a joystick device.
1481
-
1482
- | Value | Corresponding `SDL_JoystickType` |
1483
- | --- | --- |
1484
- | `'gamecontroller'` | `SDL_JOYSTICK_TYPE_GAMECONTROLLER` |
1485
- | `'wheel'` | `SDL_JOYSTICK_TYPE_WHEEL` |
1486
- | `'arcadestick'` | `SDL_JOYSTICK_TYPE_ARCADE_STICK` |
1487
- | `'flightstick'` | `SDL_JOYSTICK_TYPE_FLIGHT_STICK` |
1488
- | `'dancepad'` | `SDL_JOYSTICK_TYPE_DANCE_PAD` |
1489
- | `'guitar'` | `SDL_JOYSTICK_TYPE_GUITAR` |
1490
- | `'drumkit'` | `SDL_JOYSTICK_TYPE_DRUM_KIT` |
1491
- | `'arcadepad'` | `SDL_JOYSTICK_TYPE_ARCADE_PAD` |
1492
- | `'throttle'` | `SDL_JOYSTICK_TYPE_THROTTLE` |
1493
-
1494
1470
  ### Hat positions
1495
1471
 
1496
1472
  String values used to represent the positions of a joystick hat
1497
1473
 
1498
- | Value | Corresponding SDL enum |
1474
+ | Value | Corresponding `SDL_HAT_*` |
1499
1475
  | --- | --- |
1500
1476
  | `'centered'` | `SDL_HAT_CENTERED` |
1501
1477
  | `'up'` | `SDL_HAT_UP` |
@@ -1507,19 +1483,6 @@ String values used to represent the positions of a joystick hat
1507
1483
  | `'leftup'` | `SDL_HAT_LEFTUP` |
1508
1484
  | `'leftdown'` | `SDL_HAT_LEFTDOWN` |
1509
1485
 
1510
- ### Power levels
1511
-
1512
- String values used to represent the power level of a joystick device.
1513
-
1514
- | Value | Corresponding `SDL_JoystickPowerLevel` |
1515
- | --- | --- |
1516
- | `'empty'` | `SDL_JOYSTICK_POWER_EMPTY` |
1517
- | `'low'` | `SDL_JOYSTICK_POWER_LOW` |
1518
- | `'medium'` | `SDL_JOYSTICK_POWER_MEDIUM` |
1519
- | `'full'` | `SDL_JOYSTICK_POWER_FULL` |
1520
- | `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
1521
- | `'max'` | `SDL_JOYSTICK_POWER_MAX` |
1522
-
1523
1486
  <a id="joystick-event-deviceadd"></a>
1524
1487
 
1525
1488
  ### Event: 'deviceAdd'
@@ -1543,16 +1506,31 @@ When this event is emitted, all instances that were opened from the removed devi
1543
1506
 
1544
1507
  * `<object>[]`
1545
1508
  * `id: <number>` The unique id for the device.
1546
- * `type:`[`<JoystickType>`](#joystick-types) The type of the device.
1509
+ * `type: <JoystickType>` The type of the device.
1547
1510
  * `name: <string>` The name of the device.
1548
1511
  * `path: <string>` The implementation dependent path of the device.
1549
1512
  * `guid: <string>` The GUID of the device.
1550
- * `vendor: <number>` The USB vendor ID of the device.
1551
- * `product: <number>` The USB product ID of the device.
1552
- * `version: <number>` The USB product version of the device.
1553
- * `player: <number>` The player index for the device.
1513
+ * `vendor: <number>|<null>` The USB vendor ID of the device. Will be `null` if it can't be determined.
1514
+ * `product: <number>|<null>` The USB product ID of the device. Will be `null` if it can't be determined.
1515
+ * `version: <number>|<null>` The USB product version of the device. Will be `null` if it can't be determined.
1516
+ * `player: <number>|<null>` The player index for the device. Will be `null` if it can't be determined.
1554
1517
 
1555
1518
  A list of all the detected joystick devices.
1519
+
1520
+ Possible values for `type` are:
1521
+
1522
+ | Value | Corresponding `SDL_JoystickType` |
1523
+ | --- | --- |
1524
+ | `'gamecontroller'` | `SDL_JOYSTICK_TYPE_GAMECONTROLLER` |
1525
+ | `'wheel'` | `SDL_JOYSTICK_TYPE_WHEEL` |
1526
+ | `'arcadestick'` | `SDL_JOYSTICK_TYPE_ARCADE_STICK` |
1527
+ | `'flightstick'` | `SDL_JOYSTICK_TYPE_FLIGHT_STICK` |
1528
+ | `'dancepad'` | `SDL_JOYSTICK_TYPE_DANCE_PAD` |
1529
+ | `'guitar'` | `SDL_JOYSTICK_TYPE_GUITAR` |
1530
+ | `'drumkit'` | `SDL_JOYSTICK_TYPE_DRUM_KIT` |
1531
+ | `'arcadepad'` | `SDL_JOYSTICK_TYPE_ARCADE_PAD` |
1532
+ | `'throttle'` | `SDL_JOYSTICK_TYPE_THROTTLE` |
1533
+
1556
1534
  Sample output:
1557
1535
 
1558
1536
  ```js
@@ -1679,9 +1657,20 @@ An array of values, each corresponding to the position of one of the joystick's
1679
1657
 
1680
1658
  ### joystickInstance.power
1681
1659
 
1682
- * [`<PowerLevel>`](#power-levels)`|<null>`
1660
+ * `<PowerLevel>|<null>`
1661
+
1662
+ The current power level of the joystick device, or `null` if it is unknown.
1683
1663
 
1684
- The current power level of the joystick device, or `null` if it is unknown;
1664
+ Possible values are:
1665
+
1666
+ | Value | Corresponding `SDL_JoystickPowerLevel` |
1667
+ | --- | --- |
1668
+ | `'empty'` | `SDL_JOYSTICK_POWER_EMPTY` |
1669
+ | `'low'` | `SDL_JOYSTICK_POWER_LOW` |
1670
+ | `'medium'` | `SDL_JOYSTICK_POWER_MEDIUM` |
1671
+ | `'full'` | `SDL_JOYSTICK_POWER_FULL` |
1672
+ | `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
1673
+ | `'max'` | `SDL_JOYSTICK_POWER_MAX` |
1685
1674
 
1686
1675
  ### joystickInstance.setPlayer(index)
1687
1676
 
@@ -1813,10 +1802,10 @@ This can cause already opened controller instances to be [remapped](#event-remap
1813
1802
  * `name: <string>` The name of the device.
1814
1803
  * `path: <string>` The implementation dependent path of the device.
1815
1804
  * `guid: <string>` The GUID of the device.
1816
- * `vendor: <number>` The USB vendor ID of the device.
1817
- * `product: <number>` The USB product ID of the device.
1818
- * `version: <number>` The USB product version of the device.
1819
- * `player: <number>` The player index for the device.
1805
+ * `vendor: <number>|<null>` The USB vendor ID of the device. Will be `null` if it can't be determined.
1806
+ * `product: <number>|<null>` The USB product ID of the device. Will be `null` if it can't be determined.
1807
+ * `version: <number>|<null>` The USB product version of the device. Will be `null` if it can't be determined.
1808
+ * `player: <number>|<null>` The player index for the device. Will be `null` if it can't be determined.
1820
1809
  * `mapping: <string>` The axis and button mapping for this device.
1821
1810
 
1822
1811
  A list of all the detected controller devices.
@@ -1854,7 +1843,7 @@ Instead, objects returned by [`sdl.controller.openDevice()`](#sdlcontrolleropend
1854
1843
 
1855
1844
  ### Event: 'axisMotion'
1856
1845
 
1857
- * `axis: <string>` The name of the axis that moved.
1846
+ * `axis:`[`<Axis>`](#controllerinstanceaxes) The axis that moved.
1858
1847
  * `value: <number>` The new axis position.
1859
1848
 
1860
1849
  Fired when one of the controller's axes moves.
@@ -1863,7 +1852,7 @@ Fired when one of the controller's axes moves.
1863
1852
 
1864
1853
  ### Event: 'buttonDown'
1865
1854
 
1866
- * `button: <string>` The name of the button that was pressed.
1855
+ * `button:`[`<Button>`](#controllerinstancebuttons) The button that was pressed.
1867
1856
 
1868
1857
  Fired when one of the controller's buttons is pressed.
1869
1858
 
@@ -2041,7 +2030,7 @@ Use this constant to correct for that if your application requires it.
2041
2030
  * `<object>[]`
2042
2031
  * `id: <number>` The unique id of the device.
2043
2032
  * `name: <string>` The name of the device.
2044
- * `type: <string>` Will be either `'accelerometer'`, `'gyroscope'`, or `'unknown'`.
2033
+ * `type: <string>|<null>` Either `'accelerometer'`, `'gyroscope'`. Will be `null` if it can't be determined.
2045
2034
  * `side: <string>|<null>` Some sensors (such as those on the Joy-Con controller) have a `'left'` or `'right'` side, otherwise this value will be `null`.
2046
2035
 
2047
2036
  A list of all the detected sensor devices.
@@ -2536,7 +2525,7 @@ Changes the text contents of the clipboard.
2536
2525
  ### sdl.power.info
2537
2526
 
2538
2527
  * `<object>`
2539
- * `state: <string>` One of `'unknown'`, `'noBattery'`, `'battery'`, `'charging'`, `'charged'`.
2528
+ * `state: <string>|null` One of `'noBattery'`, `'battery'`, `'charging'`, `'charged'`. Will be `null` if it can't be determinded.
2540
2529
  * `seconds: <number>|<null>` Seconds of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
2541
2530
  * `percent: <number>|<null>` Percentage of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
2542
2531
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.9.6-0",
2
+ "version": "0.9.6-1",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -47,10 +47,7 @@ class ControllerInstance extends EventsViaPoll {
47
47
  get axes () { return this._axes }
48
48
  get buttons () { return this._buttons }
49
49
 
50
- get power () {
51
- const power = Bindings.joystick_getPower(this._device.id)
52
- return Enums.powerLevelNames[power]
53
- }
50
+ get power () { return Bindings.joystick_getPower(this._device.id) }
54
51
 
55
52
  setPlayer (player) {
56
53
  if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
@@ -2,12 +2,4 @@ const Bindings = require('./bindings')
2
2
 
3
3
  const enums = Bindings.enums_get()
4
4
 
5
- for (const [ key, obj ] of Object.entries(enums)) {
6
- const names = {}
7
- for (const [ name, value ] of Object.entries(obj)) {
8
- names[value] = name
9
- }
10
- enums[`${key}Names`] = names
11
- }
12
-
13
5
  module.exports = enums
@@ -1,6 +1,5 @@
1
1
  const Bindings = require('../bindings')
2
2
  const Globals = require('../globals')
3
- const Enums = require('../enums')
4
3
  const { video: videoModule } = require('../video')
5
4
  const { mapping } = require('../keyboard/key-mapping')
6
5
  const { joystick: joystickModule } = require('../joystick')
@@ -73,29 +72,25 @@ const handleEvent = (event) => {
73
72
  const { family, type } = event
74
73
  if (family === undefined || type === undefined) { return }
75
74
  delete event.family
76
- event.type = Enums.eventTypeNames[type]
77
75
 
78
76
  switch (family) {
79
77
  // TODO: this also needs a reconcile function
80
- case Enums.eventFamily.display: {
78
+ case 'display': {
81
79
  const { displayIndex } = event
82
80
  delete event.displayIndex
83
81
 
84
82
  const oldDisplays = Globals.displays
85
83
  Globals.displays = Bindings.video_getDisplays()
86
- for (const display of Globals.displays) {
87
- display.format = Enums.pixelFormatNames[display.format]
88
- }
89
84
  const newDisplays = Globals.displays
90
85
 
91
- event.display = event.type === Enums.eventType.displayRemove
86
+ event.display = event.type === 'displayRemove'
92
87
  ? oldDisplays[displayIndex]
93
88
  : newDisplays[displayIndex]
94
89
 
95
90
  videoModule.emit(event.type, event)
96
91
  } break
97
92
 
98
- case Enums.eventFamily.window: {
93
+ case 'window': {
99
94
  const { windowId } = event
100
95
  delete event.windowId
101
96
 
@@ -103,61 +98,61 @@ const handleEvent = (event) => {
103
98
  if (!window) { return }
104
99
 
105
100
  switch (type) {
106
- case Enums.eventType.move: {
101
+ case 'move': {
107
102
  window._x = event.x
108
103
  window._y = event.y
109
104
  } break
110
- case Enums.eventType.resize: {
105
+ case 'resize': {
111
106
  window._width = event.width
112
107
  window._height = event.height
113
108
  window._pixelWidth = event.pixelWidth
114
109
  window._pixelHeight = event.pixelHeight
115
110
  } break
116
111
 
117
- case Enums.eventType.show: {
112
+ case 'show': {
118
113
  window._visible = true
119
114
  } break
120
- case Enums.eventType.hide: {
115
+ case 'hide': {
121
116
  window._visible = false
122
117
  } break
123
- case Enums.eventType.expose: {
118
+ case 'expose': {
124
119
  // Nothing
125
120
  } break
126
121
 
127
- case Enums.eventType.minimize: {
122
+ case 'minimize': {
128
123
  window._visible = false
129
124
  window._minimized = true
130
125
  window._maximized = false
131
126
  window._fullscreen = false
132
127
  } break
133
- case Enums.eventType.maximize: {
128
+ case 'maximize': {
134
129
  window._visible = true
135
130
  window._minimized = false
136
131
  window._maximized = true
137
132
  window._fullscreen = false
138
133
  } break
139
- case Enums.eventType.restore: {
134
+ case 'restore': {
140
135
  window._visible = true
141
136
  window._minimized = false
142
137
  window._maximized = false
143
138
  window._fullscreen = false
144
139
  } break
145
140
 
146
- case Enums.eventType.focus: {
141
+ case 'focus': {
147
142
  Globals.windows.focused = window
148
143
  } break
149
- case Enums.eventType.blur: {
144
+ case 'blur': {
150
145
  Globals.windows.focused = null
151
146
  } break
152
147
 
153
- case Enums.eventType.hover: {
148
+ case 'hover': {
154
149
  Globals.windows.hovered = window
155
150
  } break
156
- case Enums.eventType.leave: {
151
+ case 'leave': {
157
152
  Globals.windows.hovered = null
158
153
  } break
159
154
 
160
- case Enums.eventType.close: {
155
+ case 'close': {
161
156
  let shouldPrevent = false
162
157
  const prevent = () => { shouldPrevent = true }
163
158
  const type2 = 'beforeClose'
@@ -172,7 +167,7 @@ const handleEvent = (event) => {
172
167
  window.emit(event.type, event)
173
168
  } break
174
169
 
175
- case Enums.eventFamily.keyboard: {
170
+ case 'keyboard': {
176
171
  const { windowId } = event
177
172
  delete event.windowId
178
173
 
@@ -185,9 +180,9 @@ const handleEvent = (event) => {
185
180
  window.emit(event.type, event)
186
181
  } break
187
182
 
188
- case Enums.eventFamily.mouse:
189
- case Enums.eventFamily.text:
190
- case Enums.eventFamily.drop: {
183
+ case 'mouse':
184
+ case 'text':
185
+ case 'drop': {
191
186
  const { windowId } = event
192
187
  delete event.windowId
193
188
 
@@ -197,8 +192,8 @@ const handleEvent = (event) => {
197
192
  window.emit(event.type, event)
198
193
  } break
199
194
 
200
- case Enums.eventFamily.joystickDevice: {
201
- if (type === Enums.eventType.deviceRemove) {
195
+ case 'joystickDevice': {
196
+ if (type === 'deviceRemove') {
202
197
  const { joystickId } = event
203
198
  delete event.joystickId
204
199
 
@@ -248,7 +243,7 @@ const handleEvent = (event) => {
248
243
  )
249
244
  } break
250
245
 
251
- case Enums.eventFamily.joystick: {
246
+ case 'joystick': {
252
247
  const { joystickId } = event
253
248
  delete event.joystickId
254
249
 
@@ -256,14 +251,14 @@ const handleEvent = (event) => {
256
251
  if (!collection) { return }
257
252
 
258
253
  switch (type) {
259
- case Enums.eventType.axisMotion: {
254
+ case 'axisMotion': {
260
255
  for (const joystickInstance of collection) {
261
256
  joystickInstance._axes[event.axis] = event.value
262
257
  joystickInstance.emit(event.type, event)
263
258
  }
264
259
  } break
265
260
 
266
- case Enums.eventType.ballMotion: {
261
+ case 'ballMotion': {
267
262
  for (const joystickInstance of collection) {
268
263
  const ball = joystickInstance._balls[event.ball]
269
264
  ball.x = event.x
@@ -272,21 +267,20 @@ const handleEvent = (event) => {
272
267
  }
273
268
  } break
274
269
 
275
- case Enums.eventType.buttonDown: {
270
+ case 'buttonDown': {
276
271
  for (const joystickInstance of collection) {
277
272
  joystickInstance._buttons[event.button] = true
278
273
  joystickInstance.emit(event.type, event)
279
274
  }
280
275
  } break
281
- case Enums.eventType.buttonUp: {
276
+ case 'buttonUp': {
282
277
  for (const joystickInstance of collection) {
283
278
  joystickInstance._buttons[event.button] = false
284
279
  joystickInstance.emit(event.type, event)
285
280
  }
286
281
  } break
287
282
 
288
- case Enums.eventType.hatMotion: {
289
- event.value = Enums.hatPositionNames[event.value]
283
+ case 'hatMotion': {
290
284
  for (const joystickInstance of collection) {
291
285
  joystickInstance._hats[event.hat] = event.value
292
286
  joystickInstance.emit(event.type, event)
@@ -297,7 +291,7 @@ const handleEvent = (event) => {
297
291
  }
298
292
  } break
299
293
 
300
- case Enums.eventFamily.controller: {
294
+ case 'controller': {
301
295
  const { controllerId } = event
302
296
  delete event.controllerId
303
297
 
@@ -305,31 +299,28 @@ const handleEvent = (event) => {
305
299
  if (!collection) { return }
306
300
 
307
301
  switch (type) {
308
- case Enums.eventType.axisMotion: {
309
- event.axis = Enums.controllerAxisNames[event.axis]
302
+ case 'axisMotion': {
310
303
  for (const controllerInstance of collection.values()) {
311
304
  controllerInstance._axes[event.axis] = event.value
312
305
  controllerInstance.emit(event.type, event)
313
306
  }
314
307
  } break
315
308
 
316
- case Enums.eventType.buttonDown: {
317
- event.button = Enums.controllerButtonNames[event.button]
309
+ case 'buttonDown': {
318
310
  for (const controllerInstance of collection.values()) {
319
311
  controllerInstance._axes[event.button] = true
320
312
  controllerInstance.emit(event.type, event)
321
313
  }
322
314
  } break
323
315
 
324
- case Enums.eventType.buttonUp: {
325
- event.button = Enums.controllerButtonNames[event.button]
316
+ case 'buttonUp': {
326
317
  for (const controllerInstance of collection.values()) {
327
318
  controllerInstance._axes[event.button] = true
328
319
  controllerInstance.emit(event.type, event)
329
320
  }
330
321
  } break
331
322
 
332
- case Enums.eventType.remap: {
323
+ case 'remap': {
333
324
  const { axes, buttons } = event
334
325
  delete event.axes
335
326
  delete event.buttons
@@ -345,7 +336,7 @@ const handleEvent = (event) => {
345
336
  }
346
337
  } break
347
338
 
348
- case Enums.eventFamily.sensor: {
339
+ case 'sensor': {
349
340
  const { sensorId } = event
350
341
  delete event.sensorId
351
342
 
@@ -353,7 +344,7 @@ const handleEvent = (event) => {
353
344
  if (!collection) { return }
354
345
 
355
346
  switch (type) {
356
- case Enums.eventType.update: {
347
+ case 'update': {
357
348
  for (const sensorInstance of collection.values()) {
358
349
  sensorInstance.emit(event.type, event)
359
350
  }
@@ -363,11 +354,11 @@ const handleEvent = (event) => {
363
354
  }
364
355
  } break
365
356
 
366
- case Enums.eventFamily.audioDevice: {
357
+ case 'audioDevice': {
367
358
  const { isRecorder } = event
368
359
  delete event.isRecorder
369
360
 
370
- if (type === Enums.eventType.deviceRemove) {
361
+ if (type === 'deviceRemove') {
371
362
  const { audioId } = event
372
363
  delete event.audioId
373
364
 
@@ -390,7 +381,7 @@ const handleEvent = (event) => {
390
381
  )
391
382
  } break
392
383
 
393
- case Enums.eventFamily.clipboard: {
384
+ case 'clipboard': {
394
385
  clipboardModule.emit(event.type, event)
395
386
  } break
396
387
 
@@ -1,8 +1,5 @@
1
- const Enums = require('../enums')
2
1
 
3
2
  const make = (device) => {
4
- const { type } = device
5
- device.type = Enums.joystickTypeNames[type]
6
3
  delete device.isController
7
4
  delete device.mapping
8
5
  }
@@ -1,5 +1,4 @@
1
1
  const Bindings = require('../bindings')
2
- const Enums = require('../enums')
3
2
  const Globals = require('../globals')
4
3
  const { EventsViaPoll } = require('../events/events-via-poll')
5
4
 
@@ -26,7 +25,7 @@ class JoystickInstance extends EventsViaPoll {
26
25
  this._axes = result.axes
27
26
  this._balls = result.balls
28
27
  this._buttons = result.buttons
29
- this._hats = result.hats.map((x) => Enums.hatPositionNames[x])
28
+ this._hats = result.hats
30
29
 
31
30
  this._device = device
32
31
 
@@ -52,11 +51,7 @@ class JoystickInstance extends EventsViaPoll {
52
51
  get buttons () { return this._buttons }
53
52
  get hats () { return this._hats }
54
53
 
55
- get power () {
56
- const power = Bindings.joystick_getPower(this._device.id)
57
- if (power === null) { return null }
58
- return Enums.powerLevelNames[power]
59
- }
54
+ get power () { return Bindings.joystick_getPower(this._device.id) }
60
55
 
61
56
  setPlayer (player) {
62
57
  if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }