Skip to content

Commit 469138b

Browse files
committed
Added support for drawPath
1 parent 44aeda7 commit 469138b

9 files changed

Lines changed: 254 additions & 128 deletions

File tree

.idea/workspace.xml

Lines changed: 52 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripting/build/Host.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ var CCLScripting = function(workerUrl){
370370
this.__defineSetter__("y", function(f){
371371
this.setY(f);
372372
});
373+
this.__defineGetter__("x", function(f){
374+
return data.x;
375+
});
376+
this.__defineGetter__("y", function(f){
377+
return data.y;
378+
});
373379
this.__defineGetter__("text", function(f){
374380
return this.DOM.textContent;
375381
});
@@ -468,7 +474,8 @@ var CCLScripting = function(workerUrl){
468474
};
469475
this.fill = {
470476
fill:"none",
471-
alpha:1
477+
alpha:1,
478+
fillRule:"nonzero"
472479
};
473480
var toRGB = function(number){
474481
var string = parseInt(number).toString(16);
@@ -497,7 +504,8 @@ var CCLScripting = function(workerUrl){
497504
var applyFill = function(p, ref){
498505
__(p, {
499506
"fill": ref.fill.fill,
500-
"fill-opacity": ref.fill.alpha
507+
"fill-opacity": ref.fill.alpha,
508+
"fill-rule": ref.fill.fillRule
501509
});
502510
};
503511

@@ -572,6 +580,53 @@ var CCLScripting = function(workerUrl){
572580
applyStroke(state.lastPath, this);
573581
}
574582
};
583+
this.drawPath = function(params){
584+
var commands = params[0];
585+
var data = params[1];
586+
this.fill.fillRule = (params[2] === "nonZero" ? "nonzero" : "evenodd");
587+
var d = "M0 0";
588+
for(var i = 0; i < commands.length; i++){
589+
switch(commands[i]){
590+
default:
591+
case 0:{
592+
/* NoOp x0 */
593+
continue;
594+
}break;
595+
case 1: {
596+
/* MoveTo x2 */
597+
d += " M" + data.splice(0,2).join(" ");
598+
}break;
599+
case 2: {
600+
/* LineTo x2 */
601+
d += " L" + data.splice(0,2).join(" ");
602+
}break;
603+
case 3: {
604+
/* CurveTo x4 */
605+
d += " Q" + data.splice(0,4).join(" ");
606+
}break;
607+
case 4: {
608+
/* wide MoveTo x4 */
609+
data.splice(0,2);
610+
d += " M" + data.splice(0,2).join(" ");
611+
}break;
612+
case 5: {
613+
/* wide LineTo x4 */
614+
data.splice(0,2);
615+
d += " L" + data.splice(0,2).join(" ");
616+
}break;
617+
case 6: {
618+
/* CubicCurveTo x6 */
619+
d += " C" + data.splice(0,6).join(" ");
620+
}break;
621+
}
622+
};
623+
var path = __("path",{
624+
"d": d
625+
});
626+
applyFill(path, this);
627+
applyStroke(path, this);
628+
defaultGroup.appendChild(path);
629+
};
575630
this.beginFill = function(params){
576631
if(params.length === 0)
577632
return;

src/scripting/build/api/Display.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,17 @@ var Display;
10481048
this._callDrawMethod("drawRoundRect", [x, y, w, h, elw, elh]);
10491049
};
10501050

1051+
/**
1052+
* Executes a list of drawing commands with their data given in the data array
1053+
* @param commands - Commands by index
1054+
* @param data - List of data
1055+
* @param winding - evenOdd or nonZero
1056+
*/
1057+
Graphics.prototype.drawPath = function (commands, data, winding) {
1058+
if (typeof winding === "undefined") { winding = "evenOdd"; }
1059+
this._callDrawMethod("drawPath", [commands, data, winding]);
1060+
};
1061+
10511062
/**
10521063
* Fill next shape with solid color
10531064
* @param color

src/scripting/build/api/ScriptManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var ScriptManager = new function(){
22
this.clearTimer = function(){
3-
Runtime.deregisterAllListeners("__self");
4-
Runtime.getMasterTimer().clearAll();
3+
//Runtime.deregisterAllListeners("__self");
4+
//Runtime.getMasterTimer().clearAll();
55
};
66

77
this.clearEl = function(){

src/scripting/src/Unpacker.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
this.__defineSetter__("y", function(f){
9292
this.setY(f);
9393
});
94+
this.__defineGetter__("x", function(f){
95+
return data.x;
96+
});
97+
this.__defineGetter__("y", function(f){
98+
return data.y;
99+
});
94100
this.__defineGetter__("text", function(f){
95101
return this.DOM.textContent;
96102
});
@@ -189,7 +195,8 @@
189195
};
190196
this.fill = {
191197
fill:"none",
192-
alpha:1
198+
alpha:1,
199+
fillRule:"nonzero"
193200
};
194201
var toRGB = function(number){
195202
var string = parseInt(number).toString(16);
@@ -218,7 +225,8 @@
218225
var applyFill = function(p, ref){
219226
__(p, {
220227
"fill": ref.fill.fill,
221-
"fill-opacity": ref.fill.alpha
228+
"fill-opacity": ref.fill.alpha,
229+
"fill-rule": ref.fill.fillRule
222230
});
223231
};
224232

@@ -293,6 +301,53 @@
293301
applyStroke(state.lastPath, this);
294302
}
295303
};
304+
this.drawPath = function(params){
305+
var commands = params[0];
306+
var data = params[1];
307+
this.fill.fillRule = (params[2] === "nonZero" ? "nonzero" : "evenodd");
308+
var d = "M0 0";
309+
for(var i = 0; i < commands.length; i++){
310+
switch(commands[i]){
311+
default:
312+
case 0:{
313+
/* NoOp x0 */
314+
continue;
315+
}break;
316+
case 1: {
317+
/* MoveTo x2 */
318+
d += " M" + data.splice(0,2).join(" ");
319+
}break;
320+
case 2: {
321+
/* LineTo x2 */
322+
d += " L" + data.splice(0,2).join(" ");
323+
}break;
324+
case 3: {
325+
/* CurveTo x4 */
326+
d += " Q" + data.splice(0,4).join(" ");
327+
}break;
328+
case 4: {
329+
/* wide MoveTo x4 */
330+
data.splice(0,2);
331+
d += " M" + data.splice(0,2).join(" ");
332+
}break;
333+
case 5: {
334+
/* wide LineTo x4 */
335+
data.splice(0,2);
336+
d += " L" + data.splice(0,2).join(" ");
337+
}break;
338+
case 6: {
339+
/* CubicCurveTo x6 */
340+
d += " C" + data.splice(0,6).join(" ");
341+
}break;
342+
}
343+
};
344+
var path = __("path",{
345+
"d": d
346+
});
347+
applyFill(path, this);
348+
applyStroke(path, this);
349+
defaultGroup.appendChild(path);
350+
};
296351
this.beginFill = function(params){
297352
if(params.length === 0)
298353
return;

src/scripting/src/api/Display/Graphics.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ module Display {
123123
this._callDrawMethod("drawRoundRect", [x, y, w, h, elw, elh]);
124124
}
125125

126+
/**
127+
* Executes a list of drawing commands with their data given in the data array
128+
* @param commands - Commands by index
129+
* @param data - List of data
130+
* @param winding - evenOdd or nonZero
131+
*/
132+
public drawPath(commands:Array<number>, data:Array<number>, winding:string = "evenOdd"):void{
133+
this._callDrawMethod("drawPath",[commands, data, winding]);
134+
}
135+
126136
/**
127137
* Fill next shape with solid color
128138
* @param color

src/scripting/src/api/ScriptManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var ScriptManager = new function(){
22
this.clearTimer = function(){
3-
Runtime.deregisterAllListeners("__self");
4-
Runtime.getMasterTimer().clearAll();
3+
//Runtime.deregisterAllListeners("__self");
4+
//Runtime.getMasterTimer().clearAll();
55
};
66

77
this.clearEl = function(){

0 commit comments

Comments
 (0)