home *** CD-ROM | disk | FTP | other *** search
/ Minami 49 / MINAMI49.ISO / Extra / winamp503_full.exe / Plugins / tooltips.m < prev    next >
Text File  |  2003-10-31  |  1KB  |  35 lines

  1. #include <lib/std.mi>
  2.  
  3. Global Group tipGroup;
  4. Global Text tipText;
  5.  
  6. System.onScriptLoaded() {
  7.   tipGroup = getScriptGroup();
  8.   tipText = tipGroup.getObject("tooltip.text");
  9. }
  10.  
  11. // When text is changed, resize the group accordingly and make sure it's fully visible
  12.  
  13. tipText.onTextChanged(String newtext) {
  14.  
  15.   int x = getMousePosX();
  16.   int y = getMousePosY()-tipGroup.getHeight(); // move above mouse by default
  17.  
  18.   int vpleft = getViewportLeftFromPoint(x, y);
  19.   int vptop = getViewportTopFromPoint(x, y);
  20.   int vpright = vpleft+getViewportWidthFromPoint(x, y);
  21.   int vpbottom = vptop+getViewportHeightFromPoint(x, y);
  22.  
  23.   int w = getTextWidth()+20;
  24.   int h = tipGroup.getHeight();
  25.  
  26.   if (x + w > vpright) x = vpright - w;
  27.   if (x < vpleft) x = vpleft;
  28.   if (x + w > vpright) { w = vpright-vpleft-64; x = 32; }
  29.   if (y + h > vpbottom) y = vpbottom - h;
  30.   if (y < vptop) y = vptop + 32; // avoid mouse
  31.   if (y + h > vpbottom) { h = vpbottom-vptop-64; y = 32; }
  32.  
  33.   tipGroup.resize(x, y, w, h);
  34. }
  35.