Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Jan 6, 2017
1 parent 2f2a202 commit 369f9c7
Show file tree
Hide file tree
Showing 56 changed files with 28,072 additions and 373 deletions.
2 changes: 1 addition & 1 deletion behaviors/rex_bHash/edittime.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ AddStringParam("Key", "The key string of the hash to get.", '""');
AddExpression(3, ef_return_any | ef_variadic_parameters, "Get value at",
"Value", "At", "Get value from the hash by key string, return JSON string if the item is an object. Add 2nd parameter to return default value when got invalid value.");
AddExpression(4, ef_return_string, "Current key", "For each", "CurKey", "Get the current key in a For Each loop.");
AddExpression(5, ef_return_any, "Current value", "For each", "CurValue", "Get the current value in a For Each loop. Add 2nd parameter to return sub-item by keys. Add 3rd parameter to return default value when got invalid value.");
AddExpression(5, ef_return_any | ef_variadic_parameters, "Current value", "For each", "CurValue", "Get the current value in a For Each loop. Add 2nd parameter to return sub-item by keys. Add 3rd parameter to return default value when got invalid value.");
AddAnyTypeParam("Key", "The key of the hash to get.", '""');
AddExpression(6, ef_return_any | ef_variadic_parameters, "Get value at",
"Value", "AtKeys", "Get value from the hash by keys, each parameter is a key.");
Expand Down
2 changes: 1 addition & 1 deletion behaviors/rex_boundary/edittime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return {
"name": "Boundary",
"id": "Rex_boundary",
"description": "Clamp position of object in the boundary, or wrap the position at the other boundary.",
"description": "Clamp or wrap position.",
"author": "Rex.Rainbow",
"help url": "https://dl.dropbox.com/u/5779181/C2Repo/rex_boundary.html",
"category": "Rex - Movement - position",
Expand Down
32 changes: 10 additions & 22 deletions behaviors/rex_button/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ cr.behaviors.Rex_Button2 = function(runtime)
behtypeProto.onCreate = function()
{
this.touchwrap = null;
this.GetX = null;
this.GetY = null;
};

behtypeProto.TouchWrapGet = function ()
Expand All @@ -45,9 +43,7 @@ cr.behaviors.Rex_Button2 = function(runtime)
obj = plugins[name].instances[0];
if ((obj != null) && (obj.check_name == "TOUCHWRAP"))
{
this.touchwrap = obj;
this.GetX = cr.plugins_.rex_TouchWrap.prototype.exps.XForID;
this.GetY = cr.plugins_.rex_TouchWrap.prototype.exps.YForID;
this.touchwrap = obj;
this.touchwrap.HookMe(this);
break;
}
Expand Down Expand Up @@ -84,7 +80,7 @@ cr.behaviors.Rex_Button2 = function(runtime)
// Transform point from canvas to instance's layer
lx = inst.layer.canvasToLayer(touchX, touchY, true);
ly = inst.layer.canvasToLayer(touchX, touchY, false);

if (inst.contains_pt(lx, ly))
_touch_insts.push(inst);
}
Expand Down Expand Up @@ -288,10 +284,10 @@ cr.behaviors.Rex_Button2 = function(runtime)
behinstProto._is_touch_inside = function ()
{
var touchwrap = this.type.touchwrap;
var touch_x = this.GetX();
var touch_y = this.GetY();
var touch_x = this.GetTouchX();
var touch_y = this.GetTouchY();
this.inst.update_bbox();
return this.inst.contains_pt(touch_x, touch_y)
return this.inst.contains_pt(touch_x, touch_y);
};
behinstProto._check_click_cancel = function (is_touch_inside)
{
Expand Down Expand Up @@ -333,7 +329,7 @@ cr.behaviors.Rex_Button2 = function(runtime)
{
if (this.clickMode == 0)
{
this.touchSrc = touch_src;
this.touchSrc = touch_src;
this._set_state(CLICK_DETECTING_STATE);
this.runtime.trigger(cr.behaviors.Rex_Button2.prototype.cnds.OnClickStart, this.inst);
}
Expand Down Expand Up @@ -373,22 +369,14 @@ cr.behaviors.Rex_Button2 = function(runtime)
}
};

behinstProto.GetX = function()
behinstProto.GetTouchX = function()
{
var touch_obj = this.type.touchwrap;
var src = (touch_obj.IsMouseMode())? 0: this.touchSrc;
this.type.GetX.call(touch_obj,
touch_obj.fake_ret, src, this.inst.layer.index);
return touch_obj.fake_ret.value;
return this.type.touchwrap.XForID(this.touchSrc, this.inst.layer.index);
};

behinstProto.GetY = function()
behinstProto.GetTouchY = function()
{
var touch_obj = this.type.touchwrap;
var src = (touch_obj.IsMouseMode())? 0: this.touchSrc;
this.type.GetY.call(touch_obj,
touch_obj.fake_ret, src, this.inst.layer.index);
return touch_obj.fake_ret.value;
return this.type.touchwrap.YForID(this.touchSrc, this.inst.layer.index);
};

behinstProto.saveToJSON = function ()
Expand Down
152 changes: 151 additions & 1 deletion behaviors/rex_canvas_floodfill/floodfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,156 @@
}

// https://github.com/binarymax/floodfill.js
var floodfill=(function(){function f(p,v,u,l,t,g,B){var k=p.length;var q=[];var o=(v+u*g)*4;var r=o,z=o,s,A,n=g*4;var h=[p[o],p[o+1],p[o+2],p[o+3]];if(!a(o,h,l,p,k,t)){return false}q.push(o);while(q.length){o=q.pop();if(e(o,h,l,p,k,t)){r=o;z=o;A=parseInt(o/n)*n;s=A+n;while(A<z&&A<(z-=4)&&e(z,h,l,p,k,t)){}while(s>r&&s>(r+=4)&&e(r,h,l,p,k,t)){}for(var m=z;m<r;m+=4){if(m-n>=0&&a(m-n,h,l,p,k,t)){q.push(m-n)}if(m+n<k&&a(m+n,h,l,p,k,t)){q.push(m+n)}}}}return p}function a(j,l,h,m,k,g){if(j<0||j>=k){return false}if(m[j+3]===0&&h.a>0){return true}if(Math.abs(l[3]-h.a)<=g&&Math.abs(l[0]-h.r)<=g&&Math.abs(l[1]-h.g)<=g&&Math.abs(l[2]-h.b)<=g){return false}if((l[3]===m[j+3])&&(l[0]===m[j])&&(l[1]===m[j+1])&&(l[2]===m[j+2])){return true}if(Math.abs(l[3]-m[j+3])<=(255-g)&&Math.abs(l[0]-m[j])<=g&&Math.abs(l[1]-m[j+1])<=g&&Math.abs(l[2]-m[j+2])<=g){return true}return false}function e(j,l,h,m,k,g){if(a(j,l,h,m,k,g)){m[j]=h.r;m[j+1]=h.g;m[j+2]=h.b;m[j+3]=h.a;return true}return false}function b(j,n,m,i,k,g,o){if(!j instanceof Uint8ClampedArray){throw new Error("data must be an instance of Uint8ClampedArray")}if(isNaN(g)||g<1){throw new Error("argument 'width' must be a positive integer")}if(isNaN(o)||o<1){throw new Error("argument 'height' must be a positive integer")}if(isNaN(n)||n<0){throw new Error("argument 'x' must be a positive integer")}if(isNaN(m)||m<0){throw new Error("argument 'y' must be a positive integer")}if(g*o*4!==j.length){throw new Error("width and height do not fit Uint8ClampedArray dimensions")}var l=Math.floor(n);var h=Math.floor(m);if(l!==n){console.warn("x truncated from",n,"to",l)}if(h!==m){console.warn("y truncated from",m,"to",h)}k=(!isNaN(k))?Math.min(Math.abs(Math.round(k)),254):0;return f(j,l,h,i,k,g,o)}var d=function(l){var h=document.createElement("div");var g={r:0,g:0,b:0,a:0};h.style.color=l;h.style.display="none";document.body.appendChild(h);var i=window.getComputedStyle(h,null).color;document.body.removeChild(h);var k=/([\.\d]+)/g;var j=i.match(k);if(j&&j.length>2){g.r=parseInt(j[0])||0;g.g=parseInt(j[1])||0;g.b=parseInt(j[2])||0;g.a=Math.round((parseFloat(j[3])||1)*255)}return g};function c(p,n,m,i,o,q,g){var s=this;var k=d(this.fillStyle);i=(isNaN(i))?0:i;o=(isNaN(o))?0:o;q=(!isNaN(q)&&q)?Math.min(Math.abs(q),s.canvas.width):s.canvas.width;g=(!isNaN(g)&&g)?Math.min(Math.abs(g),s.canvas.height):s.canvas.height;var j=s.getImageData(i,o,q,g);var l=j.data;var h=j.width;var r=j.height;if(h>0&&r>0){b(l,p,n,k,m,h,r);s.putImageData(j,i,o)}}if(typeof CanvasRenderingContext2D==="function"){CanvasRenderingContext2D.prototype.fillFlood=c}return b})();
//var floodfill=(function(){function f(p,v,u,l,t,g,B){var k=p.length;var q=[];var o=(v+u*g)*4;var r=o,z=o,s,A,n=g*4;var h=[p[o],p[o+1],p[o+2],p[o+3]];if(!a(o,h,l,p,k,t)){return false}q.push(o);while(q.length){o=q.pop();if(e(o,h,l,p,k,t)){r=o;z=o;A=parseInt(o/n)*n;s=A+n;while(A<z&&A<(z-=4)&&e(z,h,l,p,k,t)){}while(s>r&&s>(r+=4)&&e(r,h,l,p,k,t)){}for(var m=z;m<r;m+=4){if(m-n>=0&&a(m-n,h,l,p,k,t)){q.push(m-n)}if(m+n<k&&a(m+n,h,l,p,k,t)){q.push(m+n)}}}}return p}function a(j,l,h,m,k,g){if(j<0||j>=k){return false}if(m[j+3]===0&&h.a>0){return true}if(Math.abs(l[3]-h.a)<=g&&Math.abs(l[0]-h.r)<=g&&Math.abs(l[1]-h.g)<=g&&Math.abs(l[2]-h.b)<=g){return false}if((l[3]===m[j+3])&&(l[0]===m[j])&&(l[1]===m[j+1])&&(l[2]===m[j+2])){return true}if(Math.abs(l[3]-m[j+3])<=(255-g)&&Math.abs(l[0]-m[j])<=g&&Math.abs(l[1]-m[j+1])<=g&&Math.abs(l[2]-m[j+2])<=g){return true}return false}function e(j,l,h,m,k,g){if(a(j,l,h,m,k,g)){m[j]=h.r;m[j+1]=h.g;m[j+2]=h.b;m[j+3]=h.a;return true}return false}function b(j,n,m,i,k,g,o){if(!j instanceof Uint8ClampedArray){throw new Error("data must be an instance of Uint8ClampedArray")}if(isNaN(g)||g<1){throw new Error("argument 'width' must be a positive integer")}if(isNaN(o)||o<1){throw new Error("argument 'height' must be a positive integer")}if(isNaN(n)||n<0){throw new Error("argument 'x' must be a positive integer")}if(isNaN(m)||m<0){throw new Error("argument 'y' must be a positive integer")}if(g*o*4!==j.length){throw new Error("width and height do not fit Uint8ClampedArray dimensions")}var l=Math.floor(n);var h=Math.floor(m);if(l!==n){console.warn("x truncated from",n,"to",l)}if(h!==m){console.warn("y truncated from",m,"to",h)}k=(!isNaN(k))?Math.min(Math.abs(Math.round(k)),254):0;return f(j,l,h,i,k,g,o)}var d=function(l){var h=document.createElement("div");var g={r:0,g:0,b:0,a:0};h.style.color=l;h.style.display="none";document.body.appendChild(h);var i=window.getComputedStyle(h,null).color;document.body.removeChild(h);var k=/([\.\d]+)/g;var j=i.match(k);if(j&&j.length>2){g.r=parseInt(j[0])||0;g.g=parseInt(j[1])||0;g.b=parseInt(j[2])||0;g.a=Math.round((parseFloat(j[3])||1)*255)}return g};function c(p,n,m,i,o,q,g){var s=this;var k=d(this.fillStyle);i=(isNaN(i))?0:i;o=(isNaN(o))?0:o;q=(!isNaN(q)&&q)?Math.min(Math.abs(q),s.canvas.width):s.canvas.width;g=(!isNaN(g)&&g)?Math.min(Math.abs(g),s.canvas.height):s.canvas.height;var j=s.getImageData(i,o,q,g);var l=j.data;var h=j.width;var r=j.height;if(h>0&&r>0){b(l,p,n,k,m,h,r);s.putImageData(j,i,o)}}if(typeof CanvasRenderingContext2D==="function"){CanvasRenderingContext2D.prototype.fillFlood=c}return b})();

var floodfill = (function() {

//Copyright(c) Max Irwin - 2011, 2015, 2016
//MIT License

function floodfill(data,x,y,fillcolor,tolerance,width,height) {

var length = data.length;
var Q = [];
var i = (x+y*width)*4;
var e = i, w = i, me, mw, w2 = width*4;

var targetcolor = [data[i],data[i+1],data[i+2],data[i+3]];

if(!pixelCompare(i,targetcolor,fillcolor,data,length,tolerance)) { return false; }
Q.push(i);
while(Q.length) {
i = Q.pop();
if(pixelCompareAndSet(i,targetcolor,fillcolor,data,length,tolerance)) {
e = i;
w = i;
mw = parseInt(i/w2)*w2; //left bound
me = mw+w2; //right bound
while(mw<w && mw<(w-=4) && pixelCompareAndSet(w,targetcolor,fillcolor,data,length,tolerance)); //go left until edge hit
while(me>e && me>(e+=4) && pixelCompareAndSet(e,targetcolor,fillcolor,data,length,tolerance)); //go right until edge hit
for(var j=w;j<e;j+=4) {
if(j-w2>=0 && pixelCompare(j-w2,targetcolor,fillcolor,data,length,tolerance)) Q.push(j-w2); //queue y-1
if(j+w2<length && pixelCompare(j+w2,targetcolor,fillcolor,data,length,tolerance)) Q.push(j+w2); //queue y+1
}
}
}
return data;
};

function pixelCompare(i,targetcolor,fillcolor,data,length,tolerance) {
if (i<0||i>=length) return false; //out of bounds
if (data[i+3]===0 && fillcolor.a>0) return true; //surface is invisible and fill is visible

if (
Math.abs(targetcolor[3] - fillcolor.a)<=tolerance &&
Math.abs(targetcolor[0] - fillcolor.r)<=tolerance &&
Math.abs(targetcolor[1] - fillcolor.g)<=tolerance &&
Math.abs(targetcolor[2] - fillcolor.b)<=tolerance
) return false; //target is same as fill

if (
(targetcolor[3] === data[i+3]) &&
(targetcolor[0] === data[i] ) &&
(targetcolor[1] === data[i+1]) &&
(targetcolor[2] === data[i+2])
) return true; //target matches surface

if (
Math.abs(targetcolor[3] - data[i+3])<=(255-tolerance) &&
Math.abs(targetcolor[0] - data[i] )<=tolerance &&
Math.abs(targetcolor[1] - data[i+1])<=tolerance &&
Math.abs(targetcolor[2] - data[i+2])<=tolerance
) return true; //target to surface within tolerance

return false; //no match
};

function pixelCompareAndSet(i,targetcolor,fillcolor,data,length,tolerance) {
if(pixelCompare(i,targetcolor,fillcolor,data,length,tolerance)) {
//fill the color
data[i] = fillcolor.r;
data[i+1] = fillcolor.g;
data[i+2] = fillcolor.b;
data[i+3] = fillcolor.a;
return true;
}
return false;
};

function fillUint8ClampedArray(data,x,y,color,tolerance,width,height) {
if (!data instanceof Uint8ClampedArray) throw new Error("data must be an instance of Uint8ClampedArray");
if (isNaN(width) || width<1) throw new Error("argument 'width' must be a positive integer");
if (isNaN(height) || height<1) throw new Error("argument 'height' must be a positive integer");
if (isNaN(x) || x<0) throw new Error("argument 'x' must be a positive integer");
if (isNaN(y) || y<0) throw new Error("argument 'y' must be a positive integer");
if (width*height*4!==data.length) throw new Error("width and height do not fit Uint8ClampedArray dimensions");

var xi = Math.floor(x);
var yi = Math.floor(y);

if (xi!==x) console.warn("x truncated from",x,"to",xi);
if (yi!==y) console.warn("y truncated from",y,"to",yi);

//Maximum tolerance of 254, Default to 0
tolerance = (!isNaN(tolerance)) ? Math.min(Math.abs(Math.round(tolerance)),254) : 0;

return floodfill(data,xi,yi,color,tolerance,width,height);
};

var getComputedColor = function(c) {
var temp = document.createElement("div");
var color = {r:0,g:0,b:0,a:0};
temp.style.color = c;
temp.style.display = "none";
document.body.appendChild(temp);
//Use native window.getComputedStyle to parse any CSS color pattern
var style = window.getComputedStyle(temp,null).color;
document.body.removeChild(temp);

var recol = /([\.\d]+)/g;
var vals = style.match(recol);
if (vals && vals.length>2) {
//Coerce the string value into an rgba object
color.r = parseInt(vals[0])||0;
color.g = parseInt(vals[1])||0;
color.b = parseInt(vals[2])||0;
color.a = Math.round((parseFloat(vals[3])||1.0)*255);
}
return color;
};

function fillContext(x,y,tolerance,left,top,right,bottom) {
var ctx = this;

//Gets the rgba color from the context fillStyle
var color = getComputedColor(this.fillStyle);

//Defaults and type checks for image boundaries
left = (isNaN(left)) ? 0 : left;
top = (isNaN(top)) ? 0 : top;
right = (!isNaN(right)&&right) ? Math.min(Math.abs(right),ctx.canvas.width) : ctx.canvas.width;
bottom = (!isNaN(bottom)&&bottom) ? Math.min(Math.abs(bottom),ctx.canvas.height) : ctx.canvas.height;

var image = ctx.getImageData(left,top,right,bottom);

var data = image.data;
var width = image.width;
var height = image.height;

if(width>0 && height>0) {
fillUint8ClampedArray(data,x,y,color,tolerance,width,height);
ctx.putImageData(image,left,top);
}
};

if (typeof CanvasRenderingContext2D === 'function') {
CanvasRenderingContext2D.prototype.fillFlood = fillContext;
};

return fillUint8ClampedArray;

})();


// body
}());
8 changes: 6 additions & 2 deletions behaviors/rex_cursor2/edittime.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ AddCondition(2, cf_trigger, "On moving end", "Moving", "On {my} moving end", "Tr
// Expressions
AddExpression(0, ef_return_number | ef_variadic_parameters, "Mouse X position", "Position", "X", "Get the mouse cursor X co-ordinate in the layout.");
AddExpression(1, ef_return_number | ef_variadic_parameters, "Mouse Y position", "Position", "Y", "Get the mouse cursor Y co-ordinate in the layout.");
AddExpression(2, ef_return_number, "Absolute mouse X", "Position", "AbsoluteX", "Get the mouse cursor X co-ordinate on the canvas.");
AddExpression(3, ef_return_number, "Absolute mouse Y", "Position", "AbsoluteY", "Get the mouse cursor Y co-ordinate on the canvas.");

// ef_deprecated
AddExpression(2, ef_deprecated | ef_return_number, "Absolute mouse X", "Position", "AbsoluteX", "Get the mouse cursor X co-ordinate on the canvas.");
AddExpression(3, ef_deprecated | ef_return_number, "Absolute mouse Y", "Position", "AbsoluteY", "Get the mouse cursor Y co-ordinate on the canvas.");
// ef_deprecated

AddExpression(4, ef_return_number, "Get activated", "", "Activated", "The activated setting, 1 is activated.");

ACESDone();
Expand Down
Loading

0 comments on commit 369f9c7

Please sign in to comment.