aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/wndmgr/alphamgr.cpp
blob: 0bcf7fe00d9649a7d7d965afe742f566c18150b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
#include <precomp.h>
#include "alphamgr.h"
#include <api/wndmgr/layout.h>
#include <api/skin/skinparse.h>
#ifdef _WIN32
#include <tataki/blending/blending.h>
#endif
#include <bfc/util/profiler.h>
#include <bfc/wasabi_std_wnd.h>

#ifndef PI
#define PI 3.1415926536
#endif

#define ALPHAMGR_HOVERCHECK    100
#define ALPHAMGR_UPDATEALPHA   200

AlphaMgr::AlphaMgr() {
	overlayout = NULL;
	timerclient_setTimer(ALPHAMGR_HOVERCHECK, 200);
	alllinked = 0;
	autoopacify = 0;
	fast_timer_on = 0;
	big_curtransparency = 0;
	big_status = STATUS_UNKNOWN;
	big_startalpha = 0;
	big_lasttimein = 0;
	extend_px = 0;
	global_alpha = 0;
	big_enterleave_time = 0;
    fadein_ms = 1;
    fadeout_ms = 1;
    holdtime_ms = 1;
}

AlphaMgr::~AlphaMgr() 
{
	timerclient_killTimer(ALPHAMGR_HOVERCHECK);
}

void AlphaMgr::addLayout(Layout *l)
{
  checkTimer();

  if (layouts.findItem((const wchar_t *)l))
      return;

  layouts.addItem(new AlphaMgrEntry(l));
}

void AlphaMgr::removeLayout(Layout *l) {
  int p=-1;
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l, &p);
  if (p != -1) {
    if (e->getStatus() == STATUS_IN_FADINGON || e->getStatus() == STATUS_IN_ON) {
      updateInList(e, 0);
      checkTimer();
    }
    layouts.removeByPos(p);
    in_layouts.removeItem(e);
    delete e;
    checkTimer();
  }
}

// gets the currently needed transparency, according to layout overrides and global link, and then applies this
// transparency to the layout, it does not change anything in any data structure, this is only a visual update function
void AlphaMgr::updateTransparency(Layout *l) {
  if (!l) return;
  if (l->isInited()) {
    if (l->isTransparencySafe()) {
      int a = l->getTransparencyOverride();
      if (a == -1) {
        if (l->getNoParent()!=1) {
          if (a == -1 && hasAutoOpacity(l))
            a = getTransparency(l);
          else if (a == -1 && getAllLinked())
            a = getGlobalAlpha();
        }
        if (a == -1) {
          /* why the hell would it care if it's alllinked if it's an independent window ?? (noparent=1)
          if (getAllLinked())
            a = getGlobalAlpha();
          else 
          */
            a = l->getPaintingAlpha();
        }
      }
      l->setTransparency(a);
    } else {
      l->setTransparency(255);
    }
  }
}

// returns the alpha value for this slot, that's not necessarily the transparency that should be applied to the layout
// since overrides & calculations in updateTransparency and getTransparency should apply. 
int AlphaMgr::getAlpha(AlphaMgrEntry *e) {
  if (alllinked && e->getLayout()->getNoParent() != 1) return getGlobalAlpha();
  return e->getLayout()->getAlpha();
}

int AlphaMgr::getAlpha(Layout *l) {
  int p=-1;
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l, &p);
  if (p != -1) return getAlpha(e);
  return l->getAlpha();
}

int AlphaMgr::getGlobalAlpha() {
  return global_alpha;
}

void AlphaMgr::updateAllTransparency() {
  foreach(layouts)
    updateTransparency(layouts.getfor()->getLayout());
  endfor;
}

void AlphaMgr::setGlobalAlpha(int a) {
  global_alpha = a;
  updateAllTransparency();
}

int AlphaMgr::getCurve(AlphaMgrEntry *e) {
  int n;
  int status = e ? e->getStatus() : getBigStatus();
  if (e == NULL) {
    n = MulDiv(Wasabi::Std::getTickCount()-getBigEnterLeaveTime(),256,status == STATUS_IN_FADINGON ? fadein_ms : fadeout_ms);
    if (n > 255) n = 255; if (n < 0) n = 0;
  } else {
    if (e->getEnterLeaveTime() == -1) return -1;
    n = MulDiv(Wasabi::Std::getTickCount()-e->getEnterLeaveTime(),256,status == STATUS_IN_FADINGON ? fadein_ms : fadeout_ms);
    if (n > 255) n = 255; if (n < 0) n = 0;
  }
  return n;
}

// returns the value of the transparency if no override applies, you still need to check overrides (see updatetransparency)
int AlphaMgr::getTransparency(Layout *l) {
  if (getAutoOpacify()) 
    l = NULL;
  if (l == NULL) {
    if (getBigStatus() == STATUS_UNKNOWN) { 
      setBigStatus(STATUS_OUT_OFF); 
      Layout *main = SkinParser::getMainLayout();
      if (main)
        big_curtransparency = main->getTransparency();
      else
        big_curtransparency = 255;
    }
  }
  AlphaMgrEntry *e = NULL;
  if (l) e = layouts.findItem((const wchar_t *)l);
  int s = e ? e->getStatus() : getBigStatus();
  if (e && s == STATUS_UNKNOWN) {
    initStatus(e);
    s = e->getStatus();
  }
  switch (s) {
    case STATUS_IN_OFF: return e ? getAlpha(e) : getGlobalAlpha();
    case STATUS_OUT_OFF: return e ? getAlpha(e) : getGlobalAlpha();
    case STATUS_IN_ON: return 255;
    case STATUS_OUT_FADINGOUT: {
      int n = e ? getCurve(e) : getCurve(NULL);
  	  float sintrans = (float)(sin(((float)n/255)*PI-PI/2)/2+0.5);
      int na;
      if (e)
        na = (int)(((float)(getAlpha(e) - e->getStartAlpha()) * sintrans) + e->getStartAlpha());
      else 
        na = (int)(((float)(getGlobalAlpha() - getBigStartAlpha()) * sintrans) + getBigStartAlpha());
      return na;
    }
    case STATUS_IN_FADINGON: {
      int n = e ? getCurve(e) : getCurve(NULL);
  	  float sintrans = (float)(sin(((float)n/255)*PI-PI/2)/2+0.5);
      int na;
      if (e)
        na = (int)(((float)(255 - e->getStartAlpha()) * sintrans) + e->getStartAlpha());
      else
        na = (int)(((float)(255 - getBigStartAlpha()) * sintrans) + getBigStartAlpha());
      return na;
    }
    default: return e ? getAlpha(e) : getGlobalAlpha();
  }
}

int AlphaMgr::hasAutoOpacityOnHover(Layout *l) {
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  if (e) return hasAutoOpacityOnHover(e);
  return 0;
}

int AlphaMgr::hasAutoOpacity(Layout *l) {
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  if (e) return hasAutoOpacity(e);
  return 0;
}

int AlphaMgr::hasAutoOpacityOnFocus(Layout *l) {
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  if (e) return hasAutoOpacityOnFocus(e);
  return 0;
}

int AlphaMgr::hasAutoOpacityOnFocus(AlphaMgrEntry *e) {
  if (alllinked) return autoopacify == 2;
  return e->getLayout()->getAutoOpacify() == 2 && e->getLayout()->getNoParent() != 1;
}

int AlphaMgr::hasAutoOpacityOnHover(AlphaMgrEntry *e) {
  if (alllinked) return autoopacify == 1;
  return e->getLayout()->getAutoOpacify() == 1 && e->getLayout()->getNoParent() != 1;
}

int AlphaMgr::hasAutoOpacity(AlphaMgrEntry *e) {
  if (alllinked) return autoopacify;
  return e->getLayout()->getAutoOpacify() && e->getLayout()->getNoParent() != 1;
}

// we got a new layout to manage, and its status flags is not set, we should init it to something safe
void AlphaMgr::initStatus(AlphaMgrEntry *l, int applytransparency) {
  if (isMouseInLayout(l->getLayout())) {
	l->setEnterLeaveTime((uint32_t)-1);
    if (hasAutoOpacity(l)) {
      l->setStatus(STATUS_IN_FADINGON);
      l->onEnterLeave();
      l->setStartAlpha(l->getLayout()->getTransparency());
      checkTimer();
    } else {
      l->setStatus(STATUS_IN_OFF);
    }
    l->getLayout()->onMouseEnterLayout();
  } else {
    if (hasAutoOpacityOnHover(l)) {
      l->setStartAlpha(l->getLayout()->getTransparency());
      l->onEnterLeave();
      l->setStatus(STATUS_OUT_FADINGOUT);
      checkTimer();
    } else {
      l->setStatus(STATUS_OUT_OFF);
    }
    l->getLayout()->onMouseLeaveLayout();
  }
  if (applytransparency) updateTransparency(l->getLayout());
}

int AlphaMgr::isPointInLayout(Layout *l, int x, int y, api_region **rgn) 
{
  api_region *rg = NULL;
  if (!l) return 0;
  if (!l->isVisible()) return 0;
  RECT r,r2;
  l->getClientRect(&r);
  if (l->renderRatioActive()) l->multRatio(&r);
  l->getWindowRect(&r2);
  Wasabi::Std::offsetRect(&r, r2.left, r2.top);
//  OffsetRect(&r, r2.left, r2.top);
  if (x < r.left || x > r.right || y < r.top || y > r.bottom) return 0;
  if (rgn) {
    if (!*rgn) {
      rg = l->getComposedRegion();
      *rgn = rg;
    } else {
      rg = *rgn;
    }
  } else {
    rg = l->getComposedRegion();
  }
  if (!rgn) return 1;
  x -= r.left; y -= r.top;
  POINT pt={x,y};
  if (l->renderRatioActive()) l->divRatio((int*)&pt.x, (int*)&pt.y);
  if (l->getComposedRegion()->ptInRegion(&pt)) return 1;
  return 0;
}

int AlphaMgr::isFocusInLayout(Layout *l) {
  if (l->gotFocus()) return 1;
  OSWINDOWHANDLE fw = Wasabi::Std::Wnd::getFocus();
  while (fw) 
  {
    if (fw == l->gethWnd()) return 1;
    fw = Wasabi::Std::Wnd::getParent(fw);
  }
  return 0;
}

int AlphaMgr::isMouseInLayout(Layout *l) {
  int isin = 0;
  if (hasAutoOpacityOnFocus(l)) {
    return isFocusInLayout(l);
  } else {
    int x, y;
    api_region *r = NULL;
    Wasabi::Std::getMousePos(&x, &y);
    isin = isPointInLayout(l, x, y, &r);
    int ext = getExtendAutoOpacity();
    if (!isin && ext > 0) {
      isin = isPointInLayout(l, x-ext, y, &r);
      if (!isin) isin = isPointInLayout(l, x-ext, y-ext, &r);
      if (!isin) isin = isPointInLayout(l, x, y-ext, &r);
      if (!isin) isin = isPointInLayout(l, x+ext, y-ext, &r);
      if (!isin) isin = isPointInLayout(l, x+ext, y, &r);
      if (!isin) isin = isPointInLayout(l, x+ext, y+ext, &r);
      if (!isin) isin = isPointInLayout(l, x, y+ext, &r);
      if (!isin) isin = isPointInLayout(l, x-ext, y+ext, &r);
      if (!isin) isin = isPointInLayout(l, x-ext, y, &r);
    }
  }
  return isin;
}

int AlphaMgr::needForcedTransparencyFlag(Layout *l) {
  if (!l->isTransparencySafe()) return 0;
  if (l->isAlphaForced()) return 1;
  if (l->getTransparencyOverride() > 0) return 1; // should not be testing for < 255 here
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  if (hasAutoOpacity(e) && getAlpha(e) < 255) return 1;
  return 0;
}

void AlphaMgr::checkTimer() {
  int fading = 0;
  foreach(layouts)
    AlphaMgrEntry *e = layouts.getfor();
    if (e->getStatus() == STATUS_IN_FADINGON || e->getStatus() == STATUS_OUT_FADINGOUT) { fading++; break; }
  endfor;
  if (getAutoOpacify() && getBigStatus() == STATUS_IN_FADINGON || getBigStatus() == STATUS_OUT_FADINGOUT) 
    fading++;
  if (fading && !fast_timer_on) { 
    timerclient_setTimer(ALPHAMGR_UPDATEALPHA, 20); 
    fast_timer_on = 1; 
  } else if (!fading && fast_timer_on) { 
    timerclient_killTimer(ALPHAMGR_UPDATEALPHA); 
    fast_timer_on = 0; 
  }
}

void AlphaMgr::doEndCheck(AlphaMgrEntry *e) {
  if (getCurve(e) == 255) {
    switch (e ? e->getStatus() : getBigStatus()) {
      case STATUS_IN_FADINGON:
        if (e) e->setStatus(STATUS_IN_ON); else setBigStatus(STATUS_IN_ON);
        break;
      case STATUS_OUT_FADINGOUT:
        if (e) e->setStatus(STATUS_OUT_OFF); else setBigStatus(STATUS_OUT_OFF);
        break;
    }
    checkTimer();
  }
}

void AlphaMgr::updateInList(AlphaMgrEntry *e, int isin) {
  if (isin) {
    if (in_layouts.searchItem(e) == -1) 
    in_layouts.addItem(e);
  } else {
    in_layouts.removeItem(e);
  }
  
  int big_isin = in_layouts.getNumItems() > 0;
  
  if (getAutoOpacify()) {
    if (big_isin) {
      // mouse is in a layout, autoopacity is on
      switch (getBigStatus()) {
        case STATUS_OUT_OFF: 
        case STATUS_OUT_FADINGOUT:
        case STATUS_IN_OFF: { 
          setBigStartAlpha(e->getLayout()->getTransparency());
          onBigEnterLeave();
          setBigStatus(STATUS_IN_FADINGON);
          checkTimer();
          break;
        }
        case STATUS_IN_FADINGON: 
          doEndCheck(NULL);
          break;
      }
    } else {
      // mouse out of all layouts, autoopacity is on
      switch (getBigStatus()) {
        case STATUS_IN_FADINGON: 
        case STATUS_IN_ON: {
          setBigStartAlpha(getTransparency(NULL));
          onBigEnterLeave();
          setBigStatus(STATUS_OUT_FADINGOUT);
          checkTimer();
          break;
        }
        case STATUS_OUT_FADINGOUT:
          doEndCheck(NULL);
          break;
      }
    }
  } else {
    if (big_isin) {
      // mouse is in a layout, no autoopacity
      setBigStatus(STATUS_IN_OFF);
    } else {
      // mouse is out of all layouts, no autoopacity
      setBigStatus(STATUS_OUT_OFF);
    }
  }
}

int AlphaMgr::isFocusingExternalWindow() 
{  
  OSWINDOWHANDLE fw = Wasabi::Std::Wnd::getFocus();
  if (isOurExternalWindow(fw)) return 1;
  return 0;
}

int AlphaMgr::isOverExternalWindow() 
{
  int x, y;
  Wasabi::Std::getMousePos(&x, &y);
  int ext = getExtendAutoOpacity();

  POINT pt;
  pt.x = x; pt.y = y;
  OSWINDOWHANDLE w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x-ext; pt.y = y-ext;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x; pt.y = y-ext;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x+ext; pt.y = y-ext;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x+ext; pt.y = y;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x+ext; pt.y = y+ext;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x; pt.y = y+ext;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x-ext; pt.y = y+ext;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  pt.x = x-ext; pt.y = y;
  w = Wasabi::Std::Wnd::getWindowFromPoint(pt);
  if (isOurExternalWindow(w)) return 1;
  return 0;
}

int AlphaMgr::isWasabiWindow(OSWINDOWHANDLE w) 
{
#ifdef _WIN32
  wchar_t classname[256]=L"";
  GetClassNameW(w, classname, 255);
  return (w == WASABI_API_WND->main_getRootWnd()->gethWnd() || !wcscmp(classname, BASEWNDCLASSNAME));
#else
#warning port me
  return 1;
#endif
}

int AlphaMgr::isMenuWindow(OSWINDOWHANDLE w) 
{
#ifdef _WIN32
  char classname[256]="";
  GetClassNameA(w, classname, 255);
  return STRCASEEQL(classname, "#32768");
#else
  return 0;
#warning port me
#endif
}

int AlphaMgr::isOurExternalWindow(OSWINDOWHANDLE w)
{
  OSWINDOWHANDLE wnd = w;
  if (isWasabiWindow(w)) 
    return 0;

  if (isMenuWindow(wnd)) {
    wnd = Wasabi::Std::Wnd::getFocus();
    if (isWasabiWindow(wnd) || isOurExternalWindow(wnd)) 
      return 1; 
  }
  
  while (wnd) 
  {
    if (Wasabi::Std::Wnd::isPopup(wnd))
    { 
      if (isWasabiWindow(wnd)) 
        return 0; 
      OSWINDOWHANDLE _w = Wasabi::Std::Wnd::getParent(wnd);
#ifdef _WIN32
      if (!_w) _w = GetWindow(wnd, GW_OWNER);
#else
#warning port me
#endif
      if (!wnd) _w = wnd;
      return (_w == WASABI_API_WND->main_getRootWnd()->gethWnd() || isWasabiWindow(_w) || isOurExternalWindow(_w));
    }
    wnd = Wasabi::Std::Wnd::getParent(wnd);
  }
  return 0;
}

void AlphaMgr::preHoverCheck(AlphaMgrEntry *e) {
  int isin = isMouseInLayout(e->getLayout());
  uint32_t last = e->getLastTimeIn();
  uint32_t lastbig = getBigLastTimeIn();
  if (isin) { e->onLastIn(); onBigLastIn(); }
  if (!getAutoOpacify()) {
    if (!isin && last != 0 && (last > Wasabi::Std::getTickCount() - holdtime_ms))
      isin = 1;
  } else {
    if (!isin && lastbig != 0 && (lastbig > Wasabi::Std::getTickCount() - holdtime_ms))
      isin = 1;
  }
  if (!isin) {
    if (hasAutoOpacityOnFocus(e)) {
      if (isFocusingExternalWindow()) isin = 1;
    } else {
      if (isOverExternalWindow()) isin = 1;
    }
  }
  e->setNextIn(isin);
  updateInList(e, isin);
}

void AlphaMgr::hoverCheck(Layout *l) {
  AlphaMgrEntry *e = layouts.findItem((const wchar_t *)l);
  if (e) hoverCheck(e);
}

void AlphaMgr::hoverCheck(AlphaMgrEntry *e, int applytransparency) {
  if (e->getStatus() == STATUS_UNKNOWN) 
    initStatus(e);

  int isin = e->getNextIn();
   
  if (getAutoOpacify()) {
    isin = big_status == STATUS_IN_FADINGON || big_status == STATUS_IN_ON || big_status == STATUS_IN_OFF;
  }
  if (hasAutoOpacity(e)) {
    if (isin) {
      // mouse is in, autoopacity is on
      switch (e->getStatus()) {
        case STATUS_OUT_OFF: 
        case STATUS_OUT_FADINGOUT:
        case STATUS_IN_OFF: 
          e->setStartAlpha(e->getLayout()->getTransparency());
          e->onEnterLeave();
          e->setStatus(STATUS_IN_FADINGON);
          checkTimer();
          e->getLayout()->onMouseEnterLayout();
          break;
        case STATUS_IN_FADINGON:
          doEndCheck(e);
          break;
      }
    } else {
      // mouse is out, autoopacity is on
      switch (e->getStatus()) {
        case STATUS_IN_FADINGON: 
        case STATUS_IN_ON: 
          e->setStartAlpha(e->getLayout()->getTransparency());
          e->onEnterLeave();
          e->setStatus(STATUS_OUT_FADINGOUT);
          checkTimer();
          e->getLayout()->onMouseLeaveLayout();
          break;
        case STATUS_OUT_FADINGOUT:
          doEndCheck(e);
          break;
      }
    }
  } else {
    if (isin) {
      // mouse is in, no autoopacity
      e->setStatus(STATUS_IN_OFF);
    } else {
      // mouse is out, no autoopacity
      e->setStatus(STATUS_OUT_OFF);
    }
  }
//  if (applytransparency) updateTransparency(e->getLayout());
}

void AlphaMgr::timerclient_timerCallback(int id) {
  switch(id) {
    case ALPHAMGR_HOVERCHECK: {
      foreach(layouts)
        AlphaMgrEntry *e = layouts.getfor();
        preHoverCheck(e);
      endfor;
      foreach(layouts)
        AlphaMgrEntry *e = layouts.getfor();
        hoverCheck(e);
      endfor;
    }
    break;
    case ALPHAMGR_UPDATEALPHA: {
      foreach(layouts)
        AlphaMgrEntry *e = layouts.getfor();
        if (e->getStatus() == STATUS_IN_FADINGON || e->getStatus() == STATUS_OUT_FADINGOUT) updateTransparency(e->getLayout());
      endfor;
    }
    break;
  }
}

int AlphaMgr::getBigCurTransparency() {
  switch (getBigStatus()) {
    case STATUS_IN_FADINGON:
    case STATUS_OUT_FADINGOUT:
      return getTransparency(NULL);
    case STATUS_IN_ON:
      return 255;
    case STATUS_IN_OFF:
    case STATUS_OUT_OFF:
      return getGlobalAlpha();
    default: return getTransparency(NULL);
  }
}

void AlphaMgr::setBigStartAlpha(int a) {
  big_startalpha = a;
}

void AlphaMgr::setBigStatus(int s) {
  big_status = s;
}

void AlphaMgr::onBigEnterLeave() {
  big_enterleave_time = Wasabi::Std::getTickCount();
}

uint32_t AlphaMgr::getBigEnterLeaveTime() {
  return big_enterleave_time;
}

void AlphaMgr::setAutoOpacify(int l) { 
  autoopacify = l; 
  resetTimer();
  if (l == 0) {
    foreach(layouts)
      if (layouts.getfor()->getStatus() == STATUS_IN_FADINGON) layouts.getfor()->setStatus(STATUS_IN_OFF);
      if (layouts.getfor()->getStatus() == STATUS_OUT_FADINGOUT) layouts.getfor()->setStatus(STATUS_OUT_OFF);
    endfor;
  }
  updateAllTransparency();
}

void AlphaMgr::resetTimer() {
  timerclient_killTimer(ALPHAMGR_HOVERCHECK);
  if (autoopacify == 1 && alllinked)
    timerclient_setTimer(ALPHAMGR_HOVERCHECK, 99);
  else
    timerclient_setTimer(ALPHAMGR_HOVERCHECK, 300);
}