1
0

alphamgr.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. #include <precomp.h>
  2. #include "alphamgr.h"
  3. #include <api/wndmgr/layout.h>
  4. #include <api/skin/skinparse.h>
  5. #ifdef _WIN32
  6. #include <tataki/blending/blending.h>
  7. #endif
  8. #include <bfc/util/profiler.h>
  9. #include <bfc/wasabi_std_wnd.h>
  10. #ifndef PI
  11. #define PI 3.1415926536
  12. #endif
  13. #define ALPHAMGR_HOVERCHECK 100
  14. #define ALPHAMGR_UPDATEALPHA 200
  15. AlphaMgr::AlphaMgr() {
  16. overlayout = NULL;
  17. timerclient_setTimer(ALPHAMGR_HOVERCHECK, 200);
  18. alllinked = 0;
  19. autoopacify = 0;
  20. fast_timer_on = 0;
  21. big_curtransparency = 0;
  22. big_status = STATUS_UNKNOWN;
  23. big_startalpha = 0;
  24. big_lasttimein = 0;
  25. extend_px = 0;
  26. global_alpha = 0;
  27. big_enterleave_time = 0;
  28. fadein_ms = 1;
  29. fadeout_ms = 1;
  30. holdtime_ms = 1;
  31. }
  32. AlphaMgr::~AlphaMgr()
  33. {
  34. timerclient_killTimer(ALPHAMGR_HOVERCHECK);
  35. }
  36. void AlphaMgr::addLayout(Layout *l)
  37. {
  38. checkTimer();
  39. if (layouts.findItem((const wchar_t *)l))
  40. return;
  41. layouts.addItem(new AlphaMgrEntry(l));
  42. }
  43. void AlphaMgr::removeLayout(Layout *l) {
  44. int p=-1;
  45. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l, &p);
  46. if (p != -1) {
  47. if (e->getStatus() == STATUS_IN_FADINGON || e->getStatus() == STATUS_IN_ON) {
  48. updateInList(e, 0);
  49. checkTimer();
  50. }
  51. layouts.removeByPos(p);
  52. in_layouts.removeItem(e);
  53. delete e;
  54. checkTimer();
  55. }
  56. }
  57. // gets the currently needed transparency, according to layout overrides and global link, and then applies this
  58. // transparency to the layout, it does not change anything in any data structure, this is only a visual update function
  59. void AlphaMgr::updateTransparency(Layout *l) {
  60. if (!l) return;
  61. if (l->isInited()) {
  62. if (l->isTransparencySafe()) {
  63. int a = l->getTransparencyOverride();
  64. if (a == -1) {
  65. if (l->getNoParent()!=1) {
  66. if (a == -1 && hasAutoOpacity(l))
  67. a = getTransparency(l);
  68. else if (a == -1 && getAllLinked())
  69. a = getGlobalAlpha();
  70. }
  71. if (a == -1) {
  72. /* why the hell would it care if it's alllinked if it's an independent window ?? (noparent=1)
  73. if (getAllLinked())
  74. a = getGlobalAlpha();
  75. else
  76. */
  77. a = l->getPaintingAlpha();
  78. }
  79. }
  80. l->setTransparency(a);
  81. } else {
  82. l->setTransparency(255);
  83. }
  84. }
  85. }
  86. // returns the alpha value for this slot, that's not necessarily the transparency that should be applied to the layout
  87. // since overrides & calculations in updateTransparency and getTransparency should apply.
  88. int AlphaMgr::getAlpha(AlphaMgrEntry *e) {
  89. if (alllinked && e->getLayout()->getNoParent() != 1) return getGlobalAlpha();
  90. return e->getLayout()->getAlpha();
  91. }
  92. int AlphaMgr::getAlpha(Layout *l) {
  93. int p=-1;
  94. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l, &p);
  95. if (p != -1) return getAlpha(e);
  96. return l->getAlpha();
  97. }
  98. int AlphaMgr::getGlobalAlpha() {
  99. return global_alpha;
  100. }
  101. void AlphaMgr::updateAllTransparency() {
  102. foreach(layouts)
  103. updateTransparency(layouts.getfor()->getLayout());
  104. endfor;
  105. }
  106. void AlphaMgr::setGlobalAlpha(int a) {
  107. global_alpha = a;
  108. updateAllTransparency();
  109. }
  110. int AlphaMgr::getCurve(AlphaMgrEntry *e) {
  111. int n;
  112. int status = e ? e->getStatus() : getBigStatus();
  113. if (e == NULL) {
  114. n = MulDiv(Wasabi::Std::getTickCount()-getBigEnterLeaveTime(),256,status == STATUS_IN_FADINGON ? fadein_ms : fadeout_ms);
  115. if (n > 255) n = 255; if (n < 0) n = 0;
  116. } else {
  117. if (e->getEnterLeaveTime() == -1) return -1;
  118. n = MulDiv(Wasabi::Std::getTickCount()-e->getEnterLeaveTime(),256,status == STATUS_IN_FADINGON ? fadein_ms : fadeout_ms);
  119. if (n > 255) n = 255; if (n < 0) n = 0;
  120. }
  121. return n;
  122. }
  123. // returns the value of the transparency if no override applies, you still need to check overrides (see updatetransparency)
  124. int AlphaMgr::getTransparency(Layout *l) {
  125. if (getAutoOpacify())
  126. l = NULL;
  127. if (l == NULL) {
  128. if (getBigStatus() == STATUS_UNKNOWN) {
  129. setBigStatus(STATUS_OUT_OFF);
  130. Layout *main = SkinParser::getMainLayout();
  131. if (main)
  132. big_curtransparency = main->getTransparency();
  133. else
  134. big_curtransparency = 255;
  135. }
  136. }
  137. AlphaMgrEntry *e = NULL;
  138. if (l) e = layouts.findItem((const wchar_t *)l);
  139. int s = e ? e->getStatus() : getBigStatus();
  140. if (e && s == STATUS_UNKNOWN) {
  141. initStatus(e);
  142. s = e->getStatus();
  143. }
  144. switch (s) {
  145. case STATUS_IN_OFF: return e ? getAlpha(e) : getGlobalAlpha();
  146. case STATUS_OUT_OFF: return e ? getAlpha(e) : getGlobalAlpha();
  147. case STATUS_IN_ON: return 255;
  148. case STATUS_OUT_FADINGOUT: {
  149. int n = e ? getCurve(e) : getCurve(NULL);
  150. float sintrans = (float)(sin(((float)n/255)*PI-PI/2)/2+0.5);
  151. int na;
  152. if (e)
  153. na = (int)(((float)(getAlpha(e) - e->getStartAlpha()) * sintrans) + e->getStartAlpha());
  154. else
  155. na = (int)(((float)(getGlobalAlpha() - getBigStartAlpha()) * sintrans) + getBigStartAlpha());
  156. return na;
  157. }
  158. case STATUS_IN_FADINGON: {
  159. int n = e ? getCurve(e) : getCurve(NULL);
  160. float sintrans = (float)(sin(((float)n/255)*PI-PI/2)/2+0.5);
  161. int na;
  162. if (e)
  163. na = (int)(((float)(255 - e->getStartAlpha()) * sintrans) + e->getStartAlpha());
  164. else
  165. na = (int)(((float)(255 - getBigStartAlpha()) * sintrans) + getBigStartAlpha());
  166. return na;
  167. }
  168. default: return e ? getAlpha(e) : getGlobalAlpha();
  169. }
  170. }
  171. int AlphaMgr::hasAutoOpacityOnHover(Layout *l) {
  172. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  173. if (e) return hasAutoOpacityOnHover(e);
  174. return 0;
  175. }
  176. int AlphaMgr::hasAutoOpacity(Layout *l) {
  177. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  178. if (e) return hasAutoOpacity(e);
  179. return 0;
  180. }
  181. int AlphaMgr::hasAutoOpacityOnFocus(Layout *l) {
  182. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  183. if (e) return hasAutoOpacityOnFocus(e);
  184. return 0;
  185. }
  186. int AlphaMgr::hasAutoOpacityOnFocus(AlphaMgrEntry *e) {
  187. if (alllinked) return autoopacify == 2;
  188. return e->getLayout()->getAutoOpacify() == 2 && e->getLayout()->getNoParent() != 1;
  189. }
  190. int AlphaMgr::hasAutoOpacityOnHover(AlphaMgrEntry *e) {
  191. if (alllinked) return autoopacify == 1;
  192. return e->getLayout()->getAutoOpacify() == 1 && e->getLayout()->getNoParent() != 1;
  193. }
  194. int AlphaMgr::hasAutoOpacity(AlphaMgrEntry *e) {
  195. if (alllinked) return autoopacify;
  196. return e->getLayout()->getAutoOpacify() && e->getLayout()->getNoParent() != 1;
  197. }
  198. // we got a new layout to manage, and its status flags is not set, we should init it to something safe
  199. void AlphaMgr::initStatus(AlphaMgrEntry *l, int applytransparency) {
  200. if (isMouseInLayout(l->getLayout())) {
  201. l->setEnterLeaveTime((uint32_t)-1);
  202. if (hasAutoOpacity(l)) {
  203. l->setStatus(STATUS_IN_FADINGON);
  204. l->onEnterLeave();
  205. l->setStartAlpha(l->getLayout()->getTransparency());
  206. checkTimer();
  207. } else {
  208. l->setStatus(STATUS_IN_OFF);
  209. }
  210. l->getLayout()->onMouseEnterLayout();
  211. } else {
  212. if (hasAutoOpacityOnHover(l)) {
  213. l->setStartAlpha(l->getLayout()->getTransparency());
  214. l->onEnterLeave();
  215. l->setStatus(STATUS_OUT_FADINGOUT);
  216. checkTimer();
  217. } else {
  218. l->setStatus(STATUS_OUT_OFF);
  219. }
  220. l->getLayout()->onMouseLeaveLayout();
  221. }
  222. if (applytransparency) updateTransparency(l->getLayout());
  223. }
  224. int AlphaMgr::isPointInLayout(Layout *l, int x, int y, api_region **rgn)
  225. {
  226. api_region *rg = NULL;
  227. if (!l) return 0;
  228. if (!l->isVisible()) return 0;
  229. RECT r,r2;
  230. l->getClientRect(&r);
  231. if (l->renderRatioActive()) l->multRatio(&r);
  232. l->getWindowRect(&r2);
  233. Wasabi::Std::offsetRect(&r, r2.left, r2.top);
  234. // OffsetRect(&r, r2.left, r2.top);
  235. if (x < r.left || x > r.right || y < r.top || y > r.bottom) return 0;
  236. if (rgn) {
  237. if (!*rgn) {
  238. rg = l->getComposedRegion();
  239. *rgn = rg;
  240. } else {
  241. rg = *rgn;
  242. }
  243. } else {
  244. rg = l->getComposedRegion();
  245. }
  246. if (!rgn) return 1;
  247. x -= r.left; y -= r.top;
  248. POINT pt={x,y};
  249. if (l->renderRatioActive()) l->divRatio((int*)&pt.x, (int*)&pt.y);
  250. if (l->getComposedRegion()->ptInRegion(&pt)) return 1;
  251. return 0;
  252. }
  253. int AlphaMgr::isFocusInLayout(Layout *l) {
  254. if (l->gotFocus()) return 1;
  255. OSWINDOWHANDLE fw = Wasabi::Std::Wnd::getFocus();
  256. while (fw)
  257. {
  258. if (fw == l->gethWnd()) return 1;
  259. fw = Wasabi::Std::Wnd::getParent(fw);
  260. }
  261. return 0;
  262. }
  263. int AlphaMgr::isMouseInLayout(Layout *l) {
  264. int isin = 0;
  265. if (hasAutoOpacityOnFocus(l)) {
  266. return isFocusInLayout(l);
  267. } else {
  268. int x, y;
  269. api_region *r = NULL;
  270. Wasabi::Std::getMousePos(&x, &y);
  271. isin = isPointInLayout(l, x, y, &r);
  272. int ext = getExtendAutoOpacity();
  273. if (!isin && ext > 0) {
  274. isin = isPointInLayout(l, x-ext, y, &r);
  275. if (!isin) isin = isPointInLayout(l, x-ext, y-ext, &r);
  276. if (!isin) isin = isPointInLayout(l, x, y-ext, &r);
  277. if (!isin) isin = isPointInLayout(l, x+ext, y-ext, &r);
  278. if (!isin) isin = isPointInLayout(l, x+ext, y, &r);
  279. if (!isin) isin = isPointInLayout(l, x+ext, y+ext, &r);
  280. if (!isin) isin = isPointInLayout(l, x, y+ext, &r);
  281. if (!isin) isin = isPointInLayout(l, x-ext, y+ext, &r);
  282. if (!isin) isin = isPointInLayout(l, x-ext, y, &r);
  283. }
  284. }
  285. return isin;
  286. }
  287. int AlphaMgr::needForcedTransparencyFlag(Layout *l) {
  288. if (!l->isTransparencySafe()) return 0;
  289. if (l->isAlphaForced()) return 1;
  290. if (l->getTransparencyOverride() > 0) return 1; // should not be testing for < 255 here
  291. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  292. if (hasAutoOpacity(e) && getAlpha(e) < 255) return 1;
  293. return 0;
  294. }
  295. void AlphaMgr::checkTimer() {
  296. int fading = 0;
  297. foreach(layouts)
  298. AlphaMgrEntry *e = layouts.getfor();
  299. if (e->getStatus() == STATUS_IN_FADINGON || e->getStatus() == STATUS_OUT_FADINGOUT) { fading++; break; }
  300. endfor;
  301. if (getAutoOpacify() && getBigStatus() == STATUS_IN_FADINGON || getBigStatus() == STATUS_OUT_FADINGOUT)
  302. fading++;
  303. if (fading && !fast_timer_on) {
  304. timerclient_setTimer(ALPHAMGR_UPDATEALPHA, 20);
  305. fast_timer_on = 1;
  306. } else if (!fading && fast_timer_on) {
  307. timerclient_killTimer(ALPHAMGR_UPDATEALPHA);
  308. fast_timer_on = 0;
  309. }
  310. }
  311. void AlphaMgr::doEndCheck(AlphaMgrEntry *e) {
  312. if (getCurve(e) == 255) {
  313. switch (e ? e->getStatus() : getBigStatus()) {
  314. case STATUS_IN_FADINGON:
  315. if (e) e->setStatus(STATUS_IN_ON); else setBigStatus(STATUS_IN_ON);
  316. break;
  317. case STATUS_OUT_FADINGOUT:
  318. if (e) e->setStatus(STATUS_OUT_OFF); else setBigStatus(STATUS_OUT_OFF);
  319. break;
  320. }
  321. checkTimer();
  322. }
  323. }
  324. void AlphaMgr::updateInList(AlphaMgrEntry *e, int isin) {
  325. if (isin) {
  326. if (in_layouts.searchItem(e) == -1)
  327. in_layouts.addItem(e);
  328. } else {
  329. in_layouts.removeItem(e);
  330. }
  331. int big_isin = in_layouts.getNumItems() > 0;
  332. if (getAutoOpacify()) {
  333. if (big_isin) {
  334. // mouse is in a layout, autoopacity is on
  335. switch (getBigStatus()) {
  336. case STATUS_OUT_OFF:
  337. case STATUS_OUT_FADINGOUT:
  338. case STATUS_IN_OFF: {
  339. setBigStartAlpha(e->getLayout()->getTransparency());
  340. onBigEnterLeave();
  341. setBigStatus(STATUS_IN_FADINGON);
  342. checkTimer();
  343. break;
  344. }
  345. case STATUS_IN_FADINGON:
  346. doEndCheck(NULL);
  347. break;
  348. }
  349. } else {
  350. // mouse out of all layouts, autoopacity is on
  351. switch (getBigStatus()) {
  352. case STATUS_IN_FADINGON:
  353. case STATUS_IN_ON: {
  354. setBigStartAlpha(getTransparency(NULL));
  355. onBigEnterLeave();
  356. setBigStatus(STATUS_OUT_FADINGOUT);
  357. checkTimer();
  358. break;
  359. }
  360. case STATUS_OUT_FADINGOUT:
  361. doEndCheck(NULL);
  362. break;
  363. }
  364. }
  365. } else {
  366. if (big_isin) {
  367. // mouse is in a layout, no autoopacity
  368. setBigStatus(STATUS_IN_OFF);
  369. } else {
  370. // mouse is out of all layouts, no autoopacity
  371. setBigStatus(STATUS_OUT_OFF);
  372. }
  373. }
  374. }
  375. int AlphaMgr::isFocusingExternalWindow()
  376. {
  377. OSWINDOWHANDLE fw = Wasabi::Std::Wnd::getFocus();
  378. if (isOurExternalWindow(fw)) return 1;
  379. return 0;
  380. }
  381. int AlphaMgr::isOverExternalWindow()
  382. {
  383. int x, y;
  384. Wasabi::Std::getMousePos(&x, &y);
  385. int ext = getExtendAutoOpacity();
  386. POINT pt;
  387. pt.x = x; pt.y = y;
  388. OSWINDOWHANDLE w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  389. if (isOurExternalWindow(w)) return 1;
  390. pt.x = x-ext; pt.y = y-ext;
  391. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  392. if (isOurExternalWindow(w)) return 1;
  393. pt.x = x; pt.y = y-ext;
  394. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  395. if (isOurExternalWindow(w)) return 1;
  396. pt.x = x+ext; pt.y = y-ext;
  397. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  398. if (isOurExternalWindow(w)) return 1;
  399. pt.x = x+ext; pt.y = y;
  400. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  401. if (isOurExternalWindow(w)) return 1;
  402. pt.x = x+ext; pt.y = y+ext;
  403. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  404. if (isOurExternalWindow(w)) return 1;
  405. pt.x = x; pt.y = y+ext;
  406. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  407. if (isOurExternalWindow(w)) return 1;
  408. pt.x = x-ext; pt.y = y+ext;
  409. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  410. if (isOurExternalWindow(w)) return 1;
  411. pt.x = x-ext; pt.y = y;
  412. w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  413. if (isOurExternalWindow(w)) return 1;
  414. return 0;
  415. }
  416. int AlphaMgr::isWasabiWindow(OSWINDOWHANDLE w)
  417. {
  418. #ifdef _WIN32
  419. wchar_t classname[256]=L"";
  420. GetClassNameW(w, classname, 255);
  421. return (w == WASABI_API_WND->main_getRootWnd()->gethWnd() || !wcscmp(classname, BASEWNDCLASSNAME));
  422. #else
  423. #warning port me
  424. return 1;
  425. #endif
  426. }
  427. int AlphaMgr::isMenuWindow(OSWINDOWHANDLE w)
  428. {
  429. #ifdef _WIN32
  430. char classname[256]="";
  431. GetClassNameA(w, classname, 255);
  432. return STRCASEEQL(classname, "#32768");
  433. #else
  434. return 0;
  435. #warning port me
  436. #endif
  437. }
  438. int AlphaMgr::isOurExternalWindow(OSWINDOWHANDLE w)
  439. {
  440. OSWINDOWHANDLE wnd = w;
  441. if (isWasabiWindow(w))
  442. return 0;
  443. if (isMenuWindow(wnd)) {
  444. wnd = Wasabi::Std::Wnd::getFocus();
  445. if (isWasabiWindow(wnd) || isOurExternalWindow(wnd))
  446. return 1;
  447. }
  448. while (wnd)
  449. {
  450. if (Wasabi::Std::Wnd::isPopup(wnd))
  451. {
  452. if (isWasabiWindow(wnd))
  453. return 0;
  454. OSWINDOWHANDLE _w = Wasabi::Std::Wnd::getParent(wnd);
  455. #ifdef _WIN32
  456. if (!_w) _w = GetWindow(wnd, GW_OWNER);
  457. #else
  458. #warning port me
  459. #endif
  460. if (!wnd) _w = wnd;
  461. return (_w == WASABI_API_WND->main_getRootWnd()->gethWnd() || isWasabiWindow(_w) || isOurExternalWindow(_w));
  462. }
  463. wnd = Wasabi::Std::Wnd::getParent(wnd);
  464. }
  465. return 0;
  466. }
  467. void AlphaMgr::preHoverCheck(AlphaMgrEntry *e) {
  468. int isin = isMouseInLayout(e->getLayout());
  469. uint32_t last = e->getLastTimeIn();
  470. uint32_t lastbig = getBigLastTimeIn();
  471. if (isin) { e->onLastIn(); onBigLastIn(); }
  472. if (!getAutoOpacify()) {
  473. if (!isin && last != 0 && (last > Wasabi::Std::getTickCount() - holdtime_ms))
  474. isin = 1;
  475. } else {
  476. if (!isin && lastbig != 0 && (lastbig > Wasabi::Std::getTickCount() - holdtime_ms))
  477. isin = 1;
  478. }
  479. if (!isin) {
  480. if (hasAutoOpacityOnFocus(e)) {
  481. if (isFocusingExternalWindow()) isin = 1;
  482. } else {
  483. if (isOverExternalWindow()) isin = 1;
  484. }
  485. }
  486. e->setNextIn(isin);
  487. updateInList(e, isin);
  488. }
  489. void AlphaMgr::hoverCheck(Layout *l) {
  490. AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  491. if (e) hoverCheck(e);
  492. }
  493. void AlphaMgr::hoverCheck(AlphaMgrEntry *e, int applytransparency) {
  494. if (e->getStatus() == STATUS_UNKNOWN)
  495. initStatus(e);
  496. int isin = e->getNextIn();
  497. if (getAutoOpacify()) {
  498. isin = big_status == STATUS_IN_FADINGON || big_status == STATUS_IN_ON || big_status == STATUS_IN_OFF;
  499. }
  500. if (hasAutoOpacity(e)) {
  501. if (isin) {
  502. // mouse is in, autoopacity is on
  503. switch (e->getStatus()) {
  504. case STATUS_OUT_OFF:
  505. case STATUS_OUT_FADINGOUT:
  506. case STATUS_IN_OFF:
  507. e->setStartAlpha(e->getLayout()->getTransparency());
  508. e->onEnterLeave();
  509. e->setStatus(STATUS_IN_FADINGON);
  510. checkTimer();
  511. e->getLayout()->onMouseEnterLayout();
  512. break;
  513. case STATUS_IN_FADINGON:
  514. doEndCheck(e);
  515. break;
  516. }
  517. } else {
  518. // mouse is out, autoopacity is on
  519. switch (e->getStatus()) {
  520. case STATUS_IN_FADINGON:
  521. case STATUS_IN_ON:
  522. e->setStartAlpha(e->getLayout()->getTransparency());
  523. e->onEnterLeave();
  524. e->setStatus(STATUS_OUT_FADINGOUT);
  525. checkTimer();
  526. e->getLayout()->onMouseLeaveLayout();
  527. break;
  528. case STATUS_OUT_FADINGOUT:
  529. doEndCheck(e);
  530. break;
  531. }
  532. }
  533. } else {
  534. if (isin) {
  535. // mouse is in, no autoopacity
  536. e->setStatus(STATUS_IN_OFF);
  537. } else {
  538. // mouse is out, no autoopacity
  539. e->setStatus(STATUS_OUT_OFF);
  540. }
  541. }
  542. // if (applytransparency) updateTransparency(e->getLayout());
  543. }
  544. void AlphaMgr::timerclient_timerCallback(int id) {
  545. switch(id) {
  546. case ALPHAMGR_HOVERCHECK: {
  547. foreach(layouts)
  548. AlphaMgrEntry *e = layouts.getfor();
  549. preHoverCheck(e);
  550. endfor;
  551. foreach(layouts)
  552. AlphaMgrEntry *e = layouts.getfor();
  553. hoverCheck(e);
  554. endfor;
  555. }
  556. break;
  557. case ALPHAMGR_UPDATEALPHA: {
  558. foreach(layouts)
  559. AlphaMgrEntry *e = layouts.getfor();
  560. if (e->getStatus() == STATUS_IN_FADINGON || e->getStatus() == STATUS_OUT_FADINGOUT) updateTransparency(e->getLayout());
  561. endfor;
  562. }
  563. break;
  564. }
  565. }
  566. int AlphaMgr::getBigCurTransparency() {
  567. switch (getBigStatus()) {
  568. case STATUS_IN_FADINGON:
  569. case STATUS_OUT_FADINGOUT:
  570. return getTransparency(NULL);
  571. case STATUS_IN_ON:
  572. return 255;
  573. case STATUS_IN_OFF:
  574. case STATUS_OUT_OFF:
  575. return getGlobalAlpha();
  576. default: return getTransparency(NULL);
  577. }
  578. }
  579. void AlphaMgr::setBigStartAlpha(int a) {
  580. big_startalpha = a;
  581. }
  582. void AlphaMgr::setBigStatus(int s) {
  583. big_status = s;
  584. }
  585. void AlphaMgr::onBigEnterLeave() {
  586. big_enterleave_time = Wasabi::Std::getTickCount();
  587. }
  588. uint32_t AlphaMgr::getBigEnterLeaveTime() {
  589. return big_enterleave_time;
  590. }
  591. void AlphaMgr::setAutoOpacify(int l) {
  592. autoopacify = l;
  593. resetTimer();
  594. if (l == 0) {
  595. foreach(layouts)
  596. if (layouts.getfor()->getStatus() == STATUS_IN_FADINGON) layouts.getfor()->setStatus(STATUS_IN_OFF);
  597. if (layouts.getfor()->getStatus() == STATUS_OUT_FADINGOUT) layouts.getfor()->setStatus(STATUS_OUT_OFF);
  598. endfor;
  599. }
  600. updateAllTransparency();
  601. }
  602. void AlphaMgr::resetTimer() {
  603. timerclient_killTimer(ALPHAMGR_HOVERCHECK);
  604. if (autoopacify == 1 && alllinked)
  605. timerclient_setTimer(ALPHAMGR_HOVERCHECK, 99);
  606. else
  607. timerclient_setTimer(ALPHAMGR_HOVERCHECK, 300);
  608. }