melonjs 14.5.0 → 15.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/LICENSE.md +1 -1
- package/README.md +6 -6
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +7 -3
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +18 -20
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +56 -56
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +59 -59
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +25 -24
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +35 -13
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +3 -3
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +17 -19
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +55 -55
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +9 -4
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +24 -23
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/polyfill/index.js +0 -2
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +34 -12
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +186 -179
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -12,7 +12,7 @@ import Ellipse from '../../geometries/ellipse.js';
|
|
|
12
12
|
import RoundRect from '../../geometries/roundrect.js';
|
|
13
13
|
import Rect from '../../geometries/rectangle.js';
|
|
14
14
|
import Bounds from '../../physics/bounds.js';
|
|
15
|
-
import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js';
|
|
15
|
+
import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../system/event.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @classdesc
|
|
@@ -66,12 +66,15 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
66
66
|
this.isContextValid = true;
|
|
67
67
|
emit(ONCONTEXT_RESTORED, this);
|
|
68
68
|
}, false );
|
|
69
|
+
|
|
70
|
+
// reset the renderer on game reset
|
|
71
|
+
on(GAME_RESET, () => {
|
|
72
|
+
this.reset();
|
|
73
|
+
});
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
/**
|
|
72
77
|
* Reset context state
|
|
73
|
-
* @name reset
|
|
74
|
-
* @memberof CanvasRenderer
|
|
75
78
|
*/
|
|
76
79
|
reset() {
|
|
77
80
|
super.reset();
|
|
@@ -80,8 +83,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
80
83
|
|
|
81
84
|
/**
|
|
82
85
|
* Reset the canvas transform to identity
|
|
83
|
-
* @name resetTransform
|
|
84
|
-
* @memberof CanvasRenderer
|
|
85
86
|
*/
|
|
86
87
|
resetTransform() {
|
|
87
88
|
this.getContext().setTransform(1, 0, 0, 1, 0, 0);
|
|
@@ -98,9 +99,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
98
99
|
* <img src="images/lighter-blendmode.png" width="510"/> <br>
|
|
99
100
|
* - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
|
|
100
101
|
* <img src="images/screen-blendmode.png" width="510"/> <br>
|
|
101
|
-
* @name setBlendMode
|
|
102
102
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
|
|
103
|
-
* @memberof CanvasRenderer
|
|
104
103
|
* @param {string} [mode="normal"] - blend mode : "normal", "multiply", "lighter, "additive", "screen"
|
|
105
104
|
* @param {CanvasRenderingContext2D} [context]
|
|
106
105
|
*/
|
|
@@ -130,27 +129,23 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
130
129
|
|
|
131
130
|
/**
|
|
132
131
|
* prepare the framebuffer for drawing a new frame
|
|
133
|
-
* @name clear
|
|
134
|
-
* @memberof CanvasRenderer
|
|
135
132
|
*/
|
|
136
133
|
clear() {
|
|
137
134
|
if (this.settings.transparent === false) {
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
let canvas = this.getCanvas();
|
|
136
|
+
let context = this.getContext();
|
|
140
137
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
141
138
|
}
|
|
142
139
|
}
|
|
143
140
|
|
|
144
141
|
/**
|
|
145
142
|
* Clears the main framebuffer with the given color
|
|
146
|
-
* @name clearColor
|
|
147
|
-
* @memberof CanvasRenderer
|
|
148
143
|
* @param {Color|string} [color="#000000"] - CSS color.
|
|
149
144
|
* @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
|
|
150
145
|
*/
|
|
151
146
|
clearColor(color = "#000000", opaque = false) {
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
let canvas = this.getCanvas();
|
|
148
|
+
let context = this.getContext();
|
|
154
149
|
|
|
155
150
|
this.save();
|
|
156
151
|
this.resetTransform();
|
|
@@ -163,8 +158,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
163
158
|
|
|
164
159
|
/**
|
|
165
160
|
* Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).
|
|
166
|
-
* @name clearRect
|
|
167
|
-
* @memberof CanvasRenderer
|
|
168
161
|
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
169
162
|
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
170
163
|
* @param {number} width - The rectangle's width.
|
|
@@ -176,17 +169,15 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
176
169
|
|
|
177
170
|
/**
|
|
178
171
|
* Create a pattern with the specified repetition
|
|
179
|
-
* @
|
|
180
|
-
* @memberof CanvasRenderer
|
|
181
|
-
* @param {Image} image - Source image
|
|
172
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
|
|
182
173
|
* @param {string} repeat - Define how the pattern should be repeated
|
|
183
174
|
* @returns {CanvasPattern}
|
|
184
175
|
* @see ImageLayer#repeat
|
|
185
176
|
* @example
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
177
|
+
* let tileable = renderer.createPattern(image, "repeat");
|
|
178
|
+
* let horizontal = renderer.createPattern(image, "repeat-x");
|
|
179
|
+
* let vertical = renderer.createPattern(image, "repeat-y");
|
|
180
|
+
* let basic = renderer.createPattern(image, "no-repeat");
|
|
190
181
|
*/
|
|
191
182
|
createPattern(image, repeat) {
|
|
192
183
|
return this.getContext().createPattern(image, repeat);
|
|
@@ -194,9 +185,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
194
185
|
|
|
195
186
|
/**
|
|
196
187
|
* Draw an image onto the main using the canvas api
|
|
197
|
-
* @
|
|
198
|
-
* @memberof CanvasRenderer
|
|
199
|
-
* @param {Image} image - An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
|
|
188
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
|
|
200
189
|
* @param {number} sx - The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
|
|
201
190
|
* @param {number} sy - The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
|
|
202
191
|
* @param {number} sw - The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.
|
|
@@ -218,7 +207,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
218
207
|
// Fast path: don't draw fully transparent
|
|
219
208
|
return;
|
|
220
209
|
}
|
|
221
|
-
|
|
210
|
+
let context = this.getContext();
|
|
222
211
|
|
|
223
212
|
if (typeof sw === "undefined") {
|
|
224
213
|
sw = dw = image.width;
|
|
@@ -246,8 +235,8 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
246
235
|
}
|
|
247
236
|
|
|
248
237
|
// apply a tint if required
|
|
249
|
-
|
|
250
|
-
|
|
238
|
+
let source = image;
|
|
239
|
+
let tint = this.currentTint.toArray();
|
|
251
240
|
if (tint[0] !== 1.0 || tint[1] !== 1.0 || tint[2] !== 1.0) {
|
|
252
241
|
// get a tinted version of this image from the texture cache
|
|
253
242
|
source = this.cache.tint(image, this.currentTint.toRGB());
|
|
@@ -257,8 +246,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
257
246
|
|
|
258
247
|
/**
|
|
259
248
|
* Draw a pattern within the given rectangle.
|
|
260
|
-
* @name drawPattern
|
|
261
|
-
* @memberof CanvasRenderer
|
|
262
249
|
* @param {CanvasPattern} pattern - Pattern object
|
|
263
250
|
* @param {number} x
|
|
264
251
|
* @param {number} y
|
|
@@ -271,8 +258,8 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
271
258
|
// Fast path: don't draw fully transparent
|
|
272
259
|
return;
|
|
273
260
|
}
|
|
274
|
-
|
|
275
|
-
|
|
261
|
+
let context = this.getContext();
|
|
262
|
+
let fillStyle = context.fillStyle;
|
|
276
263
|
context.fillStyle = pattern;
|
|
277
264
|
context.fillRect(x, y, width, height);
|
|
278
265
|
context.fillStyle = fillStyle;
|
|
@@ -280,8 +267,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
280
267
|
|
|
281
268
|
/**
|
|
282
269
|
* Stroke an arc at the specified coordinates with given radius, start and end points
|
|
283
|
-
* @name strokeArc
|
|
284
|
-
* @memberof CanvasRenderer
|
|
285
270
|
* @param {number} x - arc center point x-axis
|
|
286
271
|
* @param {number} y - arc center point y-axis
|
|
287
272
|
* @param {number} radius
|
|
@@ -295,7 +280,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
295
280
|
// Fast path: don't draw fully transparent
|
|
296
281
|
return;
|
|
297
282
|
}
|
|
298
|
-
|
|
283
|
+
let context = this.getContext();
|
|
299
284
|
|
|
300
285
|
context.translate(x, y);
|
|
301
286
|
context.beginPath();
|
|
@@ -306,8 +291,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
306
291
|
|
|
307
292
|
/**
|
|
308
293
|
* Fill an arc at the specified coordinates with given radius, start and end points
|
|
309
|
-
* @name fillArc
|
|
310
|
-
* @memberof CanvasRenderer
|
|
311
294
|
* @param {number} x - arc center point x-axis
|
|
312
295
|
* @param {number} y - arc center point y-axis
|
|
313
296
|
* @param {number} radius
|
|
@@ -321,8 +304,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
321
304
|
|
|
322
305
|
/**
|
|
323
306
|
* Stroke an ellipse at the specified coordinates with given radius
|
|
324
|
-
* @name strokeEllipse
|
|
325
|
-
* @memberof CanvasRenderer
|
|
326
307
|
* @param {number} x - ellipse center point x-axis
|
|
327
308
|
* @param {number} y - ellipse center point y-axis
|
|
328
309
|
* @param {number} w - horizontal radius of the ellipse
|
|
@@ -334,16 +315,16 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
334
315
|
// Fast path: don't draw fully transparent
|
|
335
316
|
return;
|
|
336
317
|
}
|
|
337
|
-
|
|
318
|
+
let context = this.getContext();
|
|
338
319
|
|
|
339
|
-
|
|
320
|
+
let hw = w,
|
|
340
321
|
hh = h,
|
|
341
322
|
lx = x - hw,
|
|
342
323
|
rx = x + hw,
|
|
343
324
|
ty = y - hh,
|
|
344
325
|
by = y + hh;
|
|
345
326
|
|
|
346
|
-
|
|
327
|
+
let xmagic = hw * 0.551784,
|
|
347
328
|
ymagic = hh * 0.551784,
|
|
348
329
|
xmin = x - xmagic,
|
|
349
330
|
xmax = x + xmagic,
|
|
@@ -362,8 +343,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
362
343
|
|
|
363
344
|
/**
|
|
364
345
|
* Fill an ellipse at the specified coordinates with given radius
|
|
365
|
-
* @name fillEllipse
|
|
366
|
-
* @memberof CanvasRenderer
|
|
367
346
|
* @param {number} x - ellipse center point x-axis
|
|
368
347
|
* @param {number} y - ellipse center point y-axis
|
|
369
348
|
* @param {number} w - horizontal radius of the ellipse
|
|
@@ -375,8 +354,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
375
354
|
|
|
376
355
|
/**
|
|
377
356
|
* Stroke a line of the given two points
|
|
378
|
-
* @name strokeLine
|
|
379
|
-
* @memberof CanvasRenderer
|
|
380
357
|
* @param {number} startX - the start x coordinate
|
|
381
358
|
* @param {number} startY - the start y coordinate
|
|
382
359
|
* @param {number} endX - the end x coordinate
|
|
@@ -388,7 +365,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
388
365
|
return;
|
|
389
366
|
}
|
|
390
367
|
|
|
391
|
-
|
|
368
|
+
let context = this.getContext();
|
|
392
369
|
|
|
393
370
|
context.beginPath();
|
|
394
371
|
context.moveTo(startX, startY);
|
|
@@ -398,8 +375,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
398
375
|
|
|
399
376
|
/**
|
|
400
377
|
* Fill a line of the given two points
|
|
401
|
-
* @name fillLine
|
|
402
|
-
* @memberof CanvasRenderer
|
|
403
378
|
* @param {number} startX - the start x coordinate
|
|
404
379
|
* @param {number} startY - the start y coordinate
|
|
405
380
|
* @param {number} endX - the end x coordinate
|
|
@@ -411,8 +386,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
411
386
|
|
|
412
387
|
/**
|
|
413
388
|
* Stroke the given me.Polygon on the screen
|
|
414
|
-
* @name strokePolygon
|
|
415
|
-
* @memberof CanvasRenderer
|
|
416
389
|
* @param {Polygon} poly - the shape to draw
|
|
417
390
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
418
391
|
*/
|
|
@@ -421,13 +394,13 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
421
394
|
// Fast path: don't draw fully transparent
|
|
422
395
|
return;
|
|
423
396
|
}
|
|
424
|
-
|
|
397
|
+
let context = this.getContext();
|
|
425
398
|
|
|
426
399
|
this.translate(poly.pos.x, poly.pos.y);
|
|
427
400
|
context.beginPath();
|
|
428
401
|
context.moveTo(poly.points[0].x, poly.points[0].y);
|
|
429
|
-
|
|
430
|
-
for (
|
|
402
|
+
let point;
|
|
403
|
+
for (let i = 1; i < poly.points.length; i++) {
|
|
431
404
|
point = poly.points[i];
|
|
432
405
|
context.lineTo(point.x, point.y);
|
|
433
406
|
}
|
|
@@ -439,8 +412,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
439
412
|
|
|
440
413
|
/**
|
|
441
414
|
* Fill the given me.Polygon on the screen
|
|
442
|
-
* @name fillPolygon
|
|
443
|
-
* @memberof CanvasRenderer
|
|
444
415
|
* @param {Polygon} poly - the shape to draw
|
|
445
416
|
*/
|
|
446
417
|
fillPolygon(poly) {
|
|
@@ -449,8 +420,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
449
420
|
|
|
450
421
|
/**
|
|
451
422
|
* Stroke a rectangle at the specified coordinates
|
|
452
|
-
* @name strokeRect
|
|
453
|
-
* @memberof CanvasRenderer
|
|
454
423
|
* @param {number} x
|
|
455
424
|
* @param {number} y
|
|
456
425
|
* @param {number} width
|
|
@@ -462,15 +431,13 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
462
431
|
// Fast path: don't draw fully transparent
|
|
463
432
|
return;
|
|
464
433
|
}
|
|
465
|
-
|
|
434
|
+
let context = this.getContext();
|
|
466
435
|
|
|
467
436
|
context[fill === true ? "fillRect" : "strokeRect"](x, y, width, height);
|
|
468
437
|
}
|
|
469
438
|
|
|
470
439
|
/**
|
|
471
440
|
* Draw a filled rectangle at the specified coordinates
|
|
472
|
-
* @name fillRect
|
|
473
|
-
* @memberof CanvasRenderer
|
|
474
441
|
* @param {number} x
|
|
475
442
|
* @param {number} y
|
|
476
443
|
* @param {number} width
|
|
@@ -482,8 +449,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
482
449
|
|
|
483
450
|
/**
|
|
484
451
|
* Stroke a rounded rectangle at the specified coordinates
|
|
485
|
-
* @name strokeRoundRect
|
|
486
|
-
* @memberof CanvasRenderer
|
|
487
452
|
* @param {number} x
|
|
488
453
|
* @param {number} y
|
|
489
454
|
* @param {number} width
|
|
@@ -496,7 +461,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
496
461
|
// Fast path: don't draw fully transparent
|
|
497
462
|
return;
|
|
498
463
|
}
|
|
499
|
-
|
|
464
|
+
let context = this.getContext();
|
|
500
465
|
|
|
501
466
|
context.beginPath();
|
|
502
467
|
context.roundRect(x, y, width, height, radius);
|
|
@@ -505,8 +470,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
505
470
|
|
|
506
471
|
/**
|
|
507
472
|
* Draw a rounded filled rectangle at the specified coordinates
|
|
508
|
-
* @name fillRoundRect
|
|
509
|
-
* @memberof CanvasRenderer
|
|
510
473
|
* @param {number} x
|
|
511
474
|
* @param {number} y
|
|
512
475
|
* @param {number} width
|
|
@@ -519,8 +482,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
519
482
|
|
|
520
483
|
/**
|
|
521
484
|
* Stroke a Point at the specified coordinates
|
|
522
|
-
* @name strokePoint
|
|
523
|
-
* @memberof CanvasRenderer
|
|
524
485
|
* @param {number} x
|
|
525
486
|
* @param {number} y
|
|
526
487
|
*/
|
|
@@ -530,8 +491,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
530
491
|
|
|
531
492
|
/**
|
|
532
493
|
* Draw a a point at the specified coordinates
|
|
533
|
-
* @name fillPoint
|
|
534
|
-
* @memberof CanvasRenderer
|
|
535
494
|
* @param {number} x
|
|
536
495
|
* @param {number} y
|
|
537
496
|
* @param {number} width
|
|
@@ -541,19 +500,8 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
541
500
|
this.strokePoint(x, y);
|
|
542
501
|
}
|
|
543
502
|
|
|
544
|
-
/**
|
|
545
|
-
* return a reference to the font 2d Context
|
|
546
|
-
* @ignore
|
|
547
|
-
*/
|
|
548
|
-
getFontContext() {
|
|
549
|
-
// in canvas mode we can directly use the 2d context
|
|
550
|
-
return this.getContext();
|
|
551
|
-
}
|
|
552
|
-
|
|
553
503
|
/**
|
|
554
504
|
* save the canvas context
|
|
555
|
-
* @name save
|
|
556
|
-
* @memberof CanvasRenderer
|
|
557
505
|
*/
|
|
558
506
|
save() {
|
|
559
507
|
this.getContext().save();
|
|
@@ -561,8 +509,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
561
509
|
|
|
562
510
|
/**
|
|
563
511
|
* restores the canvas context
|
|
564
|
-
* @name restore
|
|
565
|
-
* @memberof CanvasRenderer
|
|
566
512
|
*/
|
|
567
513
|
restore() {
|
|
568
514
|
this.getContext().restore();
|
|
@@ -575,8 +521,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
575
521
|
|
|
576
522
|
/**
|
|
577
523
|
* rotates the canvas context
|
|
578
|
-
* @name rotate
|
|
579
|
-
* @memberof CanvasRenderer
|
|
580
524
|
* @param {number} angle - in radians
|
|
581
525
|
*/
|
|
582
526
|
rotate(angle) {
|
|
@@ -585,8 +529,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
585
529
|
|
|
586
530
|
/**
|
|
587
531
|
* scales the canvas context
|
|
588
|
-
* @name scale
|
|
589
|
-
* @memberof CanvasRenderer
|
|
590
532
|
* @param {number} x
|
|
591
533
|
* @param {number} y
|
|
592
534
|
*/
|
|
@@ -597,12 +539,10 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
597
539
|
/**
|
|
598
540
|
* Set the current fill & stroke style color.
|
|
599
541
|
* By default, or upon reset, the value is set to #000000.
|
|
600
|
-
* @name setColor
|
|
601
|
-
* @memberof CanvasRenderer
|
|
602
542
|
* @param {Color|string} color - css color value
|
|
603
543
|
*/
|
|
604
544
|
setColor(color) {
|
|
605
|
-
|
|
545
|
+
let context = this.getContext();
|
|
606
546
|
context.strokeStyle =
|
|
607
547
|
context.fillStyle = (
|
|
608
548
|
color instanceof Color ?
|
|
@@ -613,8 +553,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
613
553
|
|
|
614
554
|
/**
|
|
615
555
|
* Set the global alpha
|
|
616
|
-
* @name setGlobalAlpha
|
|
617
|
-
* @memberof CanvasRenderer
|
|
618
556
|
* @param {number} alpha - 0.0 to 1.0 values accepted.
|
|
619
557
|
*/
|
|
620
558
|
setGlobalAlpha(alpha) {
|
|
@@ -623,8 +561,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
623
561
|
|
|
624
562
|
/**
|
|
625
563
|
* Return the global alpha
|
|
626
|
-
* @name getGlobalAlpha
|
|
627
|
-
* @memberof CanvasRenderer
|
|
628
564
|
* @returns {number} global alpha value
|
|
629
565
|
*/
|
|
630
566
|
getGlobalAlpha() {
|
|
@@ -633,8 +569,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
633
569
|
|
|
634
570
|
/**
|
|
635
571
|
* Set the line width on the context
|
|
636
|
-
* @name setLineWidth
|
|
637
|
-
* @memberof CanvasRenderer
|
|
638
572
|
* @param {number} width - Line width
|
|
639
573
|
*/
|
|
640
574
|
setLineWidth(width) {
|
|
@@ -644,8 +578,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
644
578
|
/**
|
|
645
579
|
* Reset (overrides) the renderer transformation matrix to the
|
|
646
580
|
* identity one, and then apply the given transformation matrix.
|
|
647
|
-
* @name setTransform
|
|
648
|
-
* @memberof CanvasRenderer
|
|
649
581
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
650
582
|
*/
|
|
651
583
|
setTransform(mat2d) {
|
|
@@ -655,12 +587,10 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
655
587
|
|
|
656
588
|
/**
|
|
657
589
|
* Multiply given matrix into the renderer tranformation matrix
|
|
658
|
-
* @name transform
|
|
659
|
-
* @memberof CanvasRenderer
|
|
660
590
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
661
591
|
*/
|
|
662
592
|
transform(mat2d) {
|
|
663
|
-
|
|
593
|
+
let m = mat2d.toArray(),
|
|
664
594
|
a = m[0],
|
|
665
595
|
b = m[1],
|
|
666
596
|
c = m[3],
|
|
@@ -678,8 +608,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
678
608
|
|
|
679
609
|
/**
|
|
680
610
|
* Translates the context to the given position
|
|
681
|
-
* @name translate
|
|
682
|
-
* @memberof CanvasRenderer
|
|
683
611
|
* @param {number} x
|
|
684
612
|
* @param {number} y
|
|
685
613
|
*/
|
|
@@ -697,22 +625,20 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
697
625
|
* You can however save the current region using the save(),
|
|
698
626
|
* and restore it (with the restore() method) any time in the future.
|
|
699
627
|
* (<u>this is an experimental feature !</u>)
|
|
700
|
-
* @name clipRect
|
|
701
|
-
* @memberof CanvasRenderer
|
|
702
628
|
* @param {number} x
|
|
703
629
|
* @param {number} y
|
|
704
630
|
* @param {number} width
|
|
705
631
|
* @param {number} height
|
|
706
632
|
*/
|
|
707
633
|
clipRect(x, y, width, height) {
|
|
708
|
-
|
|
634
|
+
let canvas = this.getCanvas();
|
|
709
635
|
// if requested box is different from the current canvas size;
|
|
710
636
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
711
|
-
|
|
637
|
+
let currentScissor = this.currentScissor;
|
|
712
638
|
// if different from the current scissor box
|
|
713
639
|
if (currentScissor[0] !== x || currentScissor[1] !== y ||
|
|
714
640
|
currentScissor[2] !== width || currentScissor[3] !== height) {
|
|
715
|
-
|
|
641
|
+
let context = this.getContext();
|
|
716
642
|
context.beginPath();
|
|
717
643
|
context.rect(x, y, width, height);
|
|
718
644
|
context.clip();
|
|
@@ -729,13 +655,11 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
729
655
|
* A mask limits rendering elements to the shape and position of the given mask object.
|
|
730
656
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
731
657
|
* Mask are not preserved through renderer context save and restore.
|
|
732
|
-
* @name setMask
|
|
733
|
-
* @memberof CanvasRenderer
|
|
734
658
|
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] - the shape defining the mask to be applied
|
|
735
659
|
* @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
|
|
736
660
|
*/
|
|
737
661
|
setMask(mask, invert = false) {
|
|
738
|
-
|
|
662
|
+
let context = this.getContext();
|
|
739
663
|
|
|
740
664
|
if (this.maskLevel === 0) {
|
|
741
665
|
// only save context on the first mask
|
|
@@ -757,7 +681,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
757
681
|
ty = _y - hh,
|
|
758
682
|
by = _y + hh;
|
|
759
683
|
|
|
760
|
-
|
|
684
|
+
let xmagic = hw * 0.551784,
|
|
761
685
|
ymagic = hh * 0.551784,
|
|
762
686
|
xmin = _x - xmagic,
|
|
763
687
|
xmax = _x + xmagic,
|
|
@@ -772,10 +696,10 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
772
696
|
} else {
|
|
773
697
|
// polygon
|
|
774
698
|
const _x = mask.pos.x, _y = mask.pos.y;
|
|
775
|
-
|
|
699
|
+
let point;
|
|
776
700
|
|
|
777
701
|
context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
|
|
778
|
-
for (
|
|
702
|
+
for (let i = 1; i < mask.points.length; i++) {
|
|
779
703
|
point = mask.points[i];
|
|
780
704
|
context.lineTo(_x + point.x, _y + point.y);
|
|
781
705
|
}
|
|
@@ -794,9 +718,7 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
|
|
|
794
718
|
|
|
795
719
|
/**
|
|
796
720
|
* disable (remove) the rendering mask set through setMask.
|
|
797
|
-
* @name clearMask
|
|
798
721
|
* @see CanvasRenderer#setMask
|
|
799
|
-
* @memberof CanvasRenderer
|
|
800
722
|
*/
|
|
801
723
|
clearMask() {
|
|
802
724
|
if (this.maskLevel > 0) {
|