1
0

drawer.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. // -----------------------------------------------------------------------
  2. // Generic Video/Vis Application Drawer, by Nullsoft.
  3. //
  4. // Please #include this script, and override the appropriate events
  5. // (see end of file), rather than modifying this script into your own
  6. // version.
  7. //
  8. // *You should not have to edit this file*, it's just a bad idea, period.
  9. // If you need something that is not supported in this version, we
  10. // recommend that you contact Nullsoft to suggest the feature.
  11. //
  12. // Satisfying user experience depends on *fully working* scripts, if you
  13. // insist on taking this file and modifying it for yourself, be sure to
  14. // *thoroughly* test its behavior once you are done.
  15. //
  16. // If you do add a feature, please contact us so that your extention can
  17. // be made available to others without each skin developper making its
  18. // own (potentially broken) implementation.
  19. //
  20. // Note: this script requires mc 1.1.2+ to compile, and wa5.8+ to run.
  21. // -----------------------------------------------------------------------
  22. #ifndef included
  23. #error This script can only be compiled as a #include
  24. #endif
  25. #include <lib/std.mi>
  26. #include <lib/config.mi>
  27. #include <lib/winampconfig.mi>
  28. // call these -- the first two are mandatory
  29. Function initDrawer(Layout lay, String id); // call in your onScriptLoaded();
  30. Function shutdownDrawer(); // call in your onScriptUnloading();
  31. Function openDrawer(); // opens the drawer to the last page unless video plays, in which case it opens to it. does animations according to attribs
  32. Function openDrawerForVideo(); // opens the drawer to the video page, does animations according to attribs
  33. Function openDrawerForVis(); // opens the drawer to the vis page, does animations according to attribs
  34. Function openDrawerForNothing(); // opens the drawer without putting anything in it, does animations according to attribs
  35. Function closeDrawer(); // closes the drawer, does animations according to attribs
  36. Function detachVis();
  37. Function attachVis();
  38. Function detachVideo();
  39. Function attachVideo();
  40. Function switchToVis();
  41. Function switchToVideo();
  42. Function Int getDrawerState(); // returns OPEN or CLOSED
  43. Function Int getDrawerContent(); // returns CONTENT_VIDEO, CONTENT_VIS or CONTENT_NOTHING
  44. Function maximizeWindow();
  45. Function restoreWindow();
  46. Function Int isDrawerToTop(); // returns 1 if the drawer will open to the top or will close from the top, rather than the normal to/from bottom
  47. // whenever the main window is resized while its drawer is closed, you should compute a new layout
  48. // height for the next opening of the drawer, this will avoid opening to a gigantic height after
  49. // closing a big video and resizing the player horizontally. return -1 if you do not want this feature
  50. Function Int getDrawerOpenAutoHeight(int layoutwidth);
  51. // implement these -- mandatory
  52. Function WindowHolder getVideoWindowHolder();
  53. Function WindowHolder getVisWindowHolder();
  54. Function Int getDrawerClosedHeight();
  55. Function Int getDefaultDrawerOpenHeight();
  56. // override these -- optional
  57. Function onBeforeOpeningDrawer();
  58. Function onBeforeClosingDrawer();
  59. Function onDoneOpeningDrawer();
  60. Function onDoneClosingDrawer();
  61. Function onShowVis();
  62. Function onHideVis();
  63. Function onShowVideo();
  64. Function onHideVideo();
  65. Function onAttachVideo();
  66. Function onDetachVideo();
  67. Function onAttachVis();
  68. Function onDetachVis();
  69. Function onBeforeMaximize();
  70. Function onAfterMaximize();
  71. Function onBeforeRestore();
  72. Function onAfterRestore();
  73. Function onCancelMaximize();
  74. // bind these -- mandatory (they don't have to be exposed in the menus)
  75. Global ConfigAttribute __drawer_directiontop_attrib;
  76. Global ConfigAttribute __scrolldrawerattrib;
  77. Global ConfigAttribute __drawer_directionbypass_attrib;
  78. Global ConfigAttribute __vis_detach_attrib;
  79. Global ConfigAttribute __video_detach_attrib;
  80. // -----------------------------------------------------------------------
  81. #define VIDEO_GUID "{F0816D7B-FFFC-4343-80F2-E8199AA15CC3}"
  82. #define VIS_GUID "{0000000A-000C-0010-FF7B-01014263450C}"
  83. // this is used to temporarilly disable playback stop on video window close, in case it's set
  84. #define SKINTWEAKS_CFGPAGE "{0542AFA4-48D9-4c9f-8900-5739D52C114F}"
  85. // this is used to handle video auto fullscreen on play when the video window is attached to the drawer
  86. #define VIDEO_CONFIG_GROUP "{2135E318-6919-4bcf-99D2-62BE3FCA8FA6}"
  87. #define DEBUG
  88. #ifdef FALSE
  89. #undef FALSE
  90. #endif
  91. #define FALSE 0
  92. #ifdef TRUE
  93. #undef TRUE
  94. #endif
  95. #define TRUE -1
  96. #define CLOSED 0
  97. #define OPEN 1
  98. #define DIRECTION_NONE 0
  99. #define DIRECTION_OPENING 1
  100. #define DIRECTION_CLOSING 2
  101. #define CONTENT_NOTHING 0
  102. #define CONTENT_VIDEO 1
  103. #define CONTENT_VIS 2
  104. #define DETACHED_VIS 1
  105. #define DETACHED_VIDEO 2
  106. // avoid calling these functions directly. if you do so, be sure to know what
  107. // you're doing, and to test your script thoroughly.
  108. Function drawer_expandWindow(int withdrawer);
  109. Function drawer_reduceWindow(int withdrawer);
  110. Function drawer_showWindowContent();
  111. Function drawer_hideWindowContent();
  112. Function drawer_hideVis();
  113. Function drawer_showVis();
  114. Function drawer_hideVideo();
  115. Function drawer_showVideo();
  116. Function drawer_dc_showVis();
  117. Function drawer_dc_showVideo();
  118. Function drawer_dc_hideVis();
  119. Function drawer_dc_hideVideo();
  120. Function drawer_dc_linkup_showVis();
  121. Function drawer_dc_linkup_showVideo();
  122. Function drawer_doDetachVis();
  123. Function drawer_doAttachVis();
  124. Function drawer_doDetachVideo();
  125. Function drawer_doAttachVideo();
  126. Function drawer_disablePSOVC();
  127. Function drawer_enablePSOVC();
  128. Function drawer_linkup_showVis();
  129. Function drawer_linkup_showVideo();
  130. Function drawer_doMaximizeWindow(int notif);
  131. Global Int __drawer_direction;
  132. Global Timer __callbackTimer;
  133. Global Int __callback_vis_show, __callback_video_show, __callback_vis_hide, __callback_video_hide;
  134. Global Timer __callbackTimer2;
  135. Global Int __callback2_what;
  136. Global Timer __PSOVCTimer;
  137. Global Int __bypasscancel;
  138. Global Int __isinited;
  139. Global Int __play_auto_fs_video;
  140. Global Int __hiding_video, __hiding_vis, __showing_vis, __showing_video;
  141. Global Int __last_forcedbottom, __last_forcedtop;
  142. Global Timer __tempDisable;
  143. Global Layout __main;
  144. Global Container __maincontainer;
  145. Global String __myname;
  146. Global Int __windowshade_openvid;
  147. Global Int __windowshade_openvis;
  148. Global int __maximized;
  149. Global int __oldx,__oldy,__oldw,__oldh;
  150. // -----------------------------------------------------------------------
  151. initDrawer(Layout lay, String name) {
  152. // todo: test all attribs assigned
  153. __isinited = 0;
  154. __play_auto_fs_video = 0;
  155. __main = lay;
  156. __maincontainer = __main.getContainer();
  157. if (name == "") __myname = "Drawer";
  158. else __myname = name;
  159. __drawer_direction = DIRECTION_NONE;
  160. drawer_hideVis();
  161. drawer_hideVideo();
  162. __callbackTimer = new Timer;
  163. __callbackTimer.setDelay(1);
  164. __callbackTimer2 = new Timer;
  165. __callbackTimer2.setDelay(1);
  166. __PSOVCTimer = new Timer;
  167. __PSOVCTimer.setDelay(1000);
  168. __tempDisable = new Timer;
  169. __tempDisable.setDelay(50);
  170. __maximized = getPrivateInt("winamp5", __myname+"Maximized", 0);
  171. if (__maximized) {
  172. onBeforeMaximize();
  173. onAfterMaximize();
  174. }
  175. __oldx=getPrivateInt("winamp5", __myname+"ox", 0);
  176. __oldy=getPrivateInt("winamp5", __myname+"oy", 0);
  177. __oldw=getPrivateInt("winamp5", __myname+"ow", 0);
  178. __oldh=getPrivateInt("winamp5", __myname+"oh", 0);
  179. __last_forcedtop = getPrivateInt("winamp5", __myname+"ForcedTop", 0);
  180. __last_forcedbottom = getPrivateInt("winamp5", __myname+"ForcedBottom", 0);
  181. }
  182. // -----------------------------------------------------------------------
  183. shutdownDrawer() {
  184. delete __callbackTimer;
  185. delete __callbackTimer2;
  186. delete __PSOVCTimer;
  187. delete __tempDisable;
  188. }
  189. // -----------------------------------------------------------------------
  190. Int isDrawerToTop() {
  191. int fromtop = 0;
  192. if (__drawer_directiontop_attrib.getData() =="1") fromtop = 1;
  193. if (__drawer_directionbypass_attrib.getData() == "0") return fromtop;
  194. int curstate = getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  195. if (curstate != CLOSED) return __last_forcedtop;
  196. int h=getPrivateInt("winamp5", __myname+"Height", getDefaultDrawerOpenHeight());
  197. if (h == getDrawerClosedHeight()) h = getDefaultDrawerOpenHeight();
  198. if (__maximized) h = getViewportHeight()+__main.getSnapAdjustBottom();
  199. __last_forcedbottom = 0;
  200. __last_forcedtop = 0;
  201. // clienttoscreen auto adjusts for render ratio
  202. if (fromtop) {
  203. int y = __main.getGuiY();
  204. int curh = __main.clientToScreenH(__main.getGuiH());
  205. if (y + curh < __main.clientToScreenH(h) + getViewportTop()) {
  206. int offset = __main.getSnapAdjustBottom();
  207. if (!(y + __main.clientToScreenH(h-offset) > getViewPortTop()+getViewPortHeight())) {
  208. __last_forcedbottom = 1;
  209. return 0;
  210. }
  211. }
  212. } else {
  213. int offset = __main.getSnapAdjustBottom();
  214. int y = __main.getGuiY();
  215. if (y + __main.clientToScreenH(h-offset) > getViewPortTop()+getViewPortHeight()) {
  216. int curh = __main.clientToScreenH(__main.getGuiH());
  217. if (!(y + curh < __main.clientToScreenH(h) + getViewportTop())) {
  218. __last_forcedtop = 1;
  219. return 1;
  220. }
  221. }
  222. }
  223. return fromtop;
  224. }
  225. // -----------------------------------------------------------------------
  226. __main.onTargetReached() {
  227. unlockUI();
  228. if (__drawer_directiontop_attrib.getData() =="1") __main.reverseTarget(0);
  229. if (__drawer_direction == DIRECTION_OPENING) {
  230. setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  231. drawer_showWindowContent();
  232. onDoneOpeningDrawer();
  233. } else if (__drawer_direction == DIRECTION_CLOSING) {
  234. setPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  235. onDoneClosingDrawer();
  236. }
  237. __drawer_direction = DIRECTION_NONE;
  238. }
  239. // -----------------------------------------------------------------------
  240. drawer_expandWindow(int withdrawer) {
  241. int curstate = getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  242. #ifdef DEBUG
  243. debugstring("expand - curstate = " + integertostring(curstate), 0);
  244. #endif
  245. if (curstate == OPEN) {
  246. drawer_showWindowContent();
  247. onBeforeOpeningDrawer();
  248. onDoneOpeningDrawer();
  249. return;
  250. }
  251. int fromtop = isDrawerToTop();
  252. setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  253. int h=getPrivateInt("winamp5", __myname+"Height", getDefaultDrawerOpenHeight());
  254. if (h == getDrawerClosedHeight()) h = getDefaultDrawerOpenHeight();
  255. if (__maximized) h = getViewportHeight()+__main.getSnapAdjustBottom();
  256. int w = __main.getGuiW();
  257. if (h == __main.getHeight()) withdrawer = 0;
  258. onBeforeOpeningDrawer();
  259. int delay = 0;
  260. if (!__main.isLayoutAnimationSafe()) withdrawer = 0;
  261. if (withdrawer && StringToInteger(__scrolldrawerattrib.getData())) delay = 1;
  262. __drawer_direction = DIRECTION_OPENING;
  263. __main.setTargetX(__main.getGuiX());
  264. __main.setTargetY(__main.getGuiY());
  265. __main.setTargetW(w);
  266. __main.setTargetH(h);
  267. __main.reverseTarget(fromtop);
  268. __main.setTargetSpeed(delay);
  269. __main.gotoTarget();
  270. lockUI();
  271. if (!__maximized)
  272. setPrivateInt("winamp5", __myname+"Height", h);
  273. setPrivateInt("winamp5", __myname+"ForcedBottom", __last_forcedBottom);
  274. setPrivateInt("winamp5", __myname+"ForcedTop", __last_forcedtop);
  275. }
  276. // -----------------------------------------------------------------------
  277. drawer_reduceWindow(int withdrawer) {
  278. #ifdef DEBUG
  279. debugstring("reduce", 0);
  280. #endif
  281. drawer_hideVis();
  282. drawer_hideVideo();
  283. setPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  284. if (__drawer_direction == DIRECTION_NONE && !__maximized) { // avoid saving new size if we're currenly opening
  285. int h=__main.getHeight();
  286. setPrivateInt("winamp5", __myname+"Height", h);
  287. }
  288. drawer_hideWindowContent();
  289. onBeforeClosingDrawer();
  290. int fromtop=0;
  291. if (__drawer_directiontop_attrib.getData() =="1") fromtop = 1;
  292. int delay = 0;
  293. if (!__main.isLayoutAnimationSafe()) withdrawer = 0;
  294. if (withdrawer && StringToInteger(__scrolldrawerattrib.getData())) delay = 1;
  295. if (__drawer_directionbypass_attrib.getData() == "1") {
  296. if (__last_forcedtop) fromtop = 1;
  297. if (__last_forcedbottom) fromtop = 0;
  298. }
  299. __drawer_direction = DIRECTION_CLOSING;
  300. __main.setTargetX(__main.getGuiX());
  301. __main.setTargetY(__main.getGuiY());
  302. __main.setTargetW(__main.getGuiW());
  303. __main.setTargetH(getDrawerClosedHeight());
  304. __main.reverseTarget(fromtop);
  305. __main.setTargetSpeed(delay);
  306. __main.gotoTarget();
  307. lockUI();
  308. __last_forcedtop = 0;
  309. __last_forcedbottom = 0;
  310. setPrivateInt("winamp5", __myname+"ForcedBottom", 0);
  311. setPrivateInt("winamp5", __myname+"ForcedTop", 0);
  312. }
  313. // -----------------------------------------------------------------------
  314. openDrawer() {
  315. if (__tempDisable.isRunning()) return;
  316. __tempDisable.start();
  317. int s = getStatus();
  318. if (s == STATUS_PLAYING || s == STATUS_PAUSED) {
  319. if (!isVideo()) {
  320. if (__vis_detach_attrib.getData() == "0") {
  321. openDrawerForVis();
  322. } else if (__video_detach_attrib.getData() == "0") {
  323. openDrawerForVideo();
  324. } else {
  325. openDrawerForNothing();
  326. }
  327. } else {
  328. if (__video_detach_attrib.getData() == "0") {
  329. openDrawerForVideo();
  330. } else if (__vis_detach_attrib.getData() == "0") {
  331. openDrawerForVis();
  332. } else {
  333. openDrawerForNothing();
  334. }
  335. }
  336. } else {
  337. int Window_Content=getPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  338. if (window_content == CONTENT_VIS && __vis_detach_attrib.getData() == "0") {
  339. openDrawerForVis();
  340. } else if (window_content == CONTENT_VIDEO && __video_detach_attrib.getData() == "0") {
  341. openDrawerForVideo();
  342. } else if (__vis_detach_attrib.getData() == "0") {
  343. openDrawerForVis();
  344. } else if (__video_detach_attrib.getData() == "0") {
  345. openDrawerForVideo();
  346. } else {
  347. openDrawerForNothing();
  348. }
  349. }
  350. }
  351. // -----------------------------------------------------------------------
  352. closeDrawer() {
  353. drawer_reduceWindow(1);
  354. }
  355. // -----------------------------------------------------------------------
  356. System.onPlay() {
  357. // needed to handle video auto fullscreen on play in drawer_showVideo()
  358. WinampConfigGroup vidwcg = WinampConfig.getGroup(VIDEO_CONFIG_GROUP);
  359. boolean auto_fs = vidwcg.getBool("auto_fs");
  360. if (auto_fs && __video_detach_attrib.getData() == "0") __play_auto_fs_video = 1;
  361. else __play_auto_fs_video = 0;
  362. }
  363. System.onTitleChange(String newtitle) {
  364. // needed to handle video auto fullscreen on play in drawer_showVideo()
  365. WinampConfigGroup vidwcg = WinampConfig.getGroup(VIDEO_CONFIG_GROUP);
  366. boolean auto_fs = vidwcg.getBool("auto_fs");
  367. if (auto_fs && __video_detach_attrib.getData() == "0") __play_auto_fs_video = 1;
  368. else __play_auto_fs_video = 0;
  369. }
  370. // -----------------------------------------------------------------------
  371. System.onPause() {
  372. __play_auto_fs_video = 0;
  373. }
  374. // -----------------------------------------------------------------------
  375. System.onResume() {
  376. __play_auto_fs_video = 0;
  377. }
  378. // -----------------------------------------------------------------------
  379. System.onStop() {
  380. __play_auto_fs_video = 0;
  381. }
  382. // -----------------------------------------------------------------------
  383. // The heart of the machine, here we detect when a window wants to open
  384. // or close, and we decide what to do about it. When we return FALSE, the
  385. // window performs what it notified us about. When we return TRUE, the
  386. // showing/hiding of the window is cancelled, and it is now up to us to
  387. // show or hide the window once we're done with our animations.
  388. // To show the window ourselves, we later show a windowholder with the
  389. // autoopen="1" param, and to hide the window, we simply hide the
  390. // windowholder, and its autoclose="1" param will do the rest
  391. // -----------------------------------------------------------------------
  392. System.onGetCancelComponent(String guid, boolean goingvisible) {
  393. #ifdef DEBUG
  394. DebugString("+", 0);
  395. #endif
  396. // fix for when the UI sometimes is locked after switching video file in fullscreen
  397. unlockUI();
  398. // isVideo() hasn't been set yet in System.onPlay and System.onTitleChange, so we check it here instead.
  399. if (__play_auto_fs_video && !isVideo()) __play_auto_fs_video = 0;
  400. if (__bypasscancel) return FALSE;
  401. if (guid == VIDEO_GUID && !goingvisible && __hiding_video) return FALSE;
  402. if (guid == VIS_GUID && !goingvisible && __hiding_vis) return FALSE;
  403. if (guid == VIDEO_GUID && goingvisible && __showing_video) return FALSE;
  404. if (guid == VIS_GUID && goingvisible && __showing_vis) return FALSE;
  405. #ifdef DEBUG
  406. DebugString("--------------- onGetCancelComponent ----------------", 0);
  407. DebugString(" GUID : " + guid, 0);
  408. if (goingvisible) DebugString(" Going Visible", 0); else DebugString(" Going Invisible", 0);
  409. DebugString(" Last Content : " + IntegerToString(getPrivateInt("winamp5", __myname+"State", CONTENT_VIS)), 0);
  410. DebugString(" Drawer State : " + IntegerToString(getPrivateInt("winamp5", __myname+"OpenState", CLOSED)), 0);
  411. DebugString("-----------------------------------------------------", 0);
  412. #endif
  413. if (!__main.isVisible()) return FALSE;
  414. int Window_Content=getPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  415. int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  416. if (window_status == CLOSED) {
  417. if (guid == VIDEO_GUID) {
  418. if (__video_detach_attrib.getData() == "0") {
  419. if (goingvisible) {
  420. openDrawerForVideo();
  421. return TRUE;
  422. }
  423. }
  424. }
  425. if (guid == VIS_GUID) {
  426. if (__vis_detach_attrib.getData() == "0") {
  427. if (goingvisible) {
  428. openDrawerForVis();
  429. return TRUE;
  430. }
  431. }
  432. }
  433. } else if (window_status == OPEN) {
  434. if (goingvisible) {
  435. if (guid == VIDEO_GUID && window_content == CONTENT_VIS) {
  436. if (__video_detach_attrib.getData() == "0") {
  437. window_content = CONTENT_VIDEO;
  438. drawer_hideVis();
  439. drawer_dc_showVideo();
  440. return TRUE;
  441. }
  442. } else if (guid == VIS_GUID && window_content == CONTENT_VIDEO) {
  443. if (__vis_detach_attrib.getData() == "0") {
  444. window_content = CONTENT_VIS;
  445. drawer_disablePSOVC();
  446. drawer_hideVideo();
  447. drawer_dc_showVis();
  448. return TRUE;
  449. }
  450. }
  451. }
  452. }
  453. if (!goingvisible && window_status == OPEN) {
  454. #ifdef DEBUG
  455. DebugString("closing " + guid, 0);
  456. #endif
  457. if (guid == VIDEO_GUID && window_content == CONTENT_VIDEO) {
  458. drawer_hideVideo();
  459. drawer_reduceWindow(1);
  460. return FALSE;
  461. }
  462. if (guid == VIS_GUID && window_content == CONTENT_VIS) {
  463. drawer_hideVis();
  464. if ((getStatus() == STATUS_PLAYING ||
  465. getStatus() == STATUS_PAUSED) &&
  466. isVideo() &&
  467. __video_detach_attrib.getData() == "0") {
  468. drawer_dc_showVideo();
  469. } else {
  470. drawer_reduceWindow(1);
  471. }
  472. return FALSE;
  473. }
  474. }
  475. #ifdef DEBUG
  476. DebugString("Went thru", 0);
  477. #endif
  478. return FALSE;
  479. }
  480. // -----------------------------------------------------------------------
  481. drawer_showVis() {
  482. #ifdef DEBUG
  483. DebugString("drawer_showVis",0 );
  484. #endif
  485. __showing_vis = 1;
  486. setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  487. setPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  488. GuiObject o = getVisWindowHolder();
  489. if (o != NULL) { __bypasscancel = 1; o.show(); __bypasscancel = 0; }
  490. #ifdef DEBUG
  491. else DebugString("vis object not provided (show)", 0);
  492. #endif
  493. onShowVis();
  494. __showing_vis = 0;
  495. }
  496. // -----------------------------------------------------------------------
  497. drawer_hideVis() {
  498. __callback_vis_show = 0;
  499. #ifdef DEBUG
  500. DebugString("drawer_hideVis",0 );
  501. #endif
  502. __hiding_vis = 1;
  503. GuiObject o = getVisWindowHolder();
  504. if (o != NULL) { __bypasscancel = 1; o.hide(); __bypasscancel = 0; }
  505. #ifdef DEBUG
  506. else DebugString("video object not found (hide)", 0);
  507. #endif
  508. onHideVis();
  509. __hiding_vis = 0;
  510. }
  511. // -----------------------------------------------------------------------
  512. drawer_showVideo() {
  513. #ifdef DEBUG
  514. DebugString("drawer_showVideo",0 );
  515. #endif
  516. __showing_video = 1;
  517. setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  518. setPrivateInt("winamp5", __myname+"State", CONTENT_VIDEO);
  519. GuiObject o = getVideoWindowHolder();
  520. if (o != NULL) {
  521. __bypasscancel = 1;
  522. // hack to fix bug for auto fullscreen on play
  523. if (__play_auto_fs_video) setVideoFullscreen(FALSE);
  524. o.show();
  525. // hack to fix bug for auto fullscreen on play
  526. if (__play_auto_fs_video) setVideoFullscreen(TRUE);
  527. __bypasscancel = 0;
  528. }
  529. #ifdef DEBUG
  530. else DebugString("vis object not found (show)", 0);
  531. #endif
  532. onShowVideo();
  533. __play_auto_fs_video = 0;
  534. __showing_video = 0;
  535. }
  536. // -----------------------------------------------------------------------
  537. drawer_hideVideo() {
  538. __callback_video_show = 0;
  539. #ifdef DEBUG
  540. DebugString("drawer_hideVideo",0 );
  541. #endif
  542. __hiding_video = 1;
  543. GuiObject o = getVideoWindowHolder();
  544. if (o != NULL) { __bypasscancel = 1; o.hide(); __bypasscancel = 0; }
  545. #ifdef DEBUG
  546. else DebugString("video object not found (hide)", 0);
  547. #endif
  548. onHideVideo();
  549. __hiding_video = 0;
  550. }
  551. // -----------------------------------------------------------------------
  552. __callbackTimer.onTimer() {
  553. stop();
  554. int cvds = __callback_video_show;
  555. int cvss = __callback_vis_show;
  556. int cvdh = __callback_video_hide;
  557. int cvsh = __callback_vis_hide;
  558. __callback_video_show = 0;
  559. __callback_vis_show = 0;
  560. __callback_video_hide = 0;
  561. __callback_vis_hide = 0;
  562. if (cvds == 1) drawer_showVideo();
  563. if (cvss == 1) drawer_showVis();
  564. if (cvsh == 1) drawer_hideVis();
  565. if (cvdh == 1) drawer_hideVideo();
  566. }
  567. // -----------------------------------------------------------------------
  568. drawer_dc_showVideo() {
  569. __callback_video_show = 1;
  570. __callback_video_hide = 0;
  571. __callbackTimer.start();
  572. }
  573. // -----------------------------------------------------------------------
  574. drawer_dc_showVis() {
  575. __callback_vis_show = 1;
  576. __callback_vis_hide = 0;
  577. __callbackTimer.start();
  578. }
  579. // -----------------------------------------------------------------------
  580. drawer_dc_hideVideo() {
  581. __callback_video_show = 0;
  582. __callback_video_hide = 1;
  583. __callbackTimer.start();
  584. }
  585. // -----------------------------------------------------------------------
  586. drawer_dc_hideVis() {
  587. __callback_vis_show = 0;
  588. __callback_vis_hide = 1;
  589. __callbackTimer.start();
  590. }
  591. // -----------------------------------------------------------------------
  592. drawer_showWindowContent() {
  593. int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  594. #ifdef DEBUG
  595. DebugString("drawer_showWindowContent = " + IntegerToString(lastWindowContent), 0);
  596. #endif
  597. if (lastWindowContent==CONTENT_VIDEO) drawer_dc_showVideo();
  598. if (lastWindowContent==CONTENT_VIS) drawer_dc_showVis();
  599. }
  600. // -----------------------------------------------------------------------
  601. drawer_hideWindowContent() {
  602. int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  603. #ifdef DEBUG
  604. DebugString("drawer_hideWindowContent = " + IntegerToString(lastWindowContent), 0);
  605. #endif
  606. /*if (lastWindowContent==CONTENT_VIDEO)*/ drawer_hideVideo();
  607. /*if (lastWindowContent==CONTENT_VIS)*/ drawer_hideVis();
  608. }
  609. // -----------------------------------------------------------------------
  610. OpenDrawerForVideo() {
  611. setPrivateInt("winamp5", __myname+"State", CONTENT_VIDEO);
  612. drawer_expandWindow(1);
  613. }
  614. // -----------------------------------------------------------------------
  615. OpenDrawerForVis() {
  616. setPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  617. drawer_expandWindow(1);
  618. }
  619. // -----------------------------------------------------------------------
  620. OpenDrawerForNothing() {
  621. setPrivateInt("winamp5", __myname+"State", CONTENT_NOTHING);
  622. drawer_expandWindow(1);
  623. }
  624. // -----------------------------------------------------------------------
  625. __main.onResize(int x, int y, int w, int h) {
  626. if (!isGoingToTarget() && !__isinited) {
  627. __isinited = 1;
  628. if (h > getDrawerClosedHeight()) { setPrivateInt("winamp5", __myname+"OpenState", OPEN); drawer_expandWindow(0); }
  629. else setPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  630. }
  631. }
  632. // -----------------------------------------------------------------------
  633. __main.onUserResize(int x, int y, int w, int h) {
  634. int window_status=getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  635. if (window_status == OPEN) {
  636. int h = getHeight();
  637. if (h != getDrawerClosedHeight()) {
  638. #ifdef DEBUG
  639. DebugString("h = "+integerTostring(h), 0);
  640. #endif
  641. if (!__maximized)
  642. setPrivateInt("winamp5", __myname+"Height", h);
  643. }
  644. } else if (window_status == CLOSED) {
  645. int h = getDrawerOpenAutoHeight(w);
  646. if (h != -1) {
  647. setPrivateInt("winamp5", __myname+"Height", h);
  648. }
  649. }
  650. if (__maximized) {
  651. __maximized = 0;
  652. setPrivateInt("winamp5", __myname+"Maximized", 0);
  653. onCancelMaximize();
  654. }
  655. }
  656. // -----------------------------------------------------------------------
  657. switchToVideo() {
  658. if (__callbackTimer.isRunning()) return;
  659. if (__callbackTimer2.isRunning()) return;
  660. if (__tempDisable.isRunning()) return;
  661. __tempDisable.start();
  662. drawer_hideVis();
  663. drawer_showVideo();
  664. }
  665. // -----------------------------------------------------------------------
  666. switchToVis() {
  667. if (__callbackTimer.isRunning()) return;
  668. if (__callbackTimer2.isRunning()) return;
  669. if (__tempDisable.isRunning()) return;
  670. __tempDisable.start();
  671. drawer_disablePSOVC();
  672. drawer_hideVideo();
  673. drawer_showVis();
  674. }
  675. // -----------------------------------------------------------------------
  676. __tempDisable.onTimer() {
  677. stop();
  678. }
  679. // -----------------------------------------------------------------------
  680. detachVis() {
  681. if (__tempDisable.isRunning()) return;
  682. __tempDisable.start();
  683. __vis_detach_attrib.setData("1");
  684. }
  685. // -----------------------------------------------------------------------
  686. detachVideo() {
  687. if (__tempDisable.isRunning()) return;
  688. __tempDisable.start();
  689. __video_detach_attrib.setData("1");
  690. }
  691. // -----------------------------------------------------------------------
  692. attachVis() {
  693. if (__tempDisable.isRunning()) return;
  694. __tempDisable.start();
  695. __vis_detach_attrib.setData("0");
  696. }
  697. // -----------------------------------------------------------------------
  698. attachVideo() {
  699. if (__tempDisable.isRunning()) return;
  700. __tempDisable.start();
  701. __video_detach_attrib.setData("0");
  702. }
  703. // -----------------------------------------------------------------------
  704. __video_detach_attrib.onDataChanged() {
  705. #ifdef DEBUG
  706. DebugString("detach video changed", 0);
  707. #endif
  708. if (getData() == "1") {
  709. drawer_doDetachVideo();
  710. onDetachVideo();
  711. } else {
  712. if (getData() == "0") {
  713. drawer_doAttachVideo();
  714. onAttachVideo();
  715. }
  716. }
  717. }
  718. // -----------------------------------------------------------------------
  719. __vis_detach_attrib.onDataChanged() {
  720. #ifdef DEBUG
  721. DebugString("detach vis changed", 0);
  722. #endif
  723. if (getData() == "1") {
  724. drawer_doDetachVis();
  725. onDetachVis();
  726. } else {
  727. if (getData() == "0") {
  728. drawer_doAttachVis();
  729. onAttachVis();
  730. }
  731. }
  732. }
  733. // -----------------------------------------------------------------------
  734. drawer_doDetachVideo() {
  735. int wasvisible = isNamedWindowVisible(VIDEO_GUID);
  736. int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  737. int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  738. if (!wasvisible) return;
  739. if (lastWindowContent != CONTENT_VIDEO) return;
  740. if (window_status == OPEN) {
  741. drawer_disablePSOVC();
  742. drawer_reduceWindow(1);
  743. }
  744. drawer_dc_linkup_showVideo();
  745. }
  746. // -----------------------------------------------------------------------
  747. drawer_doDetachVis() {
  748. int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  749. int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  750. if (lastWindowContent != CONTENT_VIS) return;
  751. int wasvisible = isNamedWindowVisible(VIS_GUID);
  752. if (!wasvisible) return;
  753. if (window_status == OPEN) {
  754. drawer_hideVis();
  755. if ((getStatus() == STATUS_PLAYING ||
  756. getStatus() == STATUS_PAUSED) && isVideo() &&
  757. __video_detach_attrib.getData() == "0") {
  758. setPrivateInt("winamp5", __myname+"State", CONTENT_VIDEO);
  759. drawer_dc_showVideo();
  760. } else {
  761. drawer_reduceWindow(1);
  762. }
  763. }
  764. drawer_dc_linkup_showVis();
  765. }
  766. // -----------------------------------------------------------------------
  767. drawer_doAttachVideo() {
  768. drawer_disablePSOVC();
  769. int wasvisible = isNamedWindowVisible(VIDEO_GUID);
  770. if (wasvisible) {
  771. hideNamedWindow(VIDEO_GUID);
  772. int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  773. int window_content=getPrivateInt("winamp5", __myname+"State", 2);
  774. if (window_content == CONTENT_VIS) drawer_hideVis();
  775. if (window_status == CLOSED) openDrawerForVideo();
  776. else drawer_dc_showVideo();
  777. }
  778. }
  779. // -----------------------------------------------------------------------
  780. drawer_doAttachVis() {
  781. drawer_disablePSOVC();
  782. int wasvisible = isNamedWindowVisible(VIS_GUID);
  783. if (wasvisible) {
  784. hideNamedWindow(VIS_GUID);
  785. int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  786. int window_content=getPrivateInt("winamp5", __myname+"State", 2);
  787. if (window_content == CONTENT_VIDEO) drawer_hideVideo();
  788. if (window_status == CLOSED) openDrawerForVis();
  789. else drawer_dc_showVis();
  790. }
  791. }
  792. // -----------------------------------------------------------------------
  793. __callbackTimer2.onTimer() {
  794. stop();
  795. if (__callback2_what == DETACHED_VIDEO) drawer_linkup_showVideo();
  796. if (__callback2_what == DETACHED_VIS) drawer_linkup_showVis();
  797. }
  798. // -----------------------------------------------------------------------
  799. drawer_dc_linkup_showVis() {
  800. __callback2_what = DETACHED_VIS;
  801. __callbackTimer2.start();
  802. }
  803. // -----------------------------------------------------------------------
  804. drawer_dc_linkup_showVideo() {
  805. __callback2_what = DETACHED_VIDEO;
  806. __callbackTimer2.start();
  807. }
  808. // -----------------------------------------------------------------------
  809. drawer_linkup_showVis() {
  810. #ifdef DEBUG
  811. DebugString("show detached vis",0 );
  812. #endif
  813. showWindow(VIS_GUID, "", 0);
  814. }
  815. // -----------------------------------------------------------------------
  816. drawer_linkup_showVideo() {
  817. #ifdef DEBUG
  818. DebugString("show detached video",0 );
  819. #endif
  820. showWindow(VIDEO_GUID, "", 0);
  821. drawer_enablePSOVC();
  822. }
  823. // -----------------------------------------------------------------------
  824. drawer_disablePSOVC() {
  825. #ifdef DEBUG
  826. DebugString("disabling stop on video close",0 );
  827. #endif
  828. ConfigItem item = Config.getItem(SKINTWEAKS_CFGPAGE);
  829. if (item) {
  830. ConfigAttribute attr = item.getAttribute("Prevent video playback Stop on video window Close");
  831. if (attr) attr.setData("1");
  832. }
  833. __PSOVCTimer.start();
  834. }
  835. // -----------------------------------------------------------------------
  836. drawer_enablePSOVC() {
  837. #ifdef DEBUG
  838. DebugString("enabling stop on video close",0 );
  839. #endif
  840. __PSOVCTimer.stop();
  841. ConfigItem item = Config.getItem(SKINTWEAKS_CFGPAGE);
  842. if (item) {
  843. ConfigAttribute attr = item.getAttribute("Prevent video playback Stop on video window Close");
  844. if (attr) attr.setData("0");
  845. }
  846. }
  847. // -----------------------------------------------------------------------
  848. __PSOVCTimer.onTimer() {
  849. drawer_enablePSOVC();
  850. }
  851. // -----------------------------------------------------------------------
  852. __maincontainer.onBeforeSwitchToLayout(Layout oldl, Layout newl) {
  853. int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  854. int window_content=getPrivateInt("winamp5", __myname+"State", 2);
  855. if (oldl == __main && window_status == OPEN && window_content == CONTENT_VIDEO && getStatus() == STATUS_PLAYING && isVideo()) {
  856. drawer_disablePSOVC();
  857. __windowshade_openvid = 1;
  858. }
  859. if (oldl == __main && window_status == OPEN && window_content == CONTENT_VIS) {
  860. __windowshade_openvis = 1;
  861. }
  862. }
  863. // -----------------------------------------------------------------------
  864. __maincontainer.onSwitchToLayout(Layout newl) {
  865. // these do not call drawer_doDetachVis or drawer_doDetachVideo but showDetachVis and showDetachVideo so that the change is temporary
  866. if (__windowshade_openvid) {
  867. __windowshade_openvid = 0;
  868. drawer_linkup_showVideo();
  869. }
  870. if (__windowshade_openvis) {
  871. __windowshade_openvis = 0;
  872. drawer_linkup_showVis();
  873. }
  874. }
  875. // -----------------------------------------------------------------------
  876. Int getDrawerState() {
  877. return getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  878. }
  879. // -----------------------------------------------------------------------
  880. Int getDrawerContent() {
  881. return getPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  882. }
  883. // -----------------------------------------------------------------------
  884. maximizeWindow() {
  885. __oldx=__main.getGuiX();
  886. __oldy=__main.getGuiY();
  887. __oldw=__main.getGuiW();
  888. __oldh=__main.getGuiH();
  889. setPrivateInt("winamp5", __myname+"ox", __oldx);
  890. setPrivateInt("winamp5", __myname+"oy", __oldy);
  891. setPrivateInt("winamp5", __myname+"ow", __oldw);
  892. setPrivateInt("winamp5", __myname+"oh", __oldh);
  893. drawer_doMaximizeWindow(1);
  894. }
  895. // -----------------------------------------------------------------------
  896. drawer_doMaximizeWindow(int notif) {
  897. int vx=getViewportLeft();
  898. int vy=getViewportTop();
  899. int vw=getViewportWidth();
  900. int vh=getViewportHeight();
  901. if (notif) onBeforeMaximize();
  902. __maximized = 1;
  903. setPrivateInt("winamp5", __myname+"Maximized", 1);
  904. __main.resize(vx, vy, vw, vh+__main.getSnapAdjustBottom());
  905. if (notif) onAfterMaximize();
  906. }
  907. // -----------------------------------------------------------------------
  908. __main.onSnapAdjustChanged() {
  909. if (__maximized)
  910. drawer_doMaximizeWindow(0);
  911. }
  912. // -----------------------------------------------------------------------
  913. restoreWindow() {
  914. onBeforeRestore();
  915. __maximized = 0;
  916. setPrivateInt("winamp5", __myname+"Maximized", 0);
  917. __main.resize(__oldx, __oldy, __oldw, __oldh);
  918. onAfterRestore();
  919. }
  920. // -----------------------------------------------------------------------
  921. // default events implementations - override them in your script
  922. // -----------------------------------------------------------------------
  923. onBeforeOpeningDrawer() {}
  924. onBeforeClosingDrawer() {}
  925. onDoneOpeningDrawer() {}
  926. onDoneClosingDrawer() {}
  927. onShowVis() {}
  928. onHideVis() {}
  929. onShowVideo() {}
  930. onHideVideo() {}
  931. onAttachVideo() {}
  932. onDetachVideo() {}
  933. onAttachVis() {}
  934. onDetachVis() {}
  935. onBeforeMaximize() {}
  936. onBeforeRestore() {}
  937. onAfterMaximize() {}
  938. onAfterRestore() {}
  939. onCancelMaximize() {}