animlayer.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. #include "precomp.h"
  2. #include <api/script/scriptmgr.h>
  3. #include <api/script/script.h>
  4. #include <api/skin/widgets/animlayer.h>
  5. #include <tataki/canvas/canvas.h>
  6. const wchar_t animLayerXuiObjectStr[] = L"AnimatedLayer"; // This is the xml tag
  7. char animLayerXuiSvcName[] = "Animated Layer xui object"; // this is the name of the xuiservice
  8. AnimLayerScriptController _animlayerController;
  9. AnimLayerScriptController *animlayerController = &_animlayerController;
  10. // -- Functions table -------------------------------------
  11. function_descriptor_struct AnimLayerScriptController::exportedFunction[] = {
  12. {L"setSpeed", 1, (void*)AnimatedLayer::script_vcpu_setSpeed },
  13. {L"gotoFrame", 1, (void*)AnimatedLayer::script_vcpu_gotoFrame },
  14. {L"setStartFrame", 1, (void*)AnimatedLayer::script_vcpu_setStartFrame },
  15. {L"setEndFrame", 1, (void*)AnimatedLayer::script_vcpu_setEndFrame },
  16. {L"setAutoReplay", 1, (void*)AnimatedLayer::script_vcpu_setAutoReplay },
  17. {L"play", 0, (void*)AnimatedLayer::script_vcpu_play },
  18. {L"togglePause", 0, (void*)AnimatedLayer::script_vcpu_pause },
  19. {L"stop", 0, (void*)AnimatedLayer::script_vcpu_stop },
  20. {L"pause", 0, (void*)AnimatedLayer::script_vcpu_pause },
  21. {L"isPlaying", 0, (void*)AnimatedLayer::script_vcpu_isPlaying },
  22. {L"isPaused", 0, (void*)AnimatedLayer::script_vcpu_isPaused },
  23. {L"isStopped", 0, (void*)AnimatedLayer::script_vcpu_isStopped },
  24. {L"getStartFrame", 0, (void*)AnimatedLayer::script_vcpu_getStartFrame },
  25. {L"getEndFrame", 0, (void*)AnimatedLayer::script_vcpu_getEndFrame },
  26. {L"getLength", 0, (void*)AnimatedLayer::script_vcpu_getLength },
  27. {L"getDirection", 0, (void*)AnimatedLayer::script_vcpu_getDirection },
  28. {L"getAutoReplay", 0, (void*)AnimatedLayer::script_vcpu_getAutoReplay },
  29. {L"getCurFrame", 0, (void*)AnimatedLayer::script_vcpu_getCurFrame },
  30. {L"onPlay", 0, (void*)AnimatedLayer::script_vcpu_onPlay },
  31. {L"onPause", 0, (void*)AnimatedLayer::script_vcpu_onPause },
  32. {L"onResume", 0, (void*)AnimatedLayer::script_vcpu_onResume },
  33. {L"onStop", 0, (void*)AnimatedLayer::script_vcpu_onStop },
  34. {L"onFrame", 1, (void*)AnimatedLayer::script_vcpu_onFrame },
  35. {L"setRealtime", 1, (void*)AnimatedLayer::script_vcpu_setRealtime },
  36. };
  37. // --------------------------------------------------------
  38. const wchar_t *AnimLayerScriptController::getClassName()
  39. {
  40. return L"AnimatedLayer";
  41. }
  42. const wchar_t *AnimLayerScriptController::getAncestorClassName()
  43. {
  44. return L"Layer";
  45. }
  46. ScriptObject *AnimLayerScriptController::instantiate()
  47. {
  48. AnimatedLayer *a = new AnimatedLayer;
  49. ASSERT(a != NULL);
  50. return a->getScriptObject();
  51. }
  52. void AnimLayerScriptController::destroy(ScriptObject *o)
  53. {
  54. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  55. ASSERT(a != NULL);
  56. delete a;
  57. }
  58. void *AnimLayerScriptController::encapsulate(ScriptObject *o)
  59. {
  60. return NULL; // no encapsulation for animatedlayer yet
  61. }
  62. void AnimLayerScriptController::deencapsulate(void *o)
  63. {}
  64. int AnimLayerScriptController::getNumFunctions()
  65. {
  66. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  67. }
  68. const function_descriptor_struct *AnimLayerScriptController::getExportedFunctions()
  69. {
  70. return exportedFunction;
  71. }
  72. GUID AnimLayerScriptController::getClassGuid()
  73. {
  74. return animLayerGuid;
  75. }
  76. XMLParamPair AnimatedLayer::params[] =
  77. {
  78. {ANIMLAYER_AUTOPLAY, L"AUTOPLAY"},
  79. {ANIMLAYER_AUTOREPLAY, L"AUTOREPLAY"},
  80. {ANIMLAYER_DEBUG, L"DEBUG"},
  81. {ANIMLAYER_ELEMENTFRAMES, L"ELEMENTFRAMES"},
  82. {ANIMLAYER_END, L"END"},
  83. {ANIMLAYER_FRAMEHEIGHT, L"FRAMEHEIGHT"},
  84. {ANIMLAYER_FRAMEWIDTH, L"FRAMEWIDTH"},
  85. {ANIMLAYER_REALTIME, L"REALTIME"},
  86. {ANIMLAYER_SPEED, L"SPEED"},
  87. {ANIMLAYER_START, L"START"},
  88. };
  89. AnimatedLayer::AnimatedLayer()
  90. {
  91. getScriptObject()->vcpu_setInterface(animLayerGuid, (void *)static_cast<AnimatedLayer *>(this));
  92. getScriptObject()->vcpu_setClassName(L"AnimatedLayer");
  93. getScriptObject()->vcpu_setController(animlayerController);
  94. autoplay = 0;
  95. startframe = -1;
  96. endframe = -1;
  97. curframe = 0;
  98. autoreplay = 1;
  99. speed = 200;
  100. timerset = 0;
  101. status = ANIM_STOPPED;
  102. realtime = 0;
  103. debug = 0;
  104. style = ANIM_UNKNOWN;
  105. oldstyle = ANIM_UNKNOWN;
  106. frameHeight = AUTOWH;
  107. frameWidth = AUTOWH;
  108. multiple_elements_frames = 0;
  109. xuihandle = newXuiHandle();
  110. CreateXMLParameters(xuihandle);
  111. }
  112. void AnimatedLayer::CreateXMLParameters(int master_handle)
  113. {
  114. //ANIMLAYER_PARENT::CreateXMLParameters(master_handle);
  115. int numParams = sizeof(params) / sizeof(params[0]);
  116. hintNumberOfParams(xuihandle, numParams);
  117. for (int i = 0;i < numParams;i++)
  118. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  119. }
  120. AnimatedLayer::~AnimatedLayer()
  121. {
  122. bitmap_elements.deleteAll();
  123. regionlist.deleteAll();
  124. }
  125. int AnimatedLayer::onInit()
  126. {
  127. ANIMLAYER_PARENT::onInit();
  128. int w, h;
  129. getGuiObject()->guiobject_getGuiPosition(NULL, NULL, &w, &h, NULL, NULL, NULL, NULL);
  130. if (frameWidth == AUTOWH && w != AUTOWH) setWidth(w, 1);
  131. if (frameHeight == AUTOWH && h != AUTOWH) setHeight(h, 1);
  132. if (style == 0)
  133. {
  134. SkinBitmap *bm = getBitmap();
  135. if (bm)
  136. {
  137. if (bm->getWidth() != w) style = ANIM_HORZ;
  138. else if (bm->getHeight() != h) style = ANIM_VERT;
  139. }
  140. }
  141. if (getRegionOp())
  142. makeRegion();
  143. reloadMultipleElements();
  144. if (autoplay)
  145. {
  146. if (startframe == -1)
  147. setStartFrame(0);
  148. if (endframe == -1)
  149. setEndFrame(getLength() - 1);
  150. play();
  151. }
  152. return 1;
  153. }
  154. int AnimatedLayer::setXuiParam(int _xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *strvalue)
  155. {
  156. if (xuihandle == _xuihandle)
  157. {
  158. switch (xmlattributeid)
  159. {
  160. case ANIMLAYER_AUTOREPLAY: setAutoReplay(WTOI(strvalue)); return 1;
  161. case ANIMLAYER_AUTOPLAY: setAutoPlay(WTOI(strvalue)); return 1;
  162. case ANIMLAYER_SPEED: setSpeed(WTOI(strvalue)); return 1;
  163. case ANIMLAYER_FRAMEHEIGHT: setHeight(WTOI(strvalue)); return 1;
  164. case ANIMLAYER_FRAMEWIDTH: setWidth(WTOI(strvalue)); return 1;
  165. case ANIMLAYER_REALTIME: setRealtime(WTOI(strvalue)); return 1;
  166. case ANIMLAYER_ELEMENTFRAMES: setElementFrames(WTOI(strvalue)); return 1;
  167. case ANIMLAYER_START: setStartFrame(WTOI(strvalue)); return 1;
  168. case ANIMLAYER_END: setEndFrame(WTOI(strvalue)); return 1;
  169. case ANIMLAYER_DEBUG: debug = WTOI(strvalue); return 1;
  170. }
  171. }
  172. return ANIMLAYER_PARENT::setXuiParam(_xuihandle, xmlattributeid, xmlattributename, strvalue);
  173. }
  174. void AnimatedLayer::_invalidate()
  175. {
  176. if (realtime)
  177. {
  178. if (isVisible() && !isMinimized()) cascadeRepaint();
  179. }
  180. else
  181. invalidate();
  182. }
  183. void AnimatedLayer::setElementFrames(int n)
  184. {
  185. if (multiple_elements_frames == n) return ;
  186. multiple_elements_frames = n;
  187. if (n > 0)
  188. {
  189. if (style != ANIM_MULTI)
  190. oldstyle = style;
  191. style = ANIM_MULTI;
  192. }
  193. else
  194. {
  195. style = oldstyle;
  196. oldstyle = ANIM_UNKNOWN;
  197. }
  198. invalidateRegionCache();
  199. }
  200. void AnimatedLayer::setHeight(int h, int selfset)
  201. {
  202. ASSERTPR(selfset || style == ANIM_UNKNOWN, "can't set frameHeight if frameWidth has already been set");
  203. frameHeight = h;
  204. if (!selfset) style = ANIM_VERT;
  205. }
  206. int AnimatedLayer::getHeight()
  207. {
  208. if (style == ANIM_MULTI)
  209. {
  210. SkinBitmap *bm0 = getElementBitmap(0);
  211. if (bm0 == NULL) return AUTOWH;
  212. return bm0->getHeight();
  213. }
  214. if (style == ANIM_HORZ)
  215. return ANIMLAYER_PARENT::getHeight();
  216. return frameHeight;
  217. }
  218. void AnimatedLayer::setWidth(int w, int selfset)
  219. {
  220. ASSERTPR(selfset || style == ANIM_UNKNOWN, "can't set frameWidth if frameHeight has already been set");
  221. frameWidth = w;
  222. if (!selfset) style = ANIM_HORZ;
  223. }
  224. int AnimatedLayer::getWidth()
  225. {
  226. if (style == ANIM_MULTI)
  227. {
  228. SkinBitmap *bm0 = getElementBitmap(0);
  229. if (bm0 == NULL) return AUTOWH;
  230. return bm0->getWidth();
  231. }
  232. if (style == ANIM_VERT)
  233. return ANIMLAYER_PARENT::getWidth();
  234. return frameWidth;
  235. }
  236. void AnimatedLayer::setRealtime(int r)
  237. {
  238. realtime = r;
  239. }
  240. int AnimatedLayer::getLength()
  241. {
  242. if (style == ANIM_VERT && frameHeight < 0) return 0;
  243. if (style == ANIM_HORZ && frameWidth < 0) return 0;
  244. ASSERT(getBitmap() != NULL);
  245. if (style == ANIM_VERT)
  246. return ANIMLAYER_PARENT::getHeight() / frameHeight;
  247. else if (style == ANIM_HORZ)
  248. return ANIMLAYER_PARENT::getWidth() / frameWidth;
  249. else if (style == ANIM_MULTI)
  250. return multiple_elements_frames;
  251. return 0;
  252. }
  253. void AnimatedLayer::timerCallback(int id)
  254. {
  255. switch (id)
  256. {
  257. case TIMER_ANIM:
  258. {
  259. int oldframe = curframe;
  260. for (int i = 0;i < timerclient_getSkipped() + 1;i++)
  261. {
  262. if (curframe == getEndFrame())
  263. {
  264. if (!autoreplay)
  265. {
  266. stop();
  267. break;
  268. }
  269. else
  270. curframe = getStartFrame();
  271. }
  272. else
  273. {
  274. curframe += getDirection();
  275. if (curframe != oldframe)
  276. script_onFrame(curframe);
  277. }
  278. }
  279. if (curframe != oldframe)
  280. _invalidate();
  281. break;
  282. }
  283. default:
  284. ANIMLAYER_PARENT::timerCallback(id);
  285. break;
  286. }
  287. }
  288. int AnimatedLayer::getSourceOffsetY()
  289. {
  290. if (style == ANIM_MULTI) return 0;
  291. if (style == ANIM_HORZ) return 0;
  292. if (curframe > getLength() - 1) return 0;
  293. return curframe * getHeight();
  294. }
  295. int AnimatedLayer::getSourceOffsetX()
  296. {
  297. if (style == ANIM_MULTI) return 0;
  298. if (style == ANIM_VERT) return 0;
  299. if (curframe > getLength() - 1) return 0;
  300. return curframe * getWidth();
  301. }
  302. void AnimatedLayer::setSpeed(int s)
  303. {
  304. speed = s;
  305. if (status == ANIM_PLAYING)
  306. {
  307. stopTimer();
  308. startTimer();
  309. }
  310. }
  311. void AnimatedLayer::stopTimer()
  312. {
  313. if (timerset)
  314. {
  315. killTimer(TIMER_ANIM);
  316. timerset = 0;
  317. }
  318. }
  319. void AnimatedLayer::startTimer()
  320. {
  321. if (!timerset)
  322. {
  323. setTimer(TIMER_ANIM, speed);
  324. timerset = 1;
  325. }
  326. }
  327. void AnimatedLayer::play()
  328. {
  329. gotoFrame(startframe);
  330. startTimer();
  331. status = ANIM_PLAYING;
  332. script_onPlay();
  333. }
  334. void AnimatedLayer::stop()
  335. {
  336. stopTimer();
  337. status = ANIM_STOPPED;
  338. script_onStop();
  339. }
  340. void AnimatedLayer::pause()
  341. {
  342. if (status == ANIM_PAUSED)
  343. {
  344. startTimer();
  345. status = ANIM_PLAYING;
  346. script_onResume();
  347. }
  348. else
  349. if (status == ANIM_PLAYING)
  350. {
  351. stopTimer();
  352. status = ANIM_PAUSED;
  353. script_onPause();
  354. }
  355. }
  356. int AnimatedLayer::getCurFrame()
  357. {
  358. return curframe;
  359. }
  360. void AnimatedLayer::setStartFrame(int s)
  361. {
  362. if (s < 0) return ;
  363. startframe = s;
  364. }
  365. void AnimatedLayer::setEndFrame(int e)
  366. {
  367. if (e < 0) return ;
  368. endframe = e;
  369. }
  370. void AnimatedLayer::setAutoReplay(int r)
  371. {
  372. autoreplay = r;
  373. }
  374. void AnimatedLayer::setAutoPlay(int r)
  375. {
  376. autoplay = r;
  377. // no need to trigger an event here, we can't be in a script if we
  378. // need to autoplay at xml loading
  379. }
  380. int AnimatedLayer::getStartFrame()
  381. {
  382. return startframe == -1 ? 0 : startframe;
  383. }
  384. int AnimatedLayer::getEndFrame()
  385. {
  386. return endframe == -1 ? getLength() - 1 : endframe;
  387. }
  388. int AnimatedLayer::getSpeed()
  389. {
  390. return speed;
  391. }
  392. int AnimatedLayer::isPlaying()
  393. {
  394. return status == ANIM_PLAYING;
  395. }
  396. int AnimatedLayer::isStopped()
  397. {
  398. return status == ANIM_STOPPED;
  399. }
  400. int AnimatedLayer::isPaused()
  401. {
  402. return status == ANIM_PAUSED;
  403. }
  404. int AnimatedLayer::getAutoReplay()
  405. {
  406. return autoreplay;
  407. }
  408. int AnimatedLayer::getDirection()
  409. {
  410. return getStartFrame() < getEndFrame() ? 1 : -1;
  411. }
  412. void AnimatedLayer::gotoFrame(int n)
  413. {
  414. if (n != curframe)
  415. {
  416. curframe = n;
  417. _invalidate();
  418. script_onFrame(n);
  419. }
  420. }
  421. api_region *AnimatedLayer::getBitmapRegion()
  422. {
  423. if (curframe > getLength() - 1) return NULL;
  424. return regionlist.enumItem(getCurFrame());
  425. }
  426. void AnimatedLayer::makeRegion()
  427. {
  428. if (!isInited()) return ;
  429. regionlist.deleteAll();
  430. for (int i = 0;i < getLength();i++)
  431. {
  432. RegionI *rg;
  433. if (style == ANIM_VERT)
  434. {
  435. RECT g = {0, i * getHeight(), getWidth(), i * getHeight() + getHeight()};
  436. rg = new RegionI(getBitmap(), &g, 0, -i * getHeight(), FALSE);
  437. }
  438. else if (style == ANIM_HORZ)
  439. {
  440. RECT g = {i * getWidth(), 0, i * getWidth() + getWidth(), getHeight()};
  441. rg = new RegionI(getBitmap(), &g, -i * getWidth(), 0, FALSE);
  442. }
  443. else if (style == ANIM_MULTI)
  444. {
  445. RECT g = {0, 0, getWidth(), getHeight()};
  446. rg = new RegionI(getElementBitmap(i), &g, 0, 0, FALSE);
  447. }
  448. else
  449. return;
  450. regionlist.addItem(rg);
  451. }
  452. }
  453. void AnimatedLayer::deleteRegion()
  454. {
  455. regionlist.deleteAll();
  456. }
  457. SkinBitmap *AnimatedLayer::getBitmap()
  458. {
  459. if (style != ANIM_MULTI)
  460. return layer_getBitmap();
  461. return getElementBitmap(getCurFrame());
  462. }
  463. SkinBitmap *AnimatedLayer::getElementBitmap(int n)
  464. {
  465. return bitmap_elements.enumItem(n);
  466. }
  467. void AnimatedLayer::reloadMultipleElements()
  468. {
  469. bitmap_elements.deleteAll();
  470. if (style != ANIM_MULTI) return ;
  471. // basically blah$$$$.png becomes blah0000.png, blah0001.png etc
  472. for (int i = 0;i < multiple_elements_frames;i++)
  473. {
  474. StringW elementname(layer_getBitmapName());
  475. elementname.replaceNumericField(i);
  476. bitmap_elements.addItem(new SkinBitmap(elementname));
  477. }
  478. }
  479. void AnimatedLayer::setBitmap(const wchar_t *name)
  480. {
  481. ANIMLAYER_PARENT::setBitmap(name);
  482. reloadMultipleElements();
  483. }
  484. // Script virtuals
  485. int AnimatedLayer::script_getStartFrame()
  486. {
  487. return getStartFrame();
  488. }
  489. int AnimatedLayer::script_getEndFrame()
  490. {
  491. return getEndFrame();
  492. }
  493. int AnimatedLayer::script_getSpeed()
  494. {
  495. return getSpeed();
  496. }
  497. int AnimatedLayer::script_getCurFrame()
  498. {
  499. return getCurFrame();
  500. }
  501. int AnimatedLayer::script_getDirection()
  502. {
  503. return getDirection();
  504. }
  505. int AnimatedLayer::script_getAutoReplay()
  506. {
  507. return getAutoReplay();
  508. }
  509. int AnimatedLayer::script_getLength()
  510. {
  511. return getLength();
  512. }
  513. int AnimatedLayer::script_isPlaying()
  514. {
  515. return isPlaying();
  516. }
  517. int AnimatedLayer::script_isStopped()
  518. {
  519. return isStopped();
  520. }
  521. int AnimatedLayer::script_isPaused()
  522. {
  523. return isPaused();
  524. }
  525. void AnimatedLayer::script_play()
  526. {
  527. play();
  528. }
  529. void AnimatedLayer::script_pause()
  530. {
  531. pause();
  532. }
  533. void AnimatedLayer::script_stop()
  534. {
  535. stop();
  536. }
  537. void AnimatedLayer::script_setStartFrame(int s)
  538. {
  539. setStartFrame(s);
  540. }
  541. void AnimatedLayer::script_setEndFrame(int e)
  542. {
  543. setEndFrame(e);
  544. }
  545. void AnimatedLayer::script_setRealtime(int r)
  546. {
  547. setRealtime(r);
  548. }
  549. void AnimatedLayer::script_setAutoReplay(int r)
  550. {
  551. setAutoReplay(r);
  552. }
  553. /*
  554. void AnimatedLayer::script_gotoFrame(int n) {
  555. gotoFrame(n);
  556. }*/
  557. void AnimatedLayer::script_setSpeed(int n)
  558. {
  559. setSpeed(n);
  560. }
  561. void AnimatedLayer::script_onPause()
  562. {
  563. script_vcpu_onPause(SCRIPT_CALL, getScriptObject());
  564. }
  565. void AnimatedLayer::script_onResume()
  566. {
  567. script_vcpu_onResume(SCRIPT_CALL, getScriptObject());
  568. }
  569. void AnimatedLayer::script_onStop()
  570. {
  571. script_vcpu_onStop(SCRIPT_CALL, getScriptObject());
  572. }
  573. void AnimatedLayer::script_onPlay()
  574. {
  575. script_vcpu_onPlay(SCRIPT_CALL, getScriptObject());
  576. }
  577. void AnimatedLayer::script_onFrame(int n)
  578. {
  579. if (getRegionOp()) { invalidateRegionCache(); getParent()->invalidateWindowRegion(); }
  580. scriptVar _n = SOM::makeVar(SCRIPT_INT);
  581. SOM::assign(&_n, n);
  582. script_vcpu_onFrame(SCRIPT_CALL, getScriptObject(), _n);
  583. }
  584. // end virtuals
  585. // VCPU
  586. scriptVar AnimatedLayer::script_vcpu_gotoFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar f)
  587. {
  588. SCRIPT_FUNCTION_INIT;
  589. ASSERT(SOM::isNumeric(&f));
  590. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  591. if (a) a-> /*script_*/gotoFrame(SOM::makeInt(&f));
  592. RETURN_SCRIPT_VOID;
  593. }
  594. scriptVar AnimatedLayer::script_vcpu_getLength(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  595. {
  596. SCRIPT_FUNCTION_INIT;
  597. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  598. if (a) return MAKE_SCRIPT_INT(a->script_getLength());
  599. RETURN_SCRIPT_ZERO;
  600. }
  601. scriptVar AnimatedLayer::script_vcpu_setStartFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar s)
  602. {
  603. SCRIPT_FUNCTION_INIT;
  604. ASSERT(SOM::isNumeric(&s));
  605. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  606. if (a) a->script_setStartFrame(SOM::makeInt(&s));
  607. RETURN_SCRIPT_VOID;
  608. }
  609. scriptVar AnimatedLayer::script_vcpu_setEndFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar e)
  610. {
  611. SCRIPT_FUNCTION_INIT;
  612. ASSERT(SOM::isNumeric(&e));
  613. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  614. if (a) a->script_setEndFrame(SOM::makeInt(&e));
  615. RETURN_SCRIPT_VOID;
  616. }
  617. scriptVar AnimatedLayer::script_vcpu_setAutoReplay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar rp)
  618. {
  619. SCRIPT_FUNCTION_INIT;
  620. ASSERT(SOM::isNumeric(&rp));
  621. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  622. if (a) a->script_setAutoReplay(SOM::makeBoolean(&rp));
  623. RETURN_SCRIPT_VOID;
  624. }
  625. scriptVar AnimatedLayer::script_vcpu_play(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  626. {
  627. SCRIPT_FUNCTION_INIT;
  628. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  629. if (a) a->script_play();
  630. RETURN_SCRIPT_VOID;
  631. }
  632. scriptVar AnimatedLayer::script_vcpu_pause(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  633. {
  634. SCRIPT_FUNCTION_INIT;
  635. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  636. if (a) a->script_pause();
  637. RETURN_SCRIPT_VOID;
  638. }
  639. scriptVar AnimatedLayer::script_vcpu_stop(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  640. {
  641. SCRIPT_FUNCTION_INIT;
  642. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  643. if (a) a->script_stop();
  644. RETURN_SCRIPT_VOID;
  645. }
  646. scriptVar AnimatedLayer::script_vcpu_onPlay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  647. {
  648. SCRIPT_FUNCTION_INIT;
  649. PROCESS_HOOKS0(o, animlayerController);
  650. SCRIPT_FUNCTION_CHECKABORTEVENT;
  651. SCRIPT_EXEC_EVENT0(o);
  652. }
  653. scriptVar AnimatedLayer::script_vcpu_onStop(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  654. {
  655. SCRIPT_FUNCTION_INIT;
  656. PROCESS_HOOKS0(o, animlayerController);
  657. SCRIPT_FUNCTION_CHECKABORTEVENT;
  658. SCRIPT_EXEC_EVENT0(o);
  659. }
  660. scriptVar AnimatedLayer::script_vcpu_onPause(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  661. {
  662. SCRIPT_FUNCTION_INIT;
  663. PROCESS_HOOKS0(o, animlayerController);
  664. SCRIPT_FUNCTION_CHECKABORTEVENT;
  665. SCRIPT_EXEC_EVENT0(o);
  666. }
  667. scriptVar AnimatedLayer::script_vcpu_onResume(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  668. {
  669. SCRIPT_FUNCTION_INIT;
  670. PROCESS_HOOKS0(o, animlayerController);
  671. SCRIPT_FUNCTION_CHECKABORTEVENT;
  672. SCRIPT_EXEC_EVENT0(o);
  673. }
  674. scriptVar AnimatedLayer::script_vcpu_onFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar f)
  675. {
  676. SCRIPT_FUNCTION_INIT;
  677. PROCESS_HOOKS1(o, animlayerController, f);
  678. SCRIPT_FUNCTION_CHECKABORTEVENT;
  679. SCRIPT_EXEC_EVENT1(o, f);
  680. }
  681. scriptVar AnimatedLayer::script_vcpu_getAutoReplay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  682. {
  683. SCRIPT_FUNCTION_INIT;
  684. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  685. if (a) return MAKE_SCRIPT_INT(a->script_getAutoReplay());
  686. RETURN_SCRIPT_ZERO;
  687. }
  688. scriptVar AnimatedLayer::script_vcpu_getDirection(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  689. {
  690. SCRIPT_FUNCTION_INIT;
  691. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  692. if (a) return MAKE_SCRIPT_INT(a->script_getDirection());
  693. RETURN_SCRIPT_ZERO;
  694. }
  695. scriptVar AnimatedLayer::script_vcpu_getStartFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  696. {
  697. SCRIPT_FUNCTION_INIT;
  698. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  699. if (a) return MAKE_SCRIPT_INT(a->script_getStartFrame());
  700. RETURN_SCRIPT_ZERO;
  701. }
  702. scriptVar AnimatedLayer::script_vcpu_getEndFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  703. {
  704. SCRIPT_FUNCTION_INIT;
  705. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  706. if (a) return MAKE_SCRIPT_INT(a->script_getEndFrame());
  707. RETURN_SCRIPT_ZERO;
  708. }
  709. scriptVar AnimatedLayer::script_vcpu_isPlaying(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  710. {
  711. SCRIPT_FUNCTION_INIT;
  712. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  713. if (a) return MAKE_SCRIPT_BOOLEAN(a->script_isPlaying());
  714. RETURN_SCRIPT_ZERO;
  715. }
  716. scriptVar AnimatedLayer::script_vcpu_isPaused(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  717. {
  718. SCRIPT_FUNCTION_INIT;
  719. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  720. if (a) return MAKE_SCRIPT_BOOLEAN(a->script_isPaused());
  721. RETURN_SCRIPT_ZERO;
  722. }
  723. scriptVar AnimatedLayer::script_vcpu_isStopped(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  724. {
  725. SCRIPT_FUNCTION_INIT;
  726. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  727. if (a) return MAKE_SCRIPT_BOOLEAN(a->script_isStopped());
  728. RETURN_SCRIPT_ZERO;
  729. }
  730. scriptVar AnimatedLayer::script_vcpu_getSpeed(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  731. {
  732. SCRIPT_FUNCTION_INIT;
  733. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  734. if (a) return MAKE_SCRIPT_INT(a->script_getSpeed());
  735. RETURN_SCRIPT_ZERO;
  736. }
  737. scriptVar AnimatedLayer::script_vcpu_getCurFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  738. {
  739. SCRIPT_FUNCTION_INIT;
  740. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  741. if (a) return MAKE_SCRIPT_INT(a->script_getCurFrame());
  742. RETURN_SCRIPT_ZERO;
  743. }
  744. scriptVar AnimatedLayer::script_vcpu_setSpeed(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar s)
  745. {
  746. SCRIPT_FUNCTION_INIT;
  747. ASSERT(SOM::isNumeric(&s));
  748. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  749. if (a) a->script_setSpeed(SOM::makeInt(&s));
  750. RETURN_SCRIPT_VOID;
  751. }
  752. scriptVar AnimatedLayer::script_vcpu_setRealtime(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar r)
  753. {
  754. SCRIPT_FUNCTION_INIT;
  755. AnimatedLayer *a = static_cast<AnimatedLayer *>(o->vcpu_getInterface(animLayerGuid));
  756. if (a) a->script_setRealtime(SOM::makeInt(&r));
  757. RETURN_SCRIPT_VOID;
  758. }
  759. int AnimatedLayer::onPaint(Canvas *canvas)
  760. {
  761. int r = ANIMLAYER_PARENT::onPaint(canvas);
  762. if (debug && canvas != NULL)
  763. {
  764. Wasabi::FontInfo fontInfo;
  765. fontInfo.pointSize = 14;
  766. canvas->textOut(0, 0, StringPrintfW(L"%d", curframe), &fontInfo);
  767. }
  768. return r;
  769. }