canvasengine 1.3.0 → 2.0.1-beta.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/.cursorrules +0 -0
- package/.github/workflows/ci.yml +29 -0
- package/README.md +79 -0
- package/dist/compiler/vite.js +119 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/index.d.ts +846 -0
- package/dist/index.js +3340 -0
- package/dist/index.js.map +1 -0
- package/index.d.ts +6 -0
- package/logo.png +0 -0
- package/package.json +84 -18
- package/src/compiler/grammar.pegjs +180 -0
- package/src/compiler/vite.ts +166 -0
- 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 +12 -0
- package/src/components/types/DisplayObject.ts +68 -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 +112 -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 +14 -0
- package/src/presets/Bar.ts +89 -0
- package/src/presets/Button.ts +0 -0
- package/src/presets/Joystick.ts +286 -0
- package/src/presets/NightAmbiant.ts +122 -0
- package/src/presets/Particle.ts +53 -0
- package/src/utils/Ease.ts +33 -0
- package/src/utils/RadialGradient.ts +86 -0
- package/starter/assets/logo.png +0 -0
- package/starter/components/app.ce +18 -0
- package/starter/components/hello.ce +35 -0
- package/starter/index.html +21 -0
- package/starter/main.ts +6 -0
- package/starter/package.json +20 -0
- package/starter/tsconfig.json +32 -0
- package/starter/vite.config.ts +12 -0
- package/tsconfig.json +32 -0
- package/tsconfig.node.json +10 -0
- package/tsup.config.ts +28 -0
- package/vitest.config.ts +12 -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/Window.js
DELETED
|
@@ -1,575 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2012 by WebCreative5, 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
|
-
@doc window
|
|
25
|
-
@class Window Displays a dialog box
|
|
26
|
-
@param {CanvasEngine.Scene} scene Current scene
|
|
27
|
-
@param {Integer} width Width
|
|
28
|
-
@param {Integer} height Height
|
|
29
|
-
@param {String} border (optional) Identifier of the image to the border. The image must contain the four corners and four sides to have 9 tiles. The width and height should be divisible by three
|
|
30
|
-
@example
|
|
31
|
-
|
|
32
|
-
canvas.Scene.New({
|
|
33
|
-
name: "MyScene",
|
|
34
|
-
|
|
35
|
-
materials: {
|
|
36
|
-
images: {
|
|
37
|
-
"border": "images/window.png"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
ready: function(stage) {
|
|
42
|
-
var box;
|
|
43
|
-
this.window = canvas.Window.new(this, 230, 200, "border");
|
|
44
|
-
|
|
45
|
-
box = this.window.getBox();
|
|
46
|
-
box.x = 50;
|
|
47
|
-
box.y = 50;
|
|
48
|
-
|
|
49
|
-
this.window.open(stage);
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
*/
|
|
54
|
-
Class.create("Window", {
|
|
55
|
-
border: null,
|
|
56
|
-
width: 0,
|
|
57
|
-
height: 0,
|
|
58
|
-
bitmap: null,
|
|
59
|
-
el: null,
|
|
60
|
-
_content: null,
|
|
61
|
-
_borders: {},
|
|
62
|
-
_border_size: {
|
|
63
|
-
width: 0,
|
|
64
|
-
height: 0
|
|
65
|
-
},
|
|
66
|
-
initialize: function(scene, width, height, border) {
|
|
67
|
-
this.width = width;
|
|
68
|
-
this.height = height;
|
|
69
|
-
this.border = border;
|
|
70
|
-
this.scene = scene;
|
|
71
|
-
if (border) {
|
|
72
|
-
this.border_img = Global_CE.Materials.get(border);
|
|
73
|
-
this._construct();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
this.el = this.scene.createElement(this.width, this.height);
|
|
77
|
-
this._content = this.scene.createElement();
|
|
78
|
-
this.el.append(this._content);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
_construct: function() {
|
|
82
|
-
if (!Global_CE.Spritesheet) {
|
|
83
|
-
throw "Add Spritesheet class to use windows";
|
|
84
|
-
}
|
|
85
|
-
var borders = ["corner_upleft", "up", "corner_upright", "left", "center", "right", "corner_bottomleft", "bottom", "corner_bottomright"],
|
|
86
|
-
el, b;
|
|
87
|
-
this.el = this.scene.createElement(this.width, this.height);
|
|
88
|
-
this._border_size.width = this.border_img.width / 3;
|
|
89
|
-
this._border_size.height = this.border_img.height / 3;
|
|
90
|
-
this.spritesheet = Global_CE.Spritesheet['new'](this.border, {
|
|
91
|
-
grid: [{
|
|
92
|
-
size: [3, 3],
|
|
93
|
-
tile: [this._border_size.width, this._border_size.height],
|
|
94
|
-
set: borders
|
|
95
|
-
}]
|
|
96
|
-
});
|
|
97
|
-
this._content = this.scene.createElement();
|
|
98
|
-
for (var i=0 ; i < borders.length ; i++) {
|
|
99
|
-
b = borders[i];
|
|
100
|
-
el = this._borders[b] = this.scene.createElement();
|
|
101
|
-
if (/^corner/.test(b)) {
|
|
102
|
-
this.spritesheet.draw(el, b);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
this.spritesheet.pattern(el, b);
|
|
106
|
-
}
|
|
107
|
-
this.el.append(el);
|
|
108
|
-
}
|
|
109
|
-
this._borders["center"].zIndex(0);
|
|
110
|
-
this.el.append(this._content);
|
|
111
|
-
this.size(this.width, this.height);
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
@doc window/
|
|
116
|
-
@method size Change the size of the window and rehabilitates borders depending on the size
|
|
117
|
-
@param {Integer} width Width
|
|
118
|
-
@param {Integer} height Height
|
|
119
|
-
@return {CanvasEngine.Window}
|
|
120
|
-
*/
|
|
121
|
-
size: function(width, height) {
|
|
122
|
-
var bw = this._border_size.width,
|
|
123
|
-
bh = this._border_size.height;
|
|
124
|
-
|
|
125
|
-
function unsigned(cal) {
|
|
126
|
-
return (cal < 0 ? 0 : cal);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// corner_upleft
|
|
131
|
-
// x = 0, y = 0 by default
|
|
132
|
-
// up
|
|
133
|
-
this._borders["up"].x = bw-1;
|
|
134
|
-
this._borders["up"].fillRect(0, 0, width+1 - bw*2 , bh);
|
|
135
|
-
// corner_upright
|
|
136
|
-
this._borders["corner_upright"].x = width - bw;
|
|
137
|
-
// left
|
|
138
|
-
this._borders["left"].y = bh;
|
|
139
|
-
this._borders["left"].fillRect(0, 0, bw, unsigned(height - bh*2));
|
|
140
|
-
// right
|
|
141
|
-
this._borders["right"].x = width - bw;
|
|
142
|
-
this._borders["right"].y = bh;
|
|
143
|
-
this._borders["right"].fillRect(0, 0, bw, unsigned(height - bh*2));
|
|
144
|
-
// corner_bottomleft
|
|
145
|
-
this._borders["corner_bottomleft"].y = height - bh;
|
|
146
|
-
// bottom
|
|
147
|
-
this._borders["bottom"].x = bw-1;
|
|
148
|
-
this._borders["bottom"].y = height - bh;
|
|
149
|
-
this._borders["bottom"].fillRect(0, 0, unsigned(width+1 - bw*2), bh);
|
|
150
|
-
// corner_bottomright
|
|
151
|
-
this._borders["corner_bottomright"].x = width - bw;
|
|
152
|
-
this._borders["corner_bottomright"].y = height - bh;
|
|
153
|
-
// center
|
|
154
|
-
this._borders["center"].x = this._content.x = bw-1;
|
|
155
|
-
this._borders["center"].y = this._content.y = bh;
|
|
156
|
-
this._borders["center"].fillRect(0, 0, unsigned(width+3 - bw*2), unsigned(height - bh*2));
|
|
157
|
-
this.el.width = width;
|
|
158
|
-
this.el.height = height;
|
|
159
|
-
this.el.setOriginPoint("middle");
|
|
160
|
-
return this;
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
@doc window/
|
|
165
|
-
@method position Sets position to the window. If no parameter is assigned, the method returns the current position of the element in an object : {x: , y:}
|
|
166
|
-
@param {String|Integer} x (optional) Position X. If the parameter is a string, the window is positioned at a specific location :
|
|
167
|
-
|
|
168
|
-
* middle : The window is centered
|
|
169
|
-
* bottom : The position of window is in bottom with 3% margin
|
|
170
|
-
* top : The position of window is in top with 3% margin
|
|
171
|
-
* bottom-X : The position of window is in bottom with X margin (px) (eq: "bottom-20")
|
|
172
|
-
* top+X : The position of window is in top with X margin (px) (eq: "top+20")
|
|
173
|
-
|
|
174
|
-
@param {Integer} y (optional) Position Y
|
|
175
|
-
@example
|
|
176
|
-
|
|
177
|
-
In `ready` method
|
|
178
|
-
|
|
179
|
-
var _window = canvas.Window.new(this, 230, 200, "border");
|
|
180
|
-
|
|
181
|
-
_window.position(50, 100);
|
|
182
|
-
_window.position(); // returns {x: 50, y: 100}
|
|
183
|
-
_window.position("middle"); // Center of the window
|
|
184
|
-
|
|
185
|
-
_window.open(stage);
|
|
186
|
-
|
|
187
|
-
@return {CanvasEngine.Window}
|
|
188
|
-
*/
|
|
189
|
-
position: function(typeOrX, y) {
|
|
190
|
-
var canvas = this.scene.getCanvas(), margin;
|
|
191
|
-
if (typeOrX === undefined) {
|
|
192
|
-
return {
|
|
193
|
-
x: this.el.x,
|
|
194
|
-
y: this.el.y
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
if (y === undefined) {
|
|
198
|
-
if (typeOrX == "middle") {
|
|
199
|
-
this.el.x = canvas.width / 2 - this.width / 2;
|
|
200
|
-
this.el.y = canvas.height / 2 - this.height / 2;
|
|
201
|
-
}
|
|
202
|
-
else if (typeOrX == "bottom") {
|
|
203
|
-
this.el.x = canvas.width / 2 - this.width / 2;
|
|
204
|
-
this.el.y = canvas.height - this.height - (canvas.height * 0.03);
|
|
205
|
-
}
|
|
206
|
-
else if (typeOrX == "top") {
|
|
207
|
-
this.el.x = canvas.width / 2 - this.width / 2;
|
|
208
|
-
this.el.y = canvas.height * 0.03;
|
|
209
|
-
}
|
|
210
|
-
else if (margin = typeOrX.match(/top+([0-9]+)/)) {
|
|
211
|
-
this.el.x = canvas.width / 2 - this.width / 2;
|
|
212
|
-
this.el.y = margin[1];
|
|
213
|
-
}
|
|
214
|
-
else if (margin = typeOrX.match(/bottom-([0-9]+)/)) {
|
|
215
|
-
this.el.x = canvas.width / 2 - this.width / 2;
|
|
216
|
-
this.el.y = canvas.height - margin[1];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
this.el.x = typeOrX;
|
|
221
|
-
this.el.y = y;
|
|
222
|
-
}
|
|
223
|
-
return this;
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
@doc window/
|
|
228
|
-
@method setBackground Sets the color and opacity of the background
|
|
229
|
-
@param {String} color Background color in hexadecimal
|
|
230
|
-
@param {Integer} padding (optional) Inner margin below border (0 by default)
|
|
231
|
-
@param {Integer} opacity (optional) Opacity (1 by default)
|
|
232
|
-
@example
|
|
233
|
-
|
|
234
|
-
In `ready` method
|
|
235
|
-
|
|
236
|
-
var _window = canvas.Window.new(this, 230, 200, "border");
|
|
237
|
-
|
|
238
|
-
_window.setBackground("#ff0000", 10, .5);
|
|
239
|
-
|
|
240
|
-
_window.open(stage);
|
|
241
|
-
|
|
242
|
-
@return {CanvasEngine.Window}
|
|
243
|
-
*/
|
|
244
|
-
setBackground: function(color, padding, opacity) {
|
|
245
|
-
var background;
|
|
246
|
-
if (!padding) padding = 0;
|
|
247
|
-
opacity = opacity || 1;
|
|
248
|
-
background = this._borders["center"];
|
|
249
|
-
background.x = padding;
|
|
250
|
-
background.y = padding;
|
|
251
|
-
background.fillStyle = color;
|
|
252
|
-
background.opacity = opacity;
|
|
253
|
-
background.fillRect(0, 0, this.width - padding*2, this.height - padding*2);
|
|
254
|
-
return this;
|
|
255
|
-
},
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
@doc window/
|
|
259
|
-
@method getBox Get the element representing the entire window
|
|
260
|
-
@return {CanvasEngine.Element}
|
|
261
|
-
*/
|
|
262
|
-
getBox: function() {
|
|
263
|
-
return this.el;
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
@doc window/
|
|
268
|
-
@method getContent Retrieves the element representing the content (the center)
|
|
269
|
-
@return {CanvasEngine.Element}
|
|
270
|
-
*/
|
|
271
|
-
getContent: function() {
|
|
272
|
-
return this._content;
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
@doc window/
|
|
277
|
-
@method open Adds the dialog on a parent element and displays the window on the screen
|
|
278
|
-
@param {CanvasEngine.Element} parent Parent element
|
|
279
|
-
@return {CanvasEngine.Window}
|
|
280
|
-
*/
|
|
281
|
-
open: function(parent) {
|
|
282
|
-
parent.append(this.el);
|
|
283
|
-
return this;
|
|
284
|
-
},
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
@doc window/
|
|
288
|
-
@method remove `(>= 1.3.0)` Removes the window
|
|
289
|
-
@return {CanvasEngine.Window}
|
|
290
|
-
*/
|
|
291
|
-
remove: function() {
|
|
292
|
-
this.el.remove();
|
|
293
|
-
return this;
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
@doc cursor
|
|
298
|
-
@class cursor Adds the cursor in the window
|
|
299
|
-
@example
|
|
300
|
-
|
|
301
|
-
var canvas = CE.defines("canvas_id").
|
|
302
|
-
extend([Animation, Spritesheet, Window]).
|
|
303
|
-
ready(function() {
|
|
304
|
-
canvas.Scene.call("MyScene");
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
canvas.Scene.new({
|
|
308
|
-
name: "MyScene",
|
|
309
|
-
materials: {
|
|
310
|
-
images: {
|
|
311
|
-
img_id: "border_window.png"
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
ready: function(stage) {
|
|
315
|
-
var box = canvas.Window.new(this, 500, 300, "img_id"),
|
|
316
|
-
el, array_el, text;
|
|
317
|
-
|
|
318
|
-
var array = ["Text1", "Text2", "Text3"];
|
|
319
|
-
|
|
320
|
-
for (var i=0 ; i < array.length ; i++) {
|
|
321
|
-
el = this.createElement(480, 35);
|
|
322
|
-
el.y = i * 35;
|
|
323
|
-
el.attr('index', i);
|
|
324
|
-
text = canvas.Text.new(this, array[i]); // Text extend
|
|
325
|
-
text.style({
|
|
326
|
-
size: "18px",
|
|
327
|
-
color: "white"
|
|
328
|
-
}).draw(el, 0, 10);
|
|
329
|
-
array_el.push(el);
|
|
330
|
-
box.getContent().append(el);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
var cursor = this.createElement();
|
|
334
|
-
cursor.fillStyle = "#7778AA";
|
|
335
|
-
cursor.fillRect(-10, -10, 480, 30);
|
|
336
|
-
cursor.opacity = .5;
|
|
337
|
-
|
|
338
|
-
box.cursor.init(cursor, array_el);
|
|
339
|
-
|
|
340
|
-
box.cursor.select(function(el) {
|
|
341
|
-
console.log(el.attr('index'));
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
box.cursor.change(function(el) {
|
|
345
|
-
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
box.open(this.stage);
|
|
349
|
-
this.stage.append(cursor);
|
|
350
|
-
|
|
351
|
-
box.cursor.setIndex(0);
|
|
352
|
-
box.cursor.enable(true);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
*/
|
|
357
|
-
cursor: {
|
|
358
|
-
|
|
359
|
-
array_elements: null,
|
|
360
|
-
el: null,
|
|
361
|
-
index: 0,
|
|
362
|
-
params: {},
|
|
363
|
-
_enable: true,
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
@doc cursor/
|
|
367
|
-
@method init Initializes functionality cursors.
|
|
368
|
-
@param {CanvasEngine.Element} element (optional) Element corresponding to the cursor
|
|
369
|
-
@param {Array} array_elements Array containing all the elements that can be selected by the cursor
|
|
370
|
-
@param {Object} params (optional) Additional parameters for the cursor
|
|
371
|
-
|
|
372
|
-
* reverse (Boolean) When the cursor reaches an extreme, it goes through the extreme opposite
|
|
373
|
-
|
|
374
|
-
@return {CanvasEngine.Window.Cursor}
|
|
375
|
-
*/
|
|
376
|
-
init: function(element, array_elements, params) {
|
|
377
|
-
if (element instanceof Array) {
|
|
378
|
-
array_elements = element;
|
|
379
|
-
element = null;
|
|
380
|
-
}
|
|
381
|
-
this.params = params || {};
|
|
382
|
-
this.array_elements = array_elements;
|
|
383
|
-
this.el = element;
|
|
384
|
-
this.update();
|
|
385
|
-
return this;
|
|
386
|
-
},
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
@doc cursor/
|
|
390
|
-
@method refresh Refreshes the table containing the items that can be selected. Updated visual cursor
|
|
391
|
-
@param {Array} array_elements Array containing all the elements that can be selected by the cursor
|
|
392
|
-
@param {Boolean} change (optional) Calls the callback method assigned with the "change"
|
|
393
|
-
@return {CanvasEngine.Window.Cursor}
|
|
394
|
-
*/
|
|
395
|
-
refresh: function(array_elements, change) {
|
|
396
|
-
this.array_elements = array_elements;
|
|
397
|
-
this.setIndex(this.index, change);
|
|
398
|
-
this.update();
|
|
399
|
-
return this;
|
|
400
|
-
},
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
@doc cursor/
|
|
404
|
-
@method remove Removes the cursor visually
|
|
405
|
-
@param {Array} array_elements Array containing all the elements that can be selected by the cursor
|
|
406
|
-
@param {Boolean} change (optional) Calls the callback method assigned with the "change"
|
|
407
|
-
@return {CanvasEngine.Window.Cursor}
|
|
408
|
-
*/
|
|
409
|
-
remove: function() {
|
|
410
|
-
this.el.remove();
|
|
411
|
-
return this;
|
|
412
|
-
},
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
@doc cursor/
|
|
416
|
-
@method assignKeys Assigns keyboard events : Up, Bottom and Enter. Also assigns the click on elements for touch and mouse. Elements must, in this case, have values set for the width and height attributesr
|
|
417
|
-
@param {Boolean} reset (optional) Resets all keys
|
|
418
|
-
@return {CanvasEngine.Window.Cursor}
|
|
419
|
-
*/
|
|
420
|
-
assignKeys: function(reset) {
|
|
421
|
-
var self = this;
|
|
422
|
-
if (reset) {
|
|
423
|
-
Global_CE.Input.reset();
|
|
424
|
-
}
|
|
425
|
-
Global_CE.Input.press([Input.Up], function() {
|
|
426
|
-
if (!self._enable) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
self.setIndex(self.index-1);
|
|
430
|
-
});
|
|
431
|
-
Global_CE.Input.press([Input.Bottom], function() {
|
|
432
|
-
if (!self._enable) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
self.setIndex(self.index+1);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
function enter() {
|
|
440
|
-
if (!self._enable) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
var el = self.array_elements[self.index];
|
|
444
|
-
if (self._select && el) self._select.call(self, el);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
Global_CE.Input.press([Input.Enter], enter);
|
|
448
|
-
|
|
449
|
-
function assignTap(index) {
|
|
450
|
-
var el = this.array_elements[index];
|
|
451
|
-
|
|
452
|
-
if (el.width && el.height && this._enable) {
|
|
453
|
-
el.forceEvent();
|
|
454
|
-
el.on("touch", function() {
|
|
455
|
-
self.setIndex(index);
|
|
456
|
-
self.update();
|
|
457
|
-
enter();
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
for (var i=0 ; i < this.array_elements.length ; i++) {
|
|
462
|
-
assignTap.call(this, i);
|
|
463
|
-
}
|
|
464
|
-
return this;
|
|
465
|
-
},
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
@doc cursor/
|
|
469
|
-
@method getCurrentElement Fetches the current element where the cursor is positioned
|
|
470
|
-
@return {CanvasEngine.Element}
|
|
471
|
-
*/
|
|
472
|
-
getCurrentElement: function() {
|
|
473
|
-
return this.array_elements[this.index];
|
|
474
|
-
},
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
@doc cursor/
|
|
478
|
-
@method setIndex Sets the index of the cursor on an element. The index starts at 0. The cursor is updated visually
|
|
479
|
-
@param {Integer} index new index of cursor
|
|
480
|
-
@param {Boolean} change (optional) Calls the callback method assigned with the "change"
|
|
481
|
-
@return {CanvasEngine.Window.Cursor}
|
|
482
|
-
*/
|
|
483
|
-
setIndex: function(index, change) {
|
|
484
|
-
var h = this.array_elements.length;
|
|
485
|
-
if (index < 0) {
|
|
486
|
-
index = this.params.reverse ? h-1 : 0;
|
|
487
|
-
}
|
|
488
|
-
else if (index >= h) {
|
|
489
|
-
index = this.params.reverse ? 0 : h-1;
|
|
490
|
-
}
|
|
491
|
-
this.index = index;
|
|
492
|
-
this.update(true);
|
|
493
|
-
return true;
|
|
494
|
-
},
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
@doc cursor/
|
|
498
|
-
@method update The cursor is updated visually. If there is any item, the cursor is hidden
|
|
499
|
-
@param {Boolean} change (optional) Calls the callback method assigned with the `change`
|
|
500
|
-
@return {CanvasEngine.Window.Cursor}
|
|
501
|
-
*/
|
|
502
|
-
update: function(call_onchange) {
|
|
503
|
-
if (this.el) {
|
|
504
|
-
if (this.array_elements.length == 0) {
|
|
505
|
-
this.el.hide();
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
this.el.show();
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
var el = this.getCurrentElement(),
|
|
513
|
-
pos;
|
|
514
|
-
if (el) {
|
|
515
|
-
pos = el.position();
|
|
516
|
-
if (this.el) {
|
|
517
|
-
this.el.x = pos.left;
|
|
518
|
-
this.el.y = pos.top;
|
|
519
|
-
}
|
|
520
|
-
if (call_onchange && this._onchange && this.array_elements.length > 0) this._onchange.call(this, el);
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
@doc cursor/
|
|
526
|
-
@method enable Active cursor or not. If it is off, pressing Up, Bottom and Enter are reset. If it is enabled, the method `assignKeys` is called
|
|
527
|
-
@param {Boolean} enable (optional) Enable or disable the cursor. If no value, the current `enable` value is sent
|
|
528
|
-
@return {Boolean}
|
|
529
|
-
*/
|
|
530
|
-
enable: function(enable) {
|
|
531
|
-
if (enable != undefined) {
|
|
532
|
-
this._enable = enable;
|
|
533
|
-
if (enable) {
|
|
534
|
-
this.assignKeys();
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
Global_CE.Input.reset([Input.Enter, Input.Up, Input.bottom]);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
return this._enable;
|
|
541
|
-
},
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
@doc cursor/
|
|
545
|
-
@method change Assigns a callback function when the cursor changes element
|
|
546
|
-
@param {Function} callback Callback
|
|
547
|
-
@return {CanvasEngine.Window.Cursor}
|
|
548
|
-
*/
|
|
549
|
-
change: function(_onchange) {
|
|
550
|
-
this._onchange = _onchange;
|
|
551
|
-
return this;
|
|
552
|
-
},
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
@doc cursor/
|
|
556
|
-
@method select Assigns a callback when the element is selected (Enter key pressed)
|
|
557
|
-
@param {Function} callback Callback
|
|
558
|
-
@return {CanvasEngine.Window.Cursor}
|
|
559
|
-
*/
|
|
560
|
-
select: function(_select) {
|
|
561
|
-
this._select = _select;
|
|
562
|
-
return this;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
var Window = {
|
|
569
|
-
Window: {
|
|
570
|
-
New: function() { return this["new"].apply(this, arguments); },
|
|
571
|
-
"new": function(scene, width, height, border) {
|
|
572
|
-
return Class["new"]("Window", [scene, width, height, border]);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
};
|