-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransitions.js
343 lines (317 loc) · 8.54 KB
/
Transitions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// CTRANSITIONDATA : données transitions
//----------------------------------------------------------------------------------
/* Copyright (c) 1996-2012 Clickteam
*
* This source code is part of the HTML5 exporter for Clickteam Multimedia Fusion 2.
*
* Permission is hereby granted to any person obtaining a legal copy
* of Clickteam Multimedia Fusion 2 to use or modify this source code for
* debugging, optimizing, or customizing applications created with
* Clickteam Multimedia Fusion 2.
* Any other use of this source code is prohibited.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
CTransitionData.TRFLAG_COLOR = 0x0001;
function CTransitionData()
{
this.dllName = "";
this.transID = 0;
this.transDuration = 0;
this.transFlags = 0;
this.transColor = 0;
this.dataOffset = 0;
}
CTransitionData.prototype =
{
load: function (file)
{
var debut = file.getFilePointer();
file.skipBytes(4);
this.transID = file.readAInt();
this.transDuration = file.readAInt();
this.transFlags = file.readAInt();
this.transColor = file.readAColor();
var nameOffset = file.readAInt();
var paramOffset = file.readAInt();
file.seek(debut + nameOffset);
this.dllName = file.readAString();
this.dllName = this.dllName.substr(0, this.dllName.indexOf('.'));
this.dataOffset = (debut + paramOffset);
}
}
// CTRANSITIONS : interface avec la dll
//----------------------------------------------------------------------------------
function CTransition()
{
}
CTransition.prototype =
{
getTrans: function (data)
{
return null;
}
}
// CTRANS : interface avec un effet de transition
//----------------------------------------------------------------------------------
CTrans.LEFT_RIGHT = 0;
CTrans.RIGHT_LEFT = 1;
CTrans.TOP_BOTTOM = 2;
CTrans.BOTTOM_TOP = 3;
CTrans.CENTER_LEFTRIGHT = 0;
CTrans.LEFTRIGHT_CENTER = 1;
CTrans.CENTER_TOPBOTTOM = 2;
CTrans.TOPBOTTOM_CENTER = 3;
CTrans.TOP_LEFT = 0;
CTrans.TOP_RIGHT = 1;
CTrans.BOTTOM_LEFT = 2;
CTrans.BOTTOM_RIGHT = 3;
CTrans.CENTER = 4;
CTrans.DIR_HORZ = 0;
CTrans.DIR_VERT = 1;
CTrans.TRFLAG_FADEIN = 0x0001;
CTrans.TRFLAG_FADEOUT = 0x0002;
function CTrans()
{
this.m_initTime = 0;
this.m_currentTime = 0;
this.m_endTime = 0;
this.m_duration = 0;
this.m_overflow = false;
this.m_running = false;
this.m_starting = false;
this.source1 = null;
this.source2 = null;
this.dest = null;
this.destContext = null;
}
CTrans.prototype =
{
start: function (data, display, debut, fin)
{
this.dest = display;
this.destContext = this.dest.getContext("2d");
this.source1 = debut;
this.source2 = fin;
var date = new Date();
this.m_initTime = date.getTime();
this.m_duration = data.transDuration;
if (this.m_duration == 0)
this.m_duration = 1;
this.m_currentTime = this.m_initTime;
this.m_endTime = this.m_initTime + this.m_duration;
this.m_running = true;
this.m_starting = true;
},
finish: function ()
{
},
isCompleted: function ()
{
if (this.m_running)
{
var date = new Date();
if (date.getTime() >= this.m_endTime)
return true;
return (date.getTime() >= this.m_endTime);
}
return true;
},
getDeltaTime: function ()
{
var date = new Date();
this.m_currentTime = date.getTime();
if (this.m_currentTime > this.m_endTime)
this.m_currentTime = this.m_endTime;
return (this.m_currentTime - this.m_initTime);
},
getTimePos: function ()
{
return this.m_currentTime - this.m_initTime;
},
setTimePos: function (msTimePos)
{
this.m_initTime = (this.m_currentTime - this.msTimePos);
this.m_endTime = this.m_initTime + this.m_duration;
},
blit: function (source, xDest, yDest, xSrce, ySrce, width, height)
{
if (this.m_objectFadeOut)
this.destContext.globalCompositeOperation = "source-atop";
if (arguments.length == 1)
this.destContext.drawImage(source, 0, 0);
else if (width > 0 && height > 0)
this.destContext.drawImage(source, xSrce, ySrce, width, height, xDest, yDest, width, height);
},
stretch: function (source, xDest, yDest, wDest, hDest, xSrce, ySrce, wSrce, hSrce)
{
if (this.m_objectFadeOut)
this.destContext.globalCompositeOperation = "source-atop";
if (wDest > 0 && hDest > 0 && wSrce > 0 && hSrce > 0)
this.destContext.drawImage(source, xSrce, ySrce, wSrce, hSrce, xDest, yDest, wDest, hDest);
},
stepDraw: function (flag)
{
},
end: function ()
{
},
init: function (data, file, display, source, dest)
{
}
}
// CTRANSITIONMANAGER
//----------------------------------------------------------------------------------
function CTransitionManager(a)
{
this.app = a;
}
CTransitionManager.prototype =
{
startObjectFade: function (hoPtr, bFadeOut)
{
var pData = hoPtr.hoCommon.ocFadeIn;
if (bFadeOut)
{
pData = hoPtr.hoCommon.ocFadeOut;
}
var img = null;
var context;
if ((hoPtr.hoOEFlags & CObjectCommon.OEFLAG_ANIMATIONS) != 0)
{
var image = this.app.imageBank.getImageFromHandle(hoPtr.roc.rcImage);
img = document.createElement("canvas");
img.width = image.width;
img.height = image.height;
var context = img.getContext("2d");
if (image.mosaic == 0)
context.drawImage(image.img, 0, 0);
else
{
context.drawImage(this.app.imageBank.mosaics[image.mosaic],
image.mosaicX, image.mosaicY,
image.width, image.height, 0, 0,
image.width, image.height);
}
}
else if (hoPtr.hoType >= 32)
{
img = document.createElement("canvas");
img.width = hoPtr.hoImgWidth;
img.height = hoPtr.hoImgHeight;
var renderer = new StandardRendered(img);
if (!hoPtr.getSurface(renderer))
img = null;
}
if (img == null)
{
return null;
}
var width = img.width;
var height = img.height;
// L'image de fond
var display = document.createElement("canvas");
display.width = width;
display.height = height;
// Les images de debut et de fin
var surface1 = document.createElement("canvas");
surface1.width = width;
surface1.height = height;
var surface2 = document.createElement("canvas");
surface2.width = width;
surface2.height = height;
var context;
if (bFadeOut)
{
// Source = image
context = surface1.getContext("2d");
context.drawImage(img, 0, 0);
context = display.getContext("2d");
context.drawImage(img, 0, 0);
if ((pData.transFlags & CTransitionData.TRFLAG_COLOR) != 0)
{
this.copyColorMask(surface2, img, pData.transColor);
}
}
// Fade in
else
{
// Destination = image
context = surface2.getContext("2d");
context.drawImage(img, 0, 0);
if ((pData.transFlags & CTransitionData.TRFLAG_COLOR) != 0)
{
this.copyColorMask(surface1, img, pData.transColor);
}
}
// Charge la transition
var pTrans = this.createTransition(pData, display, surface1, surface2);
if (pTrans != null)
{
var trFlags = 0;
if ((hoPtr.hoFlags & CObject.HOF_FADEOUT) != 0)
{
pTrans.m_objectFadeOut = true;
trFlags |= CTrans.TRFLAG_FADEOUT;
}
else
{
pTrans.m_objectFadeOut = false;
trFlags |= CTrans.TRFLAG_FADEIN;
}
hoPtr.transitionImage = display;
pTrans.stepDraw(trFlags);
}
return pTrans;
},
copyColorMask: function (dest, source, couleur)
{
var context = dest.getContext("2d");
context.drawImage(source, 0, 0);
var width = source.width;
var height = source.height;
var pixels = context.getImageData(0, 0, width, height);
var x, y, alpha;
var color = couleur & 0x00FFFFFF;
var r = (couleur & 0x00FF0000) >> 16;
var g = (couleur & 0x0000FF00) >> 8;
var b = couleur & 0x000000FF;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
if (pixels.data[(y * width + x) * 4 + 3] != 0)
{
pixels.data[(y * width + x) * 4] = r;
pixels.data[(y * width + x) * 4 + 1] = g;
pixels.data[(y * width + x) * 4 + 2] = b;
}
}
}
context.putImageData(pixels, 0, 0);
},
createTransition: function (pData, display, surfaceStart, surfaceEnd)
{
var dllName = pData.dllName;
var dll = null;
// STARTCUT
if (dllName.toLowerCase() == "cctrans")
dll = new CTransitionCCTrans();
// ENDCUT
if (dll != null)
{
var trans = dll.getTrans(pData);
this.app.file.seek(pData.dataOffset);
trans.m_objectFadeOut = false;
trans.init(pData, this.app.file, display, surfaceStart, surfaceEnd);
return trans;
}
return null;
}
}