Skip to content

Commit 71afc6f

Browse files
committed
Modified scripting engine framework:
- Beginnings of Bitmap support - Fixed some bugs with the (soon to be re-written in TypeScript Host.js) - Removed unused 3D tests
1 parent d3e62de commit 71afc6f

File tree

21 files changed

+28988
-440
lines changed

21 files changed

+28988
-440
lines changed

demo/scripting/ccl.htm

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<div class="controls">
4040
<a class="button" onclick="stop();" href="javascript:;">Stop</a>
4141
<a class="button" onclick="resume();" href="javascript:;">Resume</a>
42-
<a class="button" onclick="resize();" href="javascript:;">Resize</a>
42+
<a class="button" onclick="cmresize();" href="javascript:;">Resize</a>
4343
<div style="clear:both;"></div>
4444
</div>
4545
<div style="clear:both;"></div>
@@ -52,7 +52,9 @@ <h2>Tests</h2>
5252
<a class="button" onclick="load('../../test/scripting/comment-festival-v3.xml');" href="javascript:;">Run Scripting 3 (Large) [Comment Festival v3]</a>
5353
<a class="button" onclick="load('../../test/scripting/jinzou-enemy.xml');" href="javascript:;">Run Scripting 4 (drawPath) [Jinzou Enemy]</a>
5454
<a class="button" onclick="load('../../test/scripting/crazy-night.xml');" href="javascript:;">Run Scripting 5 (textures &amp; 3d) [Crazy Night]</a>
55-
<a class="button" onclick="load('../../test/scripting/round-and-round.xml');" href="javascript:;">Run Scripting 6 (Akari engine) [Round and Round]</a>
55+
<a class="button" onclick="load('../../test/scripting/av2775802.xml');" href="javascript:;">Run Scripting 6 (Complex) [World's End Dance Hall]</a>
56+
<a class="button" onclick="load('../../test/scripting/round-and-round.xml');" href="javascript:;">Run Scripting 7 (Akari engine) [Round and Round]</a>
57+
<a class="button" onclick="load('../../test/scripting/av2739681.xml');" href="javascript:;">Run Scripting 8 (Akari engine) [Vidro Moyou]</a>
5658
<div style="clear:both;"></div>
5759
</div>
5860
</div>
@@ -153,13 +155,10 @@ <h2>Tests</h2>
153155
function timeupdate(){
154156
playhead = Date.now() - start;
155157
cm.time(playhead);
156-
if(cm.scripting && playhead - lasthead > 300 ){
157-
cm.scripting.send("Update:TimeUpdate",{
158-
"state": "playing",
159-
"time": playhead
160-
});
161-
lasthead = playhead;
162-
}
158+
cm.scripting.send("Update:TimeUpdate", {
159+
"state": "playing",
160+
"time": playhead
161+
});
163162
}
164163

165164
function load(dmf,dmfmd){
@@ -222,7 +221,7 @@ <h2>Tests</h2>
222221
lasthead = playhead;
223222
tmr = setInterval(timeupdate,42);
224223
}
225-
function resize() {
224+
function cmresize() {
226225
if (cm.large) {
227226
cm.large = false;
228227
$('player').style.height = '384px';

dist/scripting/Host.js

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,18 @@ var CCLScripting = function(workerUrl){
522522
return elem;
523523
};
524524

525+
var globalDefs = __('defs');
525526
var defaultEffects = __("defs");
526527
var defaultGroup = __("g",{
527528
});
528529
var defaultContainer = __("g",{
529530
"transform":"translate(" + this._x + "," + this._y + ")",
530531
"opacity":this._alpha,
531532
});
533+
532534
defaultContainer.appendChild(defaultGroup);
533535
var defaultGroupWithEffects = defaultContainer;
536+
this.DOM.appendChild(globalDefs);
534537
this.DOM.appendChild(defaultEffects);
535538
this.DOM.appendChild(defaultGroupWithEffects);
536539
/** PROPS **/
@@ -549,6 +552,13 @@ var CCLScripting = function(workerUrl){
549552
this.__defineSetter__("alpha", function(f){
550553
this.setAlpha(f);
551554
});
555+
this.__defineSetter__("blendMode", function(f){
556+
this.DOM.style.backgroundBlendMode = f;
557+
this.DOM.style.mixBlendMode = f;
558+
});
559+
this.__defineGetter__("blendMode", function(f){
560+
return '';
561+
});
552562
this.__defineGetter__("x", function(f){
553563
return this._x;
554564
});
@@ -772,6 +782,31 @@ var CCLScripting = function(workerUrl){
772782
this.fill.alpha = params[1];
773783
}
774784
};
785+
this.beginGradientFill = function(params) {
786+
if(params.length === 0) {
787+
return;
788+
}
789+
var gradId = 'gradient-' + params[0] + '-' + globalDefs.childNodes.length;
790+
var grad;
791+
if (params[0] === 'linear') {
792+
grad = __('linearGradient', {'id': gradId, 'spreadMethod': params[5]});
793+
} else {
794+
grad = __('radialGradient', {'id': gradId, 'spreadMethod': params[5]});
795+
}
796+
// Figure out all the stops
797+
var colors = params[1];
798+
var alphas = params[2];
799+
var ratios = params[3];
800+
for (var i = 0; i < ratios.length; i++) {
801+
grad.appendChild(__('stop', {
802+
'offset': ratios[i] / 255,
803+
'stop-color': toRGB(colors[i]),
804+
'stop-opacity': alphas[i]
805+
}));
806+
}
807+
globalDefs.appendChild(grad);
808+
this.fill.fill = 'url(#' + gradId + ')';
809+
};
775810
this.endFill = function(params){
776811
this.fill.fill = "none";
777812
};
@@ -807,7 +842,7 @@ var CCLScripting = function(workerUrl){
807842
});
808843
applyFill(r, this);
809844
applyStroke(r, this);
810-
this.DOM.appendChild(r);
845+
defaultGroup.appendChild(r);
811846
};
812847
this.drawCircle = function(params){
813848
var c = __("circle",{
@@ -889,10 +924,10 @@ var CCLScripting = function(workerUrl){
889924
var filter = filters[i];
890925
var dFilter = __("filter",{
891926
"id":"fe" + filter.type + i,
892-
"x":"-100%",
893-
"y":"-100%",
894-
"width":"400%",
895-
"height":"400%"
927+
"x":"-50%",
928+
"y":"-50%",
929+
"width":"200%",
930+
"height":"200%"
896931
});
897932
switch(filter.type){
898933
default:break;
@@ -992,6 +1027,13 @@ var CCLScripting = function(workerUrl){
9921027
this.__defineSetter__("y", function(f){
9931028
this.setY(f);
9941029
});
1030+
this.__defineSetter__("blendMode", function(f){
1031+
this.DOM.style.backgroundBlendMode = f;
1032+
this.DOM.style.mixBlendMode = f;
1033+
});
1034+
this.__defineGetter__("blendMode", function(f){
1035+
return '';
1036+
});
9951037
this.__defineGetter__("x", function(f){
9961038
return this.DOM.offsetLeft;
9971039
});
@@ -1072,10 +1114,10 @@ var CCLScripting = function(workerUrl){
10721114
return;
10731115
if(child.DOM){
10741116
if(child.getClass() === "Shape"){
1075-
child.DOM.style.left = -this.x + "px";
1076-
child.DOM.style.top = -this.y + "px";
1077-
child.setX(this.x);
1078-
child.setY(this.y);
1117+
var tX = (stage.offsetWidth / 2), tY = (stage.offsetHeight / 2);
1118+
child.offset(tX, tY);
1119+
child.DOM.style.left = -tX+ "px";
1120+
child.DOM.style.top = -tY+ "px";
10791121
}
10801122
this.DOM.appendChild(child.DOM);
10811123
}else{

0 commit comments

Comments
 (0)