Advertisement
r0k

Helpers

r0k
Jun 3rd, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* *************************************** Helper functions *****************************************
  2.  * Author : r0k and T.P Wang (for functions copied from the documentation file "helpers").
  3.  * Those functions are used by my WSH scripts, feel free to use them in your scripts but don't change
  4.  * them nor rename this file.
  5.  * Please note that if you use those functions, they might be changed in the future to adress bugs
  6.  * or add features. There is no guarantee updates will be backward compatibles. If possible they will
  7.  * be but if you use one of those functions for one of your script it might be a good idea to keep a
  8.  * copy of this file somewhere.
  9.  */
  10.  
  11. function RGB(r, g, b) { // (T.P Wang)
  12.     return (0xff000000 | (r << 16) | (g << 8) | (b));
  13. }
  14.  
  15. function RGBA(r, g, b, a) { // (T.P Wang)
  16.     return ((a << 24) | (r << 16) | (g << 8) | (b));
  17. }
  18.  
  19. function setAlpha(color, a) { // (T.P Wang)
  20.     return ((color & 0x00ffffff) | (a << 24));
  21. }
  22.  
  23. function getFont(type) {
  24.     // Retreives font used by other panels (CUI or DUI). Font type is either "item" or "label".
  25.     switch (type) {
  26.     case "item" :
  27.         __DUIflag = 3;
  28.         __CUIflag = 0;
  29.         break;
  30.     case "label" :
  31.         __DUIflag = 1;
  32.         __CUIflag = 1;
  33.         break; 
  34.     }
  35.     if (window.InstanceType) { // DUI
  36.         __font = window.GetFontDUI(__DUIflag);
  37.     } else { // CUI
  38.         __font = window.GetFontCUI(__CUIflag);
  39.     }
  40.     return __font;
  41. }
  42.  
  43. function getColor(type) {
  44.     // Retreives color used by other panels (CUI or DUI).
  45.     switch (type) {
  46.     case "text" :
  47.         __DUIflag = 0;
  48.         __CUIflag = 0;
  49.         break;
  50.     case "background" :
  51.         __DUIflag = 1;
  52.         __CUIflag = 3;
  53.         break;
  54.     case "highlight" :
  55.         __DUIflag = 2;
  56.         __CUIflag = 5;
  57.         break;
  58.     case "select" :
  59.         __DUIflag = 3;
  60.         __CUIflag = 4;
  61.         break; 
  62.     }
  63.     if(window.InstanceType) { // DUI
  64.         __color = window.GetColorDUI(__DUIflag);
  65.     } else { // CUI
  66.         __color = window.GetColorCUI(__CUIflag);
  67.     }
  68.     return __color;
  69. }
  70.  
  71. function doSplitTitleFormatString(titleFormat) {
  72.     // This function will process a title-format string and split it to return an array of sub-strings.
  73.     // The string is split at typical boudaries between parts of a title format (such as two "%" signs).
  74.     // Usefull for grouping tracks.
  75.     var _titleFormat = titleFormat.toString();
  76.     doPrint("Split TF : "+_titleFormat,"doSplitTitleFormatString");
  77.     doPrint(_titleFormat.length,"doSplitTitleFormatString");
  78.     __tfArray = [];
  79.     do {
  80.         __split1 = (_titleFormat.indexOf("%%")>0) ? _titleFormat.indexOf("%%")+1 : _titleFormat.length;
  81.         __split2 = (_titleFormat.indexOf("%$")>0) ? _titleFormat.indexOf("%$")+1 : _titleFormat.length;
  82.         __split3 = (_titleFormat.indexOf(")%")>0) ? _titleFormat.indexOf(")%")+1: _titleFormat.length;
  83.         __split4 = (_titleFormat.indexOf(")$")>0) ? _titleFormat.indexOf(")$")+1 : _titleFormat.length;
  84.         __split5 = (_titleFormat.indexOf("[")>0)  ? _titleFormat.indexOf("[") +1 : _titleFormat.length;
  85.         __splitAt = Math.min(__split1,__split2,__split3,__split4,__split5);
  86.         __extract = _titleFormat.slice(0,__splitAt);
  87.         __tfArray.push(__extract);
  88.         doPrint(__extract,"doSplitTitleFormatString");
  89.         _titleFormat = _titleFormat.slice(__splitAt);
  90.         doPrint(_titleFormat.length,"doSplitTitleFormatString");
  91.     } while (_titleFormat.length>0);
  92.     doPrint(__tfArray.join("|"),"doSplitTitleFormatString");
  93.     return __tfArray;
  94. }
  95.  
  96. function doPrint(message,callerId) {
  97.     // Simple console output. Not very useful. Will probably be removed.
  98.     var __string = $system.scriptName || "Unnamed Script"; __string += " | ";
  99.     __string += callerId || "";  __string += " | ";
  100.     __string += message;
  101.     fb.trace(__string);
  102. }
  103.  
  104. function is_resizing(_callback) {
  105.     // This function should be called from on_size() callback function in main script. It will call
  106.     // a function passed as argument when resizing is done, enabling you to redraw the window after
  107.     // resizing for instance.
  108.     // Note that a delay is required and so the result won't be immediate. If you need to use some
  109.     // output from this function at the start of the script you need some delay in your init process.
  110.     __w1 = window.Width; __h1 = window.Height;
  111.    
  112.     function check_resizing(_callback) {
  113.         __w2 = window.Width; __h2 = window.Height;
  114.         if (__h2 == __h1 && __w2 == __w1) {
  115.             _callback();
  116.         } else {
  117.             window.SetTimeout(function () {is_resizing(_callback);}, 100);
  118.         }
  119.     }
  120.     window.SetTimeout(function () {check_resizing(_callback);}, 300);
  121. }
  122.  
  123. /* **************************************** Common values *******************************************
  124.  * Stored for conveniance.
  125.  */
  126.  
  127. $buttonStates = {normal: 1, hover: 2, down: 3};
  128. var $default = { // needed in case those values are not passed to object constructors.
  129.     sort : "%album artist%[%date%]%album%[%discnumber%]%tracknumber%",
  130.     query : ".",
  131.     group : "%album artist%%album%"
  132. };
  133. Colors = {
  134.     AliceBlue           : 0xFFF0F8FF,
  135.     AntiqueWhite         : 0xFFFAEBD7,
  136.     Aqua                 : 0xFF00FFFF,
  137.     Aquamarine         : 0xFF7FFFD4,
  138.     Azure               : 0xFFF0FFFF,
  139.     Beige               : 0xFFF5F5DC,
  140.     Bisque             : 0xFFFFE4C4,
  141.     Black               : 0xFF000000,
  142.     BlanchedAlmond     : 0xFFFFEBCD,
  143.     Blue                 : 0xFF0000FF,
  144.     BlueViolet         : 0xFF8A2BE2,
  145.     Brown               : 0xFFA52A2A,
  146.     BurlyWood           : 0xFFDEB887,
  147.     CadetBlue           : 0xFF5F9EA0,
  148.     Chartreuse         : 0xFF7FFF00,
  149.     Chocolate           : 0xFFD2691E,
  150.     Coral               : 0xFFFF7F50,
  151.     CornflowerBlue     : 0xFF6495ED,
  152.     Cornsilk             : 0xFFFFF8DC,
  153.     Crimson           : 0xFFDC143C,
  154.     Cyan                 : 0xFF00FFFF,
  155.     DarkBlue             : 0xFF00008B,
  156.     DarkCyan             : 0xFF008B8B,
  157.     DarkGoldenrod       : 0xFFB8860B,
  158.     DarkGray             : 0xFFA9A9A9,
  159.     DarkGreen           : 0xFF006400,
  160.     DarkKhaki           : 0xFFBDB76B,
  161.     DarkMagenta       : 0xFF8B008B,
  162.     DarkOliveGreen     : 0xFF556B2F,
  163.     DarkOrange         : 0xFFFF8C00,
  164.     DarkOrchid         : 0xFF9932CC,
  165.     DarkRed           : 0xFF8B0000,
  166.     DarkSalmon         : 0xFFE9967A,
  167.     DarkSeaGreen         : 0xFF8FBC8B,
  168.     DarkSlateBlue       : 0xFF483D8B,
  169.     DarkSlateGray       : 0xFF2F4F4F,
  170.     DarkTurquoise       : 0xFF00CED1,
  171.     DarkViolet         : 0xFF9400D3,
  172.     DeepPink             : 0xFFFF1493,
  173.     DeepSkyBlue       : 0xFF00BFFF,
  174.     DimGray           : 0xFF696969,
  175.     DodgerBlue         : 0xFF1E90FF,
  176.     Firebrick           : 0xFFB22222,
  177.     FloralWhite       : 0xFFFFFAF0,
  178.     ForestGreen       : 0xFF228B22,
  179.     Fuchsia           : 0xFFFF00FF,
  180.     Gainsboro           : 0xFFDCDCDC,
  181.     GhostWhite         : 0xFFF8F8FF,
  182.     Gold                 : 0xFFFFD700,
  183.     Goldenrod           : 0xFFDAA520,
  184.     Gray                 : 0xFF808080,
  185.     Green               : 0xFF008000,
  186.     GreenYellow       : 0xFFADFF2F,
  187.     Honeydew             : 0xFFF0FFF0,
  188.     HotPink           : 0xFFFF69B4,
  189.     IndianRed           : 0xFFCD5C5C,
  190.     Indigo             : 0xFF4B0082,
  191.     Ivory               : 0xFFFFFFF0,
  192.     Khaki               : 0xFFF0E68C,
  193.     Lavender             : 0xFFE6E6FA,
  194.     LavenderBlush       : 0xFFFFF0F5,
  195.     LawnGreen           : 0xFF7CFC00,
  196.     LemonChiffon         : 0xFFFFFACD,
  197.     LightBlue           : 0xFFADD8E6,
  198.     LightCoral         : 0xFFF08080,
  199.     LightCyan           : 0xFFE0FFFF,
  200.     LightGoldenrodYellow : 0xFFFAFAD2,
  201.     LightGray           : 0xFFD3D3D3,
  202.     LightGreen         : 0xFF90EE90,
  203.     LightPink           : 0xFFFFB6C1,
  204.     LightSalmon       : 0xFFFFA07A,
  205.     LightSeaGreen       : 0xFF20B2AA,
  206.     LightSkyBlue         : 0xFF87CEFA,
  207.     LightSlateGray     : 0xFF778899,
  208.     LightSteelBlue     : 0xFFB0C4DE,
  209.     LightYellow       : 0xFFFFFFE0,
  210.     Lime                 : 0xFF00FF00,
  211.     LimeGreen           : 0xFF32CD32,
  212.     Linen               : 0xFFFAF0E6,
  213.     Magenta           : 0xFFFF00FF,
  214.     Maroon             : 0xFF800000,
  215.     MediumAquamarine     : 0xFF66CDAA,
  216.     MediumBlue         : 0xFF0000CD,
  217.     MediumOrchid         : 0xFFBA55D3,
  218.     MediumPurple         : 0xFF9370DB,
  219.     MediumSeaGreen     : 0xFF3CB371,
  220.     MediumSlateBlue   : 0xFF7B68EE,
  221.     MediumSpringGreen   : 0xFF00FA9A,
  222.     MediumTurquoise   : 0xFF48D1CC,
  223.     MediumVioletRed   : 0xFFC71585,
  224.     MidnightBlue         : 0xFF191970,
  225.     MintCream           : 0xFFF5FFFA,
  226.     MistyRose           : 0xFFFFE4E1,
  227.     Moccasin             : 0xFFFFE4B5,
  228.     NavajoWhite       : 0xFFFFDEAD,
  229.     Navy                 : 0xFF000080,
  230.     OldLace           : 0xFFFDF5E6,
  231.     Olive               : 0xFF808000,
  232.     OliveDrab           : 0xFF6B8E23,
  233.     Orange             : 0xFFFFA500,
  234.     OrangeRed           : 0xFFFF4500,
  235.     Orchid             : 0xFFDA70D6,
  236.     PaleGoldenrod       : 0xFFEEE8AA,
  237.     PaleGreen           : 0xFF98FB98,
  238.     PaleTurquoise       : 0xFFAFEEEE,
  239.     PaleVioletRed       : 0xFFDB7093,
  240.     PapayaWhip         : 0xFFFFEFD5,
  241.     PeachPuff           : 0xFFFFDAB9,
  242.     Peru                 : 0xFFCD853F,
  243.     Pink                 : 0xFFFFC0CB,
  244.     Plum                 : 0xFFDDA0DD,
  245.     PowderBlue         : 0xFFB0E0E6,
  246.     Purple             : 0xFF800080,
  247.     Red               : 0xFFFF0000,
  248.     RosyBrown           : 0xFFBC8F8F,
  249.     RoyalBlue           : 0xFF4169E1,
  250.     SaddleBrown       : 0xFF8B4513,
  251.     Salmon             : 0xFFFA8072,
  252.     SandyBrown         : 0xFFF4A460,
  253.     SeaGreen             : 0xFF2E8B57,
  254.     SeaShell             : 0xFFFFF5EE,
  255.     Sienna             : 0xFFA0522D,
  256.     Silver             : 0xFFC0C0C0,
  257.     SkyBlue           : 0xFF87CEEB,
  258.     SlateBlue           : 0xFF6A5ACD,
  259.     SlateGray           : 0xFF708090,
  260.     Snow                 : 0xFFFFFAFA,
  261.     SpringGreen       : 0xFF00FF7F,
  262.     SteelBlue           : 0xFF4682B4,
  263.     Tan               : 0xFFD2B48C,
  264.     Teal                 : 0xFF008080,
  265.     Thistle           : 0xFFD8BFD8,
  266.     Tomato             : 0xFFFF6347,
  267.     Transparent       : 0x00FFFFFF,
  268.     Turquoise           : 0xFF40E0D0,
  269.     Violet             : 0xFFEE82EE,
  270.     Wheat               : 0xFFF5DEB3,
  271.     White               : 0xFFFFFFFF,
  272.     WhiteSmoke         : 0xFFF5F5F5,
  273.     Yellow             : 0xFFFFFF00,
  274.     YellowGreen       : 0xFF9ACD32
  275. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement