canvasengine 1.3.0 → 2.0.0-beta.2
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/package.json +51 -17
- package/src/components/Canvas.ts +134 -0
- package/src/components/Container.ts +46 -0
- package/src/components/DisplayObject.ts +458 -0
- package/src/components/DrawMap/index.ts +65 -0
- package/src/components/Graphic.ts +147 -0
- package/src/components/NineSliceSprite.ts +46 -0
- package/src/components/ParticleEmitter.ts +39 -0
- package/src/components/Scene.ts +6 -0
- package/src/components/Sprite.ts +493 -0
- package/src/components/Text.ts +145 -0
- package/src/components/Tilemap/Tile.ts +79 -0
- package/src/components/Tilemap/TileGroup.ts +207 -0
- package/src/components/Tilemap/TileLayer.ts +163 -0
- package/src/components/Tilemap/TileSet.ts +41 -0
- package/src/components/Tilemap/index.ts +80 -0
- package/src/components/TilingSprite.ts +39 -0
- package/src/components/Viewport.ts +159 -0
- package/src/components/index.ts +13 -0
- package/src/components/types/DisplayObject.ts +69 -0
- package/src/components/types/MouseEvent.ts +3 -0
- package/src/components/types/Spritesheet.ts +389 -0
- package/src/components/types/index.ts +4 -0
- package/src/directives/Drag.ts +84 -0
- package/src/directives/KeyboardControls.ts +922 -0
- package/src/directives/Scheduler.ts +101 -0
- package/src/directives/Sound.ts +91 -0
- package/src/directives/Transition.ts +45 -0
- package/src/directives/ViewportCull.ts +40 -0
- package/src/directives/ViewportFollow.ts +26 -0
- package/src/directives/index.ts +7 -0
- package/src/engine/animation.ts +113 -0
- package/src/engine/bootstrap.ts +19 -0
- package/src/engine/directive.ts +23 -0
- package/src/engine/reactive.ts +379 -0
- package/src/engine/signal.ts +138 -0
- package/src/engine/trigger.ts +40 -0
- package/src/engine/utils.ts +135 -0
- package/src/hooks/addContext.ts +6 -0
- package/src/hooks/useProps.ts +155 -0
- package/src/hooks/useRef.ts +21 -0
- package/src/index.ts +13 -0
- package/src/utils/Ease.ts +33 -0
- package/src/utils/RadialGradient.ts +86 -0
- package/.gitattributes +0 -22
- package/.npmignore +0 -163
- package/canvasengine-1.3.0.all.min.js +0 -21
- package/canvasengine.js +0 -5802
- package/core/DB.js +0 -24
- package/core/ModelServer.js +0 -348
- package/core/Users.js +0 -190
- package/core/engine-common.js +0 -952
- package/doc/cocoonjs.md +0 -36
- package/doc/doc-lang.yml +0 -43
- package/doc/doc-router.yml +0 -14
- package/doc/doc-tuto.yml +0 -9
- package/doc/doc.yml +0 -39
- package/doc/element.md +0 -37
- package/doc/entity.md +0 -90
- package/doc/extend.md +0 -47
- package/doc/get_started.md +0 -19
- package/doc/images/entity.png +0 -0
- package/doc/multitouch.md +0 -58
- package/doc/nodejs.md +0 -142
- package/doc/scene.md +0 -44
- package/doc/text.md +0 -156
- package/examples/server/client.html +0 -31
- package/examples/server/server.js +0 -16
- package/examples/tiled_server/client.html +0 -52
- package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
- package/examples/tiled_server/server/map.json +0 -50
- package/examples/tiled_server/server/map.tmx +0 -16
- package/examples/tiled_server/server/server.js +0 -16
- package/extends/Animation.js +0 -910
- package/extends/Effect.js +0 -252
- package/extends/Gleed2d.js +0 -252
- package/extends/Hit.js +0 -1509
- package/extends/Input.js +0 -699
- package/extends/Marshal.js +0 -716
- package/extends/Scrolling.js +0 -388
- package/extends/Soundmanager2.js +0 -5466
- package/extends/Spritesheet.js +0 -196
- package/extends/Text.js +0 -366
- package/extends/Tiled.js +0 -403
- package/extends/Window.js +0 -575
- package/extends/gamepad.js +0 -397
- package/extends/socket.io.min.js +0 -2
- package/extends/swf/soundmanager2.swf +0 -0
- package/extends/swf/soundmanager2_debug.swf +0 -0
- package/extends/swf/soundmanager2_flash9.swf +0 -0
- package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
- package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
- package/extends/workers/transition.js +0 -43
- package/index.js +0 -46
- package/license.txt +0 -19
- package/readme.md +0 -483
package/extends/Spritesheet.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2012 by Samuel Ronce
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
in the Software without restriction, including without limitation the rights
|
|
7
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
furnished to do so, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be included in
|
|
12
|
-
all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
THE SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Class.create("Spritesheet", {
|
|
26
|
-
image: null,
|
|
27
|
-
_set: {},
|
|
28
|
-
initialize: function(image, set) {
|
|
29
|
-
this.image = image;
|
|
30
|
-
if (set) this.set(set);
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
@doc spritesheet/
|
|
34
|
-
@method set Assigns an identifier to an area of the spritesheet. A grid can be defined to be faster.
|
|
35
|
-
@param {Object} set : If the key is called `grid`, the image is cut from a grid. Set the grid with
|
|
36
|
-
|
|
37
|
-
* size: [Line number, column number]
|
|
38
|
-
* tile : [Width of the box, Height of the box]
|
|
39
|
-
* set : Each identifier in array starting from the firt case in top left of the grid
|
|
40
|
-
* reg : [Position X of origin point, Position Y of origin point]
|
|
41
|
-
|
|
42
|
-
If the key is not "grid", we assign a zone identifier: [x, y, width, height, 0, regX (optional), regY (optional)]
|
|
43
|
-
regX and regY are origin points
|
|
44
|
-
@example :
|
|
45
|
-
var spritesheet = canvas.Spritesheet.new("my_spritesheet");
|
|
46
|
-
spritesheet.set({
|
|
47
|
-
grid: [{
|
|
48
|
-
size: [4, 5],
|
|
49
|
-
tile: [107, 107],
|
|
50
|
-
set: ["play", "player_hover", "zoom_p", "zoom_m"]
|
|
51
|
-
}],
|
|
52
|
-
btn_play: [433, 33, 215, 188]
|
|
53
|
-
});
|
|
54
|
-
Here, there is a grid of rows and 5 columns of 107px width and height. The first box is called "play". We have another area placed at positions (433, 33), width is 215px and height is 188px. The ID of this area is "btn_play"
|
|
55
|
-
*/
|
|
56
|
-
set: function(set) {
|
|
57
|
-
var gridset, gridname, x, y, regX, regY;
|
|
58
|
-
for (var id in set) {
|
|
59
|
-
if (id == "grid") {
|
|
60
|
-
for (var i=0 ; i < set.grid.length ; i++) {
|
|
61
|
-
for (var j=0 ; j < set.grid[i].set.length ; j++) {
|
|
62
|
-
gridname = set.grid[i].set[j];
|
|
63
|
-
gridset = set.grid[i];
|
|
64
|
-
|
|
65
|
-
y = gridset.tile[1] * parseInt(j / Math.round(gridset.size[0]));
|
|
66
|
-
//y = gridset.tile[1] * parseInt(j / Math.round(gridset.size[1]));
|
|
67
|
-
x = gridset.tile[0] * (j % Math.round(gridset.size[0]));
|
|
68
|
-
|
|
69
|
-
if (!gridset.reg) {
|
|
70
|
-
gridset.reg = [0, 0];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
regX = gridset.reg[0];
|
|
74
|
-
regY = gridset.reg[1];
|
|
75
|
-
|
|
76
|
-
this._set[gridname] = [x, y, gridset.tile[0], gridset.tile[1], 0, regX, regY];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this._set[id] = set[id];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
/**
|
|
87
|
-
@doc spritesheet/
|
|
88
|
-
@method draw Draw a Sprite on the element
|
|
89
|
-
@param {CanvasEngine.Element} el
|
|
90
|
-
@param {String} id Sprite identifier defined with the method "set" (or the constructor)
|
|
91
|
-
@param {Object} (optional) dest Positions and dimensions of the final destination :
|
|
92
|
-
|
|
93
|
-
* x {Integer} Position X
|
|
94
|
-
* y {Integer} Position Y
|
|
95
|
-
* w {Integer} Width
|
|
96
|
-
* h {Integer} Height
|
|
97
|
-
|
|
98
|
-
Equivalent to
|
|
99
|
-
|
|
100
|
-
el.drawImage(--, --, --, --, --, x, y, w, h);
|
|
101
|
-
|
|
102
|
-
*/
|
|
103
|
-
draw: function(el, id, dest) {
|
|
104
|
-
dest = dest || {};
|
|
105
|
-
var tile = this._set[id];
|
|
106
|
-
if (!tile) {
|
|
107
|
-
throw "Spritesheet " + id + " don't exist";
|
|
108
|
-
}
|
|
109
|
-
var dest_x = +(dest.x || "0")-tile[5],
|
|
110
|
-
dest_y = +(dest.y || "0")-tile[6],
|
|
111
|
-
dest_w = dest.w || tile[2],
|
|
112
|
-
dest_h = dest.h || tile[3];
|
|
113
|
-
|
|
114
|
-
el.drawImage(this.image, tile[0], tile[1], tile[2], tile[3], dest_x, dest_y, dest_w, dest_h);
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
@doc spritesheet/
|
|
119
|
-
@method pattern Repeat an image of SpriteSheet. Do not forget to draw the pattern with "fillRect" or "fill"
|
|
120
|
-
@param {CanvasEngine.Element} el
|
|
121
|
-
@param {String} id Sprite identifier defined with the method "set" (or the constructor)
|
|
122
|
-
@param {String} (optional) repeatOption Type of repetition (repeat (default), no-repeat, repeat-x, repeat-y)
|
|
123
|
-
@example
|
|
124
|
-
In "ready" method of the current scene :
|
|
125
|
-
|
|
126
|
-
var spritesheet = canvas.Spritesheet.new("my_spritesheet"),
|
|
127
|
-
el = this.createElement();
|
|
128
|
-
spritesheet.set({
|
|
129
|
-
grid: [{
|
|
130
|
-
size: [3, 1],
|
|
131
|
-
tile: [32, 32],
|
|
132
|
-
set: ["border", "foo", "bar"]
|
|
133
|
-
}]
|
|
134
|
-
});
|
|
135
|
-
spritesheet.pattern(el, "border");
|
|
136
|
-
el.fillRect(0, 0, 300, 32);
|
|
137
|
-
stage.append(el);
|
|
138
|
-
|
|
139
|
-
*/
|
|
140
|
-
pattern: function(el, id, repeatOption) {
|
|
141
|
-
var tile = this._set[id],
|
|
142
|
-
img = Global_CE.Materials.cropImage(this.image, tile[0], tile[1], tile[2], tile[3]);
|
|
143
|
-
pattern = el.getScene().getCanvas().createPattern(img, repeatOption);
|
|
144
|
-
|
|
145
|
-
el.fillStyle = pattern;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
@doc spritesheet
|
|
151
|
-
@class Spritesheet Spritesheet is a Sprites collection in an image. This class aims to crop the image, retrieve each Sprite by assigning an identifier
|
|
152
|
-
@param {String} image ID image
|
|
153
|
-
@param {Object} params See the method "set"
|
|
154
|
-
@example
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var canvas = CE.defines("canvas_id").
|
|
158
|
-
extend(Spritesheet).
|
|
159
|
-
ready(function() {
|
|
160
|
-
canvas.Scene.call("MyScene");
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
canvas.Scene.new({
|
|
164
|
-
name: "MyScene",
|
|
165
|
-
materials: {
|
|
166
|
-
images: {
|
|
167
|
-
my_spritesheet: "path/to/spritesheet.png"
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
ready: function(stage) {
|
|
171
|
-
var el = this.createElement();
|
|
172
|
-
var spritesheet = canvas.Spritesheet.new("my_spritesheet", {
|
|
173
|
-
|
|
174
|
-
grid: [{
|
|
175
|
-
size: [4, 5],
|
|
176
|
-
tile: [107, 107],
|
|
177
|
-
set: ["play", "player_hover", "zoom_p", "zoom_m"]
|
|
178
|
-
}],
|
|
179
|
-
btn_play: [433, 33, 215, 188]
|
|
180
|
-
|
|
181
|
-
});
|
|
182
|
-
spritesheet.draw(el, "play");
|
|
183
|
-
stage.append(el);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
*/
|
|
188
|
-
var Spritesheet = {
|
|
189
|
-
Spritesheet: {
|
|
190
|
-
New: function() { return this["new"].apply(this, arguments); },
|
|
191
|
-
"new": function(image, set) {
|
|
192
|
-
return Class["new"]("Spritesheet", [image, set]);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
package/extends/Text.js
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2013 by Samuel Ronce
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
in the Software without restriction, including without limitation the rights
|
|
7
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
furnished to do so, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be included in
|
|
12
|
-
all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
THE SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
Class.create("Text", {
|
|
24
|
-
scene: null,
|
|
25
|
-
text: "",
|
|
26
|
-
el: null,
|
|
27
|
-
_family: null,
|
|
28
|
-
_style: {
|
|
29
|
-
"size": "20px",
|
|
30
|
-
"family": "Arial",
|
|
31
|
-
"weight": "normal",
|
|
32
|
-
"style": "normal",
|
|
33
|
-
"variant": "normal",
|
|
34
|
-
"color": "#000",
|
|
35
|
-
"transform": "none",
|
|
36
|
-
"decoration": "none",
|
|
37
|
-
"border": "none",
|
|
38
|
-
"lineHeight": 25,
|
|
39
|
-
"shadow": null,
|
|
40
|
-
"textBaseline": "alphabetic",
|
|
41
|
-
"lineWidth": null
|
|
42
|
-
},
|
|
43
|
-
lines: [],
|
|
44
|
-
|
|
45
|
-
initialize: function(scene, text) {
|
|
46
|
-
this.scene = scene;
|
|
47
|
-
this.construct(text);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
construct: function(text) {
|
|
51
|
-
text = ""+text;
|
|
52
|
-
this.el = this.scene.createElement();
|
|
53
|
-
text = this._transformHTML(text);
|
|
54
|
-
this.text = text.split("\n");
|
|
55
|
-
this.lines = [];
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
_transformHTML: function(text) {
|
|
59
|
-
text = text.replace(/<br>/g, "\n");
|
|
60
|
-
return text;
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
setImageText: function(img_id, letters, size, rowsAndCols) {
|
|
64
|
-
var el = this.scene.createElement();
|
|
65
|
-
|
|
66
|
-
if (!Global_CE.Spritesheet) {
|
|
67
|
-
throw "Add Spritesheet class to use setImageText method";
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
rowsAndCols = rowsAndCols || {rows: 1, cols: 1};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var spritesheet = Global_CE.Spritesheet.New(img_id, {
|
|
74
|
-
|
|
75
|
-
grid: [{
|
|
76
|
-
size: rowsAndCols,
|
|
77
|
-
tile: [size.width, size.height],
|
|
78
|
-
set: letters
|
|
79
|
-
}]
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
this._family = spritesheet;
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
@doc text/
|
|
87
|
-
@method style Applies a style to the text
|
|
88
|
-
@param {Object} params Styles parameters
|
|
89
|
-
|
|
90
|
-
Style: default value
|
|
91
|
-
|
|
92
|
-
* size: "20px"
|
|
93
|
-
* family: "Arial"
|
|
94
|
-
* weight: "normal"
|
|
95
|
-
* style: "normal"
|
|
96
|
-
* variant: "normal"
|
|
97
|
-
* color: "#000"
|
|
98
|
-
* transform: "none"
|
|
99
|
-
* decoration: "none"
|
|
100
|
-
* border: "none"
|
|
101
|
-
* lineHeight: 25
|
|
102
|
-
* shadow: null
|
|
103
|
-
* textBaseline: "alphabetic"
|
|
104
|
-
* lineWidth: null
|
|
105
|
-
|
|
106
|
-
@return {CanvasEngine.Text}
|
|
107
|
-
*/
|
|
108
|
-
style: function(params) {
|
|
109
|
-
if (params.size & !params.lineHeight) {
|
|
110
|
-
params.lineHeight = params.size;
|
|
111
|
-
}
|
|
112
|
-
for (var key in params) {
|
|
113
|
-
this._style[key] = params[key];
|
|
114
|
-
}
|
|
115
|
-
return this;
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
@doc text/
|
|
120
|
-
@method draw Draws the text given by the style. If an effect is assigned, consider integrating extension Timelines
|
|
121
|
-
@param {CanvasEngine.Element} parent Element parent where the text will be displayed
|
|
122
|
-
@param {Integer} x (optional) Position X (0 by default)
|
|
123
|
-
@param {Integer} y (optional) Position Y (0 by default)
|
|
124
|
-
@param {Object} effect (optional) Effect to apply on line or text letters
|
|
125
|
-
|
|
126
|
-
* line: {}
|
|
127
|
-
* frames : Duration in frames before the line is displayed
|
|
128
|
-
* onFinish : Call the function when the lines were displayed
|
|
129
|
-
* onEffect : Call function when a line has been displayed. Two parameters:
|
|
130
|
-
* text_line {String} The text line
|
|
131
|
-
* el_line {CanvasEngine.Element} the corresponding element in line
|
|
132
|
-
* _char: {}
|
|
133
|
-
* frames : Duration in frames before the character is displayed
|
|
134
|
-
* onFinish : Call the function when the characters were displayed
|
|
135
|
-
* onEffect : Call function when a character has been displayed. Two parameters:
|
|
136
|
-
* text_char {String} The text character
|
|
137
|
-
* el_char {CanvasEngine.Element} the corresponding element in character
|
|
138
|
-
|
|
139
|
-
@example
|
|
140
|
-
|
|
141
|
-
In `ready` method :
|
|
142
|
-
|
|
143
|
-
var text = RPGJS.Text.new(this, "Hello World");
|
|
144
|
-
text.style({
|
|
145
|
-
size: "18px",
|
|
146
|
-
lineWidth: 300,
|
|
147
|
-
color: "white"
|
|
148
|
-
}).draw(content, 20, 20, {
|
|
149
|
-
line: { // Animation
|
|
150
|
-
frames: 20,
|
|
151
|
-
onFinish: function() {
|
|
152
|
-
console.log("Effect is finished");
|
|
153
|
-
},
|
|
154
|
-
onEffect: function(text_line, el_line) {
|
|
155
|
-
console.log(text_line);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
@return {CanvasEngine.Text}
|
|
161
|
-
*/
|
|
162
|
-
draw: function(parent, x, y, effect) {
|
|
163
|
-
|
|
164
|
-
if (effect && !Global_CE.Timeline) {
|
|
165
|
-
throw "Add Timeline class to use effects";
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (!effect) effect = {};
|
|
169
|
-
|
|
170
|
-
if (!x) x = 0;
|
|
171
|
-
if (!y) y = 0;
|
|
172
|
-
|
|
173
|
-
var s = this._style, border, text, metrics, line_y = 0, line_h, text_line = "", shadow;
|
|
174
|
-
var canvas = this.scene.getCanvas(), self = this;
|
|
175
|
-
this.el.x = x;
|
|
176
|
-
this.el.y = y;
|
|
177
|
-
|
|
178
|
-
function setProperties(pos, line, text) {
|
|
179
|
-
line_h = parseInt(s.lineHeight);
|
|
180
|
-
line_h *= parseInt(s.size) / 20;
|
|
181
|
-
line_y = line_h * pos;
|
|
182
|
-
line.font = s.style + " " + s.weight + " " + s.variant + " " + s.size + " " + s.family;
|
|
183
|
-
line.fillStyle = s.color;
|
|
184
|
-
line.textBaseline = s.textBaseline;
|
|
185
|
-
|
|
186
|
-
if (s.shadow) {
|
|
187
|
-
shadow = s.shadow.match(/(-?[0-9]+) (-?[0-9]+) ([0-9]+) ([#a-zA-Z0-9]+)/);
|
|
188
|
-
if (shadow) {
|
|
189
|
-
line.shadowOffsetX = shadow[1];
|
|
190
|
-
line.shadowOffsetY = shadow[2];
|
|
191
|
-
line.shadowBlur = shadow[3];
|
|
192
|
-
line.shadowColor = shadow[4];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
line.fillText(text, 0, line_y);
|
|
197
|
-
|
|
198
|
-
if (s.border != "none") {
|
|
199
|
-
border = s.border.match(/([0-9]+)px ([#a-zA-Z0-9]+)/);
|
|
200
|
-
line.font = s.style + " " + s.weight + " " + s.variant + " " + (s.size + border[1]) + " " + s.family;
|
|
201
|
-
line.strokeStyle = border[2];
|
|
202
|
-
line.strokeText(text, 0, line_y);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return line;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function drawLine(pos, text) {
|
|
209
|
-
var line = self.scene.createElement();
|
|
210
|
-
|
|
211
|
-
setProperties(pos, line, text);
|
|
212
|
-
|
|
213
|
-
self.lines.push({
|
|
214
|
-
text: text,
|
|
215
|
-
el: line,
|
|
216
|
-
chars: []
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
line.opacity = 0;
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function displayChar(i_line, i_char, finish) {
|
|
224
|
-
var line = this.lines[i_line].el;
|
|
225
|
-
if (i_char >= this.lines[i_line].text.length) {
|
|
226
|
-
finish();
|
|
227
|
-
for (var i=0 ; i < this.lines[i_line].chars.length ; i++) {
|
|
228
|
-
this.lines[i_line].chars[i].el.remove();
|
|
229
|
-
}
|
|
230
|
-
this.el.append(line);
|
|
231
|
-
line.opacity = 1;
|
|
232
|
-
this.lines[i_line].el.opacity = 1;
|
|
233
|
-
if (effect._char.onFinish) effect._char.onFinish();
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
var el = this.scene.createElement(),
|
|
238
|
-
_char = this.lines[i_line].text[i_char],
|
|
239
|
-
width = canvas.measureText(_char).width,
|
|
240
|
-
self = this;
|
|
241
|
-
|
|
242
|
-
setProperties(i_line, el, _char);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
el.x = i_char * width;
|
|
246
|
-
el.opacity = 0;
|
|
247
|
-
this.el.append(el);
|
|
248
|
-
|
|
249
|
-
this.lines[i_line].chars.push({
|
|
250
|
-
_char: _char,
|
|
251
|
-
el: el
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
Global_CE.Timeline['new'](el).to({opacity: 1}, effect._char.frames).call(function() {
|
|
255
|
-
if (effect._char.onEffect) effect._char.onEffect(_char, el);
|
|
256
|
-
displayChar.call(self, i_line, i_char+1, finish);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function displayLines(i_line) {
|
|
263
|
-
var self = this, el;
|
|
264
|
-
if (i_line >= this.lines.length) {
|
|
265
|
-
if (effect.line && effect.line.onFinish) effect.line.onFinish();
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
el = this.lines[i_line].el;
|
|
269
|
-
|
|
270
|
-
if (effect.line) {
|
|
271
|
-
this.el.append(el);
|
|
272
|
-
Global_CE.Timeline['new'](el).to({opacity: 1}, effect.line.frames).call(function() {
|
|
273
|
-
if (effect.line.onEffect) effect.line.onEffect(self.lines[i_line].text, el);
|
|
274
|
-
displayLines.call(self, i_line+1);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
else if (effect._char) {
|
|
278
|
-
displayChar.call(this, i_line, 0, function() {
|
|
279
|
-
displayLines.call(self, i_line+1);
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
el.opacity = 1;
|
|
284
|
-
this.el.append(el);
|
|
285
|
-
displayLines.call(this, i_line+1);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
var metrics, testLine, testWidth, words, pos = 0;
|
|
289
|
-
for (var i=0 ; i < this.text.length ; i++) {
|
|
290
|
-
text = this.text[i];
|
|
291
|
-
if (s.lineWidth) {
|
|
292
|
-
testWidth = canvas.measureText(text, s.size, s.family).width;
|
|
293
|
-
text_line = "";
|
|
294
|
-
words = text.split(" ");
|
|
295
|
-
for(var n = 0; n < words.length; n++) {
|
|
296
|
-
testLine = text_line + words[n] + " ";
|
|
297
|
-
metrics = canvas.measureText(testLine, s.size, s.family);
|
|
298
|
-
testWidth = metrics.width;
|
|
299
|
-
if (testWidth > s.lineWidth) {
|
|
300
|
-
drawLine(pos, text_line);
|
|
301
|
-
text_line = words[n] + " ";
|
|
302
|
-
pos++;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
text_line = testLine;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (testWidth < s.lineWidth) {
|
|
309
|
-
drawLine(pos, text_line);
|
|
310
|
-
pos++;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
drawLine(i, text);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
displayLines.call(this, 0);
|
|
319
|
-
|
|
320
|
-
parent.append(this.el);
|
|
321
|
-
this.parent = parent;
|
|
322
|
-
this.pos = {x:x, y:y};
|
|
323
|
-
return this;
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
@doc text/
|
|
328
|
-
@method refresh Refreshed element and changing the text
|
|
329
|
-
@param {String} text New text
|
|
330
|
-
@return {CanvasEngine.Text}
|
|
331
|
-
*/
|
|
332
|
-
refresh: function(text) {
|
|
333
|
-
if (!this.parent) {
|
|
334
|
-
throw "Use 'draw' method before";
|
|
335
|
-
}
|
|
336
|
-
this.parent.empty();
|
|
337
|
-
this.construct(text);
|
|
338
|
-
this.draw(this.parent, this.pos.x, this.pos.y);
|
|
339
|
-
return this;
|
|
340
|
-
},
|
|
341
|
-
|
|
342
|
-
// TODO
|
|
343
|
-
getNumberLines: function() {
|
|
344
|
-
return this.lines.length;
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
@doc text
|
|
351
|
-
@class Text Draw a text with effects
|
|
352
|
-
@example
|
|
353
|
-
|
|
354
|
-
<jsfiddle>WebCreative5/AP6BX</jsfiddle>
|
|
355
|
-
|
|
356
|
-
*/
|
|
357
|
-
var Text = {
|
|
358
|
-
Text: {
|
|
359
|
-
New: function() { return this["new"].apply(this, arguments); },
|
|
360
|
-
"new": function(scene, text) {
|
|
361
|
-
return Class["new"]("Text", [scene, text]);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
|