static inline void build_style_frame(anim_frame *frame, JSObject *target) { #define ADD_PROP(const_name, prop) \ _ADD_PROP(const_name, prop, false); \ _ADD_PROP(const_name, d ## prop, true); #define _ADD_PROP(const_name, prop, _is_delta) do { \ jsval value; \ JS_GetProperty(cx, target, #prop, &value); \ double prop_val; \ JS_ValueToNumber(cx, value, &prop_val); \ if (!isnan(prop_val)) { \ style_prop *p = anim_frame_add_style_prop(frame); \ p->name = const_name; \ p->is_delta = _is_delta; \ p->target = prop_val; \ } \ } while(0) JSContext *cx = get_js_context(); ADD_PROP(X, x); ADD_PROP(Y, y); ADD_PROP(WIDTH, width); ADD_PROP(HEIGHT, height); ADD_PROP(R, r); ADD_PROP(ANCHOR_X, anchorX); ADD_PROP(ANCHOR_Y, anchorY); ADD_PROP(OPACITY, opacity); ADD_PROP(SCALE, scale); frame->type = STYLE_FRAME; }
void def_animate_cb(void *view, void *cb, double tt, double t) { JSObject *js_view = (JSObject*)view; JSObject *js_cb = (JSObject*)cb; jsval args[2] = {DOUBLE_TO_JSVAL(tt),DOUBLE_TO_JSVAL(t)}; JSContext *cx = get_js_context(); JS_BeginRequest(cx); jsval ret; JS_CallFunctionValue(cx, js_view, OBJECT_TO_JSVAL(js_cb), 2, args, &ret); JS_EndRequest(cx); }
void def_animate_finish(void *a) { JSObject *js_anim = (JSObject*)a; LOGFN("js_animate_finish"); JSContext *cx = get_js_context(); JS_BeginRequest(cx); view_animation *anim = (view_animation *)JS_GetPrivate(js_anim); JSObject *js_group = (JSObject*)anim->js_group; jsval finish_val; JS_GetProperty(cx, js_group, "onAnimationFinish", &finish_val); if (JSVAL_IS_OBJECT(finish_val)) { JSObject *finish = JSVAL_TO_OBJECT(finish_val); jsval args[] = {OBJECT_TO_JSVAL(js_anim)}; if (JS_ObjectIsFunction(cx, finish)) { jsval ret; JS_CallFunctionValue(cx, js_group, finish_val, 1, args, &ret); } } JS_EndRequest(cx); LOGFN("end def_animate_finish"); }
CEXPORT void timestep_image_map_add_to_object(JSObject *parent) { JSContext *cx = get_js_context(); JS_InitClass(cx, parent, NULL, (JSClass*)×tep_image_map_class, def_timestep_image_map_class_constructor, 12, (JSPropertySpec *)properties, (JSFunctionSpec *)functions, NULL, NULL); }
CEXPORT void animate_add_to_object(JSObject *parent) { JSContext *cx = get_js_context(); JS_InitClass(cx, parent, NULL, (JSClass*)&animate_class, def_animate_class_constructor, 2, (JSPropertySpec *)properties, (JSFunctionSpec *)functions, NULL, NULL); }